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

skeleton(metrics): createMeasure #563

Merged

Conversation

markwolff
Copy link
Member

@markwolff markwolff commented Nov 22, 2019

Which problem is this PR solving?

Short description of the changes

  • Skeleton implementation of createMeasure

TODOs

  • Implement data handling (histogramming, etc) for Measure.record (separate PR)

@codecov-io
Copy link

codecov-io commented Nov 22, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9a67900). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff            @@
##             master     #563   +/-   ##
=========================================
  Coverage          ?   91.08%           
=========================================
  Files             ?      231           
  Lines             ?    10474           
  Branches          ?      968           
=========================================
  Hits              ?     9540           
  Misses            ?      934           
  Partials          ?        0
Impacted Files Coverage Δ
...metry-core/src/trace/instrumentation/BasePlugin.ts 86.84% <ø> (ø)
...ry-plugin-dns/test/functionals/dns-disable.test.ts 100% <ø> (ø)
packages/opentelemetry-api/src/trace/status.ts 100% <ø> (ø)
...entelemetry-exporter-jaeger/test/transform.test.ts 100% <ø> (ø)
...telemetry-plugin-document-load/src/documentLoad.ts 97.95% <ø> (ø)
...s/opentelemetry-plugin-xml-http-request/src/xhr.ts 79.41% <ø> (ø)
...lugin-https/test/functionals/https-disable.test.ts 100% <ø> (ø)
...s/opentelemetry-metrics/test/MeterProvider.test.ts 100% <ø> (ø)
...ges/opentelemetry-exporter-zipkin/src/transform.ts 100% <ø> (ø)
...metry-core/src/trace/sampler/ProbabilitySampler.ts 100% <ø> (ø)
... and 125 more

@@ -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;
Copy link
Member

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.

Copy link
Member Author

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"

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@dyladan dyladan Nov 23, 2019

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

Copy link
Member

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.

Copy link
Member

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)

packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
: MetricDescriptorType.GAUGE_INT64
);

this._absolute = options.absolute !== undefined ? options.absolute : true; // Absolute default is true
Copy link
Member

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.

packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
@@ -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;
Copy link
Member

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)

packages/opentelemetry-metrics/src/types.ts Outdated Show resolved Hide resolved
packages/opentelemetry-types/src/metrics/Metric.ts Outdated Show resolved Hide resolved
@markwolff markwolff changed the title feat(metrics): Implement createMeasure skeleton(metrics): createMeasure Jan 2, 2020
@@ -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,
Copy link
Member

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

Copy link
Member Author

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);
Copy link
Contributor

@xiao-lix xiao-lix Jan 28, 2020

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member

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'> {
Copy link
Member

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.

Copy link
Member

@dyladan dyladan Jan 29, 2020

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?

Copy link
Member

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.

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

lgtm

@mayurkale22 mayurkale22 added Merge:LGTM This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.) and removed Awaiting reviewer feedback labels Feb 3, 2020
@mayurkale22 mayurkale22 merged commit 470fc62 into open-telemetry:master Feb 5, 2020
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
* 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]>
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge:LGTM This PR is ready to be merged by a Maintainer (has enough valid approvals, successful build, etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Metrics) Implement "createMeasure"
6 participants