From b6f9d2ac7bf7b7a4f2aa2848607e5274a047f132 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 2 Jun 2020 10:31:15 -0400 Subject: [PATCH] chore: rename meaure to value recorder (#1117) --- .../src/metrics/BoundInstrument.ts | 12 +- .../opentelemetry-api/src/metrics/Meter.ts | 8 +- .../opentelemetry-api/src/metrics/Metric.ts | 8 +- .../src/metrics/NoopMeter.ts | 22 +-- .../noop-implementations/noop-meter.test.ts | 19 ++- packages/opentelemetry-metrics/README.md | 7 +- .../src/BoundInstrument.ts | 8 +- packages/opentelemetry-metrics/src/Meter.ts | 31 +++- packages/opentelemetry-metrics/src/Metric.ts | 11 +- .../src/export/Batcher.ts | 4 +- ...{measureexact.ts => ValueRecorderExact.ts} | 2 +- .../src/export/aggregators/index.ts | 2 +- .../opentelemetry-metrics/src/export/types.ts | 2 +- packages/opentelemetry-metrics/src/types.ts | 2 +- .../opentelemetry-metrics/test/Meter.test.ts | 158 ++++++++++-------- 15 files changed, 168 insertions(+), 128 deletions(-) rename packages/opentelemetry-metrics/src/export/aggregators/{measureexact.ts => ValueRecorderExact.ts} (95%) diff --git a/packages/opentelemetry-api/src/metrics/BoundInstrument.ts b/packages/opentelemetry-api/src/metrics/BoundInstrument.ts index 07302bd22f..0be696d43a 100644 --- a/packages/opentelemetry-api/src/metrics/BoundInstrument.ts +++ b/packages/opentelemetry-api/src/metrics/BoundInstrument.ts @@ -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; diff --git a/packages/opentelemetry-api/src/metrics/Meter.ts b/packages/opentelemetry-api/src/metrics/Meter.ts index 0b43708c4d..5ed8bbf3a9 100644 --- a/packages/opentelemetry-api/src/metrics/Meter.ts +++ b/packages/opentelemetry-api/src/metrics/Meter.ts @@ -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 diff --git a/packages/opentelemetry-api/src/metrics/Metric.ts b/packages/opentelemetry-api/src/metrics/Metric.ts index 3996e5498b..00d4ef215e 100644 --- a/packages/opentelemetry-api/src/metrics/Metric.ts +++ b/packages/opentelemetry-api/src/metrics/Metric.ts @@ -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 @@ -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; @@ -128,9 +128,9 @@ export interface Counter extends UnboundMetric { add(value: number, labels?: Labels): void; } -export interface Measure extends UnboundMetric { +export interface ValueRecorder extends UnboundMetric { /** - * Records the given value to this measure. + * Records the given value to this value recorder. */ record(value: number, labels?: Labels): void; diff --git a/packages/opentelemetry-api/src/metrics/NoopMeter.ts b/packages/opentelemetry-api/src/metrics/NoopMeter.ts index dcd6a5dea1..eed8c4e9bf 100644 --- a/packages/opentelemetry-api/src/metrics/NoopMeter.ts +++ b/packages/opentelemetry-api/src/metrics/NoopMeter.ts @@ -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'; @@ -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; } /** @@ -103,8 +103,8 @@ export class NoopCounterMetric extends NoopMetric } } -export class NoopMeasureMetric extends NoopMetric - implements Measure { +export class NoopValueRecorderMetric extends NoopMetric + implements ValueRecorder { record( value: number, labels: Labels, @@ -131,7 +131,7 @@ export class NoopBoundCounter implements BoundCounter { } } -export class NoopBoundMeasure implements BoundMeasure { +export class NoopBoundValueRecorder implements BoundValueRecorder { record( value: number, correlationContext?: CorrelationContext, @@ -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(); diff --git a/packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts b/packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts index 7b86f5d59d..8738708eba 100644 --- a/packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts +++ b/packages/opentelemetry-api/test/noop-implementations/noop-meter.test.ts @@ -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', () => { @@ -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); }); diff --git a/packages/opentelemetry-metrics/README.md b/packages/opentelemetry-metrics/README.md index 1de26eab56..340f3ee657 100644 --- a/packages/opentelemetry-metrics/README.md +++ b/packages/opentelemetry-metrics/README.md @@ -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: diff --git a/packages/opentelemetry-metrics/src/BoundInstrument.ts b/packages/opentelemetry-metrics/src/BoundInstrument.ts index d451bcb601..8f660c3722 100644 --- a/packages/opentelemetry-metrics/src/BoundInstrument.ts +++ b/packages/opentelemetry-metrics/src/BoundInstrument.ts @@ -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( @@ -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 )}` ); diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index a13679aeb6..dd760cc5a2 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -18,7 +18,12 @@ 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, @@ -52,28 +57,36 @@ 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; } /** diff --git a/packages/opentelemetry-metrics/src/Metric.ts b/packages/opentelemetry-metrics/src/Metric.ts index 9547d210e3..dd52fd9f3c 100644 --- a/packages/opentelemetry-metrics/src/Metric.ts +++ b/packages/opentelemetry-metrics/src/Metric.ts @@ -19,7 +19,7 @@ import { Resource } from '@opentelemetry/resources'; import { BoundCounter, BaseBoundInstrument, - BoundMeasure, + BoundValueRecorder, BoundObserver, } from './BoundInstrument'; import { ObserverResult } from './ObserverResult'; @@ -139,7 +139,8 @@ export class CounterMetric extends Metric implements api.Counter { } } -export class MeasureMetric extends Metric implements api.Measure { +export class ValueRecorderMetric extends Metric + implements api.ValueRecorder { protected readonly _absolute: boolean; constructor( @@ -148,12 +149,12 @@ export class MeasureMetric extends Metric 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, diff --git a/packages/opentelemetry-metrics/src/export/Batcher.ts b/packages/opentelemetry-metrics/src/export/Batcher.ts index 7b2fbd417f..2bb6eb9d1a 100644 --- a/packages/opentelemetry-metrics/src/export/Batcher.ts +++ b/packages/opentelemetry-metrics/src/export/Batcher.ts @@ -16,7 +16,7 @@ import { CounterSumAggregator, - MeasureExactAggregator, + ValueRecorderExactAggregator, ObserverAggregator, } from './aggregators'; import { @@ -59,7 +59,7 @@ export class UngroupedBatcher extends Batcher { case MetricKind.OBSERVER: return new ObserverAggregator(); default: - return new MeasureExactAggregator(); + return new ValueRecorderExactAggregator(); } } diff --git a/packages/opentelemetry-metrics/src/export/aggregators/measureexact.ts b/packages/opentelemetry-metrics/src/export/aggregators/ValueRecorderExact.ts similarity index 95% rename from packages/opentelemetry-metrics/src/export/aggregators/measureexact.ts rename to packages/opentelemetry-metrics/src/export/aggregators/ValueRecorderExact.ts index abbad0b430..0e70a5792e 100644 --- a/packages/opentelemetry-metrics/src/export/aggregators/measureexact.ts +++ b/packages/opentelemetry-metrics/src/export/aggregators/ValueRecorderExact.ts @@ -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]; diff --git a/packages/opentelemetry-metrics/src/export/aggregators/index.ts b/packages/opentelemetry-metrics/src/export/aggregators/index.ts index 938e1ad6e3..7d1bd01d7d 100644 --- a/packages/opentelemetry-metrics/src/export/aggregators/index.ts +++ b/packages/opentelemetry-metrics/src/export/aggregators/index.ts @@ -16,5 +16,5 @@ export * from './countersum'; export * from './observer'; -export * from './measureexact'; +export * from './ValueRecorderExact'; export * from './histogram'; diff --git a/packages/opentelemetry-metrics/src/export/types.ts b/packages/opentelemetry-metrics/src/export/types.ts index 0fe741905e..8a34a34d1b 100644 --- a/packages/opentelemetry-metrics/src/export/types.ts +++ b/packages/opentelemetry-metrics/src/export/types.ts @@ -21,7 +21,7 @@ import { Resource } from '@opentelemetry/resources'; /** The kind of metric. */ export enum MetricKind { COUNTER, - MEASURE, + VALUE_RECORDER, OBSERVER, } diff --git a/packages/opentelemetry-metrics/src/types.ts b/packages/opentelemetry-metrics/src/types.ts index 8927a80830..b5ba841e68 100644 --- a/packages/opentelemetry-metrics/src/types.ts +++ b/packages/opentelemetry-metrics/src/types.ts @@ -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. */ diff --git a/packages/opentelemetry-metrics/test/Meter.test.ts b/packages/opentelemetry-metrics/test/Meter.test.ts index 5826f09a90..93244aca35 100644 --- a/packages/opentelemetry-metrics/test/Meter.test.ts +++ b/packages/opentelemetry-metrics/test/Meter.test.ts @@ -22,7 +22,7 @@ import { MetricKind, Sum, MeterProvider, - MeasureMetric, + ValueRecorderMetric, Distribution, ObserverMetric, MetricRecord, @@ -268,82 +268,94 @@ describe('Meter', () => { }); }); - describe('#measure', () => { - it('should create a measure', () => { - const measure = meter.createMeasure('name'); - assert.ok(measure instanceof Metric); + describe('#ValueRecorder', () => { + it('should create a valueRecorder', () => { + const valueRecorder = meter.createValueRecorder('name'); + assert.ok(valueRecorder instanceof Metric); }); - it('should create a measure with options', () => { - const measure = meter.createMeasure('name', { + it('should create a valueRecorder with options', () => { + const valueRecorder = meter.createValueRecorder('name', { description: 'desc', unit: '1', disabled: false, }); - assert.ok(measure instanceof Metric); + assert.ok(valueRecorder instanceof Metric); }); it('should be absolute by default', () => { - const measure = meter.createMeasure('name', { + const valueRecorder = meter.createValueRecorder('name', { description: 'desc', unit: '1', disabled: false, }); - assert.strictEqual((measure as MeasureMetric)['_absolute'], true); + assert.strictEqual( + (valueRecorder as ValueRecorderMetric)['_absolute'], + true + ); }); it('should be able to set absolute to false', () => { - const measure = meter.createMeasure('name', { + const valueRecorder = meter.createValueRecorder('name', { description: 'desc', unit: '1', disabled: false, absolute: false, }); - assert.strictEqual((measure as MeasureMetric)['_absolute'], false); + assert.strictEqual( + (valueRecorder as ValueRecorderMetric)['_absolute'], + false + ); }); it('should pipe through resource', () => { - const measure = meter.createMeasure('name') as MeasureMetric; - assert.ok(measure.resource instanceof Resource); + const valueRecorder = meter.createValueRecorder( + 'name' + ) as ValueRecorderMetric; + assert.ok(valueRecorder.resource instanceof Resource); - measure.record(1, { foo: 'bar' }); + valueRecorder.record(1, { foo: 'bar' }); - const [record] = measure.getMetricRecord(); + const [record] = valueRecorder.getMetricRecord(); assert.ok(record.resource instanceof Resource); }); describe('names', () => { it('should return no op metric if name is an empty string', () => { - const measure = meter.createMeasure(''); - assert.ok(measure instanceof api.NoopMetric); + const valueRecorder = meter.createValueRecorder(''); + assert.ok(valueRecorder instanceof api.NoopMetric); }); it('should return no op metric if name does not start with a letter', () => { - const measure1 = meter.createMeasure('1name'); - const measure_ = meter.createMeasure('_name'); - assert.ok(measure1 instanceof api.NoopMetric); - assert.ok(measure_ instanceof api.NoopMetric); + const valueRecorder1 = meter.createValueRecorder('1name'); + const valueRecorder_ = meter.createValueRecorder('_name'); + assert.ok(valueRecorder1 instanceof api.NoopMetric); + assert.ok(valueRecorder_ instanceof api.NoopMetric); }); it('should return no op metric if name is an empty string contain only letters, numbers, ".", "_", and "-"', () => { - const measure = meter.createMeasure('name with invalid characters^&*('); - assert.ok(measure instanceof api.NoopMetric); + const valueRecorder = meter.createValueRecorder( + 'name with invalid characters^&*(' + ); + assert.ok(valueRecorder instanceof api.NoopMetric); }); }); describe('.bind()', () => { const performanceTimeOrigin = hrTime(); - it('should create a measure instrument', () => { - const measure = meter.createMeasure('name') as MeasureMetric; - const boundMeasure = measure.bind(labels); - assert.doesNotThrow(() => boundMeasure.record(10)); + it('should create a valueRecorder instrument', () => { + const valueRecorder = meter.createValueRecorder( + 'name' + ) as ValueRecorderMetric; + const boundValueRecorder = valueRecorder.bind(labels); + assert.doesNotThrow(() => boundValueRecorder.record(10)); }); it('should not accept negative values by default', () => { - const measure = meter.createMeasure('name'); - const boundMeasure = measure.bind(labels); - boundMeasure.record(-10); + const valueRecorder = meter.createValueRecorder('name'); + const boundValueRecorder = valueRecorder.bind(labels); + boundValueRecorder.record(-10); meter.collect(); const [record1] = meter.getBatcher().checkPointSet(); @@ -359,11 +371,11 @@ describe('Meter', () => { }); it('should not set the instrument data when disabled', () => { - const measure = meter.createMeasure('name', { + const valueRecorder = meter.createValueRecorder('name', { disabled: true, - }) as MeasureMetric; - const boundMeasure = measure.bind(labels); - boundMeasure.record(10); + }) as ValueRecorderMetric; + const boundValueRecorder = valueRecorder.bind(labels); + boundValueRecorder.record(10); meter.collect(); const [record1] = meter.getBatcher().checkPointSet(); @@ -379,12 +391,12 @@ describe('Meter', () => { }); it('should accept negative (and positive) values when absolute is set to false', () => { - const measure = meter.createMeasure('name', { + const valueRecorder = meter.createValueRecorder('name', { absolute: false, }); - const boundMeasure = measure.bind(labels); - boundMeasure.record(-10); - boundMeasure.record(50); + const boundValueRecorder = valueRecorder.bind(labels); + boundValueRecorder.record(-10); + boundValueRecorder.record(50); meter.collect(); const [record1] = meter.getBatcher().checkPointSet(); @@ -404,11 +416,13 @@ describe('Meter', () => { }); it('should return same instrument on same label values', () => { - const measure = meter.createMeasure('name') as MeasureMetric; - const boundMeasure1 = measure.bind(labels); - boundMeasure1.record(10); - const boundMeasure2 = measure.bind(labels); - boundMeasure2.record(100); + const valueRecorder = meter.createValueRecorder( + 'name' + ) as ValueRecorderMetric; + const boundValueRecorder1 = valueRecorder.bind(labels); + boundValueRecorder1.record(10); + const boundValueRecorder2 = valueRecorder.bind(labels); + boundValueRecorder2.record(100); meter.collect(); const [record1] = meter.getBatcher().checkPointSet(); assert.deepStrictEqual( @@ -420,54 +434,58 @@ describe('Meter', () => { sum: 110, } ); - assert.strictEqual(boundMeasure1, boundMeasure2); + assert.strictEqual(boundValueRecorder1, boundValueRecorder2); }); }); describe('.unbind()', () => { - it('should remove the measure instrument', () => { - const measure = meter.createMeasure('name') as MeasureMetric; - const boundMeasure = measure.bind(labels); - assert.strictEqual(measure['_instruments'].size, 1); - measure.unbind(labels); - assert.strictEqual(measure['_instruments'].size, 0); - const boundMeasure2 = measure.bind(labels); - assert.strictEqual(measure['_instruments'].size, 1); - assert.notStrictEqual(boundMeasure, boundMeasure2); + it('should remove the valueRecorder instrument', () => { + const valueRecorder = meter.createValueRecorder( + 'name' + ) as ValueRecorderMetric; + const boundValueRecorder = valueRecorder.bind(labels); + assert.strictEqual(valueRecorder['_instruments'].size, 1); + valueRecorder.unbind(labels); + assert.strictEqual(valueRecorder['_instruments'].size, 0); + const boundValueRecorder2 = valueRecorder.bind(labels); + assert.strictEqual(valueRecorder['_instruments'].size, 1); + assert.notStrictEqual(boundValueRecorder, boundValueRecorder2); }); it('should not fail when removing non existing instrument', () => { - const measure = meter.createMeasure('name'); - measure.unbind({}); + const valueRecorder = meter.createValueRecorder('name'); + valueRecorder.unbind({}); }); it('should clear all instruments', () => { - const measure = meter.createMeasure('name') as MeasureMetric; - measure.bind(labels); - assert.strictEqual(measure['_instruments'].size, 1); - measure.clear(); - assert.strictEqual(measure['_instruments'].size, 0); + const valueRecorder = meter.createValueRecorder( + 'name' + ) as ValueRecorderMetric; + valueRecorder.bind(labels); + assert.strictEqual(valueRecorder['_instruments'].size, 1); + valueRecorder.clear(); + assert.strictEqual(valueRecorder['_instruments'].size, 0); }); }); }); describe('#observer', () => { it('should create an observer', () => { - const measure = meter.createObserver('name') as ObserverMetric; - assert.ok(measure instanceof Metric); + const valueRecorder = meter.createObserver('name') as ObserverMetric; + assert.ok(valueRecorder instanceof Metric); }); it('should create observer with options', () => { - const measure = meter.createObserver('name', { + const valueRecorder = meter.createObserver('name', { description: 'desc', unit: '1', disabled: false, }) as ObserverMetric; - assert.ok(measure instanceof Metric); + assert.ok(valueRecorder instanceof Metric); }); it('should set callback and observe value ', () => { - const measure = meter.createObserver('name', { + const valueRecorder = meter.createObserver('name', { description: 'desc', labelKeys: ['pid', 'core'], }) as ObserverMetric; @@ -478,7 +496,7 @@ describe('Meter', () => { const metricObservable = new MetricObservable(); - measure.setCallback((observerResult: api.ObserverResult) => { + valueRecorder.setCallback((observerResult: api.ObserverResult) => { observerResult.observe(getCpuUsage, { pid: '123', core: '1' }); observerResult.observe(getCpuUsage, { pid: '123', core: '2' }); observerResult.observe(getCpuUsage, { pid: '123', core: '3' }); @@ -488,7 +506,7 @@ describe('Meter', () => { metricObservable.next(0.123); - const metricRecords: MetricRecord[] = measure.getMetricRecord(); + const metricRecords: MetricRecord[] = valueRecorder.getMetricRecord(); assert.strictEqual(metricRecords.length, 5); const metric5 = metricRecords[0]; @@ -587,8 +605,8 @@ describe('Meter', () => { batcher: new CustomBatcher(), }); assert.throws(() => { - const measure = customMeter.createMeasure('myMeasure'); - measure.bind({}).record(1); + const valueRecorder = customMeter.createValueRecorder('myValueRecorder'); + valueRecorder.bind({}).record(1); }, /aggregatorFor method not implemented/); }); });