diff --git a/src/datasource/base.ts b/src/datasource/base.ts index 3657190..719b66c 100644 --- a/src/datasource/base.ts +++ b/src/datasource/base.ts @@ -1,4 +1,3 @@ -import { first as _first, map as _map } from 'lodash'; import { Observable, lastValueFrom, from, of } from 'rxjs'; import { map, mergeMap } from 'rxjs/operators'; @@ -10,10 +9,8 @@ import { DataQueryRequest, DataQueryResponse, DataSourceInstanceSettings, - DataSourceWithLogsContextSupport, DataSourceWithQueryImportSupport, getDefaultTimeRange, - LogRowModel, MetricFindValue, QueryFixAction, ScopedVars, @@ -32,10 +29,8 @@ import { isMetricAggregationWithField } from 'components/QueryEditor/MetricAggre import { bucketAggregationConfig } from 'components/QueryEditor/BucketAggregationsEditor/utils'; import { isBucketAggregationWithField } from 'components/QueryEditor/BucketAggregationsEditor/aggregations'; import ElasticsearchLanguageProvider from 'LanguageProvider'; -import { ReactNode } from 'react'; import { fieldTypeMap } from 'utils'; import { addAddHocFilter } from 'modifyQuery'; -import { LogContextProvider, LogRowContextOptions } from '@/LogContext/LogContextProvider'; import { getQueryResponseProcessor } from 'datasource/processResponse'; import { SECOND } from 'utils/time'; @@ -53,7 +48,6 @@ type FieldCapsSpec = { export class BaseQuickwitDataSource extends DataSourceWithBackend implements - DataSourceWithLogsContextSupport, DataSourceWithQueryImportSupport { index: string; @@ -63,7 +57,6 @@ export class BaseQuickwitDataSource dataLinks: DataLinkConfig[]; languageProvider: ElasticsearchLanguageProvider; - private logContextProvider: LogContextProvider; constructor( instanceSettings: DataSourceInstanceSettings, @@ -77,7 +70,6 @@ export class BaseQuickwitDataSource this.logLevelField = settingsData.logLevelField || ''; this.dataLinks = settingsData.dataLinks || []; this.languageProvider = new ElasticsearchLanguageProvider(this); - this.logContextProvider = new LogContextProvider(this); } query(request: DataQueryRequest): Observable { @@ -283,28 +275,6 @@ export class BaseQuickwitDataSource return text; } - // Log Context - - // NOTE : deprecated since grafana-data 10.3 - showContextToggle(row?: LogRowModel | undefined): boolean { - return true; - } - - getLogRowContext = async ( - row: LogRowModel, - options?: LogRowContextOptions, - origQuery?: ElasticsearchQuery - ): Promise<{ data: DataFrame[] }> => { - return await this.logContextProvider.getLogRowContext(row, options, origQuery); - } - - getLogRowContextUi( - row: LogRowModel, - runContextQuery?: (() => void), - origQuery?: ElasticsearchQuery - ): ReactNode { - return this.logContextProvider.getLogRowContextUi(row, runContextQuery, origQuery); - } /** * Returns false if the query should be skipped diff --git a/src/datasource/index.ts b/src/datasource/index.ts index 4e294b0..f818a21 100644 --- a/src/datasource/index.ts +++ b/src/datasource/index.ts @@ -1,8 +1,10 @@ import { BaseQuickwitDataSource } from './base'; import { withSupplementaryQueries } from './supplementaryQueries'; +import { withLogContext } from './logsContext'; const mixins = [ + withLogContext, withSupplementaryQueries, ] const qwds = mixins.reduce(( qwds, fn) => fn(qwds), BaseQuickwitDataSource) diff --git a/src/datasource/logsContext.ts b/src/datasource/logsContext.ts new file mode 100644 index 0000000..6358f3a --- /dev/null +++ b/src/datasource/logsContext.ts @@ -0,0 +1,39 @@ +import { DataFrame, DataSourceWithLogsContextSupport, LogRowModel, } from '@grafana/data'; +import {ElasticsearchQuery } from '@/types'; + +import { ReactNode } from 'react'; +import { LogContextProvider, LogRowContextOptions } from '@/LogContext/LogContextProvider'; + +import { BaseQuickwitDataSourceConstructor } from './base'; + +export function withLogContext ( Base: T ){ + return class DSWithLogsContext extends Base implements DataSourceWithLogsContextSupport { + protected logContextProvider: LogContextProvider; + // Log Context + constructor(...args: any[]){ + super(...args) + this.logContextProvider = new LogContextProvider(this); + } + // NOTE : deprecated since grafana-data 10.3 + showContextToggle(row?: LogRowModel | undefined): boolean { + return true; + } + + getLogRowContext = async ( + row: LogRowModel, + options?: LogRowContextOptions, + origQuery?: ElasticsearchQuery + ): Promise<{ data: DataFrame[] }> => { + return await this.logContextProvider.getLogRowContext(row, options, origQuery); + } + + getLogRowContextUi( + row: LogRowModel, + runContextQuery?: (() => void), + origQuery?: ElasticsearchQuery + ): ReactNode { + return this.logContextProvider.getLogRowContextUi(row, runContextQuery, origQuery); + } + + }; +}