From e9b15eff72247192f0dbcccd27cddbf43385d5bf Mon Sep 17 00:00:00 2001 From: Sven Grossmann Date: Tue, 11 Apr 2023 12:19:28 +0200 Subject: [PATCH] Logs: Move components to dedicated directory (#65936) * move log-context components to dedicated directory * fix any * add right format of lerna.json --- .betterer.results | 5 +---- public/app/features/explore/Logs.tsx | 2 +- public/app/features/logs/components/LogRow.tsx | 10 +++++----- public/app/features/logs/components/LogRowMessage.tsx | 4 ++-- public/app/features/logs/components/LogRows.tsx | 7 ++++--- .../{ => log-context}/LogRowContext.test.tsx | 0 .../components/{ => log-context}/LogRowContext.tsx | 3 ++- .../{ => log-context}/LogRowContextProvider.test.tsx | 6 ++++-- .../{ => log-context}/LogRowContextProvider.tsx | 5 +---- .../app/features/logs/components/log-context/types.ts | 4 ++++ public/app/plugins/datasource/cloudwatch/datasource.ts | 2 +- .../query-runner/CloudWatchLogsQueryRunner.ts | 2 +- .../app/plugins/datasource/elasticsearch/datasource.ts | 4 ++-- public/app/plugins/datasource/loki/datasource.ts | 2 +- 14 files changed, 29 insertions(+), 27 deletions(-) rename public/app/features/logs/components/{ => log-context}/LogRowContext.test.tsx (100%) rename public/app/features/logs/components/{ => log-context}/LogRowContext.tsx (99%) rename public/app/features/logs/components/{ => log-context}/LogRowContextProvider.test.tsx (97%) rename public/app/features/logs/components/{ => log-context}/LogRowContextProvider.tsx (98%) create mode 100644 public/app/features/logs/components/log-context/types.ts diff --git a/.betterer.results b/.betterer.results index 4db1152f170..21a1127350f 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2948,15 +2948,12 @@ exports[`better eslint`] = { "public/app/features/live/index.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/logs/components/LogRowContextProvider.tsx:5381": [ + "public/app/features/logs/components/log-context/LogRowContextProvider.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], [0, 0, 0, "Do not use any type assertions.", "3"] ], - "public/app/features/logs/components/LogRows.tsx:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/logs/utils.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index d883367602f..263595de654 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -43,8 +43,8 @@ import { dedupLogRows, filterLogLevels } from 'app/core/logsModel'; import store from 'app/core/store'; import { ExploreId } from 'app/types/explore'; -import { RowContextOptions } from '../logs/components/LogRowContextProvider'; import { LogRows } from '../logs/components/LogRows'; +import { RowContextOptions } from '../logs/components/log-context/types'; import { LogsMetaRow } from './LogsMetaRow'; import LogsNavigation from './LogsNavigation'; diff --git a/public/app/features/logs/components/LogRow.tsx b/public/app/features/logs/components/LogRow.tsx index ebeac4c7930..65748b5c52a 100644 --- a/public/app/features/logs/components/LogRow.tsx +++ b/public/app/features/logs/components/LogRow.tsx @@ -20,16 +20,16 @@ import { checkLogsError, escapeUnescapedString } from '../utils'; import { LogDetails } from './LogDetails'; import { LogLabels } from './LogLabels'; +import { LogRowMessage } from './LogRowMessage'; +import { LogRowMessageDisplayedFields } from './LogRowMessageDisplayedFields'; +import { getLogLevelStyles, LogRowStyles } from './getLogRowStyles'; import { LogRowContextRows, LogRowContextQueryErrors, HasMoreContextRows, LogRowContextProvider, - RowContextOptions, -} from './LogRowContextProvider'; -import { LogRowMessage } from './LogRowMessage'; -import { LogRowMessageDisplayedFields } from './LogRowMessageDisplayedFields'; -import { getLogLevelStyles, LogRowStyles } from './getLogRowStyles'; +} from './log-context/LogRowContextProvider'; +import { RowContextOptions } from './log-context/types'; interface Props extends Themeable2 { row: LogRowModel; diff --git a/public/app/features/logs/components/LogRowMessage.tsx b/public/app/features/logs/components/LogRowMessage.tsx index e8108f815a4..97a6a87b135 100644 --- a/public/app/features/logs/components/LogRowMessage.tsx +++ b/public/app/features/logs/components/LogRowMessage.tsx @@ -13,9 +13,9 @@ import { import { IconButton, Tooltip } from '@grafana/ui'; import { LogMessageAnsi } from './LogMessageAnsi'; -import { LogRowContext } from './LogRowContext'; -import { LogRowContextQueryErrors, HasMoreContextRows, LogRowContextRows } from './LogRowContextProvider'; import { LogRowStyles } from './getLogRowStyles'; +import { LogRowContext } from './log-context/LogRowContext'; +import { LogRowContextQueryErrors, HasMoreContextRows, LogRowContextRows } from './log-context/LogRowContextProvider'; export const MAX_CHARACTERS = 100000; diff --git a/public/app/features/logs/components/LogRows.tsx b/public/app/features/logs/components/LogRows.tsx index 464e37837a7..8d38e8984b7 100644 --- a/public/app/features/logs/components/LogRows.tsx +++ b/public/app/features/logs/components/LogRows.tsx @@ -11,6 +11,7 @@ import { CoreApp, DataFrame, DataSourceWithLogsContextSupport, + DataQueryResponse, } from '@grafana/data'; import { withTheme2, Themeable2 } from '@grafana/ui'; @@ -18,8 +19,8 @@ import { sortLogRows } from '../utils'; //Components import { LogRow } from './LogRow'; -import { RowContextOptions } from './LogRowContextProvider'; import { getLogRowStyles } from './getLogRowStyles'; +import { RowContextOptions } from './log-context/types'; export const PREVIEW_LIMIT = 100; @@ -42,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?: RowContextOptions) => Promise; getLogRowContextUi?: DataSourceWithLogsContextSupport['getLogRowContextUi']; getFieldLinks?: (field: Field, rowIndex: number, dataFrame: DataFrame) => Array>; onClickShowField?: (key: string) => void; @@ -148,7 +149,7 @@ class UnThemedLogRows extends PureComponent { // React profiler becomes unusable if we pass all rows to all rows and their labels, using getter instead const getRows = this.makeGetRows(orderedRows); - const getRowContext = this.props.getRowContext ? this.props.getRowContext : () => Promise.resolve([]); + const getRowContext = this.props.getRowContext ? this.props.getRowContext : () => Promise.resolve({ data: [] }); return ( diff --git a/public/app/features/logs/components/LogRowContext.test.tsx b/public/app/features/logs/components/log-context/LogRowContext.test.tsx similarity index 100% rename from public/app/features/logs/components/LogRowContext.test.tsx rename to public/app/features/logs/components/log-context/LogRowContext.test.tsx diff --git a/public/app/features/logs/components/LogRowContext.tsx b/public/app/features/logs/components/log-context/LogRowContext.tsx similarity index 99% rename from public/app/features/logs/components/LogRowContext.tsx rename to public/app/features/logs/components/log-context/LogRowContext.tsx index 53bb0cf0a99..937be311f34 100644 --- a/public/app/features/logs/components/LogRowContext.tsx +++ b/public/app/features/logs/components/log-context/LogRowContext.tsx @@ -22,7 +22,8 @@ import { useTheme2, } from '@grafana/ui'; -import { LogMessageAnsi } from './LogMessageAnsi'; +import { LogMessageAnsi } from '../LogMessageAnsi'; + import { HasMoreContextRows, LogRowContextQueryErrors, LogRowContextRows } from './LogRowContextProvider'; export enum LogGroupPosition { diff --git a/public/app/features/logs/components/LogRowContextProvider.test.tsx b/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx similarity index 97% rename from public/app/features/logs/components/LogRowContextProvider.test.tsx rename to public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx index 27f38f02087..2ae4af716cd 100644 --- a/public/app/features/logs/components/LogRowContextProvider.test.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextProvider.test.tsx @@ -3,8 +3,10 @@ import React from 'react'; import { FieldType, LogRowModel, MutableDataFrame, DataQueryResponse } from '@grafana/data'; -import { getRowContexts, LogRowContextProvider, RowContextOptions } from './LogRowContextProvider'; -import { createLogRow } from './__mocks__/logRow'; +import { createLogRow } from '../__mocks__/logRow'; + +import { getRowContexts, LogRowContextProvider } from './LogRowContextProvider'; +import { RowContextOptions } from './types'; const row = createLogRow({ entry: '4', timeEpochMs: 4 }); diff --git a/public/app/features/logs/components/LogRowContextProvider.tsx b/public/app/features/logs/components/log-context/LogRowContextProvider.tsx similarity index 98% rename from public/app/features/logs/components/LogRowContextProvider.tsx rename to public/app/features/logs/components/log-context/LogRowContextProvider.tsx index 1f0bf7ee70f..ac0e4419f87 100644 --- a/public/app/features/logs/components/LogRowContextProvider.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextProvider.tsx @@ -12,10 +12,7 @@ import { } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime'; -export interface RowContextOptions { - direction?: 'BACKWARD' | 'FORWARD'; - limit?: number; -} +import { RowContextOptions } from './types'; export interface LogRowContextRows { before?: string[]; diff --git a/public/app/features/logs/components/log-context/types.ts b/public/app/features/logs/components/log-context/types.ts new file mode 100644 index 00000000000..3497156f2c9 --- /dev/null +++ b/public/app/features/logs/components/log-context/types.ts @@ -0,0 +1,4 @@ +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 0332c147b95..118afb69331 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -16,7 +16,7 @@ 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/LogRowContextProvider'; +import { RowContextOptions } from '../../../features/logs/components/log-context/types'; import { CloudWatchAnnotationSupport } from './annotationSupport'; import { DEFAULT_METRICS_QUERY, getDefaultLogsQuery } from './defaultQueries'; diff --git a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts index 439b925341d..3dad3cf8401 100644 --- a/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts +++ b/public/app/plugins/datasource/cloudwatch/query-runner/CloudWatchLogsQueryRunner.ts @@ -31,7 +31,7 @@ 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/LogRowContextProvider'; +import { RowContextOptions } from '../../../../features/logs/components/log-context/types'; import { CloudWatchJsonData, CloudWatchLogsQuery, diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index cfb9395df41..04f2183feb9 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -37,7 +37,7 @@ 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/LogRowContextProvider'; +import { RowContextOptions } from '../../../features/logs/components/log-context/types'; import { getLogLevelFromKey } from '../../../features/logs/utils'; import { ElasticResponse } from './ElasticResponse'; @@ -561,7 +561,7 @@ export class ElasticDatasource return { data: [] }; } /** - * The LogRowContextProvider requires there is a field in the dataFrame.fields + * The LogRowContext requires there is a field in the dataFrame.fields * named `ts` for timestamp and `line` for the actual log line to display. * Unfortunatly these fields are hardcoded and are required for the lines to * be properly displayed. This code just copies the fields based on this.timeField diff --git a/public/app/plugins/datasource/loki/datasource.ts b/public/app/plugins/datasource/loki/datasource.ts index 76e5d3aa7b0..04f99951524 100644 --- a/public/app/plugins/datasource/loki/datasource.ts +++ b/public/app/plugins/datasource/loki/datasource.ts @@ -41,7 +41,7 @@ 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/LogRowContextProvider'; +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';