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): align MetricReader with specification and other language implementations #3225

Merged

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Sep 2, 2022

Which problem is this PR solving?

The spec states that:

To construct a MetricReader when setting up an SDK, the caller SHOULD provide at least the following:

  • The exporter to use, which is a MetricExporter instance.
  • The default output aggregation (optional), a function of instrument kind. If not configured, the default aggregation SHOULD be used.
  • The default output temporality (optional), a function of instrument kind. If not configured, the Cumulative temporarily SHOULD be used.

For the PeriodicExportingMetricReader the spec states configurable parameters as:

  • exportIntervalMillis - the time interval in milliseconds between two consecutive exports. The default value is 60000 (milliseconds).
  • exportTimeoutMillis - how long the export can run before it is cancelled. The default value is 30000 (milliseconds).

This PR:

  • aligns the configuration options on the MetricReader with the spec by adding configurability of aggregationTemporalitySelector and aggregationSelector
    • see Python SDK
    • see .NET SDK (only temporality via public property, per-reader aggregation not implemented)
    • the Java SDK uses an alternative approach by internally allowing overrides of the MetricReader interface
  • removes the ability to override the PeriodicExportingMetricReader's AggregationSelector
    • also not allowed in Java SDK
    • also not allowed in Python SDK
    • also not allowed in .NET SDK (per reader aggregation not implemented)
  • adds optional configuration of the PeriodicExportingMetricReader's aggregationSelector via the Exporter
  • makes implementing selectAggregationTemporality optional for PushMetricExporters
    • the PeriodicExportingMetricReader will fall back to cumulative if not specified.

As the spec does not seem entirely clear, I added some links above with references to other language SDKs' implementations. 🙂

Fixes #3213
Related #3060

Short description of the changes

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How Has This Been Tested?

  • Added unit tests
  • Existing unit tests

Checklist:

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

@pichlermarc pichlermarc changed the title feat(sdk-metrics): align MetricReader with specification feat(sdk-metrics): align MetricReader with specification and other language implementations Sep 2, 2022
@codecov
Copy link

codecov bot commented Sep 2, 2022

Codecov Report

Merging #3225 (22d7455) into main (be24d69) will increase coverage by 0.00%.
The diff coverage is 95.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3225   +/-   ##
=======================================
  Coverage   93.30%   93.30%           
=======================================
  Files         202      203    +1     
  Lines        6599     6606    +7     
  Branches     1384     1389    +5     
=======================================
+ Hits         6157     6164    +7     
  Misses        442      442           
Impacted Files Coverage Δ
...etrics/src/export/PeriodicExportingMetricReader.ts 95.65% <80.00%> (-0.43%) ⬇️
...etry-exporter-prometheus/src/PrometheusExporter.ts 92.40% <100.00%> (-0.19%) ⬇️
...etry-sdk-metrics/src/export/AggregationSelector.ts 100.00% <100.00%> (ø)
...entelemetry-sdk-metrics/src/export/MetricReader.ts 100.00% <100.00%> (ø)

@pichlermarc pichlermarc force-pushed the feature/add-optional-selectors branch from a6f863f to 05aa7e9 Compare September 2, 2022 12:50
@pichlermarc pichlermarc marked this pull request as ready for review September 2, 2022 14:46
@pichlermarc pichlermarc requested a review from a team September 2, 2022 14:46
@pichlermarc pichlermarc added the sdk:metrics Issues and PRs related to the Metrics SDK label Sep 2, 2022
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.

I think this can be a good approach to reduce the duplication on the aggregation selections.


constructor(options: PeriodicExportingMetricReaderOptions) {
super();
super({
aggregationSelector: options.exporter.selectAggregation,
Copy link
Member

Choose a reason for hiding this comment

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

options.exporter.selectAggregation should either have their receiver to be bound to options.exporter, or maybe we should make the selector an interface, with methods like selectAggregation and selectAggregationTemporality, so that we can safely pass the selector around.

interface AggregationSelector {
  selectAggregation(instrumentType): Aggregation;
  selectTemporality(instrumentType): AggregationTemporality;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, thanks! 🙂
I changed it to bind to the exporter in 2453614. 🙂

@legendecas legendecas added this to the Metrics GA milestone Sep 7, 2022
@dyladan dyladan removed this from the Metrics GA milestone Sep 7, 2022
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.

LGTM. Thank you for working on this <3

@dyladan dyladan merged commit b73c29d into open-telemetry:main Sep 12, 2022
@dyladan dyladan deleted the feature/add-optional-selectors branch September 12, 2022 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk:metrics Issues and PRs related to the Metrics SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make aggregationTemporalitySelector an optional property
4 participants