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

[sdk-metrics] Obsolete SetMaxMetricPointsPerMetricStream + standarize on "Cardinality Limit" name #5328

Merged

Conversation

CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch commented Feb 7, 2024

Follow-up to #5312

Changes

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes

@CodeBlanch CodeBlanch added pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package metrics Metrics signal related labels Feb 7, 2024
@CodeBlanch CodeBlanch requested a review from a team February 7, 2024 21:16
@reyang
Copy link
Member

reyang commented Feb 7, 2024

  • Expose MeterProviderBuilderExtensions.SetCardinalityLimit experimental API (does the same thing as SetMaxMetricPointsPerMetricStream just with a name that will match the spec concept).

Do we want to expose this at all or we want to point folks to View level limit? Asking this because the spec doesn't ask for it https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#configuration-1

CodeBlanch and others added 2 commits February 7, 2024 13:53
@CodeBlanch
Copy link
Member Author

CodeBlanch commented Feb 7, 2024

Do we want to expose this at all or we want to point folks to View level limit? Asking this because the spec doesn't ask for it

My thinking is we already exposed it with SetMaxMetricPointsPerMetricStream so we might as well name it something familiar/relatable/searchable to what the spec does have.

If you are thinking we should just do something like...

#if EXPOSE_EXPERIMENTAL_FEATURES
    [Obsolete("Use MetricStreamConfiguration.CardinalityLimit instead. This method will be removed in a future version.")]
#endif
    public static MeterProviderBuilder SetMaxMetricPointsPerMetricStream(this MeterProviderBuilder meterProviderBuilder, int maxMetricPointsPerMetricStream)

I'm also good with that.

@CodeBlanch CodeBlanch changed the title [sdk-metrics] Standarize on "Cardinality Limit" name [sdk-metrics] Obsolete SetMaxMetricPointsPerMetricStream + standarize on "Cardinality Limit" name Feb 7, 2024
@CodeBlanch
Copy link
Member Author

I had an offline discussion with @reyang. We decided to obsolete SetMaxMetricPointsPerMetricStream and NOT add an alternative global mechanism. Because it isn't part of the spec and it may be too dangerous to have.

@Yun-Ting
Copy link
Contributor

Yun-Ting commented Feb 7, 2024

I feel .SetCardinalityLimit() is a bit confusing to use:

  1. The current implementation of this method is setting a "global" value for the dimensions of each metric of a MeterProvider.
  2. If user really cares about customizing each metric, they should be encouraged to leverage view to achieve that. And the view already has the API to set the cardinality limit.

@Yun-Ting
Copy link
Contributor

Yun-Ting commented Feb 8, 2024

CardinalityLimitofMatchingViewTakesPrecedenceOverMetricProviderWhenBothWereSet can be removed.
Can update to test this scenario instead: #5328 (comment)

Comment on lines -408 to -444
// There are four distinct key/value combinations emitted for `MyFruitCounter`:
// 1. No key/value pair
// 2. (name:apple, color:red)
// 3. (name:lemon, color:yellow)
// 4. (name:apple, color:green)

// Since the maximum number of `MetricPoint`s allowed is `3`, the SDK will only export measurements for the following three combinations:
// 1. No key/value pair
// 2. (name:apple, color:red)
// 3. (name:lemon, color:yellow)

MyFruitCounter.Add(1); // Exported (No key/value pair)
MyFruitCounter.Add(1, new("name", "apple"), new("color", "red")); // Exported
MyFruitCounter.Add(2, new("name", "lemon"), new("color", "yellow")); // Exported
MyFruitCounter.Add(1, new("name", "lemon"), new("color", "yellow")); // Exported
MyFruitCounter.Add(2, new("name", "apple"), new("color", "green")); // Not exported
MyFruitCounter.Add(5, new("name", "apple"), new("color", "red")); // Exported
MyFruitCounter.Add(4, new("name", "lemon"), new("color", "yellow")); // Exported

// There are four distinct key/value combinations emitted for `AnotherFruitCounter`:
// 1. (name:kiwi)
// 2. (name:banana, color:yellow)
// 3. (name:mango, color:yellow)
// 4. (name:banana, color:green)

// Since the maximum number of `MetricPoint`s allowed is `3`, the SDK will only export measurements for the following three combinations:
// 1. No key/value pair (This is a special case. The SDK reserves a `MetricPoint` for it even if it's not explicitly emitted.)
// 2. (name:kiwi)
// 3. (name:banana, color:yellow)

AnotherFruitCounter.Add(4, new KeyValuePair<string, object>("name", "kiwi")); // Exported
AnotherFruitCounter.Add(1, new("name", "banana"), new("color", "yellow")); // Exported
AnotherFruitCounter.Add(2, new("name", "mango"), new("color", "yellow")); // Not exported
AnotherFruitCounter.Add(1, new("name", "mango"), new("color", "yellow")); // Not exported
AnotherFruitCounter.Add(2, new("name", "banana"), new("color", "green")); // Not exported
AnotherFruitCounter.Add(5, new("name", "banana"), new("color", "yellow")); // Exported
AnotherFruitCounter.Add(4, new("name", "mango"), new("color", "yellow")); // Not exported
Copy link
Member Author

Choose a reason for hiding this comment

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

@reyang I might have been too aggressive removing all of this. Do you still want it in there just showing the view instead of the global mechanism?

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion here. @utpilla might have different ideas.

Copy link
Contributor

@utpilla utpilla Feb 10, 2024

Choose a reason for hiding this comment

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

@CodeBlanch We should keep the example here. People have found it useful to understand how configuring the cardinality would affect the export.

@CodeBlanch CodeBlanch added the bug Something isn't working label Feb 8, 2024
Copy link
Contributor

@Yun-Ting Yun-Ting left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -238,6 +238,9 @@ public static MeterProviderBuilder SetMaxMetricStreams(this MeterProviderBuilder
/// <param name="meterProviderBuilder"><see cref="MeterProviderBuilder"/>.</param>
/// <param name="maxMetricPointsPerMetricStream">Maximum number of metric points allowed per metric stream.</param>
/// <returns>The supplied <see cref="MeterProviderBuilder"/> for chaining.</returns>
#if EXPOSE_EXPERIMENTAL_FEATURES
[Obsolete("Use MetricStreamConfiguration.CardinalityLimit via the AddView API instead. This method will be removed in a future version.")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[Obsolete("Use MetricStreamConfiguration.CardinalityLimit via the AddView API instead. This method will be removed in a future version.")]
[Obsolete("Use MetricStreamConfiguration.CardinalityLimit via the AddView API instead. This method will be removed in the next major version bump.")]

Copy link
Member

Choose a reason for hiding this comment

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

Or combine.. removed in a future version, along with major version bump of the package.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not going to do this here because we use similar a bunch of places but good thing for a follow-up!

docs/metrics/README.md Outdated Show resolved Hide resolved
Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

LGTM.
Left some comments on changelog/docs for better clarity for end users

@CodeBlanch CodeBlanch merged commit cf00e42 into open-telemetry:main Feb 9, 2024
37 checks passed
@CodeBlanch CodeBlanch deleted the sdk-cardinalitylimit-followup branch February 9, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Documentation related metrics Metrics signal related pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants