示例#1
0
    def request(self, method, url, **kwargs):
        domain = urlparse(url).netloc

        try:
            request = self.api_breaker.call(super().request,
                                            method=method,
                                            url=url,
                                            **kwargs)
        except requests.exceptions.Timeout:
            timeout_counter.labels(domain=domain).inc()

            raise ApiTimeoutError(
                "The request to {} took too long".format(url))
        except requests.exceptions.ConnectionError:
            connection_failed_counter.labels(domain=domain).inc()

            raise ApiConnectionError(
                "Failed to establish connection to {}.".format(url))
        except CircuitBreakerError:
            raise ApiCircuitBreaker(
                "Requests are closed because of too many failures".format(url))

        latency_histogram.labels(domain=domain,
                                 code=request.status_code).observe(
                                     request.elapsed.total_seconds())

        return request
示例#2
0
    def request(self, method, url, **kwargs):
        try:
            request = self.api_breaker.call(super().request,
                                            method=method,
                                            url=url,
                                            **kwargs)
        except requests.exceptions.Timeout:
            raise ApiTimeoutError(
                "The request to {} took too long".format(url))
        except requests.exceptions.ConnectionError:
            raise ApiConnectionError(
                "Failed to establish connection to {}.".format(url))
        except CircuitBreakerError:
            raise ApiCircuitBreaker(
                "Requests are closed because of too many failures".format(url))

        return request