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

fix: updates ValueRecorder to allow negative values #1373

Merged

Conversation

michaelgoin
Copy link
Contributor

Which problem is this PR solving?

Short description of the changes

  • Removes absolute check for ValueRecorder to allow negative values
  • Removes absolute configuration since no-longer has a valid use
  • Removes unused record(..., correlationContext, spanContext) signature(s)

@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #1373 into master will increase coverage by 0.09%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##           master    #1373      +/-   ##
==========================================
+ Coverage   93.99%   94.09%   +0.09%     
==========================================
  Files         153      153              
  Lines        4666     4656      -10     
  Branches      963      959       -4     
==========================================
- Hits         4386     4381       -5     
+ Misses        280      275       -5     
Impacted Files Coverage Δ
packages/opentelemetry-api/src/metrics/Metric.ts 100.00% <ø> (ø)
packages/opentelemetry-metrics/src/Meter.ts 96.00% <ø> (ø)
...s/opentelemetry-metrics/src/ValueRecorderMetric.ts 100.00% <ø> (ø)
packages/opentelemetry-metrics/src/types.ts 100.00% <ø> (ø)
...ackages/opentelemetry-api/src/metrics/NoopMeter.ts 87.69% <50.00%> (+6.26%) ⬆️
...kages/opentelemetry-metrics/src/BoundInstrument.ts 100.00% <100.00%> (ø)

correlationContext?: api.CorrelationContext,
spanContext?: api.SpanContext
): void {
if (this._absolute && value < 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the critical crux of the change.

Comment on lines -40 to -45
record(value: number, correlationContext: CorrelationContext): void;
record(
value: number,
correlationContext: CorrelationContext,
spanContext: SpanContext
): void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These signatures appeared completely unused. When get to the BoundValueRecorder they were just ignored, so I removed them. Have an open question in Gitter but figured I'd start with removing and can always add back if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

I believe these signatures came from the spec, but the spec on what to do with the correlations/span context was never finished.

Copy link
Contributor Author

@michaelgoin michaelgoin Aug 4, 2020

Choose a reason for hiding this comment

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

Ah, interesting. Feels like these should be left out until that is known but obviously I am new to the project and may not understand all the impacts.

I couldn't find any current usages. May be some usages in the wild outside of these repos (js/contrib) but we are also < 1.0 so figured was OK to have a breaking change to clean-up at this point.

* (Measure only, default true) Asserts that this metric will only accept
* non-negative values (e.g. disk usage).
*/
absolute?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ValueRecorder was the only thing using absolute that I could find. Via #1241 it seems like that should not be configurable. As such, seemed natural to rip out while in here.

const boundValueRecorder = valueRecorder.bind(labels);
boundValueRecorder.record(-10);
boundValueRecorder.record(10);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This diff makes things confusing but that test case was not touched, its just a shifting of code.

});

it(
'should accept negative (and positive) values when absolute is set' +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test case was modified to not pass any value for 'absolute' and then use existing assertions to assert both positive and negative values are accepted.

@michaelgoin
Copy link
Contributor Author

I think codecov is mad at me for deleting too much covered code? 🤷

Copy link
Contributor

@lykkin lykkin left a comment

Choose a reason for hiding this comment

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

LGTM

Looks like the context parameters to the record method weren't being tested, so I think it's fine to remove them. They can always be readded when the associated functionality is built out.

@dyladan
Copy link
Member

dyladan commented Aug 4, 2020

Haha actually it's mad because only 75% of lines you added are tested. Since you mostly deleted and only added a very small number of lines, it is saying you only tested 75% of the diff, even though you increased total project coverage by 0.07%.

@michaelgoin
Copy link
Contributor Author

I believe the only actual new non-test code I added was appropriately referencing the api.BoundBaseObserver for the BoundObserver so not currently planning to try to get that codecov to pass but let me know if I need to try to force it to be happy.

Also, the related issue is flagged as required for GA so not sure if you want to flag this PR or not for the project board but figured I'd mention.

Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm, but indeed the way it is shown in git it suggests you have swapped 2 tests :)

Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

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

LGTM

@michaelgoin
Copy link
Contributor Author

@dyladan merged in master. think this has the necessary approvals now (2 maintainers, 3 total reviewers)

@dyladan dyladan added the bug Something isn't working label Aug 28, 2020
@obecny obecny merged commit cb6555a into open-telemetry:master Aug 31, 2020
@michaelgoin michaelgoin deleted the allow-value-recorder-negative-values branch August 31, 2020 23:03
dyladan pushed a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
dyladan pushed a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants