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): hoist async instrument callback invocations #2822

Merged
merged 8 commits into from
May 6, 2022

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Mar 8, 2022

Which problem is this PR solving?

This PR add support for the spe changes introduced in open-telemetry/opentelemetry-specification#2361.

Blocked on:

Fixes #2782

Short description of the changes

  • Add ObservableRegistry to call all async callbacks at once.
  • All async callbacks are called before collecting synchronous instruments.
  • Add support for registering multiple async callbacks to one single async instrument.
  • Fix callbacks associated with one instrument may be invoked multiple times when the instrument is mapped with views to multiple metrics.
  • MetricStorage.collect no longer invokes async callbacks so it is marked as synchronous methods.

Type of change

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

How Has This Been Tested?

  • MeterSharedState.collect on async instruments

Checklist:

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

@codecov
Copy link

codecov bot commented Mar 8, 2022

Codecov Report

Merging #2822 (482a74f) into main (d98548b) will increase coverage by 0.12%.
The diff coverage is 95.65%.

@@            Coverage Diff             @@
##             main    #2822      +/-   ##
==========================================
+ Coverage   92.88%   93.01%   +0.12%     
==========================================
  Files         182      183       +1     
  Lines        5906     5909       +3     
  Branches     1253     1254       +1     
==========================================
+ Hits         5486     5496      +10     
+ Misses        420      413       -7     
Impacted Files Coverage Δ
...emetry-sdk-metrics-base/src/state/MetricStorage.ts 100.00% <ø> (ø)
...ry-sdk-metrics-base/src/state/SyncMetricStorage.ts 100.00% <ø> (+21.05%) ⬆️
...try-sdk-metrics-base/src/state/MeterSharedState.ts 97.50% <88.88%> (-2.50%) ⬇️
...y-sdk-metrics-base/src/state/AsyncMetricStorage.ts 100.00% <100.00%> (+14.81%) ⬆️
...y-sdk-metrics-base/src/state/ObservableRegistry.ts 100.00% <100.00%> (ø)

@legendecas legendecas force-pushed the metrics-ff/callback branch from 89c0ecd to 0cc471f Compare April 18, 2022 09:05
@dyladan
Copy link
Member

dyladan commented Apr 18, 2022

Does this depend on another PR?

@legendecas
Copy link
Member Author

@dyladan: Does this depend on another PR?

It depends on one statement in open-telemetry/opentelemetry-specification#2363:

Every currently registered Callback associated with an instrument MUST
be evaluted exactly once during collection prior to reading data for
that instrument.

# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/src/state/MeterSharedState.ts
@legendecas
Copy link
Member Author

However, I think the depended statement in open-telemetry/opentelemetry-specification#2363 is unlikely to change (as the spec PR is mainly focused on multi-instrument callbacks). To get async instruments to work correctly with views, the problem that callbacks associated with one instrument are invoked multiple times during a single collection is outstanding and needs to be fixed by this PR.

Maybe we should proceed with this PR?

@dyladan
Copy link
Member

dyladan commented Apr 21, 2022

However, I think the depended statement in open-telemetry/opentelemetry-specification#2363 is unlikely to change (as the spec PR is mainly focused on multi-instrument callbacks). To get async instruments to work correctly with views, the problem that callbacks associated with one instrument are invoked multiple times during a single collection is outstanding and needs to be fixed by this PR.

Maybe we should proceed with this PR?

I would proceed with it. I agree the statement is unlikely to change. Even if it does change, it is unlikely to become a complete contradiction and they would likely only tweak wording.

@legendecas legendecas marked this pull request as ready for review April 21, 2022 13:57
@legendecas legendecas requested a review from a team April 21, 2022 13:57
@legendecas legendecas changed the title refactor(sdk-metrics-base): add ObservableRegistry and hoist invocations feat(sdk-metrics-base): add ObservableRegistry and hoist invocations Apr 21, 2022
@legendecas legendecas changed the title feat(sdk-metrics-base): add ObservableRegistry and hoist invocations feat(sdk-metrics-base): hoist async instrument callback invocations Apr 21, 2022
@legendecas
Copy link
Member Author

legendecas commented Apr 25, 2022

@open-telemetry/javascript-approvers this is ready for review, PTAL, thank you :D

# Conflicts:
#	experimental/packages/opentelemetry-sdk-metrics-base/test/state/MetricStorageRegistry.test.ts
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.

lgtm, do you expect to tackle the timeout part afterwards ? Since its not a hard requirement on the spec part

@legendecas
Copy link
Member Author

@vmarchaud I'm not sure which timeout you are referring to. #2742 is expected to provide async observer timeout support properly.

@vmarchaud
Copy link
Member

I'm not sure which timeout you are referring to. #2742 is expected to provide async observer timeout support properly.

I didn't see this PR sorry

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

LGTM

@legendecas legendecas force-pushed the metrics-ff/callback branch from 4e8c364 to 482a74f Compare May 6, 2022 03:39
@legendecas legendecas merged commit 772e659 into open-telemetry:main May 6, 2022
@legendecas legendecas deleted the metrics-ff/callback branch May 6, 2022 13:13
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.

Define reentrant safety of JavaScript Metrics API callbacks
3 participants