-
Notifications
You must be signed in to change notification settings - Fork 828
Fix handling of empty metric collection cycles #3335
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 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3d684b5
Remove console exporter metric output if empty
ocelotl c55f8fa
Revert "Remove console exporter metric output if empty"
ocelotl 8c2a43a
Speed up test execution
ocelotl a54b100
Do not produce any metric output without metric data
ocelotl 1aeaf0c
Revert "Speed up test execution"
ocelotl 032e98f
Fix lint
ocelotl c731316
Add another test for histograms
ocelotl 7ffc2b5
Remove added spacing
ocelotl 721d012
Update typing
ocelotl d9a078c
Fix typing for collect
ocelotl 401cba9
Fix histogram test
ocelotl 0aafae5
Make return more concise
ocelotl cb97ad3
Move return inside the lock
ocelotl 58d1216
Add explanatory comment
ocelotl 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
Add another test for histograms
- Loading branch information
commit c731316aed06f672672ba2b20c786da8e72c7801
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
85 changes: 85 additions & 0 deletions
85
opentelemetry-sdk/tests/metrics/integration_test/test_histogram_export.py
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,85 @@ | ||
| # 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 unittest import TestCase | ||
|
|
||
| from opentelemetry.metrics import set_meter_provider | ||
| from opentelemetry.sdk.metrics import MeterProvider | ||
| from opentelemetry.sdk.metrics.export import InMemoryMetricReader | ||
| from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
|
|
||
| in_memory_metric_reader = InMemoryMetricReader() | ||
|
|
||
| provider = MeterProvider( | ||
| resource=Resource.create({SERVICE_NAME: "otel-test"}), | ||
| metric_readers=[in_memory_metric_reader], | ||
| ) | ||
| set_meter_provider(provider) | ||
ocelotl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| meter = provider.get_meter("my-meter") | ||
|
|
||
| histogram = meter.create_histogram("my_histogram") | ||
| counter = meter.create_counter("my_counter") | ||
ocelotl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class TestHistogramExport(TestCase): | ||
| def test_histogram_counter_collection(self): | ||
ocelotl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| histogram.record(5, {"attribute": "value"}) | ||
| counter.add(1, {"attribute": "value_counter"}) | ||
|
|
||
| metric_data = in_memory_metric_reader.get_metrics_data() | ||
|
|
||
| self.assertEqual( | ||
| len(metric_data.resource_metrics[0].scope_metrics[0].metrics), 2 | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| ( | ||
| metric_data.resource_metrics[0] | ||
| .scope_metrics[0] | ||
| .metrics[0] | ||
| .data.data_points[0] | ||
| .bucket_counts | ||
| ), | ||
| (0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), | ||
| ) | ||
| self.assertEqual( | ||
| ( | ||
| metric_data.resource_metrics[0] | ||
| .scope_metrics[0] | ||
| .metrics[1] | ||
| .data.data_points[0] | ||
| .value | ||
| ), | ||
| 1, | ||
| ) | ||
|
|
||
| metric_data = in_memory_metric_reader.get_metrics_data() | ||
|
|
||
| # FIXME ExplicitBucketHistogramAggregation is resetting counts to zero | ||
| # even if aggregation temporality is cumulative. | ||
| self.assertEqual( | ||
| len(metric_data.resource_metrics[0].scope_metrics[0].metrics), 1 | ||
| ) | ||
| self.assertEqual( | ||
| ( | ||
| metric_data.resource_metrics[0] | ||
| .scope_metrics[0] | ||
| .metrics[0] | ||
| .data.data_points[0] | ||
| .value | ||
| ), | ||
| 1, | ||
| ) | ||
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.