-
Notifications
You must be signed in to change notification settings - Fork 828
Add timeouts to metric SDK #2653
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe1d1f6
Add timeouts to metric SDK
aabmass a02aba8
comments
aabmass bb84fad
don't use TimeoutError as it is intended for OS related timeouts
aabmass b4f4822
changelog and typo
aabmass 10f9acf
isort
aabmass aa6e4a1
fix _time_ns import
aabmass f5339d0
Update CHANGELOG.md
aabmass 49084fc
use self.fail in tests
aabmass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| # 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. | ||
|
|
||
| """ | ||
| The purpose of this test is to test for backward compatibility with any user-implementable | ||
| interfaces as they were originally defined. For example, changes to the MetricExporter ABC must | ||
| be made in such a way that existing implementations (outside of this repo) continue to work | ||
| when *called* by the SDK. | ||
|
|
||
| This does not apply to classes which are not intended to be overriden by the user e.g. Meter | ||
| and PeriodicExportingMetricReader concrete class. Those may freely be modified in a | ||
| backward-compatible way for *callers*. | ||
|
|
||
| Ideally, we could use mypy for this as well, but SDK is not type checked atm. | ||
| """ | ||
|
|
||
| from typing import Iterable, Sequence | ||
| from unittest import TestCase | ||
|
|
||
| from opentelemetry.sdk._metrics import MeterProvider | ||
| from opentelemetry.sdk._metrics.export import ( | ||
| MetricExporter, | ||
| MetricExportResult, | ||
| PeriodicExportingMetricReader, | ||
| ) | ||
| from opentelemetry.sdk._metrics.metric_reader import MetricReader | ||
| from opentelemetry.sdk._metrics.point import Metric | ||
|
|
||
|
|
||
| # Do not change these classes until after major version 1 | ||
| class OrigMetricExporter(MetricExporter): | ||
| def export( | ||
| self, | ||
| metrics: Sequence[Metric], | ||
| timeout_millis: float = 10_000, | ||
| **kwargs, | ||
| ) -> MetricExportResult: | ||
| pass | ||
|
|
||
| def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: | ||
| pass | ||
|
|
||
|
|
||
| class OrigMetricReader(MetricReader): | ||
| def _receive_metrics( | ||
| self, | ||
| metrics: Iterable[Metric], | ||
| timeout_millis: float = 10_000, | ||
| **kwargs, | ||
| ) -> None: | ||
| pass | ||
|
|
||
| def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None: | ||
| self.collect() | ||
|
|
||
|
|
||
| class TestBackwardCompat(TestCase): | ||
| def test_metric_exporter(self): | ||
| exporter = OrigMetricExporter() | ||
| meter_provider = MeterProvider( | ||
| metric_readers=[PeriodicExportingMetricReader(exporter)] | ||
| ) | ||
| # produce some data | ||
| meter_provider.get_meter("foo").create_counter("mycounter").add(12) | ||
aabmass marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try: | ||
| meter_provider.shutdown() | ||
| except Exception: | ||
| self.fail() | ||
|
|
||
| def test_metric_reader(self): | ||
| reader = OrigMetricReader() | ||
| meter_provider = MeterProvider(metric_readers=[reader]) | ||
| # produce some data | ||
| meter_provider.get_meter("foo").create_counter("mycounter").add(12) | ||
| try: | ||
| meter_provider.shutdown() | ||
| except Exception: | ||
| self.fail() | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.