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

Fixes #29466
This commit is contained in:
Zoltán Bedi 2021-01-22 18:03:37 +01:00 committed by GitHub
parent 6bdc9fac45
commit 38c1d45035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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',

View File

@ -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 };
}