From c2b720835b8f7cf1f58b14ab120a723b6835aed4 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Fri, 27 Apr 2018 19:34:10 +0900 Subject: [PATCH 1/2] fix to match table column name and order --- public/app/plugins/datasource/prometheus/datasource.ts | 1 + .../app/plugins/datasource/prometheus/result_transformer.ts | 6 +++--- public/app/plugins/panel/table/module.ts | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index 2a8b3069a53..6d654438271 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -153,6 +153,7 @@ export class PrometheusDatasource { end: end, responseListLength: responseList.length, responseIndex: index, + refId: activeTargets[index].refId, }; this.resultTransformer.transform(result, response, transformerOptions); diff --git a/public/app/plugins/datasource/prometheus/result_transformer.ts b/public/app/plugins/datasource/prometheus/result_transformer.ts index 6d97b783983..d5feda7d28c 100644 --- a/public/app/plugins/datasource/prometheus/result_transformer.ts +++ b/public/app/plugins/datasource/prometheus/result_transformer.ts @@ -8,7 +8,7 @@ export class ResultTransformer { let prometheusResult = response.data.data.result; if (options.format === 'table') { - result.push(this.transformMetricDataToTable(prometheusResult, options.responseListLength, options.responseIndex)); + result.push(this.transformMetricDataToTable(prometheusResult, options.responseListLength, options.refId)); } else if (options.format === 'heatmap') { let seriesList = []; prometheusResult.sort(sortSeriesByLabel); @@ -58,7 +58,7 @@ export class ResultTransformer { return { target: metricLabel, datapoints: dps }; } - transformMetricDataToTable(md, resultCount: number, resultIndex: number) { + transformMetricDataToTable(md, resultCount: number, refId: string) { var table = new TableModel(); var i, j; var metricLabels = {}; @@ -83,7 +83,7 @@ export class ResultTransformer { metricLabels[label] = labelIndex + 1; table.columns.push({ text: label }); }); - let valueText = resultCount > 1 ? `Value #${String.fromCharCode(65 + resultIndex)}` : 'Value'; + let valueText = resultCount > 1 ? `Value #${refId}` : 'Value'; table.columns.push({ text: valueText }); // Populate rows, set value to empty string when label not present. diff --git a/public/app/plugins/panel/table/module.ts b/public/app/plugins/panel/table/module.ts index 27eab205f09..f4728982ad5 100644 --- a/public/app/plugins/panel/table/module.ts +++ b/public/app/plugins/panel/table/module.ts @@ -154,6 +154,11 @@ class TablePanelCtrl extends MetricsPanelCtrl { this.render(); } + moveQuery(target, direction) { + super.moveQuery(target, direction); + super.refresh(); + } + exportCsv() { var scope = this.$scope.$new(true); scope.tableData = this.renderer.render_values(); From 253b2cc081dc3fe2f81da2feb22b490f09494537 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 1 May 2018 05:00:56 +0900 Subject: [PATCH 2/2] add test for prometheus table column title --- .../prometheus/specs/result_transformer.jest.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts b/public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts index abcc46d7ea8..64b983fc8a7 100644 --- a/public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts +++ b/public/app/plugins/datasource/prometheus/specs/result_transformer.jest.ts @@ -47,6 +47,18 @@ describe('Prometheus Result Transformer', () => { { text: 'Value' }, ]); }); + + it('should column title include refId if response count is more than 2', () => { + var table = ctx.resultTransformer.transformMetricDataToTable(response.data.result, 2, "B"); + expect(table.type).toBe('table'); + expect(table.columns).toEqual([ + { text: 'Time', type: 'time' }, + { text: '__name__' }, + { text: 'instance' }, + { text: 'job' }, + { text: 'Value #B' }, + ]); + }); }); describe('When resultFormat is table and instant = true', () => {