Commit 243fa5ea by Torkel Ödegaard Committed by GitHub

Prometheus: Fix for prometheus legend formats for instant time series queries (#24407)

* Prometheus: Fix for prometheus legend formats for instance time series queries

* correct old test
parent 648dda96
......@@ -736,7 +736,7 @@ describe('PrometheusDatasource', () => {
const frame = toDataFrame(results.data[0]);
expect(results.data.length).toBe(1);
expect(frame.name).toBe('test{job="testjob"}');
expect(getFieldTitle(frame.fields[1])).toBe('Value');
expect(getFieldTitle(frame.fields[1])).toBe('test{job="testjob"}');
});
});
......
......@@ -116,6 +116,27 @@ describe('Prometheus Result Transformer', () => {
});
});
describe('When resultFormat is time series and instant = true', () => {
const response = {
status: 'success',
data: {
resultType: 'vector',
result: [
{
metric: { __name__: 'test', job: 'testjob' },
value: [1443454528, '3846'],
},
],
},
};
it('should return time series', () => {
const timeSeries = ctx.resultTransformer.transform({ data: response }, {});
expect(timeSeries[0].target).toBe('test{job="testjob"}');
expect(timeSeries[0].title).toBe('test{job="testjob"}');
});
});
describe('When resultFormat is heatmap', () => {
const response = {
status: 'success',
......
......@@ -143,7 +143,7 @@ export class ResultTransformer {
const dps = [];
const { name, labels } = this.createLabelInfo(md.metric, options);
dps.push([parseFloat(md.value[1]), md.value[0] * 1000]);
return { target: name, datapoints: dps, tags: labels, refId: options.refId, meta: options.meta };
return { target: name, title: name, datapoints: dps, tags: labels, refId: options.refId, meta: options.meta };
}
createLabelInfo(labels: { [key: string]: string }, options: any): { name?: string; labels: Labels; title?: string } {
......
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