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

feat(sdk-metrics): add aggregation cardinality limit #5128

Merged
merged 5 commits into from
Nov 20, 2024

Conversation

povilasv
Copy link
Contributor

@povilasv povilasv commented Nov 8, 2024

Which problem is this PR solving?

implements Otel Cardinality Limit spec.

This change allows you to:

  • configure View for custom aggregation cardinality limit.
  • allows specifying cardinality selector on metric reader
  • also applies default 2000 limit if it's not set.

Link to the spec: https://opentelemetry.io/docs/specs/otel/metrics/sdk/#cardinality-limits

Updated PR to support both async and sync storage

References #4095

Short description of the changes

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • added unit tests
  • created a small app that uses this package via npm link

Checklist:

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

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.24%. Comparing base (f1ef596) to head (94cec89).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5128      +/-   ##
==========================================
+ Coverage   93.21%   93.24%   +0.02%     
==========================================
  Files         315      315              
  Lines        8096     8122      +26     
  Branches     1622     1632      +10     
==========================================
+ Hits         7547     7573      +26     
  Misses        549      549              
Files with missing lines Coverage Δ
packages/sdk-metrics/src/export/MetricReader.ts 100.00% <100.00%> (ø)
...ckages/sdk-metrics/src/state/AsyncMetricStorage.ts 100.00% <100.00%> (ø)
...ages/sdk-metrics/src/state/DeltaMetricProcessor.ts 100.00% <100.00%> (ø)
packages/sdk-metrics/src/state/MeterSharedState.ts 96.66% <100.00%> (+0.05%) ⬆️
packages/sdk-metrics/src/state/MetricCollector.ts 100.00% <100.00%> (ø)
...ackages/sdk-metrics/src/state/SyncMetricStorage.ts 100.00% <100.00%> (ø)
packages/sdk-metrics/src/view/View.ts 100.00% <100.00%> (ø)

@povilasv povilasv force-pushed the cardinality branch 6 times, most recently from 8fdf9e7 to 21c4168 Compare November 8, 2024 14:16
@povilasv povilasv marked this pull request as ready for review November 8, 2024 14:24
@povilasv povilasv requested a review from a team as a code owner November 8, 2024 14:24
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for working on this 🙌

Are you also planning to open PRs to follow up on the rest of the cardinality limit specification as well? 🤔

I'd like to time merging this feature in a way that we have the whole spec-feature available at once, so that people can change the limit via the MetricReader as well. Doing so would also avoid inconsistency with the async storage.

packages/sdk-metrics/src/state/DeltaMetricProcessor.ts Outdated Show resolved Hide resolved
packages/sdk-metrics/src/view/View.ts Outdated Show resolved Hide resolved
packages/sdk-metrics/src/view/View.ts Outdated Show resolved Hide resolved
packages/sdk-metrics/src/view/View.ts Outdated Show resolved Hide resolved
@povilasv povilasv force-pushed the cardinality branch 3 times, most recently from cc6235c to 6bdc798 Compare November 11, 2024 12:24
@povilasv povilasv requested a review from pichlermarc November 11, 2024 12:30
@povilasv
Copy link
Contributor Author

@pichlermarc commited your suggestions and updated PR to add cardinality limiting on async storage.

I also added CardinalitySelector to MetricReader to fully implement cardinality limiting.

Let me know what you think 🙇

pichlermarc
pichlermarc previously approved these changes Nov 12, 2024
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for adding the other parts as well 🙌

packages/sdk-metrics/src/state/MetricCollector.ts Outdated Show resolved Hide resolved
@pichlermarc pichlermarc dismissed their stale review November 12, 2024 09:24

selected wrong category

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Oh, I selected the wrong category when posting the previous review, sorry - there's one more thing (see comment above) then this is good to merge. Thanks for working on this feature. 🙌

@pichlermarc pichlermarc added spec-feature This is a request to implement a new feature which is already specified by the OTel specification pkg:sdk-metrics labels Nov 12, 2024
@povilasv povilasv requested a review from pichlermarc November 12, 2024 10:05
Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

I think this looks good, thank you for implementing this @povilasv.
I'll leave this PR open for a bit to give others a chance to review as well - then I'll merge this next week 🙂

Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

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

Generally looks good! Just a nit

// If the cardinality limit is reached, we need to change the attributes
if (this._cumulativeMemoStorage.size >= this._cardinalityLimit) {
attributes = { 'otel.metric.overflow': true };
hashCode = hashAttributes(attributes);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I think this hash can be a constant value, avoid re-computing.

@povilasv
Copy link
Contributor Author

@legendecas thanks for review, updated the code

@pichlermarc pichlermarc added this pull request to the merge queue Nov 20, 2024
Merged via the queue into open-telemetry:main with commit a834861 Nov 20, 2024
19 checks passed
@povilasv povilasv deleted the cardinality branch November 23, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:sdk-metrics spec-feature This is a request to implement a new feature which is already specified by the OTel specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants