Commit 207831fa by Zoltán Bedi Committed by GitHub

Prometheus: don't override displayName property (#29441)

* Prometheus: don't override displayName property

* Rename displayName to displayNameFromDS for consistency
parent dc937492
import { DataFrame } from '@grafana/data';
import { transform } from './result_transformer';
const matrixResponse = {
status: 'success',
data: {
resultType: 'matrix',
result: [
{
metric: { __name__: 'test', job: 'testjob' },
values: [
[1, '10'],
[2, '0'],
],
},
],
},
};
describe('Prometheus Result Transformer', () => {
const options: any = { target: {}, query: {} };
describe('When nothing is returned', () => {
......@@ -306,46 +322,14 @@ describe('Prometheus Result Transformer', () => {
});
it('should fill null values', () => {
const response = {
status: 'success',
data: {
resultType: 'matrix',
result: [
{
metric: { __name__: 'test', job: 'testjob' },
values: [
[1, '10'],
[2, '0'],
],
},
],
},
};
const result = transform({ data: response } as any, { ...options, query: { step: 1, start: 0, end: 2 } });
const result = transform({ data: matrixResponse } as any, { ...options, query: { step: 1, start: 0, end: 2 } });
expect(result[0].fields[0].values.toArray()).toEqual([0, 1000, 2000]);
expect(result[0].fields[1].values.toArray()).toEqual([null, 10, 0]);
});
it('should use __name__ label as series name', () => {
const response = {
status: 'success',
data: {
resultType: 'matrix',
result: [
{
metric: { __name__: 'test', job: 'testjob' },
values: [
[1, '10'],
[2, '0'],
],
},
],
},
};
const result = transform({ data: response } as any, {
const result = transform({ data: matrixResponse } as any, {
...options,
query: {
step: 1,
......@@ -384,6 +368,12 @@ describe('Prometheus Result Transformer', () => {
expect(result[0].name).toBe('{job="testjob"}');
});
it('should not set displayName for ValueFields', () => {
const result = transform({ data: matrixResponse } as any, options);
expect(result[0].fields[1].config.displayName).toBeUndefined();
expect(result[0].fields[1].config.displayNameFromDS).toBe('test{job="testjob"}');
});
it('should align null values with step', () => {
const response = {
status: 'success',
......
......@@ -139,10 +139,10 @@ function transformToDataFrame(data: MatrixOrVectorResult, options: TransformOpti
dps.push([t, null]);
}
fields.push(getTimeField(dps, true));
fields.push(getValueField({ data: dps, parseValue: false, labels, displayName: name }));
fields.push(getValueField({ data: dps, parseValue: false, labels, displayNameFromDS: name }));
} else {
fields.push(getTimeField([data.value]));
fields.push(getValueField({ data: [data.value], labels, displayName: name }));
fields.push(getValueField({ data: [data.value], labels, displayNameFromDS: name }));
}
return {
......@@ -224,7 +224,7 @@ type ValueFieldOptions = {
valueName?: string;
parseValue?: boolean;
labels?: Labels;
displayName?: string;
displayNameFromDS?: string;
};
function getValueField({
......@@ -232,13 +232,13 @@ function getValueField({
valueName = TIME_SERIES_VALUE_FIELD_NAME,
parseValue = true,
labels,
displayName,
displayNameFromDS,
}: ValueFieldOptions): MutableField {
return {
name: valueName,
type: FieldType.number,
config: {
displayName,
displayNameFromDS,
},
labels,
values: new ArrayVector<number | null>(data.map(val => (parseValue ? parseSampleValue(val[1]) : val[1]))),
......
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