Skip to content

Commit

Permalink
merge createMeasure PR and fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Feb 10, 2020
1 parent 89c0b68 commit cf49191
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
6 changes: 5 additions & 1 deletion packages/opentelemetry-metrics/src/BoundInstrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,19 @@ export class BoundGauge extends BaseBoundInstrument
*/
export class BoundMeasure extends BaseBoundInstrument
implements types.BoundMeasure {
private readonly _absolute: boolean;

constructor(
labelSet: types.LabelSet,
disabled: boolean,
monotonic: boolean,
absolute: boolean,
valueType: types.ValueType,
logger: types.Logger,
aggregator: Aggregator
) {
super(labelSet, logger, absolute, disabled, valueType, aggregator);
super(labelSet, logger, monotonic, disabled, valueType, aggregator);
this._absolute = absolute;
}

record(
Expand Down
9 changes: 3 additions & 6 deletions packages/opentelemetry-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export class Meter implements types.Meter {
return types.NOOP_MEASURE_METRIC;
}
const opt: MetricOptions = {
// Measures are defined as absolute by default
absolute: true,
absolute: true, // Measures are defined as absolute by default
monotonic: false, // not applicable to measure, set to false
logger: this._logger,
...DEFAULT_METRIC_OPTIONS,
Expand Down Expand Up @@ -97,8 +96,7 @@ export class Meter implements types.Meter {
return types.NOOP_COUNTER_METRIC;
}
const opt: MetricOptions = {
// Counters are defined as monotonic by default
monotonic: true,
monotonic: true, // Counters are defined as monotonic by default
absolute: false, // not applicable to counter, set to false
logger: this._logger,
...DEFAULT_METRIC_OPTIONS,
Expand Down Expand Up @@ -128,8 +126,7 @@ export class Meter implements types.Meter {
return types.NOOP_GAUGE_METRIC;
}
const opt: MetricOptions = {
// Gauges are defined as non-monotonic by default
monotonic: false,
monotonic: false, // Gauges are defined as non-monotonic by default
absolute: false, // not applicable for gauges, set to false
logger: this._logger,
...DEFAULT_METRIC_OPTIONS,
Expand Down
7 changes: 2 additions & 5 deletions packages/opentelemetry-metrics/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,15 @@ export class MeasureMetric extends Metric<BoundMeasure>
options: MetricOptions,
private readonly _batcher: Batcher
) {
super(
name,
options,
MetricKind.MEASURE
);
super(name, options, MetricKind.MEASURE);

this._absolute = options.absolute !== undefined ? options.absolute : true; // Absolute default is true
}
protected _makeInstrument(labelSet: types.LabelSet): BoundMeasure {
return new BoundMeasure(
labelSet,
this._disabled,
this._monotonic,
this._absolute,
this._valueType,
this._logger,
Expand Down
27 changes: 16 additions & 11 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ import {
Sum,
MeterProvider,
MeasureMetric,
Distribution
Distribution,
} from '../src';
import * as types from '@opentelemetry/api';
import { LabelSet } from '../src/LabelSet';
import {
NoopLogger,
hrTime,
hrTimeToMilliseconds,
} from '@opentelemetry/core';
import { NoopLogger, hrTime, hrTimeToMilliseconds } from '@opentelemetry/core';
import {
CounterSumAggregator,
GaugeAggregator,
MeasureExactAggregator,
} from '../src/export/Aggregator';
import { ValueType } from '@opentelemetry/api';

Expand Down Expand Up @@ -497,8 +492,12 @@ describe('Meter', () => {

meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

assert.strictEqual((record1.aggregator.value() as Distribution), 10);
assert.deepStrictEqual(record1.aggregator.value() as Distribution, {
count: 0,
max: -Infinity,
min: Infinity,
sum: 0,
});
});

it('should accept negative (and positive) values when monotonic is set to false', () => {
Expand All @@ -511,8 +510,14 @@ describe('Meter', () => {
boundMeasure1.record(10);
const boundMeasure2 = measure.bind(labelSet);
boundMeasure2.record(100);
// @todo: re-add once record is implemented
// assert.strictEqual(boundMeasure1['_data'], 100);
meter.collect();
const [record1] = meter.getBatcher().checkPointSet();
assert.deepStrictEqual(record1.aggregator.value() as Distribution, {
count: 2,
max: 100,
min: 10,
sum: 110,
});
assert.strictEqual(boundMeasure1, boundMeasure2);
});
});
Expand Down

0 comments on commit cf49191

Please sign in to comment.