Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

feat: Allow users to register the same Meter multiple times without exception #2017

Merged
merged 3 commits into from Mar 10, 2020
Merged

feat: Allow users to register the same Meter multiple times without exception #2017

merged 3 commits into from Mar 10, 2020

Conversation

mayurkale22
Copy link
Member

No description provided.

@codecov-io
Copy link

codecov-io commented Mar 9, 2020

Codecov Report

Merging #2017 into master will increase coverage by <.01%.
The diff coverage is 55%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2017      +/-   ##
============================================
+ Coverage     83.11%   83.11%   +<.01%     
- Complexity     2249     2252       +3     
============================================
  Files           319      319              
  Lines         10527    10529       +2     
  Branches       1047     1048       +1     
============================================
+ Hits           8749     8751       +2     
- Misses         1438     1440       +2     
+ Partials        340      338       -2
Impacted Files Coverage Δ Complexity Δ
...ensus/implcore/metrics/DerivedDoubleGaugeImpl.java 94.91% <0%> (-1.64%) 11 <0> (ø)
...us/implcore/metrics/DerivedLongCumulativeImpl.java 95.45% <0%> (-1.47%) 11 <0> (ø)
...ncensus/implcore/metrics/DoubleCumulativeImpl.java 93.33% <0%> (-1.27%) 16 <0> (ø)
...ncensus/implcore/metrics/DerivedLongGaugeImpl.java 91.52% <0%> (-1.58%) 10 <0> (ø)
...pencensus/implcore/metrics/LongCumulativeImpl.java 93.33% <0%> (-1.27%) 16 <0> (ø)
.../implcore/metrics/DerivedDoubleCumulativeImpl.java 95.45% <0%> (-1.47%) 11 <0> (ø)
...o/opencensus/implcore/metrics/DoubleGaugeImpl.java 94.44% <100%> (+0.07%) 17 <1> (+1) ⬆️
.../io/opencensus/implcore/metrics/LongGaugeImpl.java 94.44% <100%> (+0.07%) 17 <1> (+1) ⬆️
...pencensus/implcore/metrics/MetricRegistryImpl.java 72.82% <75%> (+1.39%) 7 <0> (ø) ⬇️
...re/trace/export/InProcessSampledSpanStoreImpl.java 96.44% <0%> (+0.59%) 22% <0%> (ø) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6d4cbd...cc9073d. Read the comment docs.

Copy link
Contributor

@rghetia rghetia left a comment

Choose a reason for hiding this comment

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

LGTM except for one minor comment.

@rghetia
Copy link
Contributor

rghetia commented Mar 9, 2020

As discussed, please add test for

m1 = register.AddGauge("g1")
m2 = register.AddGauge("g1")

expect m1 and m2 to be the same.

@mayurkale22
Copy link
Member Author

@rghetia please review and approve when you get a chance, thank you :)

@rghetia rghetia merged commit d2367b0 into census-instrumentation:master Mar 10, 2020
@mayurkale22 mayurkale22 deleted the allow_register_same_metric branch March 10, 2020 23:37
@elharo elharo mentioned this pull request Mar 11, 2020
throw new IllegalArgumentException(
"A different metric with the same name already registered.");
if (!existingMeter.getMetricDescriptor().equals(meter.getMetricDescriptor())) {
throw new IllegalArgumentException(

Choose a reason for hiding this comment

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

(Note, this comment is not relevant for this PR, and is only intended for discussing whether this fix would also fix this specific issue for the Spanner client library).

@mayurkale22 Can you confirm that registering multiple metrics with different label values (but equal label keys) will not go down this code path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you confirm that registering multiple metrics with different label values (but equal label keys) will not go down this code path?

Yes, it is normal to have different label values - those will be represented as individual TimeSeries in the metric. i.e:

Metric:
     {name, label_keys, description, unit, type, ...}
TimeSeries
    [{labels_values1, value1}, {labels_values2, value2}, ...]

See: https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/metrics/export/Metric.java#L51

The exception will be raised only when you use the same metric name but with a different type or unit or label_keys.

Choose a reason for hiding this comment

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

That sounds good 👍 Thanks for looking into this.

I think this fix is better than what I added to the Spanner client library, so I'll close the PR.

The only concern that I still have is what it looks like in the dashboards when there are multiple different instances of a SessionPool with the same label values. I understand that it won't cause any errors in the client library, but how is it presented to the user? This situation would occur when an application is opening two connections to the same database with different SessionPoolOptions. This would also mean different values for constant metrics like MaxSessions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants