-
Notifications
You must be signed in to change notification settings - Fork 757
Basic protection against the unintended cardinality explosion #3486
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
Open
nstawski
wants to merge
43
commits into
open-telemetry:main
Choose a base branch
from
nstawski:ns-3201-dropped-attributes-count-in-exporters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
40df300
Added dropped_attributes_count to the exporter
nstawski e193119
Test for dropped_attributes_count
nstawski 4b072b0
Added check for dropped_attributes
nstawski 7e602cf
Updated to_json test
nstawski 2461984
Lint
nstawski c994f3f
Lint
nstawski 6d56b27
Fixed test
nstawski b017abb
Lint
nstawski 118ca12
Lint
nstawski 3228f14
Lint
nstawski 3baca1f
Lint
nstawski 2dca33b
Lint
nstawski 5520807
Lint
nstawski 9385b5a
Lint
nstawski 4a833df
lint
nstawski e2c5c48
Lint
nstawski 5a36085
pylint:disable=no-member for ExportLogServiceRequest in test_log_encoder
nstawski 4ceef97
Lint
nstawski ec20a7d
Changelog
nstawski 34abe7f
Merge branch 'main' into ns-3201-dropped-attributes-count-in-exporters
nstawski c157d93
Merge branch 'main' into ns-3201-dropped-attributes-count-in-exporters
nstawski 0f1eeb4
Addressed pull request comments
nstawski 64cfb27
Init
nstawski b1e5c47
Merge branch 'main' into ns-3201-dropped-attributes-count-in-exporters
nstawski afbf691
Moved the cardinality limit check out of the aggr_key check
nstawski b8de23b
Added tests
nstawski b1a76d1
Using cardinality limit
nstawski c731efb
Added tests for InMemoryMetricExporter
nstawski 3682c3f
Added aggregation_cardinality_limit on view
nstawski b273ffc
Removed the default cardinality limit on MeterProvider
nstawski 456fd2e
Changelog update
nstawski b026f10
Merge branch 'main' into ns-3201-dropped-attributes-count-in-exporters
nstawski f442889
Merge branch 'main' into ns-3201-dropped-attributes-count-in-exporters
nstawski 2ecde0f
Update opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/metr…
nstawski 8b74c76
Code cleanup, removed the InMemoryMetricExporter, updated tests
nstawski 812905b
Code cleanup
nstawski f382f7d
Code cleanup
nstawski c647a60
Code cleanup
nstawski 38a3677
Code cleanup
nstawski b5daf85
Catch the warning for the failing test
nstawski 171087f
Tests updated
nstawski 960e170
Tests updated
nstawski c50370f
Tests updated
nstawski 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
35 changes: 35 additions & 0 deletions
35
opentelemetry-sdk/tests/metrics/test_metric_cardinality_limit.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,35 @@ | ||
| from logging import WARNING | ||
| from unittest import TestCase | ||
|
|
||
| from opentelemetry.sdk.metrics import MeterProvider | ||
| from opentelemetry.sdk.metrics.export import InMemoryMetricReader | ||
|
|
||
|
|
||
| class TestMetricCardinalityLimit(TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.reader = InMemoryMetricReader() | ||
| self.meter_provider = MeterProvider(metric_readers=[self.reader]) | ||
| self.meter = self.meter_provider.get_meter("test_meter") | ||
|
|
||
| def test_metric_cardinality_limit(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are introducing the ability to configure the value we should have a test for that too. |
||
| # Assuming a Counter type metric | ||
| counter = self.meter.create_counter("cardinality_test_counter") | ||
|
|
||
| # Generate and add more than 2000 unique labels | ||
| for ind in range(2100): | ||
| label = {"key": f"value_{ind}"} | ||
| counter.add(1, label) | ||
|
|
||
| # Simulate an export to get the metrics into the in-memory exporter | ||
| self.reader.force_flush() | ||
|
|
||
| # Retrieve the metrics from the in-memory exporter | ||
| metric_data = self.reader.get_metrics_data() | ||
|
|
||
| # Check if the length of the metric data doesn't exceed 2000 | ||
| self.assertTrue(len(metric_data.resource_metrics) <= 2000) | ||
|
|
||
| # Check if a warning or an error was logged | ||
| with self.assertLogs(level=WARNING): | ||
| counter.add(1, {"key": "value_2101"}) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like these args are individually documented in the docstring above. Should we add one for this arg?