-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not clear other labelsets when updating metrics (#941)
* fix: do not clear other labelsets when updating metrics * chore: add test for batcher * chore: test for one counter with multiple labels * chore: lint * chore: fix year in copyright
- Loading branch information
Showing
4 changed files
with
81 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*! | ||
* Copyright 2020, 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 * as types from '@opentelemetry/api'; | ||
import { NoopLogger } from '@opentelemetry/core'; | ||
import { Meter, MeterProvider } from '../src'; | ||
|
||
describe('Batcher', () => { | ||
describe('Ungrouped', () => { | ||
let meter: Meter; | ||
let fooCounter: types.BoundCounter; | ||
let barCounter: types.BoundCounter; | ||
let counter: types.Metric<types.BoundCounter>; | ||
beforeEach(() => { | ||
meter = new MeterProvider({ | ||
logger: new NoopLogger(), | ||
interval: 10000, | ||
}).getMeter('test-meter'); | ||
counter = meter.createCounter('ungrouped-batcher-test', { | ||
labelKeys: ['key'], | ||
}); | ||
fooCounter = counter.bind({ key: 'foo' }); | ||
barCounter = counter.bind({ key: 'bar' }); | ||
}); | ||
|
||
it('should process a batch', () => { | ||
fooCounter.add(1); | ||
barCounter.add(1); | ||
barCounter.add(2); | ||
meter.collect(); | ||
const checkPointSet = meter.getBatcher().checkPointSet(); | ||
assert.strictEqual(checkPointSet.length, 2); | ||
for (const record of checkPointSet) { | ||
switch (record.labels.key) { | ||
case 'foo': | ||
assert.strictEqual(record.aggregator.toPoint().value, 1); | ||
break; | ||
case 'bar': | ||
assert.strictEqual(record.aggregator.toPoint().value, 3); | ||
break; | ||
default: | ||
throw new Error('Unknown labelset'); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |