Skip to content

Commit ea44e9d

Browse files
Agent API Benchmarks (#1524)
* Add agent API benchmarks * Delete placeholder benchmarks * Fix OTLP in developer mode * Enable dimensional metric benchmark * Add record_dimensional_metrics benchmark * Fix params method lookup --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 92698ac commit ea44e9d

File tree

4 files changed

+503
-42
lines changed

4 files changed

+503
-42
lines changed

newrelic/common/agent_http.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
audit_log_fp=None,
9494
default_content_encoding_header="Identity",
9595
):
96+
self._host = host
9697
self._audit_log_fp = audit_log_fp
9798

9899
def __enter__(self):
@@ -565,12 +566,20 @@ class DeveloperModeClient(SupportabilityMixin, BaseClient):
565566
def send_request(
566567
self, method="POST", path="/agent_listener/invoke_raw_method", params=None, headers=None, payload=None
567568
):
568-
request_id = self.log_request(
569-
self._audit_log_fp, "POST", f"https://fake-collector.newrelic.com{path}", params, payload, headers
570-
)
569+
# Pre-connect and OTLP endpoint requests will not have the fake- prefix, so we forcibly add it just to be sure.
570+
host = self._host if self._host.startswith("fake-") else f"fake-{self._host}"
571+
url = f"https://{host}{path}"
572+
request_id = self.log_request(self._audit_log_fp, "POST", url, params, payload, headers)
573+
574+
# Don't attempt to handle OTLP endpoint requests
575+
if host == "fake-otlp.nr-data.net":
576+
return 200, b""
577+
578+
# Requests to the collector must have a method parameter or they're invalid
571579
if not params or "method" not in params:
572580
return 400, b"Missing method parameter"
573581

582+
# If we don't have a canned response for the method, return an error
574583
method = params["method"]
575584
if method not in self.RESPONSES:
576585
return 400, b"Invalid method received"
@@ -592,8 +601,9 @@ def send_request(
592601
):
593602
result = super().send_request(method=method, path=path, params=params, headers=headers, payload=payload)
594603

595-
if result[0] == 200:
596-
agent_method = params["method"]
604+
# Check for the presence of agent_method to ensure this isn't an OTLP request
605+
agent_method = params and params.get("method")
606+
if result[0] == 200 and agent_method:
597607
self.payload[agent_method] = json_decode(payload.decode("utf-8"))
598608

599609
return result

newrelic/core/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,8 @@ def default_otlp_host(host):
689689
}
690690
otlp_host = HOST_MAP.get(host, None)
691691
if not otlp_host:
692-
default = HOST_MAP["collector.newrelic.com"]
693-
_logger.warning("Unable to find corresponding OTLP host using default %s", default)
694-
otlp_host = default
692+
otlp_host = HOST_MAP["collector.newrelic.com"]
693+
_logger.warning("Unable to find corresponding OTLP host using default %s", otlp_host)
695694
return otlp_host
696695

697696

tests/agent_benchmarks/bench_agent_active.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)