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

chore: rename meaure to value recorder #1117

Merged
merged 5 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/opentelemetry-api/src/metrics/BoundInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export interface BoundCounter {
add(value: number): void;
}

/** Measure to report instantaneous measurement of a value. */
export interface BoundMeasure {
/** ValueRecorder to report instantaneous measurement of a value. */
export interface BoundValueRecorder {
/**
* Records the given value to this measure.
* @param value the measurement to record.
* Records the given value to this value recorder.
* @param value to record.
* @param correlationContext the correlationContext associated with the
* measurements.
* values.
* @param spanContext the {@link SpanContext} that identifies the {@link Span}
* for which the measurements are associated with.
* which the values are associated with.
*/
record(value: number): void;
record(value: number, correlationContext: CorrelationContext): void;
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-api/src/metrics/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* limitations under the License.
*/

import { MetricOptions, Counter, Measure, Observer } from './Metric';
import { MetricOptions, Counter, ValueRecorder, Observer } from './Metric';

/**
* An interface to allow the recording metrics.
*
* {@link Metric}s are used for recording pre-defined aggregation (`Counter`),
* or raw values (`Measure`) in which the aggregation and labels
* or raw values (`ValueRecorder`) in which the aggregation and labels
* for the exported metric are deferred.
*/
export interface Meter {
/**
* Creates and returns a new `Measure`.
* Creates and returns a new `ValueRecorder`.
* @param name the name of the metric.
* @param [options] the metric options.
*/
createMeasure(name: string, options?: MetricOptions): Measure;
createValueRecorder(name: string, options?: MetricOptions): ValueRecorder;

/**
* Creates a new `Counter` metric. Generally, this kind of metric when the
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-api/src/metrics/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { CorrelationContext } from '../correlation_context/CorrelationContext';
import { SpanContext } from '../trace/span_context';
import { ObserverResult } from './ObserverResult';
import { BoundCounter, BoundMeasure } from './BoundInstrument';
import { BoundCounter, BoundValueRecorder } from './BoundInstrument';

/**
* Options needed for metric creation
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface MetricOptions {
monotonic?: boolean;

/**
* (Measure only, default true) Asserts that this metric will only accept
* (ValueRecorder only, default true) Asserts that this metric will only accept
* non-negative values (e.g. disk usage).
*/
absolute?: boolean;
Expand Down Expand Up @@ -113,9 +113,9 @@ export interface Counter extends UnboundMetric<BoundCounter> {
add(value: number, labels?: Labels): void;
}

export interface Measure extends UnboundMetric<BoundMeasure> {
export interface ValueRecorder extends UnboundMetric<BoundValueRecorder> {
/**
* Records the given value to this measure.
* Records the given value to this value recorder.
*/
record(value: number, labels?: Labels): void;

Expand Down
24 changes: 12 additions & 12 deletions packages/opentelemetry-api/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import {
UnboundMetric,
Labels,
Counter,
Measure,
ValueRecorder,
Observer,
} from './Metric';
import { BoundMeasure, BoundCounter } from './BoundInstrument';
import { BoundValueRecorder, BoundCounter } from './BoundInstrument';
import { CorrelationContext } from '../correlation_context/CorrelationContext';
import { SpanContext } from '../trace/span_context';
import { ObserverResult } from './ObserverResult';
Expand All @@ -33,15 +33,15 @@ import { ObserverResult } from './ObserverResult';
* constant NoopMetrics for all of its methods.
*/
export class NoopMeter implements Meter {
constructor() {}
constructor() { }

/**
* Returns constant noop measure.
* Returns constant noop value recorder.
* @param name the name of the metric.
* @param [options] the metric options.
*/
createMeasure(name: string, options?: MetricOptions): Measure {
return NOOP_MEASURE_METRIC;
createValueRecorder(name: string, options?: MetricOptions): ValueRecorder {
return NOOP_VALUE_RECORDER_METRIC;
}

/**
Expand Down Expand Up @@ -103,8 +103,8 @@ export class NoopCounterMetric extends NoopMetric<BoundCounter>
}
}

export class NoopMeasureMetric extends NoopMetric<BoundMeasure>
implements Measure {
export class NoopValueRecorderMetric extends NoopMetric<BoundValueRecorder>
implements ValueRecorder {
record(
value: number,
labels: Labels,
Expand All @@ -122,7 +122,7 @@ export class NoopMeasureMetric extends NoopMetric<BoundMeasure>
}

export class NoopObserverMetric extends NoopMetric<void> implements Observer {
setCallback(callback: (observerResult: ObserverResult) => void): void {}
setCallback(callback: (observerResult: ObserverResult) => void): void { }
}

export class NoopBoundCounter implements BoundCounter {
Expand All @@ -131,7 +131,7 @@ export class NoopBoundCounter implements BoundCounter {
}
}

export class NoopBoundMeasure implements BoundMeasure {
export class NoopBoundValueRecorder implements BoundValueRecorder {
record(
value: number,
correlationContext?: CorrelationContext,
Expand All @@ -145,7 +145,7 @@ export const NOOP_METER = new NoopMeter();
export const NOOP_BOUND_COUNTER = new NoopBoundCounter();
export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_BOUND_COUNTER);

export const NOOP_BOUND_MEASURE = new NoopBoundMeasure();
export const NOOP_MEASURE_METRIC = new NoopMeasureMetric(NOOP_BOUND_MEASURE);
export const NOOP_BOUND_VALUE_RECORDER = new NoopBoundValueRecorder();
export const NOOP_VALUE_RECORDER_METRIC = new NoopValueRecorderMetric(NOOP_BOUND_VALUE_RECORDER);

export const NOOP_OBSERVER_METRIC = new NoopObserverMetric();
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import * as assert from 'assert';
import {
NoopMeterProvider,
NOOP_BOUND_COUNTER,
NOOP_BOUND_MEASURE,
NOOP_BOUND_VALUE_RECORDER,
NOOP_COUNTER_METRIC,
NOOP_MEASURE_METRIC,
NOOP_VALUE_RECORDER_METRIC,
} from '../../src';

describe('NoopMeter', () => {
Expand All @@ -38,20 +38,20 @@ describe('NoopMeter', () => {
assert.strictEqual(counter.bind(labels), NOOP_BOUND_COUNTER);
counter.clear();

const measure = meter.createMeasure('some-name');
measure.bind(labels).record(1);
const valueRecorder = meter.createValueRecorder('some-name');
valueRecorder.bind(labels).record(1);

// ensure the correct noop const is returned
assert.strictEqual(measure, NOOP_MEASURE_METRIC);
assert.strictEqual(measure.bind(labels), NOOP_BOUND_MEASURE);
assert.strictEqual(valueRecorder, NOOP_VALUE_RECORDER_METRIC);
assert.strictEqual(valueRecorder.bind(labels), NOOP_BOUND_VALUE_RECORDER);

const options = {
component: 'tests',
description: 'the testing package',
};

const measureWithOptions = meter.createMeasure('some-name', options);
assert.strictEqual(measureWithOptions, NOOP_MEASURE_METRIC);
const valueRecorderWithOptions = meter.createValueRecorder('some-name', options);
assert.strictEqual(valueRecorderWithOptions, NOOP_VALUE_RECORDER_METRIC);
const counterWithOptions = meter.createCounter('some-name', options);
assert.strictEqual(counterWithOptions, NOOP_COUNTER_METRIC);
});
Expand Down
7 changes: 5 additions & 2 deletions packages/opentelemetry-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ setInterval(()=> {

See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/master/examples/prometheus) for a short example.

### Measure
***Work in progress***
### Value Recorder

`ValueRecorder` is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative.
Values captured by `ValueRecorder.record(value)` are treated as individual events belonging to a distribution that is being summarized.
`ValueRecorder` should be chosen either when capturing measurements that do not contribute meaningfully to a sum, or when capturing numbers that are additive in nature, but where the distribution of individual increments is considered interesting.

## Useful links
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
8 changes: 4 additions & 4 deletions packages/opentelemetry-metrics/src/BoundInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ export class BoundCounter extends BaseBoundInstrument
}

/**
* BoundMeasure is an implementation of the {@link BoundMeasure} interface.
* BoundValueRecorder is an implementation of the {@link BoundValueRecorder} interface.
*/
export class BoundMeasure extends BaseBoundInstrument
implements api.BoundMeasure {
export class BoundValueRecorder extends BaseBoundInstrument
implements api.BoundValueRecorder {
private readonly _absolute: boolean;

constructor(
Expand All @@ -119,7 +119,7 @@ export class BoundMeasure extends BaseBoundInstrument
): void {
if (this._absolute && value < 0) {
this._logger.error(
`Absolute measure cannot contain negative values for $${Object.values(
`Absolute ValueRecorder cannot contain negative values for $${Object.values(
this._labels
)}`
);
Expand Down
18 changes: 9 additions & 9 deletions packages/opentelemetry-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as api from '@opentelemetry/api';
import { ConsoleLogger } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { BaseBoundInstrument } from './BoundInstrument';
import { Metric, CounterMetric, MeasureMetric, ObserverMetric } from './Metric';
import { Metric, CounterMetric, ValueRecorderMetric, ObserverMetric } from './Metric';
import {
MetricOptions,
DEFAULT_METRIC_OPTIONS,
Expand Down Expand Up @@ -52,28 +52,28 @@ export class Meter implements api.Meter {
}

/**
* Creates and returns a new {@link Measure}.
* Creates and returns a new {@link ValueRecorder}.
* @param name the name of the metric.
* @param [options] the metric options.
*/
createMeasure(name: string, options?: api.MetricOptions): api.Measure {
createValueRecorder(name: string, options?: api.MetricOptions): api.ValueRecorder {
if (!this._isValidName(name)) {
this._logger.warn(
`Invalid metric name ${name}. Defaulting to noop metric implementation.`
);
return api.NOOP_MEASURE_METRIC;
return api.NOOP_VALUE_RECORDER_METRIC;
}
const opt: MetricOptions = {
absolute: true, // Measures are defined as absolute by default
monotonic: false, // not applicable to measure, set to false
absolute: true, // value recorders are defined as absolute by default
monotonic: false, // not applicable to value recorder, set to false
logger: this._logger,
...DEFAULT_METRIC_OPTIONS,
...options,
};

const measure = new MeasureMetric(name, opt, this._batcher, this._resource);
this._registerMetric(name, measure);
return measure;
const valueRecorder = new ValueRecorderMetric(name, opt, this._batcher, this._resource);
this._registerMetric(name, valueRecorder);
return valueRecorder;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions packages/opentelemetry-metrics/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Resource } from '@opentelemetry/resources';
import {
BoundCounter,
BaseBoundInstrument,
BoundMeasure,
BoundValueRecorder,
BoundObserver,
} from './BoundInstrument';
import { ObserverResult } from './ObserverResult';
Expand Down Expand Up @@ -139,7 +139,7 @@ export class CounterMetric extends Metric<BoundCounter> implements api.Counter {
}
}

export class MeasureMetric extends Metric<BoundMeasure> implements api.Measure {
export class ValueRecorderMetric extends Metric<BoundValueRecorder> implements api.ValueRecorder {
protected readonly _absolute: boolean;

constructor(
Expand All @@ -148,12 +148,12 @@ export class MeasureMetric extends Metric<BoundMeasure> implements api.Measure {
private readonly _batcher: Batcher,
resource: Resource
) {
super(name, options, MetricKind.MEASURE, resource);
super(name, options, MetricKind.VALUE_RECORDER, resource);

this._absolute = options.absolute !== undefined ? options.absolute : true; // Absolute default is true
}
protected _makeInstrument(labels: api.Labels): BoundMeasure {
return new BoundMeasure(
protected _makeInstrument(labels: api.Labels): BoundValueRecorder {
return new BoundValueRecorder(
labels,
this._disabled,
this._monotonic,
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-metrics/src/export/Batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
CounterSumAggregator,
MeasureExactAggregator,
ValueRecorderExactAggregator,
ObserverAggregator,
} from './aggregators';
import {
Expand Down Expand Up @@ -59,7 +59,7 @@ export class UngroupedBatcher extends Batcher {
case MetricKind.OBSERVER:
return new ObserverAggregator();
default:
return new MeasureExactAggregator();
return new ValueRecorderExactAggregator();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { hrTime } from '@opentelemetry/core';
import { Distribution } from '../types';

/** Basic aggregator keeping all raw values (events, sum, max and min). */
export class MeasureExactAggregator implements Aggregator {
export class ValueRecorderExactAggregator implements Aggregator {
private _distribution: Distribution;
private _lastUpdateTime: HrTime = [0, 0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

export * from './countersum';
export * from './observer';
export * from './measureexact';
export * from './ValueRecorderExact';
export * from './histogram';
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/src/export/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Resource } from '@opentelemetry/resources';
/** The kind of metric. */
export enum MetricKind {
COUNTER,
MEASURE,
VALUE_RECORDER,
OBSERVER,
}

Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface MetricOptions {
/** Monotonic metrics may only increase. */
monotonic: boolean;

/** (Measure only) Asserts that this metric will only accept non-negative values. */
/** (ValueRecorder only) Asserts that this metric will only accept non-negative values. */
absolute: boolean;

/** User provided logger. */
Expand Down
Loading