mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Fix show query instead of Value if no __name__ and metric (#30511)
Fixes #29466
This commit is contained in:
parent
6bdc9fac45
commit
38c1d45035
@ -353,6 +353,32 @@ describe('Prometheus Result Transformer', () => {
|
|||||||
expect(result[0].name).toEqual('test{job="testjob"}');
|
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', () => {
|
it('should set frame name to undefined if no __name__ label but there are other labels', () => {
|
||||||
const response = {
|
const response = {
|
||||||
status: 'success',
|
status: 'success',
|
||||||
|
@ -383,7 +383,11 @@ function createLabelInfo(labels: { [key: string]: string }, options: TransformOp
|
|||||||
|
|
||||||
const { __name__, ...labelsWithoutName } = labels;
|
const { __name__, ...labelsWithoutName } = labels;
|
||||||
const labelPart = formatLabels(labelsWithoutName);
|
const labelPart = formatLabels(labelsWithoutName);
|
||||||
const title = `${__name__ ?? ''}${labelPart}`;
|
let title = `${__name__ ?? ''}${labelPart}`;
|
||||||
|
|
||||||
|
if (!title) {
|
||||||
|
title = options.query;
|
||||||
|
}
|
||||||
|
|
||||||
return { name: title, labels: labelsWithoutName };
|
return { name: title, labels: labelsWithoutName };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user