Skip to content

Commit

Permalink
test: updated the PrometheusSerializer test case for the unit
Browse files Browse the repository at this point in the history
  • Loading branch information
tapico-weyert committed Jul 28, 2022
1 parent 9c92ad8 commit 22816d4
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,16 @@ describe('PrometheusSerializer', () => {
});

describe('validate against metric conventions', () => {
async function getCounterResult(name: string, unit: string | undefined = undefined, serializer: PrometheusSerializer, exportAll = false) {

async function getCounterResult(name: string, serializer: PrometheusSerializer, options: Partial<{ unit: string, exportAll: boolean }> = {}) {
const reader = new TestMetricReader();
const meterProvider = new MeterProvider({
views: [new View({ aggregation: new SumAggregation(), instrumentName: '*' })]
});
meterProvider.addMetricReader(reader);
const meter = meterProvider.getMeter('test');

const { unit, exportAll = false } = options
const counter = meter.createCounter(name, { unit: unit });
counter.add(1);

Expand All @@ -460,7 +462,7 @@ describe('PrometheusSerializer', () => {
const serializer = new PrometheusSerializer();

const unitOfMetric = 'seconds';
const result = await getCounterResult('test', unitOfMetric, serializer, true);
const result = await getCounterResult('test', serializer, { unit: unitOfMetric, exportAll: true });
assert.strictEqual(
result,
'# HELP test_total description missing\n' +
Expand All @@ -473,7 +475,7 @@ describe('PrometheusSerializer', () => {
it('should not export unit block when unit of metric is missing', async () => {
const serializer = new PrometheusSerializer();

const result = await getCounterResult('test', undefined, serializer, true);
const result = await getCounterResult('test', serializer, { exportAll: true });
assert.strictEqual(
result,
'# HELP test_total description missing\n' +
Expand All @@ -485,13 +487,13 @@ describe('PrometheusSerializer', () => {
it('should rename metric of type counter when name misses _total suffix', async () => {
const serializer = new PrometheusSerializer();

const result = await getCounterResult('test', undefined, serializer);
const result = await getCounterResult('test', serializer);
assert.strictEqual(result, `test_total 1 ${mockedHrTimeMs}\n`);
});

it('should not rename metric of type counter when name contains _total suffix', async () => {
const serializer = new PrometheusSerializer();
const result = await getCounterResult('test_total', undefined, serializer);
const result = await getCounterResult('test_total', serializer);

assert.strictEqual(result, `test_total 1 ${mockedHrTimeMs}\n`);
});
Expand Down

0 comments on commit 22816d4

Please sign in to comment.