Prometheus: Histogram table format should keep le values as strings (#91662)

* remove le value parsing as numbers

* add tests
This commit is contained in:
Brendan O'Handley 2024-08-13 10:06:53 -05:00 committed by GitHub
parent db33df5041
commit e0b8a00e78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 57 additions and 5 deletions

View File

@ -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 = {

View File

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