forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement metric reader default aggregation controls
Fixes open-telemetry#2635
- Loading branch information
Showing
10 changed files
with
276 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# 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. | ||
|
||
from typing import Dict | ||
from unittest import TestCase | ||
|
||
from opentelemetry.sdk._metrics.aggregation import ( | ||
AggregationTemporality, | ||
DefaultAggregation, | ||
LastValueAggregation, | ||
_AggregationFactory, | ||
) | ||
from opentelemetry.sdk._metrics.instrument import ( | ||
Counter, | ||
Histogram, | ||
ObservableCounter, | ||
ObservableGauge, | ||
ObservableUpDownCounter, | ||
UpDownCounter, | ||
) | ||
from opentelemetry.sdk._metrics.metric_reader import MetricReader | ||
|
||
|
||
class DummyMetricReader(MetricReader): | ||
def __init__( | ||
self, | ||
preferred_temporality: AggregationTemporality = AggregationTemporality.CUMULATIVE, | ||
preferred_aggregation: Dict[type, _AggregationFactory] = None, | ||
) -> None: | ||
super().__init__( | ||
preferred_temporality=preferred_temporality, | ||
preferred_aggregation=preferred_aggregation, | ||
) | ||
|
||
def _receive_metrics(self, metrics): | ||
pass | ||
|
||
def shutdown(self): | ||
return True | ||
|
||
|
||
class TestMetricReader(TestCase): | ||
def test_default_temporality(self): | ||
|
||
dummy_metric_reader = DummyMetricReader() | ||
|
||
self.assertEqual( | ||
dummy_metric_reader._instrument_class_aggregation.keys(), | ||
set( | ||
[ | ||
Counter, | ||
UpDownCounter, | ||
Histogram, | ||
ObservableCounter, | ||
ObservableUpDownCounter, | ||
ObservableGauge, | ||
] | ||
), | ||
) | ||
for ( | ||
value | ||
) in dummy_metric_reader._instrument_class_aggregation.values(): | ||
self.assertIsInstance(value, DefaultAggregation) | ||
|
||
dummy_metric_reader = DummyMetricReader( | ||
preferred_aggregation={Counter: LastValueAggregation()} | ||
) | ||
self.assertEqual( | ||
dummy_metric_reader._instrument_class_aggregation.keys(), | ||
set( | ||
[ | ||
Counter, | ||
UpDownCounter, | ||
Histogram, | ||
ObservableCounter, | ||
ObservableUpDownCounter, | ||
ObservableGauge, | ||
] | ||
), | ||
) | ||
self.assertIsInstance( | ||
dummy_metric_reader._instrument_class_aggregation[Counter], | ||
LastValueAggregation, | ||
) |
Oops, something went wrong.