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

fix: ignore non-number value on BaseBoundInstrument.update #1366

Merged
merged 12 commits into from
Aug 20, 2020
Merged
Prev Previous commit
Next Next commit
test: iterates a set of non-number values for test
  • Loading branch information
legendecas committed Aug 3, 2020
commit 660538e6720c333dcbb2e0e3ede4e2797b4cc5a3
111 changes: 47 additions & 64 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import { hashLabels } from '../src/Utils';
import { Batcher } from '../src/export/Batcher';
import { ValueType } from '@opentelemetry/api';

const nonNumberValues = [undefined, Symbol('123'), {}];

describe('Meter', () => {
let meter: Meter;
const keya = 'keya';
Expand Down Expand Up @@ -376,7 +378,7 @@ describe('Meter', () => {
assert.strictEqual(boundCounter, boundCounter1);
});

it('should trunk non-integer values for INT valueType', async () => {
it('should truncate non-integer values for INT valueType', async () => {
const upDownCounter = meter.createUpDownCounter('name', {
valueType: ValueType.INT,
});
Expand All @@ -388,24 +390,24 @@ describe('Meter', () => {

assert.strictEqual(record1.aggregator.toPoint().value, -1);
}
});

{
// disable type checking...
(boundCounter.add as any)(undefined);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

assert.strictEqual(record1.aggregator.toPoint().value, -1);
}
it('should ignore non-number values for INT valueType', async () => {
const upDownCounter = meter.createUpDownCounter('name', {
valueType: ValueType.DOUBLE,
});
const boundCounter = upDownCounter.bind(labels);

{
// disable type checking...
(boundCounter.add as any)({});
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();
await Promise.all(
nonNumberValues.map(async val => {
// disable type checking...
(boundCounter.add as any)(val);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

assert.strictEqual(record1.aggregator.toPoint().value, -1);
}
assert.strictEqual(record1.aggregator.toPoint().value, 0);
})
);
});

it('should ignore non-number values for DOUBLE valueType', async () => {
Expand All @@ -414,23 +416,16 @@ describe('Meter', () => {
});
const boundCounter = upDownCounter.bind(labels);

{
// disable type checking...
(boundCounter.add as any)(undefined);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

assert.strictEqual(record1.aggregator.toPoint().value, 0);
}
await Promise.all(
nonNumberValues.map(async val => {
// disable type checking...
(boundCounter.add as any)(val);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

{
// disable type checking...
(boundCounter.add as any)({});
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

assert.strictEqual(record1.aggregator.toPoint().value, 0);
}
assert.strictEqual(record1.aggregator.toPoint().value, 0);
})
);
});
});

Expand Down Expand Up @@ -715,38 +710,26 @@ describe('Meter', () => {
'name'
) as ValueRecorderMetric;
const boundValueRecorder = valueRecorder.bind(labels);
{
// disable type checking...
(boundValueRecorder.record as any)(undefined);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();
assert.deepStrictEqual(
record1.aggregator.toPoint().value as Distribution,
{
count: 0,
last: 0,
max: -Infinity,
min: Infinity,
sum: 0,
}
);
}
{
// disable type checking...
(boundValueRecorder.record as any)({});
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();
assert.deepStrictEqual(
record1.aggregator.toPoint().value as Distribution,
{
count: 0,
last: 0,
max: -Infinity,
min: Infinity,
sum: 0,
}
);
}

await Promise.all(
nonNumberValues.map(async val => {
// disable type checking...
(boundValueRecorder.record as any)(undefined);
await meter.collect();
const [record1] = meter.getBatcher().checkPointSet();

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

Expand Down