Commit 325fd29e by ElstJonas Committed by Torkel Ödegaard

Prometheus: Return labels in query results (#18535)

* Added prometheus metric labels to data returned for normal time series queries

* Fixed result transformer tests for new return layout with prometheus labels

* Fixed prettier formatting
parent 693d0a78
......@@ -76,6 +76,7 @@ export class ResultTransformer {
datapoints: dps,
query: options.query,
target: metricLabel,
labels: metricData.metric,
};
}
......
......@@ -147,9 +147,24 @@ describe('Prometheus Result Transformer', () => {
const result = ctx.resultTransformer.transform({ data: response }, options);
expect(result).toEqual([
{ target: '1', datapoints: [[10, 1445000010000], [10, 1445000020000], [0, 1445000030000]] },
{ target: '2', datapoints: [[10, 1445000010000], [0, 1445000020000], [30, 1445000030000]] },
{ target: '3', datapoints: [[10, 1445000010000], [0, 1445000020000], [10, 1445000030000]] },
{
target: '1',
query: undefined,
datapoints: [[10, 1445000010000], [10, 1445000020000], [0, 1445000030000]],
labels: { __name__: 'test', job: 'testjob', le: '1' },
},
{
target: '2',
query: undefined,
datapoints: [[10, 1445000010000], [0, 1445000020000], [30, 1445000030000]],
labels: { __name__: 'test', job: 'testjob', le: '2' },
},
{
target: '3',
query: undefined,
datapoints: [[10, 1445000010000], [0, 1445000020000], [10, 1445000030000]],
labels: { __name__: 'test', job: 'testjob', le: '3' },
},
]);
});
......@@ -205,7 +220,14 @@ describe('Prometheus Result Transformer', () => {
};
const result = ctx.resultTransformer.transform({ data: response }, options);
expect(result).toEqual([{ target: 'test{job="testjob"}', datapoints: [[10, 0], [10, 1000], [0, 2000]] }]);
expect(result).toEqual([
{
target: 'test{job="testjob"}',
query: undefined,
datapoints: [[10, 0], [10, 1000], [0, 2000]],
labels: { job: 'testjob' },
},
]);
});
it('should fill timeseries with null values', () => {
......@@ -229,7 +251,14 @@ describe('Prometheus Result Transformer', () => {
};
const result = ctx.resultTransformer.transform({ data: response }, options);
expect(result).toEqual([{ target: 'test{job="testjob"}', datapoints: [[null, 0], [10, 1000], [0, 2000]] }]);
expect(result).toEqual([
{
target: 'test{job="testjob"}',
query: undefined,
datapoints: [[null, 0], [10, 1000], [0, 2000]],
labels: { job: 'testjob' },
},
]);
});
it('should align null values with step', () => {
......@@ -254,7 +283,12 @@ describe('Prometheus Result Transformer', () => {
const result = ctx.resultTransformer.transform({ data: response }, options);
expect(result).toEqual([
{ target: 'test{job="testjob"}', datapoints: [[null, 0], [null, 2000], [10, 4000], [null, 6000], [10, 8000]] },
{
target: 'test{job="testjob"}',
query: undefined,
datapoints: [[null, 0], [null, 2000], [10, 4000], [null, 6000], [10, 8000]],
labels: { job: 'testjob' },
},
]);
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment