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';
|
||||
|
||||
// Services & Utils
|
||||
import { DataFrame, dateMath, FieldCache } from '@grafana/data';
|
||||
import { DataFrame, dateMath, FieldCache, QueryResultMeta } from '@grafana/data';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { addLabelToQuery } from 'app/plugins/datasource/prometheus/add_label_to_query';
|
||||
import { DatasourceRequestOptions } from 'app/core/services/backend_srv';
|
||||
@ -140,6 +140,10 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
time: `${timeNs + (1e9 - (timeNs % 1e9))}`,
|
||||
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(
|
||||
catchError((err: any) => this.throwUnless(err, err.cancelled, target)),
|
||||
@ -150,7 +154,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
||||
}
|
||||
|
||||
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`,
|
||||
};
|
||||
})
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
DataLink,
|
||||
Field,
|
||||
QueryResultMetaStat,
|
||||
QueryResultMeta,
|
||||
} from '@grafana/data';
|
||||
|
||||
import templateSrv from 'app/features/templating/template_srv';
|
||||
@ -146,6 +147,8 @@ function lokiMatrixToTimeSeries(matrixResult: LokiMatrixResult, options: Transfo
|
||||
target: createMetricLabel(matrixResult.metric, options),
|
||||
datapoints: lokiPointsToTimeseriesPoints(matrixResult.values, options),
|
||||
tags: matrixResult.metric,
|
||||
meta: options.meta,
|
||||
refId: options.refId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -184,6 +187,7 @@ export function lokiResultsToTableModel(
|
||||
lokiResults: Array<LokiMatrixResult | LokiVectorResult>,
|
||||
resultCount: number,
|
||||
refId: string,
|
||||
meta: QueryResultMeta,
|
||||
valueWithRefId?: boolean
|
||||
): TableModel {
|
||||
if (!lokiResults || lokiResults.length === 0) {
|
||||
@ -198,6 +202,8 @@ export function lokiResultsToTableModel(
|
||||
// Sort metric labels, create columns for them and record their index
|
||||
const sortedLabels = [...metricLabels.values()].sort();
|
||||
const table = new TableModel();
|
||||
table.refId = refId;
|
||||
table.meta = meta;
|
||||
table.columns = [
|
||||
{ text: 'Time', type: FieldType.time },
|
||||
...sortedLabels.map(label => ({ text: label, filterable: true })),
|
||||
@ -384,6 +390,11 @@ export function rangeQueryResponseToTimeSeries(
|
||||
target: LokiQuery,
|
||||
responseListLength: number
|
||||
): TimeSeries[] {
|
||||
/** Show results of Loki metric queries only in graph */
|
||||
const meta: QueryResultMeta = {
|
||||
preferredVisualisationType: 'graph',
|
||||
};
|
||||
|
||||
const transformerOptions: TransformerOptions = {
|
||||
format: target.format,
|
||||
legendFormat: target.legendFormat,
|
||||
@ -393,6 +404,7 @@ export function rangeQueryResponseToTimeSeries(
|
||||
query: query.query,
|
||||
responseListLength,
|
||||
refId: target.refId,
|
||||
meta,
|
||||
valueWithRefId: target.valueWithRefId,
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DataQuery, DataSourceJsonData } from '@grafana/data';
|
||||
import { DataQuery, DataSourceJsonData, QueryResultMeta } from '@grafana/data';
|
||||
|
||||
export interface LokiInstantQueryRequest {
|
||||
query: string;
|
||||
@ -123,5 +123,6 @@ export interface TransformerOptions {
|
||||
query: string;
|
||||
responseListLength: number;
|
||||
refId: string;
|
||||
meta?: QueryResultMeta;
|
||||
valueWithRefId?: boolean;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user