Merge pull request #11751 from mtanda/11690

fix to match table column name and order
This commit is contained in:
Marcus Efraimsson 2018-05-03 18:33:46 +02:00 committed by GitHub
commit da8f6c150b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 3 deletions

View File

@ -153,6 +153,7 @@ export class PrometheusDatasource {
end: end,
responseListLength: responseList.length,
responseIndex: index,
refId: activeTargets[index].refId,
};
this.resultTransformer.transform(result, response, transformerOptions);

View File

@ -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.

View File

@ -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', () => {

View File

@ -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();