Ejemplo n.º 1
0
 def test_proxy_map(self):
     old_http_proxy = config.OUTBOUND_HTTP_PROXY
     old_https_proxy = config.OUTBOUND_HTTPS_PROXY
     config.OUTBOUND_HTTP_PROXY = "http://localhost"
     config.OUTBOUND_HTTPS_PROXY = "https://localhost"
     assert common.get_proxies() == {
         "http": config.OUTBOUND_HTTP_PROXY,
         "https": config.OUTBOUND_HTTPS_PROXY,
     }
     config.OUTBOUND_HTTP_PROXY = ""
     assert common.get_proxies() == {"https": config.OUTBOUND_HTTPS_PROXY}
     config.OUTBOUND_HTTPS_PROXY = ""
     assert common.get_proxies() == {}
     config.OUTBOUND_HTTP_PROXY = old_http_proxy
     config.OUTBOUND_HTTPS_PROXY = old_https_proxy
Ejemplo n.º 2
0
    def append_events(self, events: List[Event]):
        # TODO: add compression to append_events
        #  it would maybe be useful to compress analytics data, but it's unclear how that will
        #  affect performance and what the benefit is. need to measure first.

        endpoint = self.endpoint_events

        if not events:
            return

        docs = []
        for event in events:
            try:
                docs.append(event.asdict())
            except Exception:
                if self.debug:
                    LOG.exception("error while recording event %s", event)

        headers = self._create_headers()

        if self.debug:
            LOG.debug("posting to %s events %s", endpoint, docs)

        # FIXME: fault tolerance/timeouts
        response = requests.post(
            endpoint, json={"events": docs}, headers=headers, proxies=get_proxies()
        )

        if self.debug:
            LOG.debug("response from %s was: %s %s", endpoint, response.status_code, response.text)

        # TODO: Add response type to analytics client
        return response
Ejemplo n.º 3
0
    def start_session(self, metadata: ClientMetadata) -> SessionResponse:
        # FIXME: re-using Event as request object this way is kind of a hack
        request = Event(
            "session", EventMetadata(self.localstack_session_id, str(now())), payload=metadata
        )

        response = requests.post(
            self.endpoint_session,
            headers=self._create_headers(),
            json=request.asdict(),
            proxies=get_proxies(),
        )

        if not response.ok:
            raise ValueError("error during session initiation with analytics backend")

        return SessionResponse(response.json())