def run(self): batch_size = scout_config.value("errors_batch_size") or 1 http = urllib3_cert_pool_manager() try: while True: errors = [] try: # Attempt to fetch the batch size off of the queue. for _ in range(batch_size): error = self._queue.get(block=True, timeout=1 * SECOND) if error: errors.append(error) except queue.Empty: pass if errors and self._send(http, errors): for _ in range(len(errors)): self._queue.task_done() # Check for stop event after each read. This allows opening, # sending, and then immediately stopping. if self._stop_event.is_set(): logger.debug("ErrorServiceThread stopping.") break except Exception as exc: logger.debug("ErrorServiceThread exception: %r", exc, exc_info=exc) finally: http.clear() logger.debug("ErrorServiceThread stopped.")
def test_request_type_error(tracked_request): ensure_installed() with pytest.raises(TypeError): http = urllib3_cert_pool_manager() connection = http.connection_from_host("example.com", scheme="https") connection.urlopen() assert len(tracked_request.complete_spans) == 1 span = tracked_request.complete_spans[0] assert span.operation == "HTTP/Unknown" assert span.tags["url"] == "https://example.com:443/"
def test_request_ignore_errors_host(tracked_request): ensure_installed() with httpretty.enabled(allow_net_connect=False): httpretty.register_uri(httpretty.POST, "https://errors.scoutapm.com", body="Hello World!") http = urllib3_cert_pool_manager() response = http.request("POST", "https://errors.scoutapm.com") assert response.status == 200 assert response.data == b"Hello World!" assert len(tracked_request.complete_spans) == 0
def test_request(tracked_request): ensure_installed() with httpretty.enabled(allow_net_connect=False): httpretty.register_uri(httpretty.GET, "https://example.com/", body="Hello World!") http = urllib3_cert_pool_manager() response = http.request("GET", "https://example.com") assert response.status == 200 assert response.data == b"Hello World!" assert len(tracked_request.complete_spans) == 1 span = tracked_request.complete_spans[0] assert span.operation == "HTTP/GET" assert span.tags["url"] == "https://example.com:443/"
def download_package(self): full_url = self.full_url() logger.debug("Downloading: %s to %s", full_url, self.package_location) http = urllib3_cert_pool_manager() response = http.request( "GET", full_url, preload_content=False, timeout=10.0, retries=3 ) try: if response.status != 200: return False with open(self.package_location, "wb") as fp: for chunk in response.stream(): fp.write(chunk) finally: response.release_conn() http.clear() return True
def test_request_no_absolute_url(caplog, tracked_request): ensure_installed() delete_absolute_url = delete_attributes(urllib3.HTTPConnectionPool, "_absolute_url") with httpretty.enabled(allow_net_connect=False), delete_absolute_url: httpretty.register_uri(httpretty.GET, "https://example.com/", body="Hello World!") http = urllib3_cert_pool_manager() response = http.request("GET", "https://example.com") assert response.status == 200 assert response.data == b"Hello World!" assert len(tracked_request.complete_spans) == 1 span = tracked_request.complete_spans[0] assert span.operation == "HTTP/GET" assert span.tags["url"] == "Unknown"