Skip to content

Commit

Permalink
Merge pull request #297 from solarwinds/NH-70998-interval-millis
Browse files Browse the repository at this point in the history
NH-70998 PeriodicExportingMetricReader with export_interval infinity
  • Loading branch information
tammy-baylis-swi authored Feb 1, 2024
2 parents f4eb1ec + d40dac7 commit 8bb1ad4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import importlib
import logging
import math
import os
import sys
import time
Expand Down Expand Up @@ -386,7 +387,11 @@ def _configure_metrics_exporter(
"Creating PeriodicExportingMetricReader using %s",
exporter_name,
)
reader = PeriodicExportingMetricReader(exporter)
# Inf interval to not invoke periodic collection
reader = PeriodicExportingMetricReader(
exporter,
export_interval_millis=math.inf,
)
metric_readers.append(reader)

# Use configured Resource attributes then merge with
Expand Down
33 changes: 29 additions & 4 deletions tests/unit/test_configurator/test_configurator_metrics_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

import math
import os
import pytest

Expand Down Expand Up @@ -144,11 +145,15 @@ def test_configure_metrics_exporter_valid(
del os.environ["OTEL_METRICS_EXPORTER"]

# Mock entry points
mock_exporter_class = mocker.MagicMock()
mock_exporter = mocker.Mock()
mock_exporter_class = mocker.Mock()
mock_exporter_class.configure_mock(return_value=mock_exporter)
mock_load = mocker.Mock()
mock_load.configure_mock(return_value=mock_exporter_class)
mock_exporter_entry_point = mocker.Mock()
mock_exporter_entry_point.configure_mock(
**{
"load": mock_exporter_class
"load": mock_load,
}
)
mock_points = iter([mock_exporter_entry_point])
Expand Down Expand Up @@ -193,6 +198,14 @@ def test_configure_metrics_exporter_valid(
]
)
mock_pemreader.assert_called_once()
mock_pemreader.assert_has_calls(
[
mocker.call(
mock_exporter,
export_interval_millis=math.inf,
)
]
)
trace_mocks.get_tracer_provider.assert_called_once()
trace_mocks.get_tracer_provider().get_tracer.assert_called_once()
mock_meterprovider.assert_called_once()
Expand Down Expand Up @@ -296,11 +309,15 @@ def test_configure_metrics_exporter_valid_invalid_mixed(
del os.environ["OTEL_METRICS_EXPORTER"]

# Mock entry points
mock_exporter_class = mocker.MagicMock()
mock_exporter = mocker.Mock()
mock_exporter_class = mocker.Mock()
mock_exporter_class.configure_mock(return_value=mock_exporter)
mock_load = mocker.Mock()
mock_load.configure_mock(return_value=mock_exporter_class)
mock_exporter_entry_point = mocker.Mock()
mock_exporter_entry_point.configure_mock(
**{
"load": mock_exporter_class
"load": mock_load,
}
)
mock_exporter_class_invalid = mocker.Mock()
Expand Down Expand Up @@ -375,6 +392,14 @@ def test_configure_metrics_exporter_valid_invalid_mixed(
)
# Called for the valid one
mock_pemreader.assert_called_once()
mock_pemreader.assert_has_calls(
[
mocker.call(
mock_exporter,
export_interval_millis=math.inf,
)
]
)
# Rest not called at all
trace_mocks.get_tracer_provider.assert_not_called()
trace_mocks.get_tracer_provider().get_tracer.assert_not_called()
Expand Down

0 comments on commit 8bb1ad4

Please sign in to comment.