Skip to content

Commit cd23f56

Browse files
umaannamalailrafeeiNayuken
authoredJul 21, 2022
Enable log forwarding by default. (#587)
* Enable log forwarding by default. (#583) * Enable log forwarding by default. * Fix catmap fixture for log forwarding compatibility. * Use isinstance check in fixtures. * Update data usage supportability metrics. (#582) * Update data usage supportability metric name. * Fix compression bug and add testing. Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Nyenty Ayuk-Enow <ayuknyenty15@gmail.com> * Update harvest_loop tests. * Update compression test to check method1 payload length for consistency. Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Nyenty Ayuk-Enow <ayuknyenty15@gmail.com> Co-authored-by: Lalleh Rafeei <lrafeei@newrelic.com> Co-authored-by: Nyenty Ayuk-Enow <ayuknyenty15@gmail.com>
1 parent 5a1d774 commit cd23f56

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed
 

‎newrelic/common/agent_http.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -524,24 +524,32 @@ def _supportability_request(params, payload, body, compression_time):
524524
# *********
525525
# Used only for supportability metrics. Do not use to drive business
526526
# logic!
527+
# payload: uncompressed
528+
# body: compressed
527529
agent_method = params and params.get("method")
528530
# *********
529531

530-
if agent_method and body:
532+
if agent_method and payload:
531533
# Compression was applied
532534
if compression_time is not None:
533535
internal_metric(
534-
"Supportability/Python/Collector/ZLIB/Bytes/%s" % agent_method,
535-
len(payload),
536+
"Supportability/Python/Collector/%s/ZLIB/Bytes" % agent_method,
537+
len(body),
536538
)
537539
internal_metric(
538-
"Supportability/Python/Collector/ZLIB/Compress/%s" % agent_method,
540+
"Supportability/Python/Collector/ZLIB/Bytes", len(body)
541+
)
542+
internal_metric(
543+
"Supportability/Python/Collector/%s/ZLIB/Compress" % agent_method,
539544
compression_time,
540545
)
541-
542546
internal_metric(
543-
"Supportability/Python/Collector/Output/Bytes/%s" % agent_method,
544-
len(body),
547+
"Supportability/Python/Collector/%s/Output/Bytes" % agent_method,
548+
len(payload),
549+
)
550+
# Top level metric to aggregate overall bytes being sent
551+
internal_metric(
552+
"Supportability/Python/Collector/Output/Bytes", len(payload)
545553
)
546554

547555
@staticmethod

‎newrelic/core/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ def default_host(license_key):
812812

813813
_settings.application_logging.enabled = _environ_as_bool("NEW_RELIC_APPLICATION_LOGGING_ENABLED", default=True)
814814
_settings.application_logging.forwarding.enabled = _environ_as_bool(
815-
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED", default=False
815+
"NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED", default=True
816816
)
817817
_settings.application_logging.metrics.enabled = _environ_as_bool(
818818
"NEW_RELIC_APPLICATION_LOGGING_METRICS_ENABLED", default=True

‎tests/agent_unittests/test_harvest_loop.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def test_default_events_harvested(allowlist_event):
896896
num_seen = 0 if (allowlist_event != "span_event_data") else 1
897897
assert app._stats_engine.span_events.num_seen == num_seen
898898

899-
assert app._stats_engine.metrics_count() == 1
899+
assert app._stats_engine.metrics_count() == 4
900900

901901

902902
@failing_endpoint("analytic_event_data")

‎tests/agent_unittests/test_http_client.py

+27-12
Original file line numberDiff line numberDiff line change
@@ -289,32 +289,47 @@ def test_http_payload_compression(server, client_cls, method, threshold):
289289
compression_threshold=threshold,
290290
) as client:
291291
with InternalTraceContext(internal_metrics):
292-
status, data = client.send_request(payload=payload, params={"method": "test"})
292+
status, data = client.send_request(payload=payload, params={"method": "method1"})
293+
294+
# Sending one additional request to valid metric aggregation for top level data usage supportability metrics
295+
with client_cls(
296+
"localhost",
297+
server.port,
298+
disable_certificate_validation=True,
299+
compression_method=method,
300+
compression_threshold=threshold,
301+
) as client:
302+
with InternalTraceContext(internal_metrics):
303+
status, data = client.send_request(payload=payload, params={"method": "method2"})
293304

294305
assert status == 200
295306
data = data.split(b"\n")
296307
sent_payload = data[-1]
297308
payload_byte_len = len(sent_payload)
298-
299309
internal_metrics = dict(internal_metrics.metrics())
300310
if client_cls is ApplicationModeClient:
301-
assert internal_metrics["Supportability/Python/Collector/Output/Bytes/test"][:2] == [
311+
assert internal_metrics["Supportability/Python/Collector/method1/Output/Bytes"][:2] == [
302312
1,
303-
payload_byte_len,
313+
len(payload),
314+
]
315+
assert internal_metrics["Supportability/Python/Collector/Output/Bytes"][:2] == [
316+
2,
317+
len(payload)*2,
304318
]
305319

306320
if threshold < 20:
307321
# Verify compression time is recorded
308-
assert internal_metrics["Supportability/Python/Collector/ZLIB/Compress/test"][0] == 1
309-
assert internal_metrics["Supportability/Python/Collector/ZLIB/Compress/test"][1] > 0
310-
311-
# Verify the original payload length is recorded
312-
assert internal_metrics["Supportability/Python/Collector/ZLIB/Bytes/test"][:2] == [1, len(payload)]
313-
314-
assert len(internal_metrics) == 3
322+
assert internal_metrics["Supportability/Python/Collector/method1/ZLIB/Compress"][0] == 1
323+
assert internal_metrics["Supportability/Python/Collector/method1/ZLIB/Compress"][1] > 0
324+
325+
# Verify the compressed payload length is recorded
326+
assert internal_metrics["Supportability/Python/Collector/method1/ZLIB/Bytes"][:2] == [1, payload_byte_len]
327+
assert internal_metrics["Supportability/Python/Collector/ZLIB/Bytes"][:2] == [2, payload_byte_len*2]
328+
329+
assert len(internal_metrics) == 8
315330
else:
316331
# Verify no ZLIB compression metrics were sent
317-
assert len(internal_metrics) == 1
332+
assert len(internal_metrics) == 3
318333
else:
319334
assert not internal_metrics
320335

‎tests/testing_support/fixtures.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2625,8 +2625,8 @@ def _validate_analytics_sample_data(wrapped, instance, args, kwargs):
26252625
_new_wrapped = _capture_samples(wrapped)
26262626

26272627
result = _new_wrapped(*args, **kwargs)
2628-
2629-
_samples = [s for s in samples if s[0]["type"] == "Transaction"]
2628+
# Check type of s[0] because it returns an integer if s is a LogEventNode
2629+
_samples = [s for s in samples if not isinstance(s[0], int) and s[0]["type"] == "Transaction"]
26302630
assert _samples, "No Transaction events captured."
26312631
for sample in _samples:
26322632
assert isinstance(sample, list)

0 commit comments

Comments
 (0)
Please sign in to comment.