Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 committed Nov 8, 2019
1 parent 431b21d commit 9b5c326
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ export class ConsoleMetricExporter implements MetricExporter {
name: descriptor.name,
description: descriptor.description,
});

for (const ts of timeseries) {
const labels = descriptor.labelKeys
.map((k, i) => [k, ts.labelValues[i]])
.reduce(
(p, c) => ({
...p,
[c[0] as string]: typeof c[1] === 'string' ? c[1] : c[1].value,
}),
{}
);
for (const point of ts.points) {
console.log({ labels: ts.labelValues, value: point.value });
console.log({ labels, value: point.value });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ describe('ConsoleMetricExporter', () => {
meter.addExporter(consoleExporter);
const gauge = meter.createGauge('gauge', {
description: 'a test description',
labelKeys: ['key1'],
labelKeys: ['key1', 'key2'],
}) as GaugeMetric;
const handle = gauge.getHandle(['labelValue1']);
const handle = gauge.getHandle(
meter.labels({ key1: 'labelValue1', key2: 'labelValue2' })
);
handle.set(10);
const [descriptor, timeseries] = spyConsole.args;
assert.deepStrictEqual(descriptor, [
{ description: 'a test description', name: 'gauge' },
]);
assert.deepStrictEqual(timeseries, [
{ labels: [{ value: 'labelValue1' }], value: 10 },
{
labels: { key1: 'labelValue1', key2: 'labelValue2' },
value: 10,
},
]);
});
});
});

0 comments on commit 9b5c326

Please sign in to comment.