diff --git a/x-pack/plugins/infra/common/alerting/logs/log_threshold/types.ts b/x-pack/plugins/infra/common/alerting/logs/log_threshold/types.ts index d697770d24a04..c0ad0af7e69fe 100644 --- a/x-pack/plugins/infra/common/alerting/logs/log_threshold/types.ts +++ b/x-pack/plugins/infra/common/alerting/logs/log_threshold/types.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import * as rt from 'io-ts'; -import { logViewReferenceRT } from '../../../log_views'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types'; export const LOG_DOCUMENT_COUNT_RULE_TYPE_ID = 'logs.alert.document.count'; @@ -181,7 +181,7 @@ const RequiredRuleParamsRT = rt.type({ count: ThresholdRT, timeUnit: timeUnitRT, timeSize: timeSizeRT, - logView: logViewReferenceRT, // In future, this should be a union of logViewReferenceRT and inlineLogViewRT + logView: persistedLogViewReferenceRT, // Alerts are only compatible with persisted Log Views }); const partialRequiredRuleParamsRT = rt.partial(RequiredRuleParamsRT.props); diff --git a/x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts b/x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts index 5f488dd532285..15f0df5222e7d 100644 --- a/x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts +++ b/x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts @@ -13,6 +13,7 @@ import { timeSizeRT, groupByRT, } from '../../alerting/logs/log_threshold/types'; +import { persistedLogViewReferenceRT } from '../../log_views'; export const LOG_ALERTS_CHART_PREVIEW_DATA_PATH = '/api/infra/log_alerts/chart_preview_data'; @@ -81,7 +82,7 @@ export type GetLogAlertsChartPreviewDataAlertParamsSubset = rt.TypeOf< export const getLogAlertsChartPreviewDataRequestPayloadRT = rt.type({ data: rt.type({ - sourceId: rt.string, + logView: persistedLogViewReferenceRT, alertParams: getLogAlertsChartPreviewDataAlertParamsSubsetRT, buckets: rt.number, }), diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts index b48e5dc3c6d81..b8b39197e5acf 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts @@ -7,6 +7,7 @@ import * as rt from 'io-ts'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { timeRangeRT, routeTimingMetadataRT } from '../../shared'; import { logEntryAnomalyRT, @@ -51,8 +52,8 @@ export type GetLogEntryAnomaliesSuccessResponsePayload = rt.TypeOf< export const getLogEntryAnomaliesRequestPayloadRT = rt.type({ data: rt.intersection([ rt.type({ - // the ID of the source configuration - sourceId: rt.string, + // log view + logView: persistedLogViewReferenceRT, // the time range to fetch the log entry anomalies from timeRange: timeRangeRT, }), diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies_datasets.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies_datasets.ts index 397e0ac936ece..94d1b25e4d9c2 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies_datasets.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies_datasets.ts @@ -6,6 +6,7 @@ */ import * as rt from 'io-ts'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { badRequestErrorRT, @@ -23,8 +24,8 @@ export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH = export const getLogEntryAnomaliesDatasetsRequestPayloadRT = rt.type({ data: rt.type({ - // the id of the source configuration - sourceId: rt.string, + // log view + logView: persistedLogViewReferenceRT, // the time range to fetch the anomalies datasets from timeRange: timeRangeRT, }), diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_categories.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_categories.ts index 308ee41f39d17..85829b7ebb00c 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_categories.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_categories.ts @@ -7,6 +7,7 @@ import * as rt from 'io-ts'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { badRequestErrorRT, forbiddenErrorRT, @@ -38,8 +39,8 @@ export const getLogEntryCategoriesRequestPayloadRT = rt.type({ rt.type({ // the number of categories to fetch categoryCount: rt.number, - // the id of the source configuration - sourceId: rt.string, + // log view + logView: persistedLogViewReferenceRT, // the time range to fetch the categories from timeRange: timeRangeRT, // a list of histograms to create diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets.ts index afeda0c1fff29..cb3ad4363f243 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets.ts @@ -13,7 +13,7 @@ import { timeRangeRT, routeTimingMetadataRT, } from '../../shared'; - +import { persistedLogViewReferenceRT } from '../../../log_views'; export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH = '/api/infra/log_analysis/results/log_entry_category_datasets'; @@ -23,8 +23,8 @@ export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH = export const getLogEntryCategoryDatasetsRequestPayloadRT = rt.type({ data: rt.type({ - // the id of the source configuration - sourceId: rt.string, + // log view + logView: persistedLogViewReferenceRT, // the time range to fetch the category datasets from timeRange: timeRangeRT, }), diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_examples.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_examples.ts index 256dc4fb97bfd..c6c349830e833 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_examples.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_examples.ts @@ -7,6 +7,7 @@ import * as rt from 'io-ts'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { badRequestErrorRT, forbiddenErrorRT, @@ -28,8 +29,8 @@ export const getLogEntryCategoryExamplesRequestPayloadRT = rt.type({ categoryId: rt.number, // the number of examples to fetch exampleCount: rt.number, - // the id of the source configuration - sourceId: rt.string, + // log view + logView: persistedLogViewReferenceRT, // the time range to fetch the category examples from timeRange: timeRangeRT, }), diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts index 2879991e18578..3aeba96058907 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts @@ -6,6 +6,7 @@ */ import * as rt from 'io-ts'; +import { persistedLogViewReferenceRT } from '../../../log_views'; import { logEntryExampleRT } from '../../../log_analysis'; import { badRequestErrorRT, @@ -28,8 +29,8 @@ export const getLogEntryExamplesRequestPayloadRT = rt.type({ dataset: rt.string, // the number of examples to fetch exampleCount: rt.number, - // the id of the source configuration - sourceId: rt.string, + // logView + logView: persistedLogViewReferenceRT, // the time range to fetch the log rate examples from timeRange: timeRangeRT, }), diff --git a/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts b/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts index ec3a6b8a2d2ec..a863d35d5b491 100644 --- a/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts +++ b/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts @@ -8,12 +8,13 @@ import * as rt from 'io-ts'; import { logEntryCursorRT, logEntryRT } from '../../log_entry'; import { logViewColumnConfigurationRT } from '../../log_views'; +import { logViewReferenceRT } from '../../log_views'; export const LOG_ENTRIES_HIGHLIGHTS_PATH = '/api/log_entries/highlights'; export const logEntriesHighlightsBaseRequestRT = rt.intersection([ rt.type({ - sourceId: rt.string, + logView: logViewReferenceRT, startTimestamp: rt.number, endTimestamp: rt.number, highlightTerms: rt.array(rt.string), diff --git a/x-pack/plugins/infra/common/http_api/log_entries/summary.ts b/x-pack/plugins/infra/common/http_api/log_entries/summary.ts index 64b40004230df..6303c06ac3698 100644 --- a/x-pack/plugins/infra/common/http_api/log_entries/summary.ts +++ b/x-pack/plugins/infra/common/http_api/log_entries/summary.ts @@ -6,11 +6,12 @@ */ import * as rt from 'io-ts'; +import { logViewReferenceRT } from '../../log_views'; export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary'; export const logEntriesSummaryRequestRT = rt.type({ - sourceId: rt.string, + logView: logViewReferenceRT, startTimestamp: rt.number, endTimestamp: rt.number, bucketSize: rt.number, diff --git a/x-pack/plugins/infra/common/log_views/types.ts b/x-pack/plugins/infra/common/log_views/types.ts index ed42fe82862bc..5bf9585bb1c2f 100644 --- a/x-pack/plugins/infra/common/log_views/types.ts +++ b/x-pack/plugins/infra/common/log_views/types.ts @@ -103,9 +103,19 @@ export const logViewStatusRT = rt.strict({ }); export type LogViewStatus = rt.TypeOf; -export const logViewReferenceRT = rt.type({ +export const persistedLogViewReferenceRT = rt.type({ logViewId: rt.string, type: rt.literal('log-view-reference'), }); +export type PersistedLogViewReference = rt.TypeOf; + +export const inlineLogViewReferenceRT = rt.type({ + type: rt.literal('log-view-inline'), + id: rt.string, + attributes: logViewAttributesRT, +}); + +export const logViewReferenceRT = rt.union([persistedLogViewReferenceRT, inlineLogViewReferenceRT]); + export type LogViewReference = rt.TypeOf; diff --git a/x-pack/plugins/infra/common/search_strategies/log_entries/log_entries.ts b/x-pack/plugins/infra/common/search_strategies/log_entries/log_entries.ts index 65bcec8c98e6a..f8daaa1b9227b 100644 --- a/x-pack/plugins/infra/common/search_strategies/log_entries/log_entries.ts +++ b/x-pack/plugins/infra/common/search_strategies/log_entries/log_entries.ts @@ -13,7 +13,7 @@ import { logEntryCursorRT, logEntryRT, } from '../../log_entry'; -import { logViewColumnConfigurationRT } from '../../log_views'; +import { logViewColumnConfigurationRT, logViewReferenceRT } from '../../log_views'; import { jsonObjectRT } from '../../typed_json'; import { searchStrategyErrorRT } from '../common/errors'; @@ -21,7 +21,7 @@ export const LOG_ENTRIES_SEARCH_STRATEGY = 'infra-log-entries'; const logEntriesBaseSearchRequestParamsRT = rt.intersection([ rt.type({ - sourceId: rt.string, + logView: logViewReferenceRT, startTimestamp: rt.number, endTimestamp: rt.number, size: rt.number, diff --git a/x-pack/plugins/infra/common/search_strategies/log_entries/log_entry.ts b/x-pack/plugins/infra/common/search_strategies/log_entries/log_entry.ts index 2dc182c4ba0e2..6d2a7891264d1 100644 --- a/x-pack/plugins/infra/common/search_strategies/log_entries/log_entry.ts +++ b/x-pack/plugins/infra/common/search_strategies/log_entries/log_entry.ts @@ -7,12 +7,13 @@ import * as rt from 'io-ts'; import { logEntryCursorRT, logEntryFieldRT } from '../../log_entry'; +import { logViewReferenceRT } from '../../log_views'; import { searchStrategyErrorRT } from '../common/errors'; export const LOG_ENTRY_SEARCH_STRATEGY = 'infra-log-entry'; export const logEntrySearchRequestParamsRT = rt.type({ - sourceId: rt.string, + logView: logViewReferenceRT, logEntryId: rt.string, }); diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx index c6b18bebc98b3..1c38dca829aef 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx @@ -13,7 +13,7 @@ import { ForLastExpression, RuleTypeParamsExpressionProps, } from '@kbn/triggers-actions-ui-plugin/public'; -import { LogViewReference, ResolvedLogViewField } from '../../../../../common/log_views'; +import { PersistedLogViewReference, ResolvedLogViewField } from '../../../../../common/log_views'; import { Comparator, isOptimizableGroupedThreshold, @@ -54,7 +54,7 @@ const DEFAULT_BASE_EXPRESSION = { const DEFAULT_FIELD = 'log.level'; -const createLogViewReference = (logViewId: string): LogViewReference => ({ +const createLogViewReference = (logViewId: string): PersistedLogViewReference => ({ logViewId, type: 'log-view-reference', }); @@ -69,7 +69,7 @@ const createDefaultCriterion = ( const createDefaultCountRuleParams = ( availableFields: ResolvedLogViewField[], - logView: LogViewReference + logView: PersistedLogViewReference ): PartialCountRuleParams => ({ ...DEFAULT_BASE_EXPRESSION, logView, @@ -82,7 +82,7 @@ const createDefaultCountRuleParams = ( const createDefaultRatioRuleParams = ( availableFields: ResolvedLogViewField[], - logView: LogViewReference + logView: PersistedLogViewReference ): PartialRatioRuleParams => ({ ...DEFAULT_BASE_EXPRESSION, logView, @@ -226,11 +226,11 @@ export const Editor: React.FC createLogViewReference(logViewId), [logViewId]); + const logViewReference = useMemo(() => createLogViewReference(logViewId), [logViewId]); const defaultCountAlertParams = useMemo( - () => createDefaultCountRuleParams(supportedFields, logViewReferemnce), - [supportedFields, logViewReferemnce] + () => createDefaultCountRuleParams(supportedFields, logViewReference), + [supportedFields, logViewReference] ); const updateType = useCallback( @@ -238,12 +238,12 @@ export const Editor: React.FC { diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/hooks/use_chart_preview_data.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/hooks/use_chart_preview_data.tsx index 9b9dc501e1591..0b99cea2fd7c9 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/hooks/use_chart_preview_data.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/hooks/use_chart_preview_data.tsx @@ -73,7 +73,7 @@ export const callGetChartPreviewDataAPI = async ( body: JSON.stringify( getLogAlertsChartPreviewDataRequestPayloadRT.encode({ data: { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, alertParams, buckets, }, diff --git a/x-pack/plugins/infra/public/containers/logs/log_entry.ts b/x-pack/plugins/infra/public/containers/logs/log_entry.ts index b9f95f3db6ab0..958097fc3baa5 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_entry.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_entry.ts @@ -30,7 +30,10 @@ export const useLogEntry = ({ return !!logEntryId && !!sourceId ? { request: { - params: logEntrySearchRequestParamsRT.encode({ sourceId, logEntryId }), + params: logEntrySearchRequestParamsRT.encode({ + logView: { type: 'log-view-reference', logViewId: sourceId }, + logEntryId, + }), }, options: { strategy: LOG_ENTRY_SEARCH_STRATEGY }, } diff --git a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_entry_highlights.tsx b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_entry_highlights.tsx index fc1026243a7e0..d9f7ab078ae0b 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_entry_highlights.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_entry_highlights.tsx @@ -37,7 +37,7 @@ export const useLogEntryHighlights = ( return await fetchLogEntriesHighlights( { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, startTimestamp, endTimestamp, center: centerPoint, diff --git a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_summary_highlights.ts b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_summary_highlights.ts index 59abb716f6cb3..e994e2a013bb7 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_highlights/log_summary_highlights.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_highlights/log_summary_highlights.ts @@ -39,7 +39,7 @@ export const useLogSummaryHighlights = ( return await fetchLogSummaryHighlights( { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, startTimestamp, endTimestamp, bucketSize, diff --git a/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_after.ts b/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_after.ts index 1e9e1dd48a47b..3ee39fbda3d49 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_after.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_after.ts @@ -58,7 +58,7 @@ export const useLogEntriesAfterRequest = ({ highlightPhrase, query: query as JsonObject, size: params.size, - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, startTimestamp, }), }, diff --git a/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_before.ts b/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_before.ts index 6e72fce5a1d2b..581d31a28a8c5 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_before.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_stream/use_fetch_log_entries_before.ts @@ -58,7 +58,7 @@ export const useLogEntriesBeforeRequest = ({ highlightPhrase, query: query as JsonObject, size: params.size, - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, startTimestamp: params.extendTo ?? startTimestamp, }), }, diff --git a/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.test.tsx b/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.test.tsx index 25e02101984f4..fe02367e4b1ff 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.test.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.test.tsx @@ -62,7 +62,7 @@ describe('useLogSummary hook', () => { expect(fetchLogSummaryMock).toHaveBeenCalledTimes(1); expect(fetchLogSummaryMock).toHaveBeenLastCalledWith( expect.objectContaining({ - sourceId: 'INITIAL_SOURCE_ID', + logView: { logViewId: 'INITIAL_SOURCE_ID', type: 'log-view-reference' }, }), expect.anything() ); @@ -74,7 +74,7 @@ describe('useLogSummary hook', () => { expect(fetchLogSummaryMock).toHaveBeenCalledTimes(2); expect(fetchLogSummaryMock).toHaveBeenLastCalledWith( expect.objectContaining({ - sourceId: 'CHANGED_SOURCE_ID', + logView: { logViewId: 'CHANGED_SOURCE_ID', type: 'log-view-reference' }, }), expect.anything() ); diff --git a/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.tsx b/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.tsx index b3e7f8235ace7..c4b933ab04cd0 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.tsx +++ b/x-pack/plugins/infra/public/containers/logs/log_summary/log_summary.tsx @@ -35,7 +35,7 @@ export const useLogSummary = ( pushLogSummaryBucketsArgs([ { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, startTimestamp, endTimestamp, bucketSize, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_datasets.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_datasets.ts index 51d4a69ada295..34358b983e12b 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_datasets.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_datasets.ts @@ -31,7 +31,7 @@ export const callGetLogEntryCategoryDatasetsAPI = async ( body: JSON.stringify( getLogEntryCategoryDatasetsRequestPayloadRT.encode({ data: { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_examples.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_examples.ts index 90727fd6f0853..e3b99750af715 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_examples.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_log_entry_category_examples.ts @@ -35,7 +35,7 @@ export const callGetLogEntryCategoryExamplesAPI = async ( data: { categoryId, exampleCount, - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_top_log_entry_categories.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_top_log_entry_categories.ts index 9472991e15c66..93e9daf0b9cb6 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_top_log_entry_categories.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/service_calls/get_top_log_entry_categories.ts @@ -36,7 +36,7 @@ export const callGetTopLogEntryCategoriesAPI = async ( body: JSON.stringify( getLogEntryCategoriesRequestPayloadRT.encode({ data: { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts index 5f0f95a3e7976..7916cad0f1e07 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts @@ -30,7 +30,7 @@ export const callGetLogEntryAnomaliesAPI = async (requestArgs: RequestArgs, fetc body: JSON.stringify( getLogEntryAnomaliesRequestPayloadRT.encode({ data: { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies_datasets.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies_datasets.ts index 9b560845186f7..16a8092f290f8 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies_datasets.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies_datasets.ts @@ -29,7 +29,7 @@ export const callGetLogEntryAnomaliesDatasetsAPI = async ( body: JSON.stringify( getLogEntryAnomaliesDatasetsRequestPayloadRT.encode({ data: { - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts index 5844e00ebfe4e..0e44e5b02feb7 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts @@ -32,7 +32,7 @@ export const callGetLogEntryExamplesAPI = async (requestArgs: RequestArgs, fetch data: { dataset, exampleCount, - sourceId, + logView: { type: 'log-view-reference', logViewId: sourceId }, timeRange: { startTime, endTime, diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts index e62fd9291fc33..bd033b5285b3e 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts @@ -158,7 +158,10 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) = const [, , { logViews }] = await libs.getStartServices(); const logQueryFields: LogQueryFields | undefined = await logViews .getClient(savedObjectsClient, esClient) - .getResolvedLogView(sourceId) + .getResolvedLogView({ + type: 'log-view-reference', + logViewId: sourceId, + }) .then( ({ indices }) => ({ indexPattern: indices }), () => undefined diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index 37eb4698ff089..1d0470c244fd1 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -188,7 +188,7 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) => const { indices, timestampField, runtimeMappings } = await logViews .getClient(savedObjectsClient, scopedClusterClient.asCurrentUser) - .getResolvedLogView(validatedParams.logView.logViewId); + .getResolvedLogView(validatedParams.logView); if (!isRatioRuleParams(validatedParams)) { await executeAlert( diff --git a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts index 1e0daad376a1a..fcda9b30b0dac 100644 --- a/x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts +++ b/x-pack/plugins/infra/server/lib/domains/log_entries_domain/log_entries_domain.ts @@ -15,6 +15,7 @@ import { LogColumn, LogEntry, LogEntryCursor } from '../../../../common/log_entr import { LogViewColumnConfiguration, logViewFieldColumnConfigurationRT, + LogViewReference, ResolvedLogView, } from '../../../../common/log_views'; import { decodeOrThrow } from '../../../../common/runtime_types'; @@ -66,7 +67,7 @@ export class InfraLogEntriesDomain { public async getLogEntriesAround( requestContext: InfraPluginRequestHandlerContext, - sourceId: string, + logView: LogViewReference, params: LogEntriesAroundParams, columnOverrides?: LogViewColumnConfiguration[] ): Promise<{ entries: LogEntry[]; hasMoreBefore?: boolean; hasMoreAfter?: boolean }> { @@ -84,7 +85,7 @@ export class InfraLogEntriesDomain { const { entries: entriesBefore, hasMoreBefore } = await this.getLogEntries( requestContext, - sourceId, + logView, { startTimestamp, endTimestamp, @@ -110,7 +111,7 @@ export class InfraLogEntriesDomain { const { entries: entriesAfter, hasMoreAfter } = await this.getLogEntries( requestContext, - sourceId, + logView, { startTimestamp, endTimestamp, @@ -126,7 +127,7 @@ export class InfraLogEntriesDomain { public async getLogEntries( requestContext: InfraPluginRequestHandlerContext, - sourceId: string, + logView: LogViewReference, params: LogEntriesParams, columnOverrides?: LogViewColumnConfiguration[] ): Promise<{ entries: LogEntry[]; hasMoreBefore?: boolean; hasMoreAfter?: boolean }> { @@ -134,7 +135,7 @@ export class InfraLogEntriesDomain { const { savedObjects, elasticsearch } = await requestContext.core; const resolvedLogView = await logViews .getClient(savedObjects.client, elasticsearch.client.asCurrentUser) - .getResolvedLogView(sourceId); + .getResolvedLogView(logView); const columnDefinitions = columnOverrides ?? resolvedLogView.columns; const messageFormattingRules = compileFormattingRules( @@ -184,7 +185,7 @@ export class InfraLogEntriesDomain { public async getLogSummaryBucketsBetween( requestContext: InfraPluginRequestHandlerContext, - sourceId: string, + logView: LogViewReference, start: number, end: number, bucketSize: number, @@ -194,7 +195,7 @@ export class InfraLogEntriesDomain { const { savedObjects, elasticsearch } = await requestContext.core; const resolvedLogView = await logViews .getClient(savedObjects.client, elasticsearch.client.asCurrentUser) - .getResolvedLogView(sourceId); + .getResolvedLogView(logView); const dateRangeBuckets = await this.adapter.getContainedLogSummaryBuckets( requestContext, resolvedLogView, @@ -208,7 +209,7 @@ export class InfraLogEntriesDomain { public async getLogSummaryHighlightBucketsBetween( requestContext: InfraPluginRequestHandlerContext, - sourceId: string, + logView: LogViewReference, startTimestamp: number, endTimestamp: number, bucketSize: number, @@ -219,7 +220,7 @@ export class InfraLogEntriesDomain { const { savedObjects, elasticsearch } = await requestContext.core; const resolvedLogView = await logViews .getClient(savedObjects.client, elasticsearch.client.asCurrentUser) - .getResolvedLogView(sourceId); + .getResolvedLogView(logView); const messageFormattingRules = compileFormattingRules( getBuiltinRules(resolvedLogView.messageField) ); diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts index 22bf5466ee3b4..b17afa68d2d4d 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts @@ -16,7 +16,7 @@ import { logEntryRateJobTypes, Pagination, } from '../../../common/log_analysis'; -import { ResolvedLogView } from '../../../common/log_views'; +import { PersistedLogViewReference, ResolvedLogView } from '../../../common/log_views'; import { startTracingSpan, TracingSpan } from '../../../common/performance_tracing'; import { decodeOrThrow } from '../../../common/runtime_types'; import type { @@ -54,11 +54,11 @@ interface MappedAnomalyHit { async function getCompatibleAnomaliesJobIds( spaceId: string, - sourceId: string, + logViewId: string, mlAnomalyDetectors: MlAnomalyDetectors ) { - const logRateJobId = getJobId(spaceId, sourceId, logEntryRateJobTypes[0]); - const logCategoriesJobId = getJobId(spaceId, sourceId, logEntryCategoriesJobTypes[0]); + const logRateJobId = getJobId(spaceId, logViewId, logEntryRateJobTypes[0]); + const logCategoriesJobId = getJobId(spaceId, logViewId, logEntryCategoriesJobTypes[0]); const jobIds: string[] = []; let jobSpans: TracingSpan[] = []; @@ -99,7 +99,7 @@ export async function getLogEntryAnomalies( context: InfraPluginRequestHandlerContext & { infra: Promise>; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number, sort: AnomaliesSort, @@ -114,7 +114,7 @@ export async function getLogEntryAnomalies( timing: { spans: jobSpans }, } = await getCompatibleAnomaliesJobIds( infraContext.spaceId, - sourceId, + logView.logViewId, infraContext.mlAnomalyDetectors ); @@ -155,7 +155,7 @@ export async function getLogEntryAnomalies( const logEntryCategoriesCountJobId = getJobId( infraContext.spaceId, - sourceId, + logView.logViewId, logEntryCategoriesJobTypes[0] ); @@ -331,7 +331,7 @@ export async function getLogEntryExamples( context: InfraPluginRequestHandlerContext & { infra: Promise>; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number, dataset: string, @@ -345,7 +345,7 @@ export async function getLogEntryExamples( const jobId = getJobId( infraContext.spaceId, - sourceId, + logView.logViewId, categoryId != null ? logEntryCategoriesJobTypes[0] : logEntryRateJobTypes[0] ); @@ -370,7 +370,7 @@ export async function getLogEntryExamples( timing: { spans: fetchLogEntryExamplesSpans }, } = await fetchLogEntryExamples( context, - sourceId, + logView, indices, runtimeMappings, timestampField, @@ -397,7 +397,7 @@ export async function fetchLogEntryExamples( context: InfraPluginRequestHandlerContext & { infra: Promise>; }, - sourceId: string, + logView: PersistedLogViewReference, indices: string, runtimeMappings: estypes.MappingRuntimeFields, timestampField: string, @@ -420,7 +420,7 @@ export async function fetchLogEntryExamples( const logEntryCategoriesCountJobId = getJobId( infraContext.spaceId, - sourceId, + logView.logViewId, logEntryCategoriesJobTypes[0] ); @@ -483,7 +483,7 @@ export async function getLogEntryAnomaliesDatasets( spaceId: string; }; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number ) { @@ -492,7 +492,7 @@ export async function getLogEntryAnomaliesDatasets( timing: { spans: jobSpans }, } = await getCompatibleAnomaliesJobIds( context.infra.spaceId, - sourceId, + logView.logViewId, context.infra.mlAnomalyDetectors ); diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts index 9152945002e2a..d8eb18e4890b5 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts @@ -15,7 +15,7 @@ import { logEntryCategoriesJobTypes, } from '../../../common/log_analysis'; import { LogEntryContext } from '../../../common/log_entry'; -import { ResolvedLogView } from '../../../common/log_views'; +import { PersistedLogViewReference, ResolvedLogView } from '../../../common/log_views'; import { startTracingSpan } from '../../../common/performance_tracing'; import { decodeOrThrow } from '../../../common/runtime_types'; import type { MlAnomalyDetectors, MlSystem } from '../../types'; @@ -47,7 +47,7 @@ export async function getTopLogEntryCategories( spaceId: string; }; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number, categoryCount: number, @@ -59,7 +59,7 @@ export async function getTopLogEntryCategories( const logEntryCategoriesCountJobId = getJobId( context.infra.spaceId, - sourceId, + logView.logViewId, logEntryCategoriesJobTypes[0] ); @@ -119,13 +119,13 @@ export async function getLogEntryCategoryDatasets( spaceId: string; }; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number ) { const logEntryCategoriesCountJobId = getJobId( context.infra.spaceId, - sourceId, + logView.logViewId, logEntryCategoriesJobTypes[0] ); @@ -143,7 +143,7 @@ export async function getLogEntryCategoryExamples( spaceId: string; }; }, - sourceId: string, + logView: PersistedLogViewReference, startTime: number, endTime: number, categoryId: number, @@ -154,7 +154,7 @@ export async function getLogEntryCategoryExamples( const logEntryCategoriesCountJobId = getJobId( context.infra.spaceId, - sourceId, + logView.logViewId, logEntryCategoriesJobTypes[0] ); diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts index 7da6298fff76a..1e043fed0986a 100644 --- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts +++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts @@ -24,13 +24,13 @@ export async function getLogEntryRateBuckets( spaceId: string; }; }, - sourceId: string, + logViewId: string, startTime: number, endTime: number, bucketDuration: number, datasets?: string[] ) { - const logRateJobId = getJobId(context.infra.spaceId, sourceId, 'log-entry-rate'); + const logRateJobId = getJobId(context.infra.spaceId, logViewId, 'log-entry-rate'); let mlModelPlotBuckets: LogRateModelPlotBucket[] = []; let afterLatestBatchKey: CompositeTimestampPartitionKey | undefined; diff --git a/x-pack/plugins/infra/server/routes/log_alerts/chart_preview_data.ts b/x-pack/plugins/infra/server/routes/log_alerts/chart_preview_data.ts index 95b0c8320559e..fbc530397f4e3 100644 --- a/x-pack/plugins/infra/server/routes/log_alerts/chart_preview_data.ts +++ b/x-pack/plugins/infra/server/routes/log_alerts/chart_preview_data.ts @@ -29,11 +29,11 @@ export const initGetLogAlertsChartPreviewDataRoute = ({ }, framework.router.handleLegacyErrors(async (requestContext, request, response) => { const { - data: { sourceId, buckets, alertParams }, + data: { logView, buckets, alertParams }, } = request.body; const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(sourceId); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); try { const { series } = await getChartPreviewData( diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts index dd6254cf560e2..13df82f8fe343 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts @@ -31,7 +31,7 @@ export const initGetLogEntryAnomaliesRoute = ({ framework }: InfraBackendLibs) = framework.router.handleLegacyErrors(async (requestContext, request, response) => { const { data: { - sourceId, + logView, timeRange: { startTime, endTime }, sort: sortParam, pagination: paginationParam, @@ -51,7 +51,7 @@ export const initGetLogEntryAnomaliesRoute = ({ framework }: InfraBackendLibs) = timing, } = await getLogEntryAnomalies( infraMlContext, - sourceId, + logView, startTime, endTime, sort, diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies_datasets.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies_datasets.ts index 1d1f620063b2e..5f7aec90376af 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies_datasets.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies_datasets.ts @@ -29,7 +29,7 @@ export const initGetLogEntryAnomaliesDatasetsRoute = ({ framework }: InfraBacken framework.router.handleLegacyErrors(async (requestContext, request, response) => { const { data: { - sourceId, + logView, timeRange: { startTime, endTime }, }, } = request.body; @@ -39,7 +39,7 @@ export const initGetLogEntryAnomaliesDatasetsRoute = ({ framework }: InfraBacken const { datasets, timing } = await getLogEntryAnomaliesDatasets( { infra: await infraMlContext.infra }, - sourceId, + logView, startTime, endTime ); diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_categories.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_categories.ts index 6e2e8e8a6c2ad..1a484a0662e05 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_categories.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_categories.ts @@ -31,7 +31,7 @@ export const initGetLogEntryCategoriesRoute = ({ framework }: InfraBackendLibs) data: { categoryCount, histograms, - sourceId, + logView, timeRange: { startTime, endTime }, datasets, sort, @@ -43,7 +43,7 @@ export const initGetLogEntryCategoriesRoute = ({ framework }: InfraBackendLibs) const { data: topLogEntryCategories, timing } = await getTopLogEntryCategories( { infra: await infraMlContext.infra }, - sourceId, + logView, startTime, endTime, categoryCount, diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets.ts index de5ac9dac4b07..92f0cd576a0f8 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets.ts @@ -29,7 +29,7 @@ export const initGetLogEntryCategoryDatasetsRoute = ({ framework }: InfraBackend framework.router.handleLegacyErrors(async (requestContext, request, response) => { const { data: { - sourceId, + logView, timeRange: { startTime, endTime }, }, } = request.body; @@ -39,7 +39,7 @@ export const initGetLogEntryCategoryDatasetsRoute = ({ framework }: InfraBackend const { data: logEntryCategoryDatasets, timing } = await getLogEntryCategoryDatasets( { infra: await infraMlContext.infra }, - sourceId, + logView, startTime, endTime ); diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_examples.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_examples.ts index b51aed45b7e11..40de491c1673f 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_examples.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_examples.ts @@ -34,20 +34,20 @@ export const initGetLogEntryCategoryExamplesRoute = ({ data: { categoryId, exampleCount, - sourceId, + logView, timeRange: { startTime, endTime }, }, } = request.body; const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(sourceId); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); try { const infraMlContext = await assertHasInfraMlPlugins(requestContext); const { data: logEntryCategoryExamples, timing } = await getLogEntryCategoryExamples( { infra: await infraMlContext.infra, core: await infraMlContext.core }, - sourceId, + logView, startTime, endTime, categoryId, diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts index fb82a2cd90df5..23ba1072a60fc 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts @@ -34,21 +34,21 @@ export const initGetLogEntryExamplesRoute = ({ data: { dataset, exampleCount, - sourceId, + logView, timeRange: { startTime, endTime }, categoryId, }, } = request.body; const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(sourceId); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); try { const infraMlContext = await assertHasInfraMlPlugins(requestContext); const { data: logEntryExamples, timing } = await getLogEntryExamples( infraMlContext, - sourceId, + logView, startTime, endTime, dataset, diff --git a/x-pack/plugins/infra/server/routes/log_entries/highlights.ts b/x-pack/plugins/infra/server/routes/log_entries/highlights.ts index bb7c615358c0e..aa8876951ee6c 100644 --- a/x-pack/plugins/infra/server/routes/log_entries/highlights.ts +++ b/x-pack/plugins/infra/server/routes/log_entries/highlights.ts @@ -38,14 +38,14 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa fold(throwErrors(Boom.badRequest), identity) ); - const { startTimestamp, endTimestamp, sourceId, query, size, highlightTerms } = payload; + const { startTimestamp, endTimestamp, logView, query, size, highlightTerms } = payload; let entriesPerHighlightTerm; if ('center' in payload) { entriesPerHighlightTerm = await Promise.all( highlightTerms.map((highlightTerm) => - logEntries.getLogEntriesAround(requestContext, sourceId, { + logEntries.getLogEntriesAround(requestContext, logView, { startTimestamp, endTimestamp, query: parseFilterQuery(query), @@ -65,7 +65,7 @@ export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBa entriesPerHighlightTerm = await Promise.all( highlightTerms.map((highlightTerm) => - logEntries.getLogEntries(requestContext, sourceId, { + logEntries.getLogEntries(requestContext, logView, { startTimestamp, endTimestamp, query: parseFilterQuery(query), diff --git a/x-pack/plugins/infra/server/routes/log_entries/summary.ts b/x-pack/plugins/infra/server/routes/log_entries/summary.ts index 3ff0ded8a7c24..dd48c21a590ae 100644 --- a/x-pack/plugins/infra/server/routes/log_entries/summary.ts +++ b/x-pack/plugins/infra/server/routes/log_entries/summary.ts @@ -37,11 +37,11 @@ export const initLogEntriesSummaryRoute = ({ framework, logEntries }: InfraBacke logEntriesSummaryRequestRT.decode(request.body), fold(throwErrors(Boom.badRequest), identity) ); - const { sourceId, startTimestamp, endTimestamp, bucketSize, query } = payload; + const { logView, startTimestamp, endTimestamp, bucketSize, query } = payload; const buckets = await logEntries.getLogSummaryBucketsBetween( requestContext, - sourceId, + logView, startTimestamp, endTimestamp, bucketSize, diff --git a/x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts b/x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts index ca219cac41e2b..206e02bc57278 100644 --- a/x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts +++ b/x-pack/plugins/infra/server/routes/log_entries/summary_highlights.ts @@ -39,11 +39,11 @@ export const initLogEntriesSummaryHighlightsRoute = ({ logEntriesSummaryHighlightsRequestRT.decode(request.body), fold(throwErrors(Boom.badRequest), identity) ); - const { sourceId, startTimestamp, endTimestamp, bucketSize, query, highlightTerms } = payload; + const { logView, startTimestamp, endTimestamp, bucketSize, query, highlightTerms } = payload; const bucketsPerHighlightTerm = await logEntries.getLogSummaryHighlightBucketsBetween( requestContext, - sourceId, + logView, startTimestamp, endTimestamp, bucketSize, diff --git a/x-pack/plugins/infra/server/routes/snapshot/index.ts b/x-pack/plugins/infra/server/routes/snapshot/index.ts index 27c49032c03f4..0c893171b5b67 100644 --- a/x-pack/plugins/infra/server/routes/snapshot/index.ts +++ b/x-pack/plugins/infra/server/routes/snapshot/index.ts @@ -43,7 +43,10 @@ export const initSnapshotRoute = (libs: InfraBackendLibs) => { const [, , { logViews }] = await libs.getStartServices(); const logQueryFields: LogQueryFields | undefined = await logViews .getScopedClient(request) - .getResolvedLogView(snapshotRequest.sourceId) + .getResolvedLogView({ + type: 'log-view-reference', + logViewId: snapshotRequest.sourceId, + }) .then( ({ indices }) => ({ indexPattern: indices }), () => undefined diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts index 99579c5a588c6..bb21053cfe9d8 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts @@ -57,7 +57,7 @@ describe('LogEntries search strategy', () => { logEntriesSearchStrategy.search( { params: { - sourceId: 'SOURCE_ID', + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, startTimestamp: 100, endTimestamp: 200, size: 3, @@ -143,7 +143,7 @@ describe('LogEntries search strategy', () => { { id: requestId, params: { - sourceId: 'SOURCE_ID', + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, startTimestamp: 100, endTimestamp: 200, size: 3, @@ -223,7 +223,7 @@ describe('LogEntries search strategy', () => { { id: logEntriesSearchRequestStateRT.encode({ esRequestId: 'UNKNOWN_ID' }), params: { - sourceId: 'SOURCE_ID', + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, startTimestamp: 100, endTimestamp: 200, size: 3, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts index 81ef319828be1..f0f5c6304d615 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.ts @@ -72,7 +72,7 @@ export const logEntriesSearchStrategyProvider = ({ const request = decodeOrThrow(asyncRequestRT)(rawRequest); const resolvedLogView$ = defer(() => - logViews.getScopedClient(dependencies.request).getResolvedLogView(request.params.sourceId) + logViews.getScopedClient(dependencies.request).getResolvedLogView(request.params.logView) ).pipe(take(1), shareReplay(1)); const messageFormattingRules$ = defer(() => diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts index d2d28174490c8..19d5345122374 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts @@ -56,7 +56,10 @@ describe('LogEntry search strategy', () => { const response = await lastValueFrom( logEntrySearchStrategy.search( { - params: { sourceId: 'SOURCE_ID', logEntryId: 'LOG_ENTRY_ID' }, + params: { + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, + logEntryId: 'LOG_ENTRY_ID', + }, }, {}, mockDependencies @@ -141,7 +144,10 @@ describe('LogEntry search strategy', () => { logEntrySearchStrategy.search( { id: requestId, - params: { sourceId: 'SOURCE_ID', logEntryId: 'LOG_ENTRY_ID' }, + params: { + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, + logEntryId: 'LOG_ENTRY_ID', + }, }, {}, mockDependencies @@ -193,7 +199,10 @@ describe('LogEntry search strategy', () => { const response = logEntrySearchStrategy.search( { id: logEntrySearchRequestStateRT.encode({ esRequestId: 'UNKNOWN_ID' }), - params: { sourceId: 'SOURCE_ID', logEntryId: 'LOG_ENTRY_ID' }, + params: { + logView: { type: 'log-view-reference', logViewId: 'SOURCE_ID' }, + logEntryId: 'LOG_ENTRY_ID', + }, }, {}, mockDependencies diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts index 714e0b792c612..1d558094e351d 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.ts @@ -48,7 +48,7 @@ export const logEntrySearchStrategyProvider = ({ const request = decodeOrThrow(asyncRequestRT)(rawRequest); const resolvedLogView$ = defer(() => - logViews.getScopedClient(dependencies.request).getResolvedLogView(request.params.sourceId) + logViews.getScopedClient(dependencies.request).getResolvedLogView(request.params.logView) ).pipe(take(1), shareReplay(1)); const recoveredRequest$ = of(request).pipe( diff --git a/x-pack/plugins/infra/server/services/log_views/log_views_client.mock.ts b/x-pack/plugins/infra/server/services/log_views/log_views_client.mock.ts index 5c20297b82c65..5738c94c8aa40 100644 --- a/x-pack/plugins/infra/server/services/log_views/log_views_client.mock.ts +++ b/x-pack/plugins/infra/server/services/log_views/log_views_client.mock.ts @@ -5,12 +5,15 @@ * 2.0. */ +import { LogViewReference } from '../../../common/log_views'; import { createResolvedLogViewMock } from '../../../common/log_views/resolved_log_view.mock'; import { ILogViewsClient } from './types'; export const createLogViewsClientMock = (): jest.Mocked => ({ getLogView: jest.fn(), - getResolvedLogView: jest.fn((logViewId: string) => Promise.resolve(createResolvedLogViewMock())), + getResolvedLogView: jest.fn((logViewReference: LogViewReference) => + Promise.resolve(createResolvedLogViewMock()) + ), putLogView: jest.fn(), resolveLogView: jest.fn(), }); diff --git a/x-pack/plugins/infra/server/services/log_views/log_views_client.ts b/x-pack/plugins/infra/server/services/log_views/log_views_client.ts index 9f43cee871f73..3f832c6770717 100644 --- a/x-pack/plugins/infra/server/services/log_views/log_views_client.ts +++ b/x-pack/plugins/infra/server/services/log_views/log_views_client.ts @@ -19,7 +19,9 @@ import { LogIndexReference, LogView, LogViewAttributes, + LogViewReference, LogViewsStaticConfig, + persistedLogViewReferenceRT, ResolvedLogView, resolveLogView, } from '../../../common/log_views'; @@ -65,8 +67,10 @@ export class LogViewsClient implements ILogViewsClient { ); } - public async getResolvedLogView(logViewId: string): Promise { - const logView = await this.getLogView(logViewId); + public async getResolvedLogView(logViewReference: LogViewReference): Promise { + const logView = persistedLogViewReferenceRT.is(logViewReference) + ? await this.getLogView(logViewReference.logViewId) + : logViewReference; const resolvedLogView = await this.resolveLogView(logView.id, logView.attributes); return resolvedLogView; } diff --git a/x-pack/plugins/infra/server/services/log_views/types.ts b/x-pack/plugins/infra/server/services/log_views/types.ts index 50b4e65cf7548..b5f91cb3587b4 100644 --- a/x-pack/plugins/infra/server/services/log_views/types.ts +++ b/x-pack/plugins/infra/server/services/log_views/types.ts @@ -16,6 +16,7 @@ import { PluginStart as DataViewsServerPluginStart } from '@kbn/data-views-plugi import { LogView, LogViewAttributes, + LogViewReference, LogViewsStaticConfig, ResolvedLogView, } from '../../../common/log_views'; @@ -44,7 +45,7 @@ export interface LogViewsServiceStart { export interface ILogViewsClient { getLogView(logViewId: string): Promise; - getResolvedLogView(logViewId: string): Promise; + getResolvedLogView(logView: LogViewReference): Promise; putLogView(logViewId: string, logViewAttributes: Partial): Promise; resolveLogView(logViewId: string, logViewAttributes: LogViewAttributes): Promise; } diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts b/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts index aba182274c9a3..2e328e91f8c25 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts @@ -54,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) { .set(COMMON_HEADERS) .send( logEntriesHighlightsRequestRT.encode({ - sourceId: 'default', + logView: { type: 'log-view-reference', logViewId: 'default' }, startTimestamp: KEY_BEFORE_START.time, endTimestamp: KEY_AFTER_END.time, highlightTerms: ['some string that does not exist'], @@ -82,7 +82,7 @@ export default function ({ getService }: FtrProviderContext) { .set(COMMON_HEADERS) .send( logEntriesHighlightsRequestRT.encode({ - sourceId: 'default', + logView: { type: 'log-view-reference', logViewId: 'default' }, startTimestamp: KEY_BEFORE_START.time, endTimestamp: KEY_AFTER_END.time, highlightTerms: ['message of document 0'], @@ -130,7 +130,7 @@ export default function ({ getService }: FtrProviderContext) { .set(COMMON_HEADERS) .send( logEntriesHighlightsRequestRT.encode({ - sourceId: 'default', + logView: { type: 'log-view-reference', logViewId: 'default' }, startTimestamp: KEY_BEFORE_START.time, endTimestamp: KEY_AFTER_END.time, highlightTerms: ['generate_test_data/simple_logs'], @@ -166,7 +166,7 @@ export default function ({ getService }: FtrProviderContext) { .set(COMMON_HEADERS) .send( logEntriesHighlightsRequestRT.encode({ - sourceId: 'default', + logView: { type: 'log-view-reference', logViewId: 'default' }, startTimestamp: KEY_BEFORE_START.time, endTimestamp: KEY_AFTER_END.time, query: JSON.stringify({ diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_summary.ts b/x-pack/test/api_integration/apis/metrics_ui/log_summary.ts index 4ac098f95764d..3ccfc4c267c7b 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/log_summary.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/log_summary.ts @@ -49,7 +49,7 @@ export default function ({ getService }: FtrProviderContext) { .set(COMMON_HEADERS) .send( logEntriesSummaryRequestRT.encode({ - sourceId: 'default', + logView: { type: 'log-view-reference', logViewId: 'default' }, startTimestamp, endTimestamp, bucketSize,