-
Notifications
You must be signed in to change notification settings - Fork 826
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): merge uncollected delta accumulations (#3667)
Co-authored-by: Marc Pichler <[email protected]>
- Loading branch information
1 parent
d82a098
commit 2276977
Showing
4 changed files
with
97 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
packages/sdk-metrics/test/regression/two-metric-readers-async-instrument.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,65 @@ | ||
/* | ||
* 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 { DataPointType, MeterProvider, MetricReader } from '../../src'; | ||
import { TestDeltaMetricReader } from '../export/TestMetricReader'; | ||
import { assertDataPoint, assertMetricData } from '../util'; | ||
|
||
// https://github.com/open-telemetry/opentelemetry-js/issues/3664 | ||
|
||
describe('two-metric-readers-async-instrument', () => { | ||
it('both metric readers should collect metrics', async () => { | ||
const meterProvider = new MeterProvider(); | ||
const reader1 = new TestDeltaMetricReader(); | ||
const reader2 = new TestDeltaMetricReader(); | ||
|
||
meterProvider.addMetricReader(reader1); | ||
meterProvider.addMetricReader(reader2); | ||
|
||
const meter = meterProvider.getMeter('my-meter'); | ||
|
||
let counter = 1; | ||
const asyncUpDownCounter = meter.createObservableUpDownCounter( | ||
'my_async_updowncounter' | ||
); | ||
asyncUpDownCounter.addCallback(observableResult => { | ||
observableResult.observe(counter); | ||
}); | ||
|
||
await assertCollection(reader1, 1); | ||
await assertCollection(reader2, 1); | ||
|
||
counter = 10; | ||
await assertCollection(reader1, 9); | ||
await assertCollection(reader2, 9); | ||
|
||
async function assertCollection(reader: MetricReader, value: number) { | ||
const { errors, resourceMetrics } = await reader.collect(); | ||
assert.strictEqual(errors.length, 0); | ||
|
||
// Collected only one Metric. | ||
assert.strictEqual(resourceMetrics.scopeMetrics.length, 1); | ||
assert.strictEqual(resourceMetrics.scopeMetrics[0].metrics.length, 1); | ||
const metric = resourceMetrics.scopeMetrics[0].metrics[0]; | ||
|
||
assertMetricData(metric, DataPointType.SUM, { | ||
name: 'my_async_updowncounter', | ||
}); | ||
assertDataPoint(metric.dataPoints[0], {}, value); | ||
} | ||
}); | ||
}); |
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