Skip to content

Commit

Permalink
fix: add more test and @todo comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Nov 1, 2019
1 parent 2674970 commit 0ec801a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/opentelemetry-metrics/src/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class Meter implements types.Meter {
metric: Metric<T>
): void {
if (this._metrics.has(name)) {
// @todo: decide how to handle already registered metric
// 1: Replace the old registered metric by the new
// 2. Throw error
// 3. skip duplicate metric (current approach)
this._logger.error(
`A metric with the name ${name} has already been registered.`
);
Expand Down
24 changes: 24 additions & 0 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ describe('Meter', () => {
});
});

describe('.registerMetric()', () => {
it('skip already registered Metric', () => {
const counter1 = meter.createCounter('name1') as CounterMetric;
counter1.getHandle(labelValues).add(10);

// should skip below metric
const counter2 = meter.createCounter('name1', {
valueType: types.ValueType.INT,
}) as CounterMetric;
counter2.getHandle(labelValues).add(500);

assert.strictEqual(meter.getMetrics().length, 1);
const [{ descriptor, timeseries }] = meter.getMetrics();
assert.deepStrictEqual(descriptor.name, 'name1');
assert.deepStrictEqual(
descriptor.type,
MetricDescriptorType.COUNTER_DOUBLE
);
assert.strictEqual(timeseries.length, 1);
assert.strictEqual(timeseries[0].points.length, 1);
assert.strictEqual(timeseries[0].points[0].value, 10);
});
});

describe('names', () => {
it('should create counter with valid names', () => {
const counter1 = meter.createCounter('name1');
Expand Down

0 comments on commit 0ec801a

Please sign in to comment.