mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore/Loki: Show results of instant queries only in table and time series only in graph (#25845)
* Show results of instant queries only in table and rest in graph
* Add type to QueryResultMeta
* Update log row hover background only if context is not open
* Revert "Update log row hover background only if context is not open"
This reverts commit 144197c954
.
This commit is contained in:
parent
6eabe6c29f
commit
69f9b6f945
@ -4,7 +4,7 @@ import { Observable, from, merge, of } from 'rxjs';
|
|||||||
import { map, filter, catchError, switchMap } from 'rxjs/operators';
|
import { map, filter, catchError, switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
// Services & Utils
|
// Services & Utils
|
||||||
import { DataFrame, dateMath, FieldCache } from '@grafana/data';
|
import { DataFrame, dateMath, FieldCache, QueryResultMeta } from '@grafana/data';
|
||||||
import { getBackendSrv } from '@grafana/runtime';
|
import { getBackendSrv } from '@grafana/runtime';
|
||||||
import { addLabelToQuery } from 'app/plugins/datasource/prometheus/add_label_to_query';
|
import { addLabelToQuery } from 'app/plugins/datasource/prometheus/add_label_to_query';
|
||||||
import { DatasourceRequestOptions } from 'app/core/services/backend_srv';
|
import { DatasourceRequestOptions } from 'app/core/services/backend_srv';
|
||||||
@ -140,6 +140,10 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
time: `${timeNs + (1e9 - (timeNs % 1e9))}`,
|
time: `${timeNs + (1e9 - (timeNs % 1e9))}`,
|
||||||
limit: Math.min(options.maxDataPoints || Infinity, this.maxLines),
|
limit: Math.min(options.maxDataPoints || Infinity, this.maxLines),
|
||||||
};
|
};
|
||||||
|
/** Show results of Loki instant queries only in table */
|
||||||
|
const meta: QueryResultMeta = {
|
||||||
|
preferredVisualisationType: 'table',
|
||||||
|
};
|
||||||
|
|
||||||
return this._request(INSTANT_QUERY_ENDPOINT, query).pipe(
|
return this._request(INSTANT_QUERY_ENDPOINT, query).pipe(
|
||||||
catchError((err: any) => this.throwUnless(err, err.cancelled, target)),
|
catchError((err: any) => this.throwUnless(err, err.cancelled, target)),
|
||||||
@ -150,7 +154,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: [lokiResultsToTableModel(response.data.data.result, responseListLength, target.refId, true)],
|
data: [lokiResultsToTableModel(response.data.data.result, responseListLength, target.refId, meta, true)],
|
||||||
key: `${target.refId}_instant`,
|
key: `${target.refId}_instant`,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,7 @@ import {
|
|||||||
DataLink,
|
DataLink,
|
||||||
Field,
|
Field,
|
||||||
QueryResultMetaStat,
|
QueryResultMetaStat,
|
||||||
|
QueryResultMeta,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
|
|
||||||
import templateSrv from 'app/features/templating/template_srv';
|
import templateSrv from 'app/features/templating/template_srv';
|
||||||
@ -146,6 +147,8 @@ function lokiMatrixToTimeSeries(matrixResult: LokiMatrixResult, options: Transfo
|
|||||||
target: createMetricLabel(matrixResult.metric, options),
|
target: createMetricLabel(matrixResult.metric, options),
|
||||||
datapoints: lokiPointsToTimeseriesPoints(matrixResult.values, options),
|
datapoints: lokiPointsToTimeseriesPoints(matrixResult.values, options),
|
||||||
tags: matrixResult.metric,
|
tags: matrixResult.metric,
|
||||||
|
meta: options.meta,
|
||||||
|
refId: options.refId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +187,7 @@ export function lokiResultsToTableModel(
|
|||||||
lokiResults: Array<LokiMatrixResult | LokiVectorResult>,
|
lokiResults: Array<LokiMatrixResult | LokiVectorResult>,
|
||||||
resultCount: number,
|
resultCount: number,
|
||||||
refId: string,
|
refId: string,
|
||||||
|
meta: QueryResultMeta,
|
||||||
valueWithRefId?: boolean
|
valueWithRefId?: boolean
|
||||||
): TableModel {
|
): TableModel {
|
||||||
if (!lokiResults || lokiResults.length === 0) {
|
if (!lokiResults || lokiResults.length === 0) {
|
||||||
@ -198,6 +202,8 @@ export function lokiResultsToTableModel(
|
|||||||
// Sort metric labels, create columns for them and record their index
|
// Sort metric labels, create columns for them and record their index
|
||||||
const sortedLabels = [...metricLabels.values()].sort();
|
const sortedLabels = [...metricLabels.values()].sort();
|
||||||
const table = new TableModel();
|
const table = new TableModel();
|
||||||
|
table.refId = refId;
|
||||||
|
table.meta = meta;
|
||||||
table.columns = [
|
table.columns = [
|
||||||
{ text: 'Time', type: FieldType.time },
|
{ text: 'Time', type: FieldType.time },
|
||||||
...sortedLabels.map(label => ({ text: label, filterable: true })),
|
...sortedLabels.map(label => ({ text: label, filterable: true })),
|
||||||
@ -384,6 +390,11 @@ export function rangeQueryResponseToTimeSeries(
|
|||||||
target: LokiQuery,
|
target: LokiQuery,
|
||||||
responseListLength: number
|
responseListLength: number
|
||||||
): TimeSeries[] {
|
): TimeSeries[] {
|
||||||
|
/** Show results of Loki metric queries only in graph */
|
||||||
|
const meta: QueryResultMeta = {
|
||||||
|
preferredVisualisationType: 'graph',
|
||||||
|
};
|
||||||
|
|
||||||
const transformerOptions: TransformerOptions = {
|
const transformerOptions: TransformerOptions = {
|
||||||
format: target.format,
|
format: target.format,
|
||||||
legendFormat: target.legendFormat,
|
legendFormat: target.legendFormat,
|
||||||
@ -393,6 +404,7 @@ export function rangeQueryResponseToTimeSeries(
|
|||||||
query: query.query,
|
query: query.query,
|
||||||
responseListLength,
|
responseListLength,
|
||||||
refId: target.refId,
|
refId: target.refId,
|
||||||
|
meta,
|
||||||
valueWithRefId: target.valueWithRefId,
|
valueWithRefId: target.valueWithRefId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { DataQuery, DataSourceJsonData } from '@grafana/data';
|
import { DataQuery, DataSourceJsonData, QueryResultMeta } from '@grafana/data';
|
||||||
|
|
||||||
export interface LokiInstantQueryRequest {
|
export interface LokiInstantQueryRequest {
|
||||||
query: string;
|
query: string;
|
||||||
@ -123,5 +123,6 @@ export interface TransformerOptions {
|
|||||||
query: string;
|
query: string;
|
||||||
responseListLength: number;
|
responseListLength: number;
|
||||||
refId: string;
|
refId: string;
|
||||||
|
meta?: QueryResultMeta;
|
||||||
valueWithRefId?: boolean;
|
valueWithRefId?: boolean;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user