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

MetricReader TemporalityPreference #3153

Merged

Conversation

alanwest
Copy link
Member

@alanwest alanwest commented Apr 8, 2022

This PR introduces a new enumeration called MetricReaderTemporalityPreference and provides it as a setting on MetricReader. MetricReader no longer contains a Temporality configuration setting.

MetricReaderTemporalityPreference embodies the two preferences outlined in the specification of the OTLP exporter. Other preferences may be introduced in the future - for example, this table suggests a potential future "stateless" temporality preference.

For the purposes of this PR, a "temporality preference" is effectively a mapping of instrument type (e.g., Counter, Histogram, AsyncCounter, etc) to an AggregationTemporality (i.e., either Cumulative or Delta). This mapping will become important with the introduction of the UpDownCounter in .NET 7.

The proposed names of the preferences and the corresponding mappings from instrument type to AggregationTemporality are as follows

Instrument Cumulative preference MonotonicDelta* preference
Counter<> Cumulative Delta
ObservableCounter<> Cumulative Delta
UpDownCounter<> Cumulative Cumulative
ObservableUpDownCounter<> Cumulative Cumulative
Histogram<> Cumulative Delta
ObservableGauge<> N/A N/A
  • I choose the name MonotonicDelta because simply Delta may be misleading. The idea is that this preference uses delta temporality for all but the "non-monotonic" instruments. Furthermore, there may be a future where a true Delta preference may be needed - though as of yet, no one has specified a need for such a thing.

With the removal of the MetricReader.Temporality setting, I also deleted the AggregationTemporalityAttribute class. This was only being used by the Prometheus package. It should only be possible to configure a MetricReader paired with the Prometheus exporter with MetricReaderTemporalityPreference.Cumulative. This attribute was enforcing this. My thought is that a stable version of the Prometheus package will come later. At that time maybe we can reintroduce an MetricReaderTemporalityPreferenceAttribute class to enforce this, or maybe we will take another approach. Removing AggregationTemporalityAttribute for now gives us more options to explore after the 1.2 release.

@alanwest alanwest requested a review from a team April 8, 2022 23:26
@codecov
Copy link

codecov bot commented Apr 8, 2022

Codecov Report

Merging #3153 (2fc0b58) into main (4cabb23) will increase coverage by 0.03%.
The diff coverage is 90.90%.

❗ Current head 2fc0b58 differs from pull request most recent head 453cc9c. Consider uploading reports for the commit 453cc9c to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3153      +/-   ##
==========================================
+ Coverage   84.75%   84.78%   +0.03%     
==========================================
  Files         260      259       -1     
  Lines        9273     9295      +22     
==========================================
+ Hits         7859     7881      +22     
  Misses       1414     1414              
Impacted Files Coverage Δ
...elemetry.Exporter.Prometheus/PrometheusExporter.cs 90.90% <ø> (ø)
src/OpenTelemetry/Metrics/MetricReaderExt.cs 84.68% <80.95%> (-1.39%) ⬇️
src/OpenTelemetry/Metrics/MetricReader.cs 86.44% <89.18%> (+1.21%) ⬆️
...rometheusExporterMeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...ry/Internal/PeriodicExportingMetricReaderHelper.cs 100.00% <100.00%> (ø)
...OpenTelemetry/Metrics/BaseExportingMetricReader.cs 86.15% <100.00%> (-0.81%) ⬇️
src/OpenTelemetry/Metrics/MeterProviderSdk.cs 89.50% <100.00%> (+0.31%) ⬆️
src/OpenTelemetry/Metrics/MetricReaderOptions.cs 100.00% <100.00%> (ø)
...OpenTelemetry/Metrics/MetricStreamConfiguration.cs 65.00% <100.00%> (+1.84%) ⬆️
src/OpenTelemetry/Metrics/MetricStreamIdentity.cs 90.00% <100.00%> (ø)
... and 4 more

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 overall. Blocking for the following:

  1. Changelog update (with Breaking change warning)
  2. MonotonicDelta -> Delta, for being consistent with spec, even though it could be confusing.

@cijothomas
Copy link
Member

@joaopgrassi @utpilla tagging folks whom I know have written own MetricExporters, and will need to adjust when this PR is merged.

@cijothomas
Copy link
Member

@MikeGoldsmith in case you need.. (I saw some HoneyComb MetricExporter..)

@cijothomas cijothomas merged commit 89a740e into open-telemetry:main Apr 12, 2022
Cumulative = 1,

/// <summary>
/// All measurements that are monotnic in nature are aggregated using delta temporality.
Copy link
Member

Choose a reason for hiding this comment

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

@alanwest nit: "monotnic" -> "monotonic"

Copy link
Member Author

Choose a reason for hiding this comment

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

#3162 💥

/// All measurements that are monotnic in nature are aggregated using delta temporality.
/// Aggregations of non-monotonic measurements use cumulative temporality.
/// </summary>
Delta = 2,
Copy link
Member

Choose a reason for hiding this comment

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

@alanwest Thinking out loud here, could we be more descriptive with the names? Like...

AlwaysCumulative,
DeltaMonotonicCumulativeNonmonotonic

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md The OTLP ENV variable called this simply cumulative, delta.
Though I agree a more descriptive name is nicer, I also prefer if we keep it close to the spec. (its really an OTLP spec, but thats the only place spec ever mentions this...)

Copy link
Member Author

@alanwest alanwest Apr 13, 2022

Choose a reason for hiding this comment

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

They are totally waaay more descriptive 😆. I originally had them as Cumulative and MonotonicDelta, but the spec has no such term. In discussing with @cijothomas, we decided to keep the names from the OTLP spec used for the OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE environment variable - https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md. We have not yet implemented this environment variable, but the meaning of the values CUMULATIVE and DELTA of this variable will map to this new enum.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops sorry my response was redundant... Is it just me or does GitHub not seem to refresh stuff reliably?

Copy link
Member

Choose a reason for hiding this comment

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

Is it just me or does GitHub not seem to refresh stuff reliably?

Same here, I keep seeing such issue.

Copy link
Member

Choose a reason for hiding this comment

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

I personally don't have an issue with the environment variable values being different from the enumeration names, but if that's what you guys want to do, fine by me. Could also use string constants instead of enum, I don't think the numeric values are significant to the implementation but I didn't look at every file on this PR. Eg:

public static class MetricReaderTemporalityPreference
{
   public const string AlwaysCumulative = "Cumulative";
   public const string DeltaMonotonicCumulativeNonmonotonic = "Delta";
}

Copy link
Member

Choose a reason for hiding this comment

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

+1 on being explicit about naming.

BTW, which one is more idiomatic in .NET OpenTelemetry.Metrics.MetricReaderTemporalityPreference or OpenTelemetry.Metrics.MetricReader.TemporalityPreference (inner class)?

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.

4 participants