Skip to content

Commit

Permalink
feat: add prom export for VALUE_RECORDER, SUM_OBSERVER & UP_DOWN_SUM_…
Browse files Browse the repository at this point in the history
…OBSERVER
  • Loading branch information
paulfairless committed Aug 14, 2020
1 parent 878451a commit f5f3b70
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/opentelemetry-exporter-prometheus/src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,12 @@ export class PrometheusExporter implements MetricExporter {
return new Counter(metricObject);
case MetricKind.UP_DOWN_COUNTER:
return new Gauge(metricObject);
// case MetricKind.VALUE_RECORDER:
// case MetricKind.SUM_OBSERVER:
// case MetricKind.UP_DOWN_SUM_OBSERVER:
case MetricKind.VALUE_RECORDER:
return new Gauge(metricObject);
case MetricKind.SUM_OBSERVER:
return new Counter(metricObject);
case MetricKind.UP_DOWN_SUM_OBSERVER:
return new Gauge(metricObject);
case MetricKind.VALUE_OBSERVER:
return new Gauge(metricObject);
default:
Expand Down
116 changes: 115 additions & 1 deletion packages/opentelemetry-exporter-prometheus/test/prometheus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,121 @@ describe('PrometheusExporter', () => {
});
});
});
});

it('should export a SumObserver as a counter', done => {
function getValue() {
return 20;
}

meter.createSumObserver('sum_observer', {
description: 'a test description',
},
(observerResult: ObserverResult) => {
observerResult.observe(getValue(), {
key1: "labelValue1",
})
});

meter.collect().then(() => {
exporter.export(meter.getBatcher().checkPointSet(), () => {
http
.get('http://localhost:9464/metrics', res => {
res.on('data', chunk => {
const body = chunk.toString();
const lines = body.split('\n');

assert.deepStrictEqual(lines, [
'# HELP sum_observer a test description',
'# TYPE sum_observer counter',
`sum_observer{key1="labelValue1"} 20 ${mockedTimeMS}`,
'',
]);
});

done();
})
.on('error', errorHandler(done));
});
});
});

it('should export a UpDownSumObserver as a gauge', done => {
function getValue() {
return 20;
}

meter.createUpDownSumObserver('updown_observer', {
description: 'a test description',
},
(observerResult: ObserverResult) => {
observerResult.observe(getValue(), {
key1: "labelValue1",
})
});

meter.collect().then(() => {
exporter.export(meter.getBatcher().checkPointSet(), () => {
http
.get('http://localhost:9464/metrics', res => {
res.on('data', chunk => {
const body = chunk.toString();
const lines = body.split('\n');

assert.deepStrictEqual(lines, [
'# HELP updown_observer a test description',
'# TYPE updown_observer gauge',
'updown_observer{key1="labelValue1"} 20',
'',
]);
});

done();
})
.on('error', errorHandler(done));
});
});
});

it('should export a ValueRecorder as a guage', done => {

const valueRecorder = meter.createValueRecorder('value_recorder', {
description: 'a test description',
});

valueRecorder.bind({ key1: 'labelValue1' }).record(20);


meter.collect().then(() => {
exporter.export(meter.getBatcher().checkPointSet(), () => {
http
.get('http://localhost:9464/metrics', res => {
res.on('data', chunk => {

const body = chunk.toString();
const lines = body.split('\n');

assert.strictEqual(
lines[0],
'# HELP value_recorder a test description'
);
assert.strictEqual(lines[1], '# TYPE value_recorder gauge');

const line3 = lines[2].split(' ');
assert.strictEqual(
line3[0],
'value_recorder{key1="labelValue1"}'
);
assert.equal(line3[1], 20);

done();
});
})
.on('error', errorHandler(done));
});
});
});

});

describe('configuration', () => {
let meter: Meter;
Expand Down

0 comments on commit f5f3b70

Please sign in to comment.