Ejemplo n.º 1
0
    def send(self, method, payload=()):
        params, headers, payload = self._to_http(method, payload)

        try:
            response = self.client.send_request(params=params,
                                                headers=headers,
                                                payload=payload)
        except NetworkInterfaceException:
            # All HTTP errors are currently retried
            raise RetryDataForRequest

        status, data = response

        if not 200 <= status < 300:
            if status == 413:
                internal_count_metric(
                    "Supportability/Python/Collector/MaxPayloadSizeLimit/%s" %
                    method,
                    1,
                )
            level, message = self.LOG_MESSAGES.get(
                status, self.LOG_MESSAGES["default"])
            _logger.log(
                level,
                message,
                {
                    "proxy_host": self._proxy_host,
                    "proxy_port": self._proxy_port,
                    "proxy_user": self._proxy_user,
                    "method": method,
                    "status_code": status,
                    "headers": headers,
                    "params": {
                        k: v
                        for k, v in params.items()
                        if k in self.PARAMS_ALLOWLIST
                    },
                    "content": payload,
                    "agent_run_id": self._run_token,
                },
            )
            exception = self.STATUS_CODE_RESPONSE.get(status,
                                                      DiscardDataForRequest)
            raise exception
        if status == 200:
            return json_decode(data.decode("utf-8"))["return_value"]
Ejemplo n.º 2
0
    def _supportability_response(status, exc, connection="direct"):
        if exc or not 200 <= status < 300:
            internal_count_metric("Supportability/Python/Collector/Failures",
                                  1)
            internal_count_metric(
                "Supportability/Python/Collector/Failures/%s" % connection, 1)

            if exc:
                internal_count_metric(
                    "Supportability/Python/Collector/Exception/"
                    "%s" % callable_name(exc),
                    1,
                )
            else:
                internal_count_metric(
                    "Supportability/Python/Collector/HTTPError/%d" % status, 1)
 def record_error(cls, resource, data):
     # As per spec
     internal_count_metric(
             'Supportability/utilization/%s/error' % cls.VENDOR_NAME, 1)
     _logger.warning('Invalid %r data (%r): %r',
             cls.VENDOR_NAME, resource, data)