mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Histogram table format should keep le
values as strings (#91662)
* remove le value parsing as numbers * add tests
This commit is contained in:
parent
db33df5041
commit
e0b8a00e78
@ -350,6 +350,62 @@ describe('Prometheus Result Transformer', () => {
|
||||
expect(series.data[1].meta?.preferredVisualisationType).toEqual('rawPrometheus' as PreferredVisualisationType);
|
||||
});
|
||||
|
||||
it('histogram results with table format have le values as strings for table filtering', () => {
|
||||
const options = {
|
||||
targets: [
|
||||
{
|
||||
format: 'table',
|
||||
refId: 'A',
|
||||
},
|
||||
],
|
||||
} as unknown as DataQueryRequest<PromQuery>;
|
||||
const response = {
|
||||
state: 'Done',
|
||||
data: [
|
||||
createDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
{ name: 'Time', type: FieldType.time, values: [6, 5, 4] },
|
||||
{
|
||||
name: 'Value',
|
||||
type: FieldType.number,
|
||||
values: [10, 10, 0],
|
||||
labels: { le: '1' },
|
||||
},
|
||||
],
|
||||
}),
|
||||
createDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
{ name: 'Time', type: FieldType.time, values: [6, 5, 4] },
|
||||
{
|
||||
name: 'Value',
|
||||
type: FieldType.number,
|
||||
values: [30, 10, 40],
|
||||
labels: { le: '+Inf' },
|
||||
},
|
||||
],
|
||||
}),
|
||||
createDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
{ name: 'Time', type: FieldType.time, values: [6, 5, 4] },
|
||||
{
|
||||
name: 'Value',
|
||||
type: FieldType.number,
|
||||
values: [20, 10, 30],
|
||||
labels: { le: '2' },
|
||||
},
|
||||
],
|
||||
}),
|
||||
],
|
||||
} as unknown as DataQueryResponse;
|
||||
|
||||
const series = transformV2(response, options, {});
|
||||
const leFields = series.data[0].fields.filter((f) => f.name === 'le');
|
||||
const leValuesAreStrings = leFields[0].values.every((v) => typeof v === 'string');
|
||||
expect(leValuesAreStrings).toBe(true);
|
||||
});
|
||||
// Heatmap frames can either have a name of the metric, or if there is no metric, a name of "Value"
|
||||
it('results with heatmap format (no metric name) should be correctly transformed', () => {
|
||||
const options = {
|
||||
|
@ -202,11 +202,10 @@ export function transformDFToTable(dfs: DataFrame[]): DataFrame[] {
|
||||
.forEach((label) => {
|
||||
// If we don't have label in labelFields, add it
|
||||
if (!labelFields.some((l) => l.name === label)) {
|
||||
const numberField = label === HISTOGRAM_QUANTILE_LABEL_NAME;
|
||||
labelFields.push({
|
||||
name: label,
|
||||
config: { filterable: true },
|
||||
type: numberField ? FieldType.number : FieldType.string,
|
||||
type: FieldType.string,
|
||||
values: [],
|
||||
});
|
||||
}
|
||||
@ -280,9 +279,6 @@ function getDataLinks(options: ExemplarTraceIdDestination): DataLink[] {
|
||||
|
||||
function getLabelValue(metric: PromMetric, label: string): string | number {
|
||||
if (metric.hasOwnProperty(label)) {
|
||||
if (label === HISTOGRAM_QUANTILE_LABEL_NAME) {
|
||||
return parseSampleValue(metric[label]);
|
||||
}
|
||||
return metric[label];
|
||||
}
|
||||
return '';
|
||||
|
Loading…
Reference in New Issue
Block a user