From 7bc0692801e5bb384935be141c9ae9ad9f18fd18 Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Thu, 13 Apr 2023 13:07:28 +0200 Subject: [PATCH] Logs: Add new LogRowContext types to `@grafana/data` (#66404) * Logs: Add new LogRowContext types to grafana/data * use right type for `RowContextOptions` * add missing renames --- packages/grafana-data/src/types/logs.ts | 16 +++++++++----- public/app/features/explore/Logs.tsx | 4 ++-- .../app/features/logs/components/LogRow.tsx | 4 ++-- .../app/features/logs/components/LogRows.tsx | 4 ++-- .../LogRowContextProvider.test.tsx | 11 +++++----- .../log-context/LogRowContextProvider.tsx | 10 ++++----- .../logs/components/log-context/types.ts | 4 ---- .../datasource/cloudwatch/datasource.ts | 5 ++--- .../CloudWatchLogsQueryRunner.test.ts | 7 ++++++- .../query-runner/CloudWatchLogsQueryRunner.ts | 9 ++++---- .../datasource/elasticsearch/datasource.ts | 21 ++++++++++--------- .../loki/LogContextProvider.test.ts | 10 ++++++--- .../datasource/loki/LogContextProvider.ts | 7 ++++--- .../app/plugins/datasource/loki/datasource.ts | 7 ++++--- public/app/plugins/datasource/loki/types.ts | 4 ++-- 15 files changed, 68 insertions(+), 55 deletions(-) delete mode 100644 public/app/features/logs/components/log-context/types.ts diff --git a/packages/grafana-data/src/types/logs.ts b/packages/grafana-data/src/types/logs.ts index d6508191bd9..5e0d078a4b2 100644 --- a/packages/grafana-data/src/types/logs.ts +++ b/packages/grafana-data/src/types/logs.ts @@ -139,6 +139,16 @@ export enum LogsDedupDescription { signature = 'De-duplication of successive lines that have identical punctuation and whitespace.', } +export interface LogRowContextOptions { + direction?: LogRowContextQueryDirection; + limit?: number; +} + +export enum LogRowContextQueryDirection { + Backward = 'BACKWARD', + Forward = 'FORWARD', +} + /** * Data sources that allow showing context rows around the provided LowRowModel should implement this method. * This will enable "context" button in Logs Panel. @@ -147,11 +157,7 @@ export interface DataSourceWithLogsContextSupport( - row: LogRowModel, - options?: TContextQueryOptions, - query?: TQuery - ) => Promise; + getLogRowContext: (row: LogRowModel, options?: LogRowContextOptions, query?: TQuery) => Promise; /** * This method can be used to show "context" button based on runtime conditions (for example row model data or plugin settings, etc.) diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 63964d11b06..c1c2e0e8a96 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -26,6 +26,7 @@ import { DataHoverClearEvent, EventBus, DataSourceWithLogsContextSupport, + LogRowContextOptions, } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; @@ -44,7 +45,6 @@ import store from 'app/core/store'; import { ExploreId } from 'app/types/explore'; import { LogRows } from '../logs/components/LogRows'; -import { RowContextOptions } from '../logs/components/log-context/types'; import { LogsMetaRow } from './LogsMetaRow'; import LogsNavigation from './LogsNavigation'; @@ -79,7 +79,7 @@ interface Props extends Themeable2 { onClickFilterOutLabel: (key: string, value: string) => void; onStartScanning?: () => void; onStopScanning?: () => void; - getRowContext?: (row: LogRowModel, options?: RowContextOptions) => Promise; + getRowContext?: (row: LogRowModel, options?: LogRowContextOptions) => Promise; getLogRowContextUi?: DataSourceWithLogsContextSupport['getLogRowContextUi']; getFieldLinks: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array>; addResultsToCache: () => void; diff --git a/public/app/features/logs/components/LogRow.tsx b/public/app/features/logs/components/LogRow.tsx index 65748b5c52a..ef10135df72 100644 --- a/public/app/features/logs/components/LogRow.tsx +++ b/public/app/features/logs/components/LogRow.tsx @@ -11,6 +11,7 @@ import { CoreApp, DataFrame, DataSourceWithLogsContextSupport, + LogRowContextOptions, } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime'; import { TimeZone } from '@grafana/schema'; @@ -29,7 +30,6 @@ import { HasMoreContextRows, LogRowContextProvider, } from './log-context/LogRowContextProvider'; -import { RowContextOptions } from './log-context/types'; interface Props extends Themeable2 { row: LogRowModel; @@ -50,7 +50,7 @@ interface Props extends Themeable2 { onClickFilterLabel?: (key: string, value: string) => void; onClickFilterOutLabel?: (key: string, value: string) => void; onContextClick?: () => void; - getRowContext: (row: LogRowModel, options?: RowContextOptions) => Promise; + getRowContext: (row: LogRowModel, options?: LogRowContextOptions) => Promise; getLogRowContextUi?: (row: LogRowModel) => React.ReactNode; getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array>; showContextToggle?: (row?: LogRowModel) => boolean; diff --git a/public/app/features/logs/components/LogRows.tsx b/public/app/features/logs/components/LogRows.tsx index 8d38e8984b7..2109c479c0d 100644 --- a/public/app/features/logs/components/LogRows.tsx +++ b/public/app/features/logs/components/LogRows.tsx @@ -12,6 +12,7 @@ import { DataFrame, DataSourceWithLogsContextSupport, DataQueryResponse, + LogRowContextOptions, } from '@grafana/data'; import { withTheme2, Themeable2 } from '@grafana/ui'; @@ -20,7 +21,6 @@ import { sortLogRows } from '../utils'; //Components import { LogRow } from './LogRow'; import { getLogRowStyles } from './getLogRowStyles'; -import { RowContextOptions } from './log-context/types'; export const PREVIEW_LIMIT = 100; @@ -43,7 +43,7 @@ export interface Props extends Themeable2 { showContextToggle?: (row?: LogRowModel) => boolean; onClickFilterLabel?: (key: string, value: string) => void; onClickFilterOutLabel?: (key: string, value: string) => void; - getRowContext?: (row: LogRowModel, options?: RowContextOptions) => Promise; + getRowContext?: (row: LogRowModel, options?: LogRowContextOptions) => Promise; getLogRowContextUi?: DataSourceWithLogsContextSupport['getLogRowContextUi']; getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array>; onClickShowField?: (key: string) => void; diff --git a/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx b/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx index 2ae4af716cd..79a2aee3e27 100644 --- a/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx @@ -1,12 +1,11 @@ import { render, screen } from '@testing-library/react'; import React from 'react'; -import { FieldType, LogRowModel, MutableDataFrame, DataQueryResponse } from '@grafana/data'; +import { FieldType, LogRowModel, MutableDataFrame, DataQueryResponse, LogRowContextOptions } from '@grafana/data'; import { createLogRow } from '../__mocks__/logRow'; import { getRowContexts, LogRowContextProvider } from './LogRowContextProvider'; -import { RowContextOptions } from './types'; const row = createLogRow({ entry: '4', timeEpochMs: 4 }); @@ -35,7 +34,7 @@ describe('getRowContexts', () => { ], }); let called = false; - const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise => { + const getRowContextMock = (row: LogRowModel, options?: LogRowContextOptions): Promise => { if (!called) { called = true; return Promise.resolve({ data: [firstResult] }); @@ -70,7 +69,7 @@ describe('getRowContexts', () => { ], }); let called = false; - const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise => { + const getRowContextMock = (row: LogRowModel, options?: LogRowContextOptions): Promise => { if (!called) { called = true; return Promise.resolve({ data: [firstResult] }); @@ -95,7 +94,7 @@ describe('getRowContexts', () => { const firstError = new Error('Error 1'); const secondError = new Error('Error 2'); let called = false; - const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise => { + const getRowContextMock = (row: LogRowModel, options?: LogRowContextOptions): Promise => { if (!called) { called = true; return Promise.reject(firstError); @@ -142,7 +141,7 @@ describe('LogRowContextProvider', () => { }); let called = false; - const getRowContextMock = (row: LogRowModel, options?: RowContextOptions): Promise => { + const getRowContextMock = (row: LogRowModel, options?: LogRowContextOptions): Promise => { if (!called) { called = true; return Promise.resolve({ data: [firstResult] }); diff --git a/public/app/features/logs/components/log-context/LogRowContextProvider.tsx b/public/app/features/logs/components/log-context/LogRowContextProvider.tsx index ac0e4419f87..a9fed25c431 100644 --- a/public/app/features/logs/components/log-context/LogRowContextProvider.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextProvider.tsx @@ -6,14 +6,14 @@ import { DataQueryResponse, Field, FieldCache, + LogRowContextOptions, + LogRowContextQueryDirection, LogRowModel, LogsSortOrder, toDataFrame, } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime'; -import { RowContextOptions } from './types'; - export interface LogRowContextRows { before?: string[]; after?: string[]; @@ -37,7 +37,7 @@ interface ResultType { interface LogRowContextProviderProps { row: LogRowModel; logsSortOrder?: LogsSortOrder | null; - getRowContext: (row: LogRowModel, options?: RowContextOptions) => Promise; + getRowContext: (row: LogRowModel, options?: LogRowContextOptions) => Promise; children: (props: { result: LogRowContextRows; errors: LogRowContextQueryErrors; @@ -50,7 +50,7 @@ interface LogRowContextProviderProps { } export const getRowContexts = async ( - getRowContext: (row: LogRowModel, options?: RowContextOptions) => Promise, + getRowContext: (row: LogRowModel, options?: LogRowContextOptions) => Promise, row: LogRowModel, limit: number, logsSortOrder?: LogsSortOrder | null @@ -62,7 +62,7 @@ export const getRowContexts = async ( getRowContext(row, { // The start time is inclusive so we will get the one row we are using as context entry limit: limit + 1, - direction: 'FORWARD', + direction: LogRowContextQueryDirection.Forward, }), ]; diff --git a/public/app/features/logs/components/log-context/types.ts b/public/app/features/logs/components/log-context/types.ts deleted file mode 100644 index 3497156f2c9..00000000000 --- a/public/app/features/logs/components/log-context/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface RowContextOptions { - direction?: 'BACKWARD' | 'FORWARD'; - limit?: number; -} diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index 118afb69331..1ee0ebd28e9 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -9,6 +9,7 @@ import { DataSourceInstanceSettings, DataSourceWithLogsContextSupport, LoadingState, + LogRowContextOptions, LogRowModel, ScopedVars, } from '@grafana/data'; @@ -16,8 +17,6 @@ import { DataSourceWithBackend } from '@grafana/runtime'; import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv'; -import { RowContextOptions } from '../../../features/logs/components/log-context/types'; - import { CloudWatchAnnotationSupport } from './annotationSupport'; import { DEFAULT_METRICS_QUERY, getDefaultLogsQuery } from './defaultQueries'; import { isCloudWatchAnnotationQuery, isCloudWatchLogsQuery, isCloudWatchMetricsQuery } from './guards'; @@ -136,7 +135,7 @@ export class CloudWatchDatasource getLogRowContext = async ( row: LogRowModel, - context?: RowContextOptions, + context?: LogRowContextOptions, query?: CloudWatchLogsQuery ): Promise<{ data: DataFrame[] }> => { return this.logsQueryRunner.getLogRowContext(row, context, query); diff --git a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts index 7dd13f85b22..85e6c23d022 100644 --- a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts +++ b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.test.ts @@ -8,6 +8,7 @@ import { MutableDataFrame, dateTime, DataQueryRequest, + LogRowContextQueryDirection, } from '@grafana/data'; import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv'; @@ -61,7 +62,11 @@ describe('CloudWatchLogsQueryRunner', () => { expect(fetchMock.mock.calls[0][0].data.queries[0].endTime).toBe(4); expect(fetchMock.mock.calls[0][0].data.queries[0].region).toBe(undefined); - await runner.getLogRowContext(row, { direction: 'FORWARD' }, { ...validLogsQuery, region: 'eu-east' }); + await runner.getLogRowContext( + row, + { direction: LogRowContextQueryDirection.Forward }, + { ...validLogsQuery, region: 'eu-east' } + ); expect(fetchMock.mock.calls[1][0].data.queries[0].startTime).toBe(4); expect(fetchMock.mock.calls[1][0].data.queries[0].region).toBe('eu-east'); }); diff --git a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts index 3dad3cf8401..0f4beed4989 100644 --- a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts +++ b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts @@ -24,6 +24,8 @@ import { DataQueryResponse, DataSourceInstanceSettings, LoadingState, + LogRowContextOptions, + LogRowContextQueryDirection, LogRowModel, rangeUtil, } from '@grafana/data'; @@ -31,7 +33,6 @@ import { BackendDataSourceResponse, config, FetchError, FetchResponse, toDataQue import { TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { TemplateSrv } from 'app/features/templating/template_srv'; -import { RowContextOptions } from '../../../../features/logs/components/log-context/types'; import { CloudWatchJsonData, CloudWatchLogsQuery, @@ -325,7 +326,7 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest { getLogRowContext = async ( row: LogRowModel, - { limit = 10, direction = 'BACKWARD' }: RowContextOptions = {}, + { limit = 10, direction = LogRowContextQueryDirection.Backward }: LogRowContextOptions = {}, query?: CloudWatchLogsQuery ): Promise<{ data: DataFrame[] }> => { let logStreamField = null; @@ -347,13 +348,13 @@ export class CloudWatchLogsQueryRunner extends CloudWatchRequest { const requestParams: GetLogEventsRequest = { limit, - startFromHead: direction !== 'BACKWARD', + startFromHead: direction !== LogRowContextQueryDirection.Backward, region: query?.region, logGroupName: parseLogGroupName(logField!.values.get(row.rowIndex)), logStreamName: logStreamField!.values.get(row.rowIndex), }; - if (direction === 'BACKWARD') { + if (direction === LogRowContextQueryDirection.Backward) { requestParams.endTime = row.timeEpochMs; } else { requestParams.startTime = row.timeEpochMs; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 612da1585ff..2defa6c8526 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -31,13 +31,14 @@ import { rangeUtil, Field, sortDataFrame, + LogRowContextQueryDirection, + LogRowContextOptions, } from '@grafana/data'; import { BackendSrvRequest, DataSourceWithBackend, getBackendSrv, getDataSourceSrv, config } from '@grafana/runtime'; import { queryLogsVolume } from 'app/core/logsModel'; import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv'; -import { RowContextOptions } from '../../../features/logs/components/log-context/types'; import { getLogLevelFromKey } from '../../../features/logs/utils'; import { ElasticResponse } from './ElasticResponse'; @@ -500,7 +501,7 @@ export class ElasticDatasource return true; } - getLogRowContext = async (row: LogRowModel, options?: RowContextOptions): Promise<{ data: DataFrame[] }> => { + getLogRowContext = async (row: LogRowModel, options?: LogRowContextOptions): Promise<{ data: DataFrame[] }> => { const { disableElasticsearchBackendQuerying } = config.featureToggles; if (!disableElasticsearchBackendQuerying) { const contextRequest = this.makeLogContextDataRequest(row, options); @@ -523,10 +524,10 @@ export class ElasticDatasource } else { const sortField = row.dataFrame.fields.find((f) => f.name === 'sort'); const searchAfter = sortField?.values.get(row.rowIndex) || [row.timeEpochMs]; - const sort = options?.direction === 'FORWARD' ? 'asc' : 'desc'; + const sort = options?.direction === LogRowContextQueryDirection.Forward ? 'asc' : 'desc'; const header = - options?.direction === 'FORWARD' + options?.direction === LogRowContextQueryDirection.Forward ? this.getQueryHeader('query_then_fetch', dateTime(row.timeEpochMs)) : this.getQueryHeader('query_then_fetch', undefined, dateTime(row.timeEpochMs)); @@ -539,7 +540,7 @@ export class ElasticDatasource { range: { [this.timeField]: { - [options?.direction === 'FORWARD' ? 'gte' : 'lte']: row.timeEpochMs, + [options?.direction === LogRowContextQueryDirection.Forward ? 'gte' : 'lte']: row.timeEpochMs, format: 'epoch_millis', }, }, @@ -1109,15 +1110,15 @@ export class ElasticDatasource return freshDatabaseVersion; } - private makeLogContextDataRequest = (row: LogRowModel, options?: RowContextOptions) => { - const direction = options?.direction || 'BACKWARD'; + private makeLogContextDataRequest = (row: LogRowModel, options?: LogRowContextOptions) => { + const direction = options?.direction || LogRowContextQueryDirection.Backward; const logQuery: Logs = { type: 'logs', id: '1', settings: { limit: options?.limit ? options?.limit.toString() : '10', // Sorting of results in the context query - sortDirection: direction === 'BACKWARD' ? 'desc' : 'asc', + sortDirection: direction === LogRowContextQueryDirection.Backward ? 'desc' : 'asc', // Used to get the next log lines before/after the current log line using sort field of selected log line searchAfter: row.dataFrame.fields.find((f) => f.name === 'sort')?.values.get(row.rowIndex) ?? [row.timeEpochMs], }, @@ -1266,7 +1267,7 @@ function createContextTimeRange(rowTimeEpochMs: number, direction: string, inter // For log context, we want to request data from 7 subsequent/previous indices if (intervalPattern) { const intervalInfo = intervalMap[intervalPattern]; - if (direction === 'FORWARD') { + if (direction === LogRowContextQueryDirection.Forward) { return { from: dateTime(rowTimeEpochMs).utc(), to: dateTime(rowTimeEpochMs).add(offset, intervalInfo.amount).utc().startOf(intervalInfo.startOf), @@ -1279,7 +1280,7 @@ function createContextTimeRange(rowTimeEpochMs: number, direction: string, inter } // If we don't have an interval pattern, we can't do this, so we just request data from 7h before/after } else { - if (direction === 'FORWARD') { + if (direction === LogRowContextQueryDirection.Forward) { return { from: dateTime(rowTimeEpochMs).utc(), to: dateTime(rowTimeEpochMs).add(offset, 'hours').utc(), diff --git a/public/app/plugins/datasource/loki/LogContextProvider.test.ts b/public/app/plugins/datasource/loki/LogContextProvider.test.ts index 26a4989059e..6a494ef8b79 100644 --- a/public/app/plugins/datasource/loki/LogContextProvider.test.ts +++ b/public/app/plugins/datasource/loki/LogContextProvider.test.ts @@ -1,4 +1,4 @@ -import { FieldType, LogRowModel, MutableDataFrame } from '@grafana/data'; +import { FieldType, LogRowContextQueryDirection, LogRowModel, MutableDataFrame } from '@grafana/data'; import LokiLanguageProvider from './LanguageProvider'; import { LogContextProvider } from './LogContextProvider'; @@ -47,14 +47,18 @@ describe('new context ui', () => { describe('prepareLogRowContextQueryTarget', () => { const lcp = new LogContextProvider(defaultLanguageProviderMock); it('creates query with only labels from /labels API', async () => { - const contextQuery = await lcp.prepareLogRowContextQueryTarget(defaultLogRow, 10, 'BACKWARD'); + const contextQuery = await lcp.prepareLogRowContextQueryTarget( + defaultLogRow, + 10, + LogRowContextQueryDirection.Backward + ); expect(contextQuery.query.expr).toContain('uniqueParsedLabel'); expect(contextQuery.query.expr).not.toContain('baz'); }); it('should call languageProvider.start to fetch labels', async () => { - await lcp.prepareLogRowContextQueryTarget(defaultLogRow, 10, 'BACKWARD'); + await lcp.prepareLogRowContextQueryTarget(defaultLogRow, 10, LogRowContextQueryDirection.Backward); expect(lcp.languageProvider.start).toBeCalled(); }); }); diff --git a/public/app/plugins/datasource/loki/LogContextProvider.ts b/public/app/plugins/datasource/loki/LogContextProvider.ts index 7549e6dede3..f8dedc90c3b 100644 --- a/public/app/plugins/datasource/loki/LogContextProvider.ts +++ b/public/app/plugins/datasource/loki/LogContextProvider.ts @@ -1,4 +1,4 @@ -import { FieldCache, FieldType, LogRowModel, TimeRange, toUtc } from '@grafana/data'; +import { FieldCache, FieldType, LogRowContextQueryDirection, LogRowModel, TimeRange, toUtc } from '@grafana/data'; import { DataQuery } from '@grafana/schema'; import LokiLanguageProvider from './LanguageProvider'; @@ -20,14 +20,15 @@ export class LogContextProvider { async prepareLogRowContextQueryTarget( row: LogRowModel, limit: number, - direction: 'BACKWARD' | 'FORWARD', + direction: LogRowContextQueryDirection, origQuery?: DataQuery ): Promise<{ query: LokiQuery; range: TimeRange }> { let expr = await this.prepareContextExpr(row, origQuery); const contextTimeBuffer = 2 * 60 * 60 * 1000; // 2h buffer - const queryDirection = direction === 'FORWARD' ? LokiQueryDirection.Forward : LokiQueryDirection.Backward; + const queryDirection = + direction === LogRowContextQueryDirection.Forward ? LokiQueryDirection.Forward : LokiQueryDirection.Backward; const query: LokiQuery = { expr, diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index 06f1c31092b..527ba30ca42 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -31,6 +31,8 @@ import { rangeUtil, ScopedVars, TimeRange, + LogRowContextOptions, + LogRowContextQueryDirection, } from '@grafana/data'; import { BackendSrvRequest, config, DataSourceWithBackend, FetchError } from '@grafana/runtime'; import { DataQuery } from '@grafana/schema'; @@ -40,7 +42,6 @@ import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv'; import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv'; import { serializeParams } from '../../../core/utils/fetch'; -import { RowContextOptions } from '../../../features/logs/components/log-context/types'; import { getLogLevelFromKey } from '../../../features/logs/utils'; import { renderLegendFormat } from '../prometheus/legend'; import { replaceVariables, returnVariables } from '../prometheus/querybuilder/shared/parsingUtils'; @@ -646,10 +647,10 @@ export class LokiDatasource getLogRowContext = async ( row: LogRowModel, - options?: RowContextOptions, + options?: LogRowContextOptions, origQuery?: DataQuery ): Promise<{ data: DataFrame[] }> => { - const direction = (options && options.direction) || 'BACKWARD'; + const direction = (options && options.direction) || LogRowContextQueryDirection.Backward; const limit = (options && options.limit) || 10; const { query, range } = await this.logContextProvider.prepareLogRowContextQueryTarget( row, diff --git a/public/app/plugins/datasource/loki/types.ts b/public/app/plugins/datasource/loki/types.ts index 607c376bf8e..7b0261ee56c 100644 --- a/public/app/plugins/datasource/loki/types.ts +++ b/public/app/plugins/datasource/loki/types.ts @@ -8,7 +8,7 @@ export interface LokiInstantQueryRequest { query: string; limit?: number; time?: string; - direction?: 'BACKWARD' | 'FORWARD'; + direction?: LokiQueryDirection; } export interface LokiRangeQueryRequest { @@ -17,7 +17,7 @@ export interface LokiRangeQueryRequest { start?: number; end?: number; step?: number; - direction?: 'BACKWARD' | 'FORWARD'; + direction?: LokiQueryDirection; } export enum LokiResultType {