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-base): implement async instruments support #2686

Merged

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Dec 22, 2021

Which problem is this PR solving?

This is the continuation part of #2636 for async instruments metric streams.

This is a prototype implementation described in https://docs.google.com/document/d/1EluDhj5UanNATS3hR8xx30sv55Se7uYjsGYslvNWHtc/edit#.

Short description of the changes

  1. Add AsyncMetricStorage for async instruments.
  2. Add support for handling cumulative measurements recording in DeltaMetricProcessor.

Pending spec clarifications:

Depends on:

Type of change

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

How Has This Been Tested?

  • AsyncMetricStorage
  • DeltaMetricProcessor.batchCumulate
  • Meter.createObservableGauge
  • Meter.createObservableCounter
  • Meter.createObservableUpDownCounter

Checklist:

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

@codecov
Copy link

codecov bot commented Dec 22, 2021

Codecov Report

Merging #2686 (4774f09) into main (395fb04) will increase coverage by 0.17%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #2686      +/-   ##
==========================================
+ Coverage   93.04%   93.22%   +0.17%     
==========================================
  Files         155      157       +2     
  Lines        5378     5432      +54     
  Branches     1137     1141       +4     
==========================================
+ Hits         5004     5064      +60     
+ Misses        374      368       -6     
Impacted Files Coverage Δ
...pentelemetry-sdk-metrics-base/src/state/HashMap.ts 100.00% <0.00%> (ø)
...ry-sdk-metrics-base/src/state/SyncMetricStorage.ts 100.00% <0.00%> (ø)
...y-sdk-metrics-base/src/view/AttributesProcessor.ts 100.00% <0.00%> (ø)
...sdk-metrics-base/src/state/DeltaMetricProcessor.ts 100.00% <0.00%> (ø)
...telemetry-sdk-metrics-base/src/ObservableResult.ts 100.00% <0.00%> (ø)
...y-sdk-metrics-base/src/state/AsyncMetricStorage.ts 100.00% <0.00%> (ø)
...ckages/opentelemetry-sdk-metrics-base/src/Meter.ts 94.11% <0.00%> (+15.54%) ⬆️

# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/src/Meter.ts
@legendecas legendecas marked this pull request as ready for review December 29, 2021 15:53
@legendecas legendecas requested a review from a team December 29, 2021 15:53
@legendecas
Copy link
Member Author

This PR is ready for review :)

Copy link
Member

@vmarchaud vmarchaud left a comment

Choose a reason for hiding this comment

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

overall looks good (again i'm no export in the metrics spec so i encourage more people to review this)

): Promise<Maybe<MetricData>> {
const observableResult = new ObservableResult();
// TODO: timeout with callback
await this._callback(observableResult);
Copy link
Member

Choose a reason for hiding this comment

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

Will the timeout be added in a follow-up PR? callWithTimeout() is available in utils.ts, however I'm not too sure what an appropriate timeout would be. 🤔 I checked the Java SDK and it does not seem like they handle timeouts there.

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'd believe so. Since MetricReader.collect already has a timeout option, I'd believe the timeout should be applied on async metric observations, as the timeout is not reasonable for synchronous instrumentation in JavaScript (we can't cancel or interrupt sync operations with pure JavaScript) and other parts of a collection (they are all synchronous).

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good!

export class ObservableResult implements metrics.ObservableResult {
buffer = new AttributeHashMap<number>();

observe(value: number, attributes: metrics.Attributes = {}): void {
Copy link
Member

Choose a reason for hiding this comment

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

Should we document that if more than one measurement with same attributes is observed in one collection cycle then last one is kept?

Copy link
Member Author

Choose a reason for hiding this comment

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

Submitted: #2712

@legendecas legendecas merged commit 1577f35 into open-telemetry:main Jan 19, 2022
@legendecas legendecas deleted the metrics-ff/async-instruments branch January 19, 2022 15:31
@dyladan dyladan added the enhancement New feature or request label Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants