-
Notifications
You must be signed in to change notification settings - Fork 851
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
chore: rename Metric Handle to Bound Instrument #638
chore: rename Metric Handle to Bound Instrument #638
Conversation
6aaa73f
to
2836cee
Compare
Codecov Report
@@ Coverage Diff @@
## master #638 +/- ##
=========================================
- Coverage 89.88% 89.68% -0.2%
=========================================
Files 213 212 -1
Lines 10234 10065 -169
Branches 933 935 +2
=========================================
- Hits 9199 9027 -172
- Misses 1035 1038 +3
|
2836cee
to
9e8d389
Compare
9e8d389
to
343294f
Compare
8ba8768
to
df15b31
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going through and commenting on these and I noticed a trend where you renamed handle
=> instrument
which is not accurate. All metrics are instruments even if they are not bound. The renaming that should have been done was handle
to boundInstrument
or binding
depending on context.
getting-started/README.md
Outdated
const labelSet = meter.labels({ route: req.path }); | ||
const handle = requestCount.getHandle(labelSet); | ||
handles.set(req.path, handle); | ||
const instrument = requestCount.bind(labelSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this boundInstrument
and the map boundInstruments
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about boundCounter
and the map boundInstruments
?
getting-started/README.md
Outdated
@@ -253,7 +253,7 @@ app.use(countAllRequests()); | |||
|
|||
Now, when we make requests to our service our meter will count all requests. | |||
|
|||
**Note**: Creating a new `labelSet` and `handle` on every request is not ideal as creating the `labelSet` can often be an expensive operation. This is why handles are created and stored in a `Map` according to the route key. | |||
**Note**: Creating a new `labelSet` and `instrument` on every request is not ideal as creating the `labelSet` can often be an expensive operation. This is why instruments are created and stored in a `Map` according to the route key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Note**: Creating a new `labelSet` and `instrument` on every request is not ideal as creating the `labelSet` can often be an expensive operation. This is why instruments are created and stored in a `Map` according to the route key. | |
**Note**: Creating a new `labelSet` and `binding` on every request is not ideal as creating the `labelSet` can often be an expensive operation. This is why bound instruments are created and stored in a `Map` according to the route key. |
getting-started/README.md
Outdated
const labelSet = meter.labels({ route: req.path }); | ||
const handle = requestCount.getHandle(labelSet); | ||
handles.set(req.path, handle); | ||
const instrument = requestCount.bind(labelSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls rename boundInstrument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boundCounter
?
const labelSet = meter.labels({ route: req.path }); | ||
const handle = requestCount.getHandle(labelSet); | ||
handles.set(req.path, handle); | ||
const instrument = requestCount.bind(labelSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls rename boundInstrument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boundCounter
?
/** A Handle for Counter Metric. */ | ||
export interface CounterHandle { | ||
/** An Instrument for Counter Metric. */ | ||
export interface CounterInstrument { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would rather call this something like BoundCounter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll also rename the others to BoundGauge
and BoundMeasure
} | ||
|
||
/** | ||
* Removes the Handle from the metric, if it is present. | ||
* @param labels the canonicalized LabelSet used to associate with this metric handle. | ||
* Removes the Instrument from the metric, if it is present. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binding
* Removes the Instrument from the metric, if it is present. | |
* Removes the Binding from the metric, if it is present. |
} | ||
} | ||
} | ||
|
||
export class NoopCounterHandle implements CounterHandle { | ||
export class NoopCounterInstrument implements CounterInstrument { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to call this something like NoopBoundCounter
@@ -165,13 +171,17 @@ export class NoopMeasureHandle implements MeasureHandle { | |||
} | |||
} | |||
|
|||
export const NOOP_GAUGE_HANDLE = new NoopGaugeHandle(); | |||
export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_GAUGE_HANDLE); | |||
export const NOOP_GAUGE_INSTRUMENT = new NoopGaugeInstrument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be named like NOOP_BOUND_GAUGE
|
||
const handle = counter.getHandle(meter.labels({ key1: 'labelValue1' })); | ||
handle.add(10); | ||
const instrument = counter.bind(meter.labels({ key1: 'labelValue1' })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename boundInstrument
Ok good this was my main question that you answered, because I didn't understand the difference between |
df15b31
to
98e9891
Compare
@cthulhu-bot please do not change history on your branch by doing force push until the code review is complete. It makes it hard to track history. |
Sorry i'm used to amending commits and force pushing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* chore: fix renames in metrics test * chore: fix formatting * chore: rename BaseInstrument to BaseBoundInstrument
22e047d
to
bbde5ce
Compare
Last force push was just to squash everything down and rebase on top of the master branch, should be good to go |
@cthulhu-bot i'd like to get more @open-telemetry/javascript-approvers to look at this before moving |
@open-telemetry/javascript-approvers ping, we need more reviews for this one! |
@mayurkale22 how many reviews do you think we need for this? I had hoped @bg451 would have time to look since he wrote the original implementation, but if not I think this is a relatively safe change as I'm not aware of anyone using metrics yet anyways. |
Even I was waiting for @bg451's approval, but make sense to merge it now given that we already have three approvals and relatively safe change. |
Which problem is this PR solving?
Short description of the changes
Updated references of:
handle
->instrument
getHandle
->bind
removeHandle
->unbind
getDefaultHandle
->getDefaultBound
The spec appears to make a distinction between
instrument
andbound instrument
:https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-metrics-user.md#metric-calling-conventions
But I couldn't find any delineation separating these 2 types in this repo. Hence the change of Handle to BoundInstrument and all other subtypes defined as instruments (Counter, Gauge, etc).
Further down it also present the concept of
Binding
as just a method on the individual instrument types: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-metrics-user.md#bound-instrument-apiSo maybe the
BoundInstruments
file in opentelemetry-metrics should be namedInstrument
instead?Please let me know if I missed anything in the rename or renamed something that shouldn't have been.
Thank you!