-
Notifications
You must be signed in to change notification settings - Fork 821
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
Changes from 1 commit
93d923b
60c7974
660538e
5a67737
56521b7
ae07012
9ff4219
e793a68
4e9de29
0e07065
63eb24b
5a51e93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ import { Resource } from '@opentelemetry/resources'; | |
import { UpDownSumObserverMetric } from '../src/UpDownSumObserverMetric'; | ||
import { hashLabels } from '../src/Utils'; | ||
import { Batcher } from '../src/export/Batcher'; | ||
import { ValueType } from '@opentelemetry/api'; | ||
|
||
describe('Meter', () => { | ||
let meter: Meter; | ||
|
@@ -374,6 +375,63 @@ describe('Meter', () => { | |
assert.strictEqual(record1.aggregator.toPoint().value, 20); | ||
assert.strictEqual(boundCounter, boundCounter1); | ||
}); | ||
|
||
it('should trunk non-integer values for INT valueType', async () => { | ||
const upDownCounter = meter.createUpDownCounter('name', { | ||
valueType: ValueType.INT, | ||
}); | ||
const boundCounter = upDownCounter.bind(labels); | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why extra brackets are needed here and in few other places ? If you want to separate cases perhaps it's a moment where it should go into separate unit test or simply make an array of values to test and then use a loop to test each value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The brackets give lexical scope to the These should be separate tests as they are not all testing truncation |
||
boundCounter.add(-1.1); | ||
await meter.collect(); | ||
const [record1] = meter.getBatcher().checkPointSet(); | ||
|
||
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); | ||
} | ||
|
||
{ | ||
// disable type checking... | ||
(boundCounter.add as any)({}); | ||
await meter.collect(); | ||
const [record1] = meter.getBatcher().checkPointSet(); | ||
|
||
assert.strictEqual(record1.aggregator.toPoint().value, -1); | ||
} | ||
}); | ||
|
||
it('should ignore non-number values for DOUBLE valueType', async () => { | ||
const upDownCounter = meter.createUpDownCounter('name', { | ||
valueType: ValueType.DOUBLE, | ||
}); | ||
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); | ||
} | ||
|
||
{ | ||
// disable type checking... | ||
(boundCounter.add as any)({}); | ||
await meter.collect(); | ||
const [record1] = meter.getBatcher().checkPointSet(); | ||
|
||
assert.strictEqual(record1.aggregator.toPoint().value, 0); | ||
} | ||
}); | ||
}); | ||
|
||
describe('.unbind()', () => { | ||
|
@@ -651,6 +709,45 @@ describe('Meter', () => { | |
); | ||
assert.strictEqual(boundValueRecorder1, boundValueRecorder2); | ||
}); | ||
|
||
it('should ignore non-number values', async () => { | ||
const valueRecorder = meter.createValueRecorder( | ||
'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, | ||
} | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('.unbind()', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "trunk" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely trunc or truncate. @legendecas Please avoid abbreviations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore
then ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's a typo and it should be fixed, and the other cases should be made into their own tests.