mirror of
https://github.com/grafana/grafana.git
synced 2025-01-02 12:17:01 -06:00
Prometheus: Set type of labels to string (#30831)
This commit is contained in:
parent
99acad4448
commit
0427df8f60
@ -1,4 +1,4 @@
|
||||
import { DataFrame } from '@grafana/data';
|
||||
import { DataFrame, FieldType } from '@grafana/data';
|
||||
import { transform } from './result_transformer';
|
||||
|
||||
jest.mock('@grafana/runtime', () => ({
|
||||
@ -101,15 +101,20 @@ describe('Prometheus Result Transformer', () => {
|
||||
1443454531000,
|
||||
]);
|
||||
expect(result[0].fields[0].name).toBe('Time');
|
||||
expect(result[0].fields[0].type).toBe(FieldType.time);
|
||||
expect(result[0].fields[1].values.toArray()).toEqual(['test', 'test', 'test2', 'test2']);
|
||||
expect(result[0].fields[1].name).toBe('__name__');
|
||||
expect(result[0].fields[1].config.filterable).toBe(true);
|
||||
expect(result[0].fields[1].type).toBe(FieldType.string);
|
||||
expect(result[0].fields[2].values.toArray()).toEqual(['', '', 'localhost:8080', 'localhost:8080']);
|
||||
expect(result[0].fields[2].name).toBe('instance');
|
||||
expect(result[0].fields[2].type).toBe(FieldType.string);
|
||||
expect(result[0].fields[3].values.toArray()).toEqual(['testjob', 'testjob', 'otherjob', 'otherjob']);
|
||||
expect(result[0].fields[3].name).toBe('job');
|
||||
expect(result[0].fields[3].type).toBe(FieldType.string);
|
||||
expect(result[0].fields[4].values.toArray()).toEqual([3846, 3848, 3847, 3849]);
|
||||
expect(result[0].fields[4].name).toEqual('Value');
|
||||
expect(result[0].fields[4].type).toBe(FieldType.number);
|
||||
expect(result[0].refId).toBe('A');
|
||||
});
|
||||
|
||||
@ -168,6 +173,7 @@ describe('Prometheus Result Transformer', () => {
|
||||
};
|
||||
const result = transform({ data: response } as any, { ...options, target: { format: 'table' } });
|
||||
expect(result[0].fields[1].values.toArray()).toEqual([102]);
|
||||
expect(result[0].fields[1].type).toEqual(FieldType.number);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -299,10 +299,13 @@ function transformMetricDataToTable(md: MatrixOrVectorResult[], options: Transfo
|
||||
const metricFields = Object.keys(md.reduce((acc, series) => ({ ...acc, ...series.metric }), {}))
|
||||
.sort()
|
||||
.map((label) => {
|
||||
// Labels have string field type, otherwise table tries to figure out the type which can result in unexpected results
|
||||
// Only "le" label has a number field type
|
||||
const numberField = label === 'le';
|
||||
return {
|
||||
name: label,
|
||||
config: { filterable: true },
|
||||
type: FieldType.other,
|
||||
type: numberField ? FieldType.number : FieldType.string,
|
||||
values: new ArrayVector(),
|
||||
};
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user