Skip to content

Commit b538ee8

Browse files
committed
Use a specific client for supportability metrics.
1 parent 1ddaabf commit b538ee8

File tree

3 files changed

+63
-44
lines changed

3 files changed

+63
-44
lines changed

newrelic/common/agent_http.py

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,7 @@ def finalize(self):
9696

9797
@staticmethod
9898
def _supportability_request(params, payload, body, compression_time):
99-
# *********
100-
# Used only for supportability metrics. Do not use to drive business
101-
# logic!
102-
agent_method = params and params.get("method")
103-
# *********
104-
105-
if agent_method and body:
106-
# Compression was applied
107-
if compression_time is not None:
108-
internal_metric(
109-
"Supportability/Python/Collector/ZLIB/Bytes/%s" % agent_method,
110-
len(payload),
111-
)
112-
internal_metric(
113-
"Supportability/Python/Collector/ZLIB/Compress/%s" % agent_method,
114-
compression_time,
115-
)
116-
117-
internal_metric(
118-
"Supportability/Python/Collector/Output/Bytes/%s" % agent_method,
119-
len(body),
120-
)
99+
pass
121100

122101
@classmethod
123102
def log_request(
@@ -166,22 +145,7 @@ def log_request(
166145

167146
@staticmethod
168147
def _supportability_response(status, exc, connection="direct"):
169-
if exc or not 200 <= status < 300:
170-
internal_count_metric("Supportability/Python/Collector/Failures", 1)
171-
internal_count_metric(
172-
"Supportability/Python/Collector/Failures/%s" % connection, 1
173-
)
174-
175-
if exc:
176-
internal_count_metric(
177-
"Supportability/Python/Collector/Exception/"
178-
"%s" % callable_name(exc),
179-
1,
180-
)
181-
else:
182-
internal_count_metric(
183-
"Supportability/Python/Collector/HTTPError/%d" % status, 1
184-
)
148+
pass
185149

186150
@classmethod
187151
def log_response(cls, fp, log_id, status, headers, data, connection="direct"):
@@ -544,7 +508,57 @@ def __init__(
544508
)
545509

546510

547-
class DeveloperModeClient(BaseClient):
511+
class SupportabilityMixin(object):
512+
@staticmethod
513+
def _supportability_request(params, payload, body, compression_time):
514+
# *********
515+
# Used only for supportability metrics. Do not use to drive business
516+
# logic!
517+
agent_method = params and params.get("method")
518+
# *********
519+
520+
if agent_method and body:
521+
# Compression was applied
522+
if compression_time is not None:
523+
internal_metric(
524+
"Supportability/Python/Collector/ZLIB/Bytes/%s" % agent_method,
525+
len(payload),
526+
)
527+
internal_metric(
528+
"Supportability/Python/Collector/ZLIB/Compress/%s" % agent_method,
529+
compression_time,
530+
)
531+
532+
internal_metric(
533+
"Supportability/Python/Collector/Output/Bytes/%s" % agent_method,
534+
len(body),
535+
)
536+
537+
@staticmethod
538+
def _supportability_response(status, exc, connection="direct"):
539+
if exc or not 200 <= status < 300:
540+
internal_count_metric("Supportability/Python/Collector/Failures", 1)
541+
internal_count_metric(
542+
"Supportability/Python/Collector/Failures/%s" % connection, 1
543+
)
544+
545+
if exc:
546+
internal_count_metric(
547+
"Supportability/Python/Collector/Exception/"
548+
"%s" % callable_name(exc),
549+
1,
550+
)
551+
else:
552+
internal_count_metric(
553+
"Supportability/Python/Collector/HTTPError/%d" % status, 1
554+
)
555+
556+
557+
class ApplicationModeClient(SupportabilityMixin, HttpClient):
558+
pass
559+
560+
561+
class DeveloperModeClient(SupportabilityMixin, BaseClient):
548562
RESPONSES = {
549563
"preconnect": {u"redirect_host": u"fake-collector.newrelic.com"},
550564
"agent_settings": [],

newrelic/core/agent_protocol.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from newrelic import version
55
from newrelic.common import system_info
6-
from newrelic.common.agent_http import HttpClient, ServerlessModeClient
6+
from newrelic.common.agent_http import ApplicationModeClient, ServerlessModeClient
77
from newrelic.core.internal_metrics import internal_count_metric
88
from newrelic.common.encoding_utils import (
99
json_decode,
@@ -138,7 +138,7 @@ class AgentProtocol(object):
138138
"VERBOSE": _logger.debug,
139139
}
140140

141-
def __init__(self, settings, host=None, client_cls=HttpClient):
141+
def __init__(self, settings, host=None, client_cls=ApplicationModeClient):
142142
if settings.audit_log_file:
143143
audit_log_fp = open(settings.audit_log_file, "a")
144144
else:
@@ -417,7 +417,12 @@ def _apply_high_security_mode_fixups(cls, server_settings, local_settings):
417417

418418
@classmethod
419419
def connect(
420-
cls, app_name, linked_applications, environment, settings, client_cls=HttpClient
420+
cls,
421+
app_name,
422+
linked_applications,
423+
environment,
424+
settings,
425+
client_cls=ApplicationModeClient,
421426
):
422427
with cls(settings, client_cls=client_cls) as preconnect:
423428
redirect_host = preconnect.send("preconnect")["redirect_host"]

newrelic/core/data_collector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import logging
2222

2323
from newrelic.common.agent_http import (
24+
ApplicationModeClient,
2425
DeveloperModeClient,
25-
HttpClient,
2626
ServerlessModeClient,
2727
)
2828
from newrelic.core.agent_protocol import AgentProtocol, ServerlessModeProtocol
@@ -34,7 +34,7 @@
3434

3535
class Session(object):
3636
PROTOCOL = AgentProtocol
37-
CLIENT = HttpClient
37+
CLIENT = ApplicationModeClient
3838

3939
def __init__(self, app_name, linked_applications, environment, settings):
4040
self._protocol = self.PROTOCOL.connect(

0 commit comments

Comments
 (0)