Skip to content

Commit

Permalink
chore: rename meaure to value recorder (open-telemetry#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent 9a5fbe4 commit ff04606
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
12 changes: 6 additions & 6 deletions 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 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 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 @@ -128,9 +128,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
22 changes: 12 additions & 10 deletions 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 @@ -36,12 +36,12 @@ export class NoopMeter implements Meter {
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 @@ -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,9 @@ 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();
19 changes: 11 additions & 8 deletions api/test/noop-implementations/noop-meter.test.ts
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,23 @@ 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

0 comments on commit ff04606

Please sign in to comment.