Skip to content
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

Basic protection against the unintended cardinality explosion #3486

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

nstawski
Copy link
Contributor

Description

This pull request adds the limit on the metrics to prevent the unintended cardinality explosion. For more information, see #2700
New tests are added for this functionality. Additionally, I moved the InMemoryMetricExporter so it could be used for more tests, and added tests for it.

Fixes #2700

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Added opentelemetry-sdk/tests/metrics/test_in_memory_metric_exporter.py
  • Added opentelemetry-sdk/tests/metrics/test_metric_cardinality_limit.py
  • Updated ns-3201-dropped-attributes-count-in-exporters to use the moved InMemoryMetricExporter

Does This PR Require a Contrib Repo Change?

Answer the following question based on these examples of changes that would require a Contrib Repo Change:

  • The OTel specification has changed which prompted this PR to update the method interfaces of opentelemetry-api/ or opentelemetry-sdk/

  • The method interfaces of test/util have changed

  • Scripts in scripts/ that were copied over to the Contrib repo have changed

  • Configuration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in

    • pyproject.toml
    • isort.cfg
    • .flake8
  • When a new .github/CODEOWNER is added

  • Major changes to project information, such as in:

    • README.md
    • CONTRIBUTING.md
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added

@nstawski nstawski requested a review from a team October 26, 2023 19:44
@nstawski nstawski marked this pull request as draft October 26, 2023 19:48
@nstawski nstawski marked this pull request as ready for review October 27, 2023 15:25
Copy link
Member

@pmcollins pmcollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice enhancement. Just some notes/nits below.

@@ -96,6 +96,7 @@ def __init__(
attribute_keys: Optional[Set[str]] = None,
aggregation: Optional[Aggregation] = None,
instrument_unit: Optional[str] = None,
aggregation_cardinality_limit: Optional[int] = None,
Copy link
Member

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?

class TestMetricCardinalityLimit(TestCase):

def setUp(self):
self.exporter = InMemoryMetricExporter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but if there were multiple tests in this class at some point, setUp might be vestigial now.

self.meter_provider = MeterProvider(metric_readers=[self.reader])
self.meter = self.meter_provider.get_meter("test_meter")

def test_metric_cardinality_limit(self):
Copy link
Contributor

Choose a reason for hiding this comment

The 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.


class _ViewInstrumentMatch:
def __init__(
self,
view: View,
instrument: Instrument,
instrument_class_aggregation: Dict[type, Aggregation],
aggregation_cardinality_limit: Optional[int],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why _ViewInstrumentMatch, MetricReaderStorage and View all have their separate configurations for aggregation_cardinality_limit. Shouldn't this be only configured from View and propagated down?


def setUp(self):
self.exporter = InMemoryMetricExporter()
self.reader = PeriodicExportingMetricReader(exporter=self.exporter, export_interval_millis=500)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Srikanth's comment on the other PR, can we just use InMemoryMetricReader instead? Here is an example from another test https://github.com/open-telemetry/opentelemetry-python/blob/91ac1bea6ed2b50e7e17b91cec2770674f869517/opentelemetry-sdk/tests/metrics/integration_test/test_histogram_export.py#L25C9-L39

@nstawski nstawski requested a review from a team as a code owner October 8, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Basic protection against the unintended cardinality explosion or similar problems
4 participants