-
Notifications
You must be signed in to change notification settings - Fork 842
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
skeleton(metrics): createMeasure #563
skeleton(metrics): createMeasure #563
Conversation
@@ -40,6 +40,9 @@ export interface MetricOptions { | |||
/** Monotonic allows this metric to accept negative values. */ | |||
monotonic: boolean; | |||
|
|||
/** (Measure only) Absolute asserts that this metric will only accept positive values. Default true */ | |||
absolute?: boolean; |
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.
For me, monotonic
and absolute
flags looks almost the same.
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 agree. Even though the spec calls for absolute
for measures, I wonder if it should be proposed to reuse the same config name for all metrics? The only difference between them is that their effects are "reversed"
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 should open issue against specs and ask for clarification. It is highly encouraged to escalate issues on top level. WDYT?
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.
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.
IMO absolute and monotonic don't mean the same thing at all. absolute means non-negative, monotonic means only counts up. An absolute, non monotonic measure may measure something like disk usage which can go up and down but never be below zero.
edit: also made this comment the issue you created
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.
@markwolff can you add the @dyladan explanation into the jsdoc? Currently both descriptions sounds similar for me and it is hard to understand the difference between them.
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.
Per spec open-telemetry/opentelemetry-specification#364 we will keep absolute
and monotonic
as they mean different things.
Suggest JSDoc:
- Absolute: Asserts that this metric may only have a positive value (e.g. disk usage)
- Monotonic: Asserts that this metric may only increase (e.g. time spent)
: MetricDescriptorType.GAUGE_INT64 | ||
); | ||
|
||
this._absolute = options.absolute !== undefined ? options.absolute : true; // Absolute default is true |
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.
Another approach, what if we make absolute
as a mandatory attribute in SDK (opentelemetry-metrics/src/types.ts) similar to other attributes. Most of these attributes are optional in opentelemetry-types
but to make life easier, we made it mandatory in the SDK with default values.
@@ -40,6 +40,9 @@ export interface MetricOptions { | |||
/** Monotonic allows this metric to accept negative values. */ | |||
monotonic: boolean; | |||
|
|||
/** (Measure only) Absolute asserts that this metric will only accept positive values. Default true */ | |||
absolute?: boolean; |
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.
Per spec open-telemetry/opentelemetry-specification#364 we will keep absolute
and monotonic
as they mean different things.
Suggest JSDoc:
- Absolute: Asserts that this metric may only have a positive value (e.g. disk usage)
- Monotonic: Asserts that this metric may only increase (e.g. time spent)
@@ -130,12 +130,44 @@ export class GaugeHandle extends BaseHandle implements types.GaugeHandle { | |||
* MeasureHandle is an implementation of the {@link MeasureHandle} interface. | |||
*/ | |||
export class MeasureHandle extends BaseHandle implements types.MeasureHandle { | |||
constructor( | |||
labelSet: types.LabelSet, | |||
private readonly _disabled: boolean, |
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.
if something is readonly and disabled, is there no way to enable it? How is this different than noop
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.
It seems like it is just a way for sdk to create noop handles via ctor, but I'm not sure if there are any benefits to it over just having NoopHandle
or something else. It is a lot less code with just _disabled
! Maybe @mayurkale22 would know?
describe('.bind()', () => { | ||
it('should create a measure handle', () => { | ||
const measure = meter.createMeasure('name') as MeasureMetric; | ||
const handle = measure.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.
nit: update name handle
to bind
?
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 boundMeasure
would make more sense
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.
@markwolff Could you please fix last round of comments and resolve the conflicts? Looks good to go after that.
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.
Rebased and addressed this comment 8e53f1e
value = Math.trunc(value); | ||
} | ||
|
||
//@todo: implement this._data logic |
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.
Does this need to be done before merge?
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 dont think so, I am gonna update this in my PR(#738) once this is merged.
@@ -199,3 +200,38 @@ export class GaugeMetric extends Metric<BoundGauge> | |||
this.bind(labelSet).set(value); | |||
} | |||
} | |||
|
|||
export class MeasureMetric extends Metric<BoundMeasure> | |||
implements Pick<types.MetricUtils, 'record'> { |
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 in the future, we have to include recordBatch
API, which will provide users a convenient way to add multiple events/measurements once.
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.
Is that in your PR?
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.
No. We can include it later once the initial pipeline is working.
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
* feat: implement createMeasure * fix: linting * fix: disable broken tests * fix: labelSet log statement * fix: absolute always set to true * fix: linting * fix: add jsdoc, adjust optionals * fix: failing tests * fix: linting * refactor: rename test handle var Co-authored-by: Mayur Kale <[email protected]>
Which problem is this PR solving?
Short description of the changes
createMeasure
TODOs
Measure.record
(separate PR)