forked from open-telemetry/opentelemetry-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sdk-metrics): ignore NaN value recordings for histograms (open-te…
…lemetry#4455) * fix(sdk-metrics): ignore NaN value recordings * fix(changelog): add changelog entry * test(exporter-prometheus): adapt tests * fix(sdk-metrics): ignore in accumulation instead * fix(changelog): update changelog
- Loading branch information
1 parent
171620f
commit 9bf303b
Showing
8 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
packages/sdk-metrics/test/regression/histogram-recording-nan.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as assert from 'assert'; | ||
import { | ||
Aggregation, | ||
AggregationTemporality, | ||
MeterProvider, | ||
MetricReader, | ||
DataPoint, | ||
ExponentialHistogram, | ||
Histogram, | ||
} from '../../src'; | ||
import { TestMetricReader } from '../export/TestMetricReader'; | ||
|
||
describe('histogram-recording-nan', () => { | ||
it('exponential histogram should not count NaN', async () => { | ||
const reader = new TestMetricReader({ | ||
aggregationTemporalitySelector() { | ||
return AggregationTemporality.CUMULATIVE; | ||
}, | ||
aggregationSelector(type) { | ||
return Aggregation.ExponentialHistogram(); | ||
}, | ||
}); | ||
const meterProvider = new MeterProvider({ | ||
readers: [reader], | ||
}); | ||
|
||
const meter = meterProvider.getMeter('my-meter'); | ||
const hist = meter.createHistogram('testhist'); | ||
|
||
hist.record(1); | ||
hist.record(2); | ||
hist.record(4); | ||
hist.record(NaN); | ||
|
||
const resourceMetrics1 = await collectNoErrors(reader); | ||
const dataPoint1 = resourceMetrics1.scopeMetrics[0].metrics[0] | ||
.dataPoints[0] as DataPoint<ExponentialHistogram>; | ||
|
||
assert.deepStrictEqual( | ||
dataPoint1.value.count, | ||
3, | ||
'Sum of bucket count values should match overall count' | ||
); | ||
}); | ||
|
||
it('explicit bucket histogram should not count NaN', async () => { | ||
const reader = new TestMetricReader({ | ||
aggregationTemporalitySelector() { | ||
return AggregationTemporality.CUMULATIVE; | ||
}, | ||
aggregationSelector(type) { | ||
return Aggregation.Histogram(); | ||
}, | ||
}); | ||
const meterProvider = new MeterProvider({ | ||
readers: [reader], | ||
}); | ||
|
||
const meter = meterProvider.getMeter('my-meter'); | ||
const hist = meter.createHistogram('testhist'); | ||
|
||
hist.record(1); | ||
hist.record(2); | ||
hist.record(4); | ||
hist.record(NaN); | ||
|
||
const resourceMetrics1 = await collectNoErrors(reader); | ||
const dataPoint1 = resourceMetrics1.scopeMetrics[0].metrics[0] | ||
.dataPoints[0] as DataPoint<Histogram>; | ||
|
||
assert.deepStrictEqual( | ||
dataPoint1.value.count, | ||
3, | ||
'Sum of bucket count values should match overall count' | ||
); | ||
}); | ||
|
||
const collectNoErrors = async (reader: MetricReader) => { | ||
const { resourceMetrics, errors } = await reader.collect(); | ||
assert.strictEqual(errors.length, 0); | ||
return resourceMetrics; | ||
}; | ||
}); |