Commit 38c1d450 by Zoltán Bedi Committed by GitHub

Prometheus: Fix show query instead of Value if no __name__ and metric (#30511)

Fixes #29466
parent 6bdc9fac
......@@ -353,6 +353,32 @@ describe('Prometheus Result Transformer', () => {
expect(result[0].name).toEqual('test{job="testjob"}');
});
it('should use query as series name when __name__ is not available and metric is empty', () => {
const response = {
status: 'success',
data: {
resultType: 'matrix',
result: [
{
metric: {},
values: [[0, '10']],
},
],
},
};
const expr = 'histogram_quantile(0.95, sum(rate(tns_request_duration_seconds_bucket[5m])) by (le))';
const result = transform({ data: response } as any, {
...options,
query: {
step: 1,
start: 0,
end: 2,
expr,
},
});
expect(result[0].name).toEqual(expr);
});
it('should set frame name to undefined if no __name__ label but there are other labels', () => {
const response = {
status: 'success',
......
......@@ -383,7 +383,11 @@ function createLabelInfo(labels: { [key: string]: string }, options: TransformOp
const { __name__, ...labelsWithoutName } = labels;
const labelPart = formatLabels(labelsWithoutName);
const title = `${__name__ ?? ''}${labelPart}`;
let title = `${__name__ ?? ''}${labelPart}`;
if (!title) {
title = options.query;
}
return { name: title, labels: labelsWithoutName };
}
......
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