Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-70998 Set histogram preferred temporality delta #296

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@
from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.composite import CompositePropagator
from opentelemetry.sdk._configuration import _OTelSDKConfigurator
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.sdk.metrics import Histogram, MeterProvider
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
PeriodicExportingMetricReader,
)
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
Expand Down Expand Up @@ -358,6 +361,8 @@ def _configure_metrics_exporter(
return
environ_exporter_names = environ_exporter.split(",")

# Report all histograms with delta aggregation, including response_time
temporality_delta = {Histogram: AggregationTemporality.DELTA}
metric_readers = []
for exporter_name in environ_exporter_names:
exporter = None
Expand All @@ -367,7 +372,7 @@ def _configure_metrics_exporter(
"opentelemetry_metrics_exporter",
exporter_name,
)
).load()()
).load()(preferred_temporality=temporality_delta)
except Exception as ex:
logger.exception("A exception was raised: %s", ex)
logger.exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_configure_metrics_exporter_invalid(
test_configurator._configure_metrics_exporter(
mock_apmconfig_enabled_expt,
)

mock_pemreader.assert_not_called()
trace_mocks.get_tracer_provider.assert_not_called()
trace_mocks.get_tracer_provider().get_tracer.assert_not_called()
Expand Down Expand Up @@ -167,12 +168,30 @@ def test_configure_metrics_exporter_valid(
# Mock Otel
get_resource_mocks(mocker)
trace_mocks = get_trace_mocks(mocker)
mock_histogram = mocker.patch(
"solarwinds_apm.configurator.Histogram"
)
mock_agg_temp = mocker.patch(
"solarwinds_apm.configurator.AggregationTemporality"
)
mock_agg_temp.DELTA = "foo-delta"

# Test!
test_configurator = configurator.SolarWindsConfigurator()
test_configurator._configure_metrics_exporter(
mock_apmconfig_enabled_expt,
)
mock_exporter_entry_point.load.assert_called_once()
mock_exporter_entry_point.load.assert_has_calls(
[
mocker.call(),
mocker.call()(
preferred_temporality={
mock_histogram: "foo-delta"
}
)
]
)
mock_pemreader.assert_called_once()
trace_mocks.get_tracer_provider.assert_called_once()
trace_mocks.get_tracer_provider().get_tracer.assert_called_once()
Expand Down Expand Up @@ -229,6 +248,13 @@ def test_configure_metrics_exporter_invalid_valid_mixed(
# Mock Otel
get_resource_mocks(mocker)
trace_mocks = get_trace_mocks(mocker)
mock_histogram = mocker.patch(
"solarwinds_apm.configurator.Histogram"
)
mock_agg_temp = mocker.patch(
"solarwinds_apm.configurator.AggregationTemporality"
)
mock_agg_temp.DELTA = "foo-delta"

# Test!
test_configurator = configurator.SolarWindsConfigurator()
Expand All @@ -242,6 +268,11 @@ def test_configure_metrics_exporter_invalid_valid_mixed(
mocker.call("opentelemetry_metrics_exporter", "invalid_exporter"),
]
)
mock_exporter_entry_point_invalid.load.assert_has_calls(
[
mocker.call(),
]
)
# Not called at all
mock_pemreader.assert_not_called()
trace_mocks.get_tracer_provider.assert_not_called()
Expand Down Expand Up @@ -305,6 +336,13 @@ def test_configure_metrics_exporter_valid_invalid_mixed(
# Mock Otel
get_resource_mocks(mocker)
trace_mocks = get_trace_mocks(mocker)
mock_histogram = mocker.patch(
"solarwinds_apm.configurator.Histogram"
)
mock_agg_temp = mocker.patch(
"solarwinds_apm.configurator.AggregationTemporality"
)
mock_agg_temp.DELTA = "foo-delta"

# Test!
test_configurator = configurator.SolarWindsConfigurator()
Expand All @@ -318,6 +356,23 @@ def test_configure_metrics_exporter_valid_invalid_mixed(
mocker.call("opentelemetry_metrics_exporter", "invalid_exporter"),
]
)
mock_exporter_entry_point.load.assert_called_once()
mock_exporter_entry_point.load.assert_has_calls(
[
mocker.call(),
mocker.call()(
preferred_temporality={
mock_histogram: "foo-delta"
}
)
]
)
mock_exporter_entry_point_invalid.load.assert_called_once()
mock_exporter_entry_point_invalid.load.assert_has_calls(
[
mocker.call(),
]
)
# Called for the valid one
mock_pemreader.assert_called_once()
# Rest not called at all
Expand Down