Prometheus: Show results of instant queries only in table (#24508)

* Show results of instant queries only in table, remove them from graph

* Update table model
This commit is contained in:
Ivana Huckova 2020-05-11 22:47:15 +02:00 committed by GitHub
parent c8d3d15292
commit 143a26769b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 9 deletions

View File

@ -15,7 +15,7 @@ export enum LoadingState {
Error = 'Error',
}
type PreferredVisualisationType = 'graph' | 'table';
export type PreferredVisualisationType = 'graph' | 'table';
export interface QueryResultMeta {
/** DatasSource Specific Values */

View File

@ -1,5 +1,5 @@
import _ from 'lodash';
import { Column, TableData } from '@grafana/data';
import { Column, TableData, QueryResultMeta } from '@grafana/data';
/**
* Extends the standard Column class with variables that get
@ -18,6 +18,7 @@ export default class TableModel implements TableData {
type: string;
columnMap: any;
refId: string;
meta?: QueryResultMeta;
constructor(table?: any) {
this.columns = [];

View File

@ -7,6 +7,7 @@ import {
toDataFrame,
getDisplayProcessor,
ExploreMode,
PreferredVisualisationType,
} from '@grafana/data';
import { ExploreItemState } from 'app/types/explore';
import TableModel, { mergeTablesIntoModel } from 'app/core/table_model';
@ -29,13 +30,14 @@ export class ResultProcessor {
}
const onlyTimeSeries = this.dataFrames.filter(frame => isTimeSeries(frame, this.state.datasourceInstance?.meta.id));
const timeSeriesToShowInGraph = onlyTimeSeries.filter(frame => shouldShowInVisualisationType(frame, 'graph'));
if (onlyTimeSeries.length === 0) {
if (timeSeriesToShowInGraph.length === 0) {
return null;
}
return getGraphSeriesModel(
onlyTimeSeries,
timeSeriesToShowInGraph,
this.timeZone,
{},
{ showBars: false, showLines: true, showPoints: false },
@ -48,7 +50,7 @@ export class ResultProcessor {
return null;
}
const onlyTables = this.dataFrames.filter(frame => shouldShowInTable(frame));
const onlyTables = this.dataFrames.filter(frame => shouldShowInVisualisationType(frame, 'table'));
if (onlyTables.length === 0) {
return null;
@ -125,8 +127,8 @@ function isTimeSeries(frame: DataFrame, datasource?: string): boolean {
return false;
}
function shouldShowInTable(frame: DataFrame) {
if (frame.meta?.preferredVisualisationType && frame.meta?.preferredVisualisationType !== 'table') {
function shouldShowInVisualisationType(frame: DataFrame, visualisation: PreferredVisualisationType) {
if (frame.meta?.preferredVisualisationType && frame.meta?.preferredVisualisationType !== visualisation) {
return false;
}

View File

@ -1,6 +1,6 @@
import _ from 'lodash';
import TableModel from 'app/core/table_model';
import { TimeSeries, FieldType, Labels, formatLabels } from '@grafana/data';
import { TimeSeries, FieldType, Labels, formatLabels, QueryResultMeta } from '@grafana/data';
import { TemplateSrv } from 'app/features/templating/template_srv';
export class ResultTransformer {
@ -15,6 +15,7 @@ export class ResultTransformer {
prometheusResult,
options.responseListLength,
options.refId,
options.meta,
options.valueWithRefId
),
];
@ -81,9 +82,16 @@ export class ResultTransformer {
};
}
transformMetricDataToTable(md: any, resultCount: number, refId: string, valueWithRefId?: boolean): TableModel {
transformMetricDataToTable(
md: any,
resultCount: number,
refId: string,
meta: QueryResultMeta,
valueWithRefId?: boolean
): TableModel {
const table = new TableModel();
table.refId = refId;
table.meta = meta;
let i: number, j: number;
const metricLabels: { [key: string]: number } = {};