diff --git a/x-pack/plugins/infra/common/http_api/index.ts b/x-pack/plugins/infra/common/http_api/index.ts index e9dc741f39652..9f63896dbca9f 100644 --- a/x-pack/plugins/infra/common/http_api/index.ts +++ b/x-pack/plugins/infra/common/http_api/index.ts @@ -5,12 +5,9 @@ * 2.0. */ -export * from './log_analysis'; export * from './metadata_api'; -export * from './log_entries'; export * from './metrics_explorer'; export * from './metrics_api'; -export * from './log_alerts'; export * from './snapshot_api'; export * from './host_details'; export * from './infra'; @@ -20,4 +17,9 @@ export * from './infra'; */ export * from './latest'; export * as inventoryViewsV1 from './inventory_views/v1'; +export * as logAlertsV1 from './log_alerts/v1'; +export * as logAnalysisResultsV1 from './log_analysis/results/v1'; +export * as logAnalysisValidationV1 from './log_analysis/validation/v1'; +export * as logEntriesV1 from './log_entries/v1'; +export * as logViewsV1 from './log_views/v1'; export * as metricsExplorerViewsV1 from './metrics_explorer_views/v1'; diff --git a/x-pack/plugins/infra/common/http_api/latest.ts b/x-pack/plugins/infra/common/http_api/latest.ts index effdbeda041da..28cdf220f710e 100644 --- a/x-pack/plugins/infra/common/http_api/latest.ts +++ b/x-pack/plugins/infra/common/http_api/latest.ts @@ -6,4 +6,9 @@ */ export * from './inventory_views/v1'; +export * from './log_alerts/v1'; +export * from './log_analysis/results/v1'; +export * from './log_analysis/validation/v1'; +export * from './log_entries/v1'; +export * from './log_views/v1'; export * from './metrics_explorer_views/v1'; 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/v1/chart_preview_data.ts similarity index 96% rename from x-pack/plugins/infra/common/http_api/log_alerts/chart_preview_data.ts rename to x-pack/plugins/infra/common/http_api/log_alerts/v1/chart_preview_data.ts index 8a7cbf692433e..5647b9d09bdcc 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/v1/chart_preview_data.ts @@ -12,8 +12,8 @@ import { timeUnitRT, timeSizeRT, groupByRT, -} from '../../alerting/logs/log_threshold/types'; -import { persistedLogViewReferenceRT } from '../../log_views'; +} 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'; diff --git a/x-pack/plugins/infra/common/http_api/log_alerts/index.ts b/x-pack/plugins/infra/common/http_api/log_alerts/v1/index.ts similarity index 100% rename from x-pack/plugins/infra/common/http_api/log_alerts/index.ts rename to x-pack/plugins/infra/common/http_api/log_alerts/v1/index.ts diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/v1/index.ts similarity index 100% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/index.ts 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/v1/log_entry_anomalies.ts similarity index 92% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_anomalies.ts index b8b39197e5acf..56ee97a468462 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/v1/log_entry_anomalies.ts @@ -7,15 +7,15 @@ import * as rt from 'io-ts'; -import { persistedLogViewReferenceRT } from '../../../log_views'; -import { timeRangeRT, routeTimingMetadataRT } from '../../shared'; +import { persistedLogViewReferenceRT } from '../../../../log_views'; +import { timeRangeRT, routeTimingMetadataRT } from '../../../shared'; import { logEntryAnomalyRT, logEntryAnomalyDatasetsRT, anomaliesSortRT, paginationRT, paginationCursorRT, -} from '../../../log_analysis'; +} from '../../../../log_analysis'; export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH = '/api/infra/log_analysis/results/log_entry_anomalies'; 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/v1/log_entry_anomalies_datasets.ts similarity index 94% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies_datasets.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_anomalies_datasets.ts index 94d1b25e4d9c2..8de55d96ba3c0 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/v1/log_entry_anomalies_datasets.ts @@ -6,14 +6,14 @@ */ import * as rt from 'io-ts'; -import { persistedLogViewReferenceRT } from '../../../log_views'; +import { persistedLogViewReferenceRT } from '../../../../log_views'; import { badRequestErrorRT, forbiddenErrorRT, timeRangeRT, routeTimingMetadataRT, -} from '../../shared'; +} from '../../../shared'; export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH = '/api/infra/log_analysis/results/log_entry_anomalies_datasets'; 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/v1/log_entry_categories.ts similarity index 92% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_categories.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_categories.ts index 85829b7ebb00c..9e838174bb6a1 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/v1/log_entry_categories.ts @@ -7,15 +7,15 @@ import * as rt from 'io-ts'; -import { persistedLogViewReferenceRT } from '../../../log_views'; +import { persistedLogViewReferenceRT } from '../../../../log_views'; import { badRequestErrorRT, forbiddenErrorRT, timeRangeRT, routeTimingMetadataRT, -} from '../../shared'; +} from '../../../shared'; -import { logEntryCategoryRT, categoriesSortRT } from '../../../log_analysis'; +import { logEntryCategoryRT, categoriesSortRT } from '../../../../log_analysis'; export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH = '/api/infra/log_analysis/results/log_entry_categories'; 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/v1/log_entry_category_datasets.ts similarity index 94% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_category_datasets.ts index cb3ad4363f243..6523559103fdc 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/v1/log_entry_category_datasets.ts @@ -12,8 +12,8 @@ import { forbiddenErrorRT, timeRangeRT, routeTimingMetadataRT, -} from '../../shared'; -import { persistedLogViewReferenceRT } from '../../../log_views'; +} 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'; diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets_stats.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_category_datasets_stats.ts similarity index 96% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets_stats.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_category_datasets_stats.ts index 7380f133b971e..d069aac79ebb8 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_datasets_stats.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_category_datasets_stats.ts @@ -7,7 +7,7 @@ import * as rt from 'io-ts'; -import { timeRangeRT, routeTimingMetadataRT } from '../../shared'; +import { timeRangeRT, routeTimingMetadataRT } from '../../../shared'; export const LOG_ANALYSIS_GET_LATEST_LOG_ENTRY_CATEGORY_DATASETS_STATS_PATH = '/api/infra/log_analysis/results/latest_log_entry_category_datasets_stats'; 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/v1/log_entry_category_examples.ts similarity index 92% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_category_examples.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_category_examples.ts index c6c349830e833..00fff8aabf9d1 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/v1/log_entry_category_examples.ts @@ -7,14 +7,14 @@ import * as rt from 'io-ts'; -import { persistedLogViewReferenceRT } from '../../../log_views'; +import { persistedLogViewReferenceRT } from '../../../../log_views'; import { badRequestErrorRT, forbiddenErrorRT, timeRangeRT, routeTimingMetadataRT, -} from '../../shared'; -import { logEntryContextRT } from '../../../log_entry'; +} from '../../../shared'; +import { logEntryContextRT } from '../../../../log_entry'; export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH = '/api/infra/log_analysis/results/log_entry_category_examples'; 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/v1/log_entry_examples.ts similarity index 82% rename from x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/results/v1/log_entry_examples.ts index 3aeba96058907..8233962df6bfa 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/v1/log_entry_examples.ts @@ -6,14 +6,14 @@ */ import * as rt from 'io-ts'; -import { persistedLogViewReferenceRT } from '../../../log_views'; -import { logEntryExampleRT } from '../../../log_analysis'; +import { persistedLogViewReferenceRT } from '../../../../log_views'; +import { logEntryExampleRT } from '../../../../log_analysis'; import { badRequestErrorRT, forbiddenErrorRT, timeRangeRT, routeTimingMetadataRT, -} from '../../shared'; +} from '../../../shared'; export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH = '/api/infra/log_analysis/results/log_entry_examples'; @@ -48,7 +48,7 @@ export type GetLogEntryExamplesRequestPayload = rt.TypeOf< * response */ -export const getLogEntryExamplesSuccessReponsePayloadRT = rt.intersection([ +export const getLogEntryExamplesSuccessResponsePayloadRT = rt.intersection([ rt.type({ data: rt.type({ examples: rt.array(logEntryExampleRT), @@ -60,11 +60,11 @@ export const getLogEntryExamplesSuccessReponsePayloadRT = rt.intersection([ ]); export type GetLogEntryExamplesSuccessReponsePayload = rt.TypeOf< - typeof getLogEntryExamplesSuccessReponsePayloadRT + typeof getLogEntryExamplesSuccessResponsePayloadRT >; export const getLogEntryExamplesResponsePayloadRT = rt.union([ - getLogEntryExamplesSuccessReponsePayloadRT, + getLogEntryExamplesSuccessResponsePayloadRT, badRequestErrorRT, forbiddenErrorRT, ]); diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/datasets.ts similarity index 100% rename from x-pack/plugins/infra/common/http_api/log_analysis/validation/datasets.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/datasets.ts diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/index.ts similarity index 100% rename from x-pack/plugins/infra/common/http_api/log_analysis/validation/index.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/index.ts diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts b/x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/log_entry_rate_indices.ts similarity index 96% rename from x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts rename to x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/log_entry_rate_indices.ts index 73b88e052398a..b1c5327fae3ba 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/validation/log_entry_rate_indices.ts +++ b/x-pack/plugins/infra/common/http_api/log_analysis/validation/v1/log_entry_rate_indices.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { mappingRuntimeFieldRT } from '../../shared/es_request'; +import { mappingRuntimeFieldRT } from '../../../shared/es_request'; export const LOG_ANALYSIS_VALIDATE_INDICES_PATH = '/api/infra/log_analysis/validation/log_entry_rate_indices'; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts b/x-pack/plugins/infra/common/http_api/log_entries/v1/highlights.ts similarity index 91% rename from x-pack/plugins/infra/common/http_api/log_entries/highlights.ts rename to x-pack/plugins/infra/common/http_api/log_entries/v1/highlights.ts index a863d35d5b491..f879ca3f87961 100644 --- a/x-pack/plugins/infra/common/http_api/log_entries/highlights.ts +++ b/x-pack/plugins/infra/common/http_api/log_entries/v1/highlights.ts @@ -6,9 +6,9 @@ */ import * as rt from 'io-ts'; -import { logEntryCursorRT, logEntryRT } from '../../log_entry'; -import { logViewColumnConfigurationRT } from '../../log_views'; -import { logViewReferenceRT } from '../../log_views'; +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'; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/index.ts b/x-pack/plugins/infra/common/http_api/log_entries/v1/index.ts similarity index 100% rename from x-pack/plugins/infra/common/http_api/log_entries/index.ts rename to x-pack/plugins/infra/common/http_api/log_entries/v1/index.ts diff --git a/x-pack/plugins/infra/common/http_api/log_entries/summary.ts b/x-pack/plugins/infra/common/http_api/log_entries/v1/summary.ts similarity index 95% rename from x-pack/plugins/infra/common/http_api/log_entries/summary.ts rename to x-pack/plugins/infra/common/http_api/log_entries/v1/summary.ts index 6303c06ac3698..318ff44b296c0 100644 --- a/x-pack/plugins/infra/common/http_api/log_entries/summary.ts +++ b/x-pack/plugins/infra/common/http_api/log_entries/v1/summary.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { logViewReferenceRT } from '../../log_views'; +import { logViewReferenceRT } from '../../../log_views'; export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary'; diff --git a/x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts b/x-pack/plugins/infra/common/http_api/log_entries/v1/summary_highlights.ts similarity index 96% rename from x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts rename to x-pack/plugins/infra/common/http_api/log_entries/v1/summary_highlights.ts index b1cc00e6ce987..f12bc72fc12f5 100644 --- a/x-pack/plugins/infra/common/http_api/log_entries/summary_highlights.ts +++ b/x-pack/plugins/infra/common/http_api/log_entries/v1/summary_highlights.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { logEntryCursorRT } from '../../log_entry'; +import { logEntryCursorRT } from '../../../log_entry'; import { logEntriesSummaryRequestRT, logEntriesSummaryBucketRT } from './summary'; export const LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH = '/api/log_entries/summary_highlights'; diff --git a/x-pack/plugins/infra/common/http_api/log_views/index.ts b/x-pack/plugins/infra/common/http_api/log_views/index.ts index a39f939eb5e98..ebf93020d0d11 100644 --- a/x-pack/plugins/infra/common/http_api/log_views/index.ts +++ b/x-pack/plugins/infra/common/http_api/log_views/index.ts @@ -6,5 +6,3 @@ */ export { getLogViewUrl, LOG_VIEW_URL } from './common'; -export * from './get_log_view'; -export * from './put_log_view'; diff --git a/x-pack/plugins/infra/common/http_api/log_views/get_log_view.ts b/x-pack/plugins/infra/common/http_api/log_views/v1/get_log_view.ts similarity index 78% rename from x-pack/plugins/infra/common/http_api/log_views/get_log_view.ts rename to x-pack/plugins/infra/common/http_api/log_views/v1/get_log_view.ts index 6135d7b31bc82..bb0e6acec9f3b 100644 --- a/x-pack/plugins/infra/common/http_api/log_views/get_log_view.ts +++ b/x-pack/plugins/infra/common/http_api/log_views/v1/get_log_view.ts @@ -6,13 +6,15 @@ */ import * as rt from 'io-ts'; -import { logViewRT } from '../../log_views'; +import { logViewRT } from '../../../log_views'; export const getLogViewRequestParamsRT = rt.type({ // the id of the log view logViewId: rt.string, }); +export type GetLogViewRequestParams = rt.TypeOf; + export const getLogViewResponsePayloadRT = rt.type({ data: logViewRT, }); diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/index.ts b/x-pack/plugins/infra/common/http_api/log_views/v1/index.ts similarity index 79% rename from x-pack/plugins/infra/common/http_api/log_analysis/index.ts rename to x-pack/plugins/infra/common/http_api/log_views/v1/index.ts index a642cd830b6fb..8d22801fe9b24 100644 --- a/x-pack/plugins/infra/common/http_api/log_analysis/index.ts +++ b/x-pack/plugins/infra/common/http_api/log_views/v1/index.ts @@ -5,5 +5,5 @@ * 2.0. */ -export * from './results'; -export * from './validation'; +export * from './get_log_view'; +export * from './put_log_view'; diff --git a/x-pack/plugins/infra/common/http_api/log_views/put_log_view.ts b/x-pack/plugins/infra/common/http_api/log_views/v1/put_log_view.ts similarity index 90% rename from x-pack/plugins/infra/common/http_api/log_views/put_log_view.ts rename to x-pack/plugins/infra/common/http_api/log_views/v1/put_log_view.ts index 22451aa3645c6..4967444cf0f1a 100644 --- a/x-pack/plugins/infra/common/http_api/log_views/put_log_view.ts +++ b/x-pack/plugins/infra/common/http_api/log_views/v1/put_log_view.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { logViewAttributesRT, logViewRT } from '../../log_views'; +import { logViewAttributesRT, logViewRT } from '../../../log_views'; export const putLogViewRequestParamsRT = rt.type({ logViewId: rt.string, @@ -15,6 +15,7 @@ export const putLogViewRequestParamsRT = rt.type({ export const putLogViewRequestPayloadRT = rt.type({ attributes: rt.partial(logViewAttributesRT.type.props), }); + export type PutLogViewRequestPayload = rt.TypeOf; export const putLogViewResponsePayloadRT = rt.type({ diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx index 4bd1ade4b89cb..52b21b9d24693 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/criterion_preview_chart.tsx @@ -46,7 +46,7 @@ import { Color, colorTransformer } from '../../../../../common/color_palette'; import { GetLogAlertsChartPreviewDataAlertParamsSubset, getLogAlertsChartPreviewDataAlertParamsSubsetRT, -} from '../../../../../common/http_api/log_alerts'; +} from '../../../../../common/http_api'; import { useChartPreviewData } from './hooks/use_chart_preview_data'; import { decodeOrThrow } from '../../../../../common/runtime_types'; import { useKibanaTimeZoneSetting } from '../../../../hooks/use_kibana_time_zone_setting'; 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 1b15a7e2c6eed..d633a055c46ef 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 @@ -5,21 +5,21 @@ * 2.0. */ -import { useState, useMemo } from 'react'; import { HttpHandler } from '@kbn/core/public'; import { useKibana } from '@kbn/kibana-react-plugin/public'; +import { useMemo, useState } from 'react'; import { isRatioRule } from '../../../../../../common/alerting/logs/log_threshold'; -import { PersistedLogViewReference } from '../../../../../../common/log_views'; -import { ExecutionTimeRange } from '../../../../../types'; -import { useTrackedPromise } from '../../../../../utils/use_tracked_promise'; import { + GetLogAlertsChartPreviewDataAlertParamsSubset, + getLogAlertsChartPreviewDataRequestPayloadRT, GetLogAlertsChartPreviewDataSuccessResponsePayload, getLogAlertsChartPreviewDataSuccessResponsePayloadRT, - getLogAlertsChartPreviewDataRequestPayloadRT, LOG_ALERTS_CHART_PREVIEW_DATA_PATH, } from '../../../../../../common/http_api'; +import { PersistedLogViewReference } from '../../../../../../common/log_views'; import { decodeOrThrow } from '../../../../../../common/runtime_types'; -import { GetLogAlertsChartPreviewDataAlertParamsSubset } from '../../../../../../common/http_api/log_alerts'; +import { ExecutionTimeRange } from '../../../../../types'; +import { useTrackedPromise } from '../../../../../utils/use_tracked_promise'; interface Options { logViewReference: PersistedLogViewReference; @@ -147,6 +147,7 @@ export const callGetChartPreviewDataAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLogAlertsChartPreviewDataSuccessResponsePayloadRT)(response); diff --git a/x-pack/plugins/infra/public/components/log_stream/log_stream.story_decorators.tsx b/x-pack/plugins/infra/public/components/log_stream/log_stream.story_decorators.tsx index e8675105012ad..3e600d2c95449 100644 --- a/x-pack/plugins/infra/public/components/log_stream/log_stream.story_decorators.tsx +++ b/x-pack/plugins/infra/public/components/log_stream/log_stream.story_decorators.tsx @@ -21,7 +21,7 @@ import { ISearchOptions, } from '@kbn/data-plugin/public'; import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public'; -import { getLogViewResponsePayloadRT } from '../../../common/http_api/log_views'; +import { getLogViewResponsePayloadRT } from '../../../common/http_api'; import { defaultLogViewAttributes } from '../../../common/log_views'; import { LogEntriesSearchResponsePayload, diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/get_latest_categories_datasets_stats.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/get_latest_categories_datasets_stats.ts index f1d9553806290..8a6b15d5c80ff 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/get_latest_categories_datasets_stats.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/get_latest_categories_datasets_stats.ts @@ -42,6 +42,7 @@ export const callGetLatestCategoriesDatasetsStatsAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLatestLogEntryCategoryDatasetsStatsSuccessResponsePayloadRT)(response); diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts index 2e626b03755d2..fc27310814efc 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_datasets.ts @@ -37,6 +37,7 @@ export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: H }, }) ), + version: '1', }); return decodeOrThrow(validateLogEntryDatasetsResponsePayloadRT)(response); diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts index d636cefa04905..92c12e0b08a36 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/api/validate_indices.ts @@ -31,6 +31,7 @@ export const callValidateIndicesAPI = async (requestArgs: RequestArgs, fetch: Ht // @ts-expect-error TODO: fix after elasticsearch-js bump validationIndicesRequestPayloadRT.encode({ data: { indices, fields, runtimeMappings } }) ), + version: '1', }); return decodeOrThrow(validationIndicesResponsePayloadRT)(response); diff --git a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts index d82b8f66c8b77..d6e95b7feebe5 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_analysis/log_analysis_module_types.ts @@ -10,7 +10,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { ValidateLogEntryDatasetsResponsePayload, ValidationIndicesResponsePayload, -} from '../../../../common/http_api/log_analysis'; +} from '../../../../common/http_api'; import { DatasetFilter } from '../../../../common/log_analysis'; import { DeleteJobsResponsePayload } from './api/ml_cleanup'; import { FetchJobStatusResponsePayload } from './api/ml_get_jobs_summary_api'; diff --git a/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_entries_highlights.ts b/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_entries_highlights.ts index 87d70cbfd8e18..91f418f943247 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_entries_highlights.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_entries_highlights.ts @@ -23,6 +23,7 @@ export const fetchLogEntriesHighlights = async ( const response = await fetch(LOG_ENTRIES_HIGHLIGHTS_PATH, { method: 'POST', body: JSON.stringify(logEntriesHighlightsRequestRT.encode(requestArgs)), + version: '1', }); return decodeOrThrow(logEntriesHighlightsResponseRT)(response); diff --git a/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_summary_highlights.ts b/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_summary_highlights.ts index 3686f4e0fdefe..8753926fceb8d 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_summary_highlights.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_highlights/api/fetch_log_summary_highlights.ts @@ -22,6 +22,7 @@ export const fetchLogSummaryHighlights = async ( const response = await fetch(LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, { method: 'POST', body: JSON.stringify(logEntriesSummaryHighlightsRequestRT.encode(requestArgs)), + version: '1', }); return decodeOrThrow(logEntriesSummaryHighlightsResponseRT)(response); diff --git a/x-pack/plugins/infra/public/containers/logs/log_summary/api/fetch_log_summary.ts b/x-pack/plugins/infra/public/containers/logs/log_summary/api/fetch_log_summary.ts index 552dea6612bec..5d89b50e6eaae 100644 --- a/x-pack/plugins/infra/public/containers/logs/log_summary/api/fetch_log_summary.ts +++ b/x-pack/plugins/infra/public/containers/logs/log_summary/api/fetch_log_summary.ts @@ -22,6 +22,7 @@ export const fetchLogSummary = async ( const response = await fetch(LOG_ENTRIES_SUMMARY_PATH, { method: 'POST', body: JSON.stringify(logEntriesSummaryRequestRT.encode(requestArgs)), + version: '1', }); return decodeOrThrow(logEntriesSummaryResponseRT)(response); diff --git a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts index 0115d321164ee..9f939a3f15ac9 100644 --- a/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts +++ b/x-pack/plugins/infra/public/containers/ml/infra_ml_module_types.ts @@ -9,7 +9,7 @@ import { HttpHandler } from '@kbn/core/public'; import { ValidateLogEntryDatasetsResponsePayload, ValidationIndicesResponsePayload, -} from '../../../common/http_api/log_analysis'; +} from '../../../common/http_api'; import { DeleteJobsResponsePayload } from './api/ml_cleanup'; import { FetchJobStatusResponsePayload } from './api/ml_get_jobs_summary_api'; import { GetMlModuleResponsePayload } from './api/ml_get_module'; 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 e2f34f644ecaa..db17c0b866b7b 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 @@ -12,7 +12,7 @@ import { getLogEntryCategoryDatasetsRequestPayloadRT, getLogEntryCategoryDatasetsSuccessReponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; import { decodeOrThrow } from '../../../../../common/runtime_types'; interface RequestArgs { @@ -40,6 +40,7 @@ export const callGetLogEntryCategoryDatasetsAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLogEntryCategoryDatasetsSuccessReponsePayloadRT)(response); 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 52f9f17747b5a..a27e734235c3b 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 @@ -12,7 +12,7 @@ import { getLogEntryCategoryExamplesRequestPayloadRT, getLogEntryCategoryExamplesSuccessReponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; import { decodeOrThrow } from '../../../../../common/runtime_types'; interface RequestArgs { @@ -44,6 +44,7 @@ export const callGetLogEntryCategoryExamplesAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLogEntryCategoryExamplesSuccessReponsePayloadRT)(response); 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 0cd04d999183f..5104ad897c880 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 @@ -12,7 +12,7 @@ import { getLogEntryCategoriesRequestPayloadRT, getLogEntryCategoriesSuccessReponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; import { CategoriesSort } from '../../../../../common/log_analysis'; import { decodeOrThrow } from '../../../../../common/runtime_types'; @@ -66,6 +66,7 @@ export const callGetTopLogEntryCategoriesAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLogEntryCategoriesSuccessReponsePayloadRT)(response); diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/use_log_entry_categories_results.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/use_log_entry_categories_results.ts index 98a3e1148d4e6..7ef8d57b29d9f 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_categories/use_log_entry_categories_results.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_categories/use_log_entry_categories_results.ts @@ -11,7 +11,7 @@ import { PersistedLogViewReference } from '../../../../common/log_views'; import { GetLogEntryCategoriesSuccessResponsePayload, GetLogEntryCategoryDatasetsSuccessResponsePayload, -} from '../../../../common/http_api/log_analysis'; +} from '../../../../common/http_api'; import { CategoriesSort } from '../../../../common/log_analysis'; import { useTrackedPromise, CanceledPromiseError } from '../../../utils/use_tracked_promise'; import { callGetTopLogEntryCategoriesAPI } from './service_calls/get_top_log_entry_categories'; 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 ef39f6ac5f012..dc8ab4772473d 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 @@ -11,7 +11,7 @@ import { getLogEntryAnomaliesRequestPayloadRT, getLogEntryAnomaliesSuccessReponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; import { decodeOrThrow } from '../../../../../common/runtime_types'; import { AnomaliesSort, Pagination } from '../../../../../common/log_analysis'; @@ -42,6 +42,7 @@ export const callGetLogEntryAnomaliesAPI = async (requestArgs: RequestArgs, fetc }, }) ), + version: '1', }); return decodeOrThrow(getLogEntryAnomaliesSuccessReponsePayloadRT)(response); 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 8915f514d1bfb..093a906008582 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 @@ -12,7 +12,7 @@ import { getLogEntryAnomaliesDatasetsRequestPayloadRT, getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; interface RequestArgs { logViewReference: PersistedLogViewReference; @@ -38,6 +38,7 @@ export const callGetLogEntryAnomaliesDatasetsAPI = async ( }, }) ), + version: '1', }); return decodeOrThrow(getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT)(response); 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 75580caa6db8a..f6d90692ad470 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 @@ -10,9 +10,9 @@ import { PersistedLogViewReference } from '../../../../../common/log_views'; import { getLogEntryExamplesRequestPayloadRT, - getLogEntryExamplesSuccessReponsePayloadRT, + getLogEntryExamplesSuccessResponsePayloadRT, LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH, -} from '../../../../../common/http_api/log_analysis'; +} from '../../../../../common/http_api'; import { decodeOrThrow } from '../../../../../common/runtime_types'; interface RequestArgs { @@ -42,7 +42,8 @@ export const callGetLogEntryExamplesAPI = async (requestArgs: RequestArgs, fetch }, }) ), + version: '1', }); - return decodeOrThrow(getLogEntryExamplesSuccessReponsePayloadRT)(response); + return decodeOrThrow(getLogEntryExamplesSuccessResponsePayloadRT)(response); }; diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts index f68aa20d41f0e..db4fc77964173 100644 --- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts +++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts @@ -11,7 +11,7 @@ import { PersistedLogViewReference } from '../../../../common/log_views'; import { useTrackedPromise, CanceledPromiseError } from '../../../utils/use_tracked_promise'; import { callGetLogEntryAnomaliesAPI } from './service_calls/get_log_entry_anomalies'; import { callGetLogEntryAnomaliesDatasetsAPI } from './service_calls/get_log_entry_anomalies_datasets'; -import { GetLogEntryAnomaliesDatasetsSuccessResponsePayload } from '../../../../common/http_api/log_analysis'; +import { GetLogEntryAnomaliesDatasetsSuccessResponsePayload } from '../../../../common/http_api'; import { AnomaliesSort, Pagination, diff --git a/x-pack/plugins/infra/public/services/log_views/log_views_client.ts b/x-pack/plugins/infra/public/services/log_views/log_views_client.ts index fc3d59e8f10a3..7b669e47949be 100644 --- a/x-pack/plugins/infra/public/services/log_views/log_views_client.ts +++ b/x-pack/plugins/infra/public/services/log_views/log_views_client.ts @@ -10,11 +10,8 @@ import { HttpStart } from '@kbn/core/public'; import { ISearchGeneric } from '@kbn/data-plugin/public'; import { DataViewsContract } from '@kbn/data-views-plugin/public'; import { lastValueFrom } from 'rxjs'; -import { - getLogViewResponsePayloadRT, - getLogViewUrl, - putLogViewRequestPayloadRT, -} from '../../../common/http_api/log_views'; +import { getLogViewResponsePayloadRT, putLogViewRequestPayloadRT } from '../../../common/http_api'; +import { getLogViewUrl } from '../../../common/http_api/log_views'; import { FetchLogViewError, FetchLogViewStatusError, @@ -48,9 +45,11 @@ export class LogViewsClient implements ILogViewsClient { } const { logViewId } = logViewReference; - const response = await this.http.get(getLogViewUrl(logViewId)).catch((error) => { - throw new FetchLogViewError(`Failed to fetch log view "${logViewId}": ${error}`); - }); + const response = await this.http + .get(getLogViewUrl(logViewId), { version: '1' }) + .catch((error) => { + throw new FetchLogViewError(`Failed to fetch log view "${logViewId}": ${error}`); + }); const { data } = decodeOrThrow( getLogViewResponsePayloadRT, @@ -133,6 +132,7 @@ export class LogViewsClient implements ILogViewsClient { body: JSON.stringify( putLogViewRequestPayloadRT.encode({ attributes: logViewAttributes }) ), + version: '1', }) .catch((error) => { throw new PutLogViewError(`Failed to write log view "${logViewId}": ${error}`); diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts b/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts index b8774df2f5253..22351750fbab4 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/adapter_types.ts @@ -24,6 +24,7 @@ import { PluginSetupContract as AlertingPluginContract } from '@kbn/alerting-plu import { MlPluginSetup } from '@kbn/ml-plugin/server'; import { RuleRegistryPluginSetupContract } from '@kbn/rule-registry-plugin/server'; import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server'; +import { VersionedRouteConfig } from '@kbn/core-http-server'; export interface InfraServerPluginSetupDeps { alerting: AlertingPluginContract; @@ -173,3 +174,7 @@ export interface InfraFieldDef { export type InfraRouteConfig = { method: RouteMethod; } & RouteConfig; + +export type InfraVersionedRouteConfig = { + method: RouteMethod; +} & VersionedRouteConfig; diff --git a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts index 7080a513da82c..c10987b75c43b 100644 --- a/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/framework/kibana_framework_adapter.ts @@ -24,6 +24,7 @@ import { InfraRouteConfig, InfraServerPluginSetupDeps, InfraServerPluginStartDeps, + InfraVersionedRouteConfig, } from './adapter_types'; interface FrozenIndexParams { @@ -78,6 +79,37 @@ export class KibanaFramework { } } + public registerVersionedRoute( + config: InfraVersionedRouteConfig + ) { + const defaultOptions = { + tags: ['access:infra'], + }; + const routeConfig = { + access: config.access, + path: config.path, + // Currently we have no use of custom options beyond tags, this can be extended + // beyond defaultOptions if it's needed. + options: defaultOptions, + }; + switch (config.method) { + case 'get': + return this.router.versioned.get(routeConfig); + case 'post': + return this.router.versioned.post(routeConfig); + case 'delete': + return this.router.versioned.delete(routeConfig); + case 'put': + return this.router.versioned.put(routeConfig); + case 'patch': + return this.router.versioned.patch(routeConfig); + default: + throw new RangeError( + `#registerVersionedRoute: "${config.method}" is not an accepted method` + ); + } + } + callWithRequest( requestContext: InfraPluginRequestHandlerContext, endpoint: 'search', diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts index 4455eb5f53657..43f4e6924012c 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_chart_preview.ts @@ -18,7 +18,7 @@ import { GetLogAlertsChartPreviewDataAlertParamsSubset, Point, Series, -} from '../../../../common/http_api/log_alerts'; +} from '../../../../common/http_api'; import { ResolvedLogView } from '../../../../common/log_views'; import { decodeOrThrow } from '../../../../common/runtime_types'; import type { InfraPluginRequestHandlerContext } from '../../../types'; 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 d04a9a9bf491a..9a963c3f84e72 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 @@ -6,12 +6,9 @@ */ import Boom from '@hapi/boom'; +import { logAlertsV1 } from '../../../common/http_api'; import { InfraBackendLibs } from '../../lib/infra_types'; -import { - LOG_ALERTS_CHART_PREVIEW_DATA_PATH, - getLogAlertsChartPreviewDataSuccessResponsePayloadRT, - getLogAlertsChartPreviewDataRequestPayloadRT, -} from '../../../common/http_api/log_alerts/chart_preview_data'; + import { createValidationFunction } from '../../../common/runtime_types'; import { getChartPreviewData } from '../../lib/alerting/log_threshold/log_threshold_chart_preview'; @@ -19,49 +16,58 @@ export const initGetLogAlertsChartPreviewDataRoute = ({ framework, getStartServices, }: Pick) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ALERTS_CHART_PREVIEW_DATA_PATH, - validate: { - body: createValidationFunction(getLogAlertsChartPreviewDataRequestPayloadRT), + path: logAlertsV1.LOG_ALERTS_CHART_PREVIEW_DATA_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAlertsV1.getLogAlertsChartPreviewDataRequestPayloadRT + ), + }, + }, }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { logView, buckets, alertParams, executionTimeRange }, - } = request.body; + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { logView, buckets, alertParams, executionTimeRange }, + } = request.body; - const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); + const [, , { logViews }] = await getStartServices(); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); - try { - const { series } = await getChartPreviewData( - requestContext, - resolvedLogView, - framework.callWithRequest, - alertParams, - buckets, - executionTimeRange - ); + try { + const { series } = await getChartPreviewData( + requestContext, + resolvedLogView, + framework.callWithRequest, + alertParams, + buckets, + executionTimeRange + ); - return response.ok({ - body: getLogAlertsChartPreviewDataSuccessResponsePayloadRT.encode({ - data: { series }, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAlertsV1.getLogAlertsChartPreviewDataSuccessResponsePayloadRT.encode({ + data: { series }, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + return response.customError({ + statusCode: error.statusCode ?? 500, + body: { + message: error.message ?? 'An unexpected error occurred', + }, + }); + } + }) + ); }; 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 13df82f8fe343..e48292a12e95b 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 @@ -6,13 +6,9 @@ */ import Boom from '@hapi/boom'; +import { logAnalysisResultsV1 } from '../../../../common/http_api'; import { InfraBackendLibs } from '../../../lib/infra_types'; -import { - LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, - getLogEntryAnomaliesSuccessReponsePayloadRT, - getLogEntryAnomaliesRequestPayloadRT, - GetLogEntryAnomaliesRequestPayload, -} from '../../../../common/http_api/log_analysis'; + import { AnomaliesSort, Pagination } from '../../../../common/log_analysis'; import { createValidationFunction } from '../../../../common/runtime_types'; import { assertHasInfraMlPlugins } from '../../../utils/request_context'; @@ -20,83 +16,94 @@ import { getLogEntryAnomalies } from '../../../lib/log_analysis'; import { isMlPrivilegesError } from '../../../lib/log_analysis/errors'; export const initGetLogEntryAnomaliesRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, - validate: { - body: createValidationFunction(getLogEntryAnomaliesRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - logView, - timeRange: { startTime, endTime }, - sort: sortParam, - pagination: paginationParam, - datasets, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryAnomaliesRequestPayloadRT + ), + }, }, - } = request.body; - - const { sort, pagination } = getSortAndPagination(sortParam, paginationParam); + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + logView, + timeRange: { startTime, endTime }, + sort: sortParam, + pagination: paginationParam, + datasets, + }, + } = request.body; - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + const { sort, pagination } = getSortAndPagination(sortParam, paginationParam); - const { - data: logEntryAnomalies, - paginationCursors, - hasMoreEntries, - timing, - } = await getLogEntryAnomalies( - infraMlContext, - logView, - startTime, - endTime, - sort, - pagination, - datasets - ); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - return response.ok({ - body: getLogEntryAnomaliesSuccessReponsePayloadRT.encode({ - data: { - anomalies: logEntryAnomalies, - hasMoreEntries, - paginationCursors, - }, + const { + data: logEntryAnomalies, + paginationCursors, + hasMoreEntries, timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + } = await getLogEntryAnomalies( + infraMlContext, + logView, + startTime, + endTime, + sort, + pagination, + datasets + ); + + return response.ok({ + body: logAnalysisResultsV1.getLogEntryAnomaliesSuccessReponsePayloadRT.encode({ + data: { + anomalies: logEntryAnomalies, + hasMoreEntries, + paginationCursors, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; const getSortAndPagination = ( - sort: Partial = {}, - pagination: Partial = {} + sort: Partial = {}, + pagination: Partial< + logAnalysisResultsV1.GetLogEntryAnomaliesRequestPayload['data']['pagination'] + > = {} ): { sort: AnomaliesSort; pagination: Pagination; 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 5f7aec90376af..3151c6ac82b4e 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 @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLogEntryAnomaliesDatasetsRequestPayloadRT, - getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT, - LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH, -} from '../../../../common/http_api/log_analysis'; + +import { logAnalysisResultsV1 } from '../../../../common/http_api'; import { createValidationFunction } from '../../../../common/runtime_types'; import type { InfraBackendLibs } from '../../../lib/infra_types'; import { getLogEntryAnomaliesDatasets } from '../../../lib/log_analysis'; @@ -18,61 +15,70 @@ import { assertHasInfraMlPlugins } from '../../../utils/request_context'; import { isMlPrivilegesError } from '../../../lib/log_analysis/errors'; export const initGetLogEntryAnomaliesDatasetsRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH, - validate: { - body: createValidationFunction(getLogEntryAnomaliesDatasetsRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - logView, - timeRange: { startTime, endTime }, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryAnomaliesDatasetsRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + logView, + timeRange: { startTime, endTime }, + }, + } = request.body; - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { datasets, timing } = await getLogEntryAnomaliesDatasets( - { infra: await infraMlContext.infra }, - logView, - startTime, - endTime - ); + const { datasets, timing } = await getLogEntryAnomaliesDatasets( + { infra: await infraMlContext.infra }, + logView, + startTime, + endTime + ); - return response.ok({ - body: getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT.encode({ - data: { - datasets, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLogEntryAnomaliesDatasetsSuccessReponsePayloadRT.encode({ + data: { + datasets, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; 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 1a484a0662e05..25994b7d14a20 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 @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLogEntryCategoriesRequestPayloadRT, - getLogEntryCategoriesSuccessReponsePayloadRT, - LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH, -} from '../../../../common/http_api/log_analysis'; + +import { logAnalysisResultsV1 } from '../../../../common/http_api'; import { createValidationFunction } from '../../../../common/runtime_types'; import type { InfraBackendLibs } from '../../../lib/infra_types'; import { getTopLogEntryCategories } from '../../../lib/log_analysis'; @@ -18,74 +15,83 @@ import { assertHasInfraMlPlugins } from '../../../utils/request_context'; import { isMlPrivilegesError } from '../../../lib/log_analysis/errors'; export const initGetLogEntryCategoriesRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH, - validate: { - body: createValidationFunction(getLogEntryCategoriesRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - categoryCount, - histograms, - logView, - timeRange: { startTime, endTime }, - datasets, - sort, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryCategoriesRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + categoryCount, + histograms, + logView, + timeRange: { startTime, endTime }, + datasets, + sort, + }, + } = request.body; - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { data: topLogEntryCategories, timing } = await getTopLogEntryCategories( - { infra: await infraMlContext.infra }, - logView, - startTime, - endTime, - categoryCount, - datasets ?? [], - histograms.map((histogram) => ({ - bucketCount: histogram.bucketCount, - endTime: histogram.timeRange.endTime, - id: histogram.id, - startTime: histogram.timeRange.startTime, - })), - sort - ); + const { data: topLogEntryCategories, timing } = await getTopLogEntryCategories( + { infra: await infraMlContext.infra }, + logView, + startTime, + endTime, + categoryCount, + datasets ?? [], + histograms.map((histogram) => ({ + bucketCount: histogram.bucketCount, + endTime: histogram.timeRange.endTime, + id: histogram.id, + startTime: histogram.timeRange.startTime, + })), + sort + ); - return response.ok({ - body: getLogEntryCategoriesSuccessReponsePayloadRT.encode({ - data: { - categories: topLogEntryCategories, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLogEntryCategoriesSuccessReponsePayloadRT.encode({ + data: { + categories: topLogEntryCategories, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; 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 92f0cd576a0f8..ba9e389b4a48e 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 @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLogEntryCategoryDatasetsRequestPayloadRT, - getLogEntryCategoryDatasetsSuccessReponsePayloadRT, - LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH, -} from '../../../../common/http_api/log_analysis'; + +import { logAnalysisResultsV1 } from '../../../../common/http_api'; import { createValidationFunction } from '../../../../common/runtime_types'; import type { InfraBackendLibs } from '../../../lib/infra_types'; import { getLogEntryCategoryDatasets } from '../../../lib/log_analysis'; @@ -18,61 +15,70 @@ import { assertHasInfraMlPlugins } from '../../../utils/request_context'; import { isMlPrivilegesError } from '../../../lib/log_analysis/errors'; export const initGetLogEntryCategoryDatasetsRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH, - validate: { - body: createValidationFunction(getLogEntryCategoryDatasetsRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - logView, - timeRange: { startTime, endTime }, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryCategoryDatasetsRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + logView, + timeRange: { startTime, endTime }, + }, + } = request.body; - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { data: logEntryCategoryDatasets, timing } = await getLogEntryCategoryDatasets( - { infra: await infraMlContext.infra }, - logView, - startTime, - endTime - ); + const { data: logEntryCategoryDatasets, timing } = await getLogEntryCategoryDatasets( + { infra: await infraMlContext.infra }, + logView, + startTime, + endTime + ); - return response.ok({ - body: getLogEntryCategoryDatasetsSuccessReponsePayloadRT.encode({ - data: { - datasets: logEntryCategoryDatasets, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLogEntryCategoryDatasetsSuccessReponsePayloadRT.encode({ + data: { + datasets: logEntryCategoryDatasets, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets_stats.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets_stats.ts index 5844405ec062d..ec8589416efb4 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets_stats.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_category_datasets_stats.ts @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLatestLogEntryCategoryDatasetsStatsRequestPayloadRT, - getLatestLogEntryCategoryDatasetsStatsSuccessResponsePayloadRT, - LOG_ANALYSIS_GET_LATEST_LOG_ENTRY_CATEGORY_DATASETS_STATS_PATH, -} from '../../../../common/http_api/log_analysis'; +import { logAnalysisResultsV1 } from '../../../../common/http_api'; + import { createValidationFunction } from '../../../../common/runtime_types'; import type { InfraBackendLibs } from '../../../lib/infra_types'; import { getLatestLogEntriesCategoriesDatasetsStats } from '../../../lib/log_analysis'; @@ -18,63 +15,74 @@ import { isMlPrivilegesError } from '../../../lib/log_analysis/errors'; import { assertHasInfraMlPlugins } from '../../../utils/request_context'; export const initGetLogEntryCategoryDatasetsStatsRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LATEST_LOG_ENTRY_CATEGORY_DATASETS_STATS_PATH, - validate: { - body: createValidationFunction(getLatestLogEntryCategoryDatasetsStatsRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - jobIds, - timeRange: { startTime, endTime }, - includeCategorizerStatuses, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LATEST_LOG_ENTRY_CATEGORY_DATASETS_STATS_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLatestLogEntryCategoryDatasetsStatsRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + jobIds, + timeRange: { startTime, endTime }, + includeCategorizerStatuses, + }, + } = request.body; - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { data: datasetStats, timing } = await getLatestLogEntriesCategoriesDatasetsStats( - { infra: await infraMlContext.infra }, - jobIds, - startTime, - endTime, - includeCategorizerStatuses - ); + const { data: datasetStats, timing } = await getLatestLogEntriesCategoriesDatasetsStats( + { infra: await infraMlContext.infra }, + jobIds, + startTime, + endTime, + includeCategorizerStatuses + ); - return response.ok({ - body: getLatestLogEntryCategoryDatasetsStatsSuccessResponsePayloadRT.encode({ - data: { - datasetStats, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLatestLogEntryCategoryDatasetsStatsSuccessResponsePayloadRT.encode( + { + data: { + datasetStats, + }, + timing, + } + ), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; 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 40de491c1673f..b17a50d23974d 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 @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLogEntryCategoryExamplesRequestPayloadRT, - getLogEntryCategoryExamplesSuccessReponsePayloadRT, - LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, -} from '../../../../common/http_api/log_analysis'; +import { logAnalysisResultsV1 } from '../../../../common/http_api'; + import { createValidationFunction } from '../../../../common/runtime_types'; import type { InfraBackendLibs } from '../../../lib/infra_types'; import { getLogEntryCategoryExamples } from '../../../lib/log_analysis'; @@ -21,69 +18,78 @@ export const initGetLogEntryCategoryExamplesRoute = ({ framework, getStartServices, }: Pick) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, - validate: { - body: createValidationFunction(getLogEntryCategoryExamplesRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - categoryId, - exampleCount, - logView, - timeRange: { startTime, endTime }, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryCategoryExamplesRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + categoryId, + exampleCount, + logView, + timeRange: { startTime, endTime }, + }, + } = request.body; - const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); + const [, , { logViews }] = await getStartServices(); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { data: logEntryCategoryExamples, timing } = await getLogEntryCategoryExamples( - { infra: await infraMlContext.infra, core: await infraMlContext.core }, - logView, - startTime, - endTime, - categoryId, - exampleCount, - resolvedLogView - ); + const { data: logEntryCategoryExamples, timing } = await getLogEntryCategoryExamples( + { infra: await infraMlContext.infra, core: await infraMlContext.core }, + logView, + startTime, + endTime, + categoryId, + exampleCount, + resolvedLogView + ); - return response.ok({ - body: getLogEntryCategoryExamplesSuccessReponsePayloadRT.encode({ - data: { - examples: logEntryCategoryExamples, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLogEntryCategoryExamplesSuccessReponsePayloadRT.encode({ + data: { + examples: logEntryCategoryExamples, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; 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 23ba1072a60fc..2b413dce7f294 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 @@ -6,11 +6,8 @@ */ import Boom from '@hapi/boom'; -import { - getLogEntryExamplesRequestPayloadRT, - getLogEntryExamplesSuccessReponsePayloadRT, - LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH, -} from '../../../../common/http_api/log_analysis'; +import { logAnalysisResultsV1 } from '../../../../common/http_api'; + import { createValidationFunction } from '../../../../common/runtime_types'; import { InfraBackendLibs } from '../../../lib/infra_types'; import { getLogEntryExamples } from '../../../lib/log_analysis'; @@ -21,72 +18,81 @@ export const initGetLogEntryExamplesRoute = ({ framework, getStartServices, }: Pick) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH, - validate: { - body: createValidationFunction(getLogEntryExamplesRequestPayloadRT), - }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - const { - data: { - dataset, - exampleCount, - logView, - timeRange: { startTime, endTime }, - categoryId, + path: logAnalysisResultsV1.LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisResultsV1.getLogEntryExamplesRequestPayloadRT + ), + }, }, - } = request.body; + }, + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + const { + data: { + dataset, + exampleCount, + logView, + timeRange: { startTime, endTime }, + categoryId, + }, + } = request.body; - const [, , { logViews }] = await getStartServices(); - const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); + const [, , { logViews }] = await getStartServices(); + const resolvedLogView = await logViews.getScopedClient(request).getResolvedLogView(logView); - try { - const infraMlContext = await assertHasInfraMlPlugins(requestContext); + try { + const infraMlContext = await assertHasInfraMlPlugins(requestContext); - const { data: logEntryExamples, timing } = await getLogEntryExamples( - infraMlContext, - logView, - startTime, - endTime, - dataset, - exampleCount, - resolvedLogView, - framework.callWithRequest, - categoryId - ); + const { data: logEntryExamples, timing } = await getLogEntryExamples( + infraMlContext, + logView, + startTime, + endTime, + dataset, + exampleCount, + resolvedLogView, + framework.callWithRequest, + categoryId + ); - return response.ok({ - body: getLogEntryExamplesSuccessReponsePayloadRT.encode({ - data: { - examples: logEntryExamples, - }, - timing, - }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisResultsV1.getLogEntryExamplesSuccessResponsePayloadRT.encode({ + data: { + examples: logEntryExamples, + }, + timing, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } + + if (isMlPrivilegesError(error)) { + return response.customError({ + statusCode: 403, + body: { + message: error.message, + }, + }); + } - if (isMlPrivilegesError(error)) { return response.customError({ - statusCode: 403, + statusCode: error.statusCode ?? 500, body: { - message: error.message, + message: error.message ?? 'An unexpected error occurred', }, }); } - - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + }) + ); }; diff --git a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts index 4237ee2ae9abc..f76fd3a5173cf 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/validation/datasets.ts @@ -9,65 +9,72 @@ import Boom from '@hapi/boom'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { InfraBackendLibs } from '../../../lib/infra_types'; -import { - LOG_ANALYSIS_VALIDATE_DATASETS_PATH, - validateLogEntryDatasetsRequestPayloadRT, - validateLogEntryDatasetsResponsePayloadRT, -} from '../../../../common/http_api'; import { createValidationFunction } from '../../../../common/runtime_types'; +import { logAnalysisValidationV1 } from '../../../../common/http_api'; export const initValidateLogAnalysisDatasetsRoute = ({ framework, logEntries, }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_VALIDATE_DATASETS_PATH, - validate: { - body: createValidationFunction(validateLogEntryDatasetsRequestPayloadRT), + path: logAnalysisValidationV1.LOG_ANALYSIS_VALIDATE_DATASETS_PATH, + }) + .addVersion( + { + version: '1', + validate: { + request: { + body: createValidationFunction( + logAnalysisValidationV1.validateLogEntryDatasetsRequestPayloadRT + ), + }, + }, }, - }, - framework.router.handleLegacyErrors(async (requestContext, request, response) => { - try { - const { - data: { indices, timestampField, startTime, endTime, runtimeMappings }, - } = request.body; + framework.router.handleLegacyErrors(async (requestContext, request, response) => { + try { + const { + data: { indices, timestampField, startTime, endTime, runtimeMappings }, + } = request.body; - const datasets = await Promise.all( - indices.map(async (indexName) => { - const indexDatasets = await logEntries.getLogEntryDatasets( - requestContext, - timestampField, - indexName, - startTime, - endTime, - runtimeMappings as estypes.MappingRuntimeFields - ); + const datasets = await Promise.all( + indices.map(async (indexName) => { + const indexDatasets = await logEntries.getLogEntryDatasets( + requestContext, + timestampField, + indexName, + startTime, + endTime, + runtimeMappings as estypes.MappingRuntimeFields + ); - return { - indexName, - datasets: indexDatasets, - }; - }) - ); + return { + indexName, + datasets: indexDatasets, + }; + }) + ); - return response.ok({ - body: validateLogEntryDatasetsResponsePayloadRT.encode({ data: { datasets } }), - }); - } catch (error) { - if (Boom.isBoom(error)) { - throw error; - } + return response.ok({ + body: logAnalysisValidationV1.validateLogEntryDatasetsResponsePayloadRT.encode({ + data: { datasets }, + }), + }); + } catch (error) { + if (Boom.isBoom(error)) { + throw error; + } - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); - } - }) - ); + return response.customError({ + statusCode: error.statusCode ?? 500, + body: { + message: error.message ?? 'An unexpected error occurred', + }, + }); + } + }) + ); }; diff --git a/x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts b/x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts index 6b7293e4c8559..06ebd4d98b0f8 100644 --- a/x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts +++ b/x-pack/plugins/infra/server/routes/log_analysis/validation/indices.ts @@ -12,83 +12,85 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { schema } from '@kbn/config-schema'; import { InfraBackendLibs } from '../../../lib/infra_types'; -import { - LOG_ANALYSIS_VALIDATE_INDICES_PATH, - validationIndicesRequestPayloadRT, - validationIndicesResponsePayloadRT, - ValidationIndicesError, -} from '../../../../common/http_api'; import { throwErrors } from '../../../../common/runtime_types'; +import { logAnalysisValidationV1 } from '../../../../common/http_api'; const escapeHatch = schema.object({}, { unknowns: 'allow' }); export const initValidateLogAnalysisIndicesRoute = ({ framework }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ANALYSIS_VALIDATE_INDICES_PATH, - validate: { body: escapeHatch }, - }, - async (requestContext, request, response) => { - const payload = pipe( - validationIndicesRequestPayloadRT.decode(request.body), - fold(throwErrors(Boom.badRequest), identity) - ); + path: logAnalysisValidationV1.LOG_ANALYSIS_VALIDATE_INDICES_PATH, + }) + .addVersion( + { + version: '1', + validate: { request: { body: escapeHatch } }, + }, + async (requestContext, request, response) => { + const payload = pipe( + logAnalysisValidationV1.validationIndicesRequestPayloadRT.decode(request.body), + fold(throwErrors(Boom.badRequest), identity) + ); - const { fields, indices, runtimeMappings } = payload.data; - const errors: ValidationIndicesError[] = []; + const { fields, indices, runtimeMappings } = payload.data; + const errors: logAnalysisValidationV1.ValidationIndicesError[] = []; - // Query each pattern individually, to map correctly the errors - await Promise.all( - indices.map(async (index) => { - const fieldCaps = await ( - await requestContext.core - ).elasticsearch.client.asCurrentUser.fieldCaps({ - allow_no_indices: true, - fields: fields.map((field) => field.name), - ignore_unavailable: true, - index, - body: { - runtime_mappings: runtimeMappings, - }, - }); - - if (fieldCaps.indices.length === 0) { - errors.push({ - error: 'INDEX_NOT_FOUND', + // Query each pattern individually, to map correctly the errors + await Promise.all( + indices.map(async (index) => { + const fieldCaps = await ( + await requestContext.core + ).elasticsearch.client.asCurrentUser.fieldCaps({ + allow_no_indices: true, + fields: fields.map((field) => field.name), + ignore_unavailable: true, index, + body: { + runtime_mappings: runtimeMappings, + }, }); - return; - } - - fields.forEach(({ name: fieldName, validTypes }) => { - const fieldMetadata = fieldCaps.fields[fieldName]; - if (fieldMetadata === undefined) { + if (fieldCaps.indices.length === 0) { errors.push({ - error: 'FIELD_NOT_FOUND', + error: 'INDEX_NOT_FOUND', index, - field: fieldName, }); - } else { - const fieldTypes = Object.keys(fieldMetadata); + return; + } + + fields.forEach(({ name: fieldName, validTypes }) => { + const fieldMetadata = fieldCaps.fields[fieldName]; - if (!fieldTypes.every((fieldType) => validTypes.includes(fieldType))) { + if (fieldMetadata === undefined) { errors.push({ - error: `FIELD_NOT_VALID`, + error: 'FIELD_NOT_FOUND', index, field: fieldName, }); + } else { + const fieldTypes = Object.keys(fieldMetadata); + + if (!fieldTypes.every((fieldType) => validTypes.includes(fieldType))) { + errors.push({ + error: `FIELD_NOT_VALID`, + index, + field: fieldName, + }); + } } - } - }); - }) - ); + }); + }) + ); - return response.ok({ - body: validationIndicesResponsePayloadRT.encode({ data: { errors } }), - }); - } - ); + return response.ok({ + body: logAnalysisValidationV1.validationIndicesResponsePayloadRT.encode({ + data: { errors }, + }), + }); + } + ); }; 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 aa8876951ee6c..9d81e0d349f46 100644 --- a/x-pack/plugins/infra/server/routes/log_entries/highlights.ts +++ b/x-pack/plugins/infra/server/routes/log_entries/highlights.ts @@ -12,90 +12,92 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { schema } from '@kbn/config-schema'; +import { logEntriesV1 } from '../../../common/http_api'; import { throwErrors } from '../../../common/runtime_types'; import { InfraBackendLibs } from '../../lib/infra_types'; -import { - LOG_ENTRIES_HIGHLIGHTS_PATH, - logEntriesHighlightsRequestRT, - logEntriesHighlightsResponseRT, -} from '../../../common/http_api/log_entries'; + import { parseFilterQuery } from '../../utils/serialized_query'; import { LogEntriesParams } from '../../lib/domains/log_entries_domain'; const escapeHatch = schema.object({}, { unknowns: 'allow' }); export const initLogEntriesHighlightsRoute = ({ framework, logEntries }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ENTRIES_HIGHLIGHTS_PATH, - validate: { body: escapeHatch }, - }, - async (requestContext, request, response) => { - const payload = pipe( - logEntriesHighlightsRequestRT.decode(request.body), - fold(throwErrors(Boom.badRequest), identity) - ); + path: logEntriesV1.LOG_ENTRIES_HIGHLIGHTS_PATH, + }) + .addVersion( + { + version: '1', + validate: { request: { body: escapeHatch } }, + }, + async (requestContext, request, response) => { + const payload = pipe( + logEntriesV1.logEntriesHighlightsRequestRT.decode(request.body), + fold(throwErrors(Boom.badRequest), identity) + ); - const { startTimestamp, endTimestamp, logView, query, size, highlightTerms } = payload; + const { startTimestamp, endTimestamp, logView, query, size, highlightTerms } = payload; - let entriesPerHighlightTerm; + let entriesPerHighlightTerm; - if ('center' in payload) { - entriesPerHighlightTerm = await Promise.all( - highlightTerms.map((highlightTerm) => - logEntries.getLogEntriesAround(requestContext, logView, { - startTimestamp, - endTimestamp, - query: parseFilterQuery(query), - center: payload.center, - size, - highlightTerm, - }) - ) - ); - } else { - let cursor: LogEntriesParams['cursor']; - if ('before' in payload) { - cursor = { before: payload.before }; - } else if ('after' in payload) { - cursor = { after: payload.after }; - } + if ('center' in payload) { + entriesPerHighlightTerm = await Promise.all( + highlightTerms.map((highlightTerm) => + logEntries.getLogEntriesAround(requestContext, logView, { + startTimestamp, + endTimestamp, + query: parseFilterQuery(query), + center: payload.center, + size, + highlightTerm, + }) + ) + ); + } else { + let cursor: LogEntriesParams['cursor']; + if ('before' in payload) { + cursor = { before: payload.before }; + } else if ('after' in payload) { + cursor = { after: payload.after }; + } - entriesPerHighlightTerm = await Promise.all( - highlightTerms.map((highlightTerm) => - logEntries.getLogEntries(requestContext, logView, { - startTimestamp, - endTimestamp, - query: parseFilterQuery(query), - cursor, - size, - highlightTerm, - }) - ) - ); - } + entriesPerHighlightTerm = await Promise.all( + highlightTerms.map((highlightTerm) => + logEntries.getLogEntries(requestContext, logView, { + startTimestamp, + endTimestamp, + query: parseFilterQuery(query), + cursor, + size, + highlightTerm, + }) + ) + ); + } - return response.ok({ - body: logEntriesHighlightsResponseRT.encode({ - data: entriesPerHighlightTerm.map(({ entries }) => { - if (entries.length > 0) { - return { - entries, - topCursor: entries[0].cursor, - bottomCursor: entries[entries.length - 1].cursor, - }; - } else { - return { - entries, - topCursor: null, - bottomCursor: null, - }; - } + return response.ok({ + body: logEntriesV1.logEntriesHighlightsResponseRT.encode({ + data: entriesPerHighlightTerm.map(({ entries }) => { + if (entries.length > 0) { + return { + entries, + topCursor: entries[0].cursor, + bottomCursor: entries[entries.length - 1].cursor, + }; + } else { + return { + entries, + topCursor: null, + bottomCursor: null, + }; + } + }), }), - }), - }); - } - ); + }); + } + ); }; 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 dd48c21a590ae..ee042f51d1dc8 100644 --- a/x-pack/plugins/infra/server/routes/log_entries/summary.ts +++ b/x-pack/plugins/infra/server/routes/log_entries/summary.ts @@ -12,53 +12,55 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { schema } from '@kbn/config-schema'; +import { logEntriesV1 } from '../../../common/http_api'; import { throwErrors } from '../../../common/runtime_types'; import { InfraBackendLibs } from '../../lib/infra_types'; -import { - LOG_ENTRIES_SUMMARY_PATH, - logEntriesSummaryRequestRT, - logEntriesSummaryResponseRT, -} from '../../../common/http_api/log_entries'; + import { parseFilterQuery } from '../../utils/serialized_query'; import { UsageCollector } from '../../usage/usage_collector'; const escapeHatch = schema.object({}, { unknowns: 'allow' }); export const initLogEntriesSummaryRoute = ({ framework, logEntries }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ENTRIES_SUMMARY_PATH, - validate: { body: escapeHatch }, - }, - async (requestContext, request, response) => { - const payload = pipe( - logEntriesSummaryRequestRT.decode(request.body), - fold(throwErrors(Boom.badRequest), identity) - ); - const { logView, startTimestamp, endTimestamp, bucketSize, query } = payload; + path: logEntriesV1.LOG_ENTRIES_SUMMARY_PATH, + }) + .addVersion( + { + version: '1', + validate: { request: { body: escapeHatch } }, + }, + async (requestContext, request, response) => { + const payload = pipe( + logEntriesV1.logEntriesSummaryRequestRT.decode(request.body), + fold(throwErrors(Boom.badRequest), identity) + ); + const { logView, startTimestamp, endTimestamp, bucketSize, query } = payload; - const buckets = await logEntries.getLogSummaryBucketsBetween( - requestContext, - logView, - startTimestamp, - endTimestamp, - bucketSize, - parseFilterQuery(query) - ); + const buckets = await logEntries.getLogSummaryBucketsBetween( + requestContext, + logView, + startTimestamp, + endTimestamp, + bucketSize, + parseFilterQuery(query) + ); - UsageCollector.countLogs(); + UsageCollector.countLogs(); - return response.ok({ - body: logEntriesSummaryResponseRT.encode({ - data: { - start: startTimestamp, - end: endTimestamp, - buckets, - }, - }), - }); - } - ); + return response.ok({ + body: logEntriesV1.logEntriesSummaryResponseRT.encode({ + data: { + start: startTimestamp, + end: endTimestamp, + buckets, + }, + }), + }); + } + ); }; 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 206e02bc57278..e831ec51c4145 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 @@ -12,14 +12,11 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { schema } from '@kbn/config-schema'; +import { logEntriesV1 } from '../../../common/http_api'; import { throwErrors } from '../../../common/runtime_types'; import { InfraBackendLibs } from '../../lib/infra_types'; -import { - LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, - logEntriesSummaryHighlightsRequestRT, - logEntriesSummaryHighlightsResponseRT, -} from '../../../common/http_api/log_entries'; + import { parseFilterQuery } from '../../utils/serialized_query'; const escapeHatch = schema.object({}, { unknowns: 'allow' }); @@ -28,38 +25,44 @@ export const initLogEntriesSummaryHighlightsRoute = ({ framework, logEntries, }: InfraBackendLibs) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'post', - path: LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, - validate: { body: escapeHatch }, - }, - async (requestContext, request, response) => { - const payload = pipe( - logEntriesSummaryHighlightsRequestRT.decode(request.body), - fold(throwErrors(Boom.badRequest), identity) - ); - const { logView, startTimestamp, endTimestamp, bucketSize, query, highlightTerms } = payload; + path: logEntriesV1.LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, + }) + .addVersion( + { + version: '1', + validate: { request: { body: escapeHatch } }, + }, + async (requestContext, request, response) => { + const payload = pipe( + logEntriesV1.logEntriesSummaryHighlightsRequestRT.decode(request.body), + fold(throwErrors(Boom.badRequest), identity) + ); + const { logView, startTimestamp, endTimestamp, bucketSize, query, highlightTerms } = + payload; - const bucketsPerHighlightTerm = await logEntries.getLogSummaryHighlightBucketsBetween( - requestContext, - logView, - startTimestamp, - endTimestamp, - bucketSize, - highlightTerms, - parseFilterQuery(query) - ); + const bucketsPerHighlightTerm = await logEntries.getLogSummaryHighlightBucketsBetween( + requestContext, + logView, + startTimestamp, + endTimestamp, + bucketSize, + highlightTerms, + parseFilterQuery(query) + ); - return response.ok({ - body: logEntriesSummaryHighlightsResponseRT.encode({ - data: bucketsPerHighlightTerm.map((buckets) => ({ - start: startTimestamp, - end: endTimestamp, - buckets, - })), - }), - }); - } - ); + return response.ok({ + body: logEntriesV1.logEntriesSummaryHighlightsResponseRT.encode({ + data: bucketsPerHighlightTerm.map((buckets) => ({ + start: startTimestamp, + end: endTimestamp, + buckets, + })), + }), + }); + } + ); }; diff --git a/x-pack/plugins/infra/server/routes/log_views/get_log_view.ts b/x-pack/plugins/infra/server/routes/log_views/get_log_view.ts index 3f2bb8ec14427..0c3cb7cbac2af 100644 --- a/x-pack/plugins/infra/server/routes/log_views/get_log_view.ts +++ b/x-pack/plugins/infra/server/routes/log_views/get_log_view.ts @@ -5,11 +5,8 @@ * 2.0. */ -import { - getLogViewRequestParamsRT, - getLogViewResponsePayloadRT, - LOG_VIEW_URL, -} from '../../../common/http_api/log_views'; +import { logViewsV1 } from '../../../common/http_api'; +import { LOG_VIEW_URL } from '../../../common/http_api/log_views'; import { createValidationFunction } from '../../../common/runtime_types'; import type { KibanaFramework } from '../../lib/adapters/framework/kibana_framework_adapter'; import type { InfraPluginStartServicesAccessor } from '../../types'; @@ -21,35 +18,42 @@ export const initGetLogViewRoute = ({ framework: KibanaFramework; getStartServices: InfraPluginStartServicesAccessor; }) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'get', path: LOG_VIEW_URL, - validate: { - params: createValidationFunction(getLogViewRequestParamsRT), + }) + .addVersion( + { + version: '1', + validate: { + request: { + params: createValidationFunction(logViewsV1.getLogViewRequestParamsRT), + }, + }, }, - }, - async (_requestContext, request, response) => { - const { logViewId } = request.params; - const { logViews } = (await getStartServices())[2]; - const logViewsClient = logViews.getScopedClient(request); + async (_requestContext, request, response) => { + const { logViewId } = request.params; + const { logViews } = (await getStartServices())[2]; + const logViewsClient = logViews.getScopedClient(request); - try { - const logView = await logViewsClient.getLogView(logViewId); + try { + const logView = await logViewsClient.getLogView(logViewId); - return response.ok({ - body: getLogViewResponsePayloadRT.encode({ - data: logView, - }), - }); - } catch (error) { - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); + return response.ok({ + body: logViewsV1.getLogViewResponsePayloadRT.encode({ + data: logView, + }), + }); + } catch (error) { + return response.customError({ + statusCode: error.statusCode ?? 500, + body: { + message: error.message ?? 'An unexpected error occurred', + }, + }); + } } - } - ); + ); }; diff --git a/x-pack/plugins/infra/server/routes/log_views/put_log_view.ts b/x-pack/plugins/infra/server/routes/log_views/put_log_view.ts index cf6eb74347310..310960156abfc 100644 --- a/x-pack/plugins/infra/server/routes/log_views/put_log_view.ts +++ b/x-pack/plugins/infra/server/routes/log_views/put_log_view.ts @@ -5,12 +5,8 @@ * 2.0. */ -import { - LOG_VIEW_URL, - putLogViewRequestParamsRT, - putLogViewRequestPayloadRT, - putLogViewResponsePayloadRT, -} from '../../../common/http_api/log_views'; +import { logViewsV1 } from '../../../common/http_api'; +import { LOG_VIEW_URL } from '../../../common/http_api/log_views'; import { createValidationFunction } from '../../../common/runtime_types'; import type { KibanaFramework } from '../../lib/adapters/framework/kibana_framework_adapter'; import type { InfraPluginStartServicesAccessor } from '../../types'; @@ -22,37 +18,44 @@ export const initPutLogViewRoute = ({ framework: KibanaFramework; getStartServices: InfraPluginStartServicesAccessor; }) => { - framework.registerRoute( - { + framework + .registerVersionedRoute({ + access: 'internal', method: 'put', path: LOG_VIEW_URL, - validate: { - params: createValidationFunction(putLogViewRequestParamsRT), - body: createValidationFunction(putLogViewRequestPayloadRT), + }) + .addVersion( + { + version: '1', + validate: { + request: { + params: createValidationFunction(logViewsV1.putLogViewRequestParamsRT), + body: createValidationFunction(logViewsV1.putLogViewRequestPayloadRT), + }, + }, }, - }, - async (_requestContext, request, response) => { - const { logViewId } = request.params; - const { attributes } = request.body; - const { logViews } = (await getStartServices())[2]; - const logViewsClient = logViews.getScopedClient(request); + async (_requestContext, request, response) => { + const { logViewId } = request.params; + const { attributes } = request.body; + const { logViews } = (await getStartServices())[2]; + const logViewsClient = logViews.getScopedClient(request); - try { - const logView = await logViewsClient.putLogView(logViewId, attributes); + try { + const logView = await logViewsClient.putLogView(logViewId, attributes); - return response.ok({ - body: putLogViewResponsePayloadRT.encode({ - data: logView, - }), - }); - } catch (error) { - return response.customError({ - statusCode: error.statusCode ?? 500, - body: { - message: error.message ?? 'An unexpected error occurred', - }, - }); + return response.ok({ + body: logViewsV1.putLogViewResponsePayloadRT.encode({ + data: logView, + }), + }); + } catch (error) { + return response.customError({ + statusCode: error.statusCode ?? 500, + body: { + message: error.message ?? 'An unexpected error occurred', + }, + }); + } } - } - ); + ); }; diff --git a/x-pack/plugins/infra/tsconfig.json b/x-pack/plugins/infra/tsconfig.json index 2f86464b357fb..73caa71b4665f 100644 --- a/x-pack/plugins/infra/tsconfig.json +++ b/x-pack/plugins/infra/tsconfig.json @@ -64,6 +64,7 @@ "@kbn/observability-shared-plugin", "@kbn/ui-theme", "@kbn/ml-anomaly-utils", + "@kbn/core-http-server", ], "exclude": ["target/**/*"] } diff --git a/x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts b/x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts index f924966146755..1019b768aa369 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts @@ -10,7 +10,7 @@ import { LOG_ANALYSIS_VALIDATE_DATASETS_PATH, validateLogEntryDatasetsRequestPayloadRT, validateLogEntryDatasetsResponsePayloadRT, -} from '@kbn/infra-plugin/common/http_api/log_analysis/validation/datasets'; +} from '@kbn/infra-plugin/common/http_api'; import { decodeOrThrow } from '@kbn/infra-plugin/common/runtime_types'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -31,6 +31,7 @@ export default function ({ getService }: FtrProviderContext) { .post(LOG_ANALYSIS_VALIDATE_DATASETS_PATH) .set({ 'kbn-xsrf': 'some-xsrf-token', + 'Elastic-Api-Version': '1', }) .send( validateLogEntryDatasetsRequestPayloadRT.encode({ 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 2e328e91f8c25..6efb17e1571cc 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 @@ -32,6 +32,7 @@ const KEY_AFTER_END = { const COMMON_HEADERS = { 'kbn-xsrf': 'some-xsrf-token', + 'Elastic-Api-Version': '1', }; export default function ({ getService }: FtrProviderContext) { 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 3ccfc4c267c7b..9c7c5548fcdbc 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 @@ -19,7 +19,7 @@ import { LOG_ENTRIES_SUMMARY_PATH, logEntriesSummaryRequestRT, logEntriesSummaryResponseRT, -} from '@kbn/infra-plugin/common/http_api/log_entries'; +} from '@kbn/infra-plugin/common/http_api'; import { FtrProviderContext } from '../../ftr_provider_context'; @@ -28,6 +28,7 @@ const LATEST_TIME_WITH_DATA = new Date('2018-10-17T19:57:21.611Z').valueOf(); const COMMON_HEADERS = { 'kbn-xsrf': 'some-xsrf-token', + 'Elastic-Api-Version': '1', }; export default function ({ getService }: FtrProviderContext) { diff --git a/x-pack/test/common/services/infra_log_views.ts b/x-pack/test/common/services/infra_log_views.ts index 94f7efef7992d..a6a87da67e1aa 100644 --- a/x-pack/test/common/services/infra_log_views.ts +++ b/x-pack/test/common/services/infra_log_views.ts @@ -7,11 +7,11 @@ import { getLogViewResponsePayloadRT, - getLogViewUrl, PutLogViewRequestPayload, putLogViewRequestPayloadRT, putLogViewResponsePayloadRT, -} from '@kbn/infra-plugin/common/http_api/log_views'; +} from '@kbn/infra-plugin/common/http_api'; +import { getLogViewUrl } from '@kbn/infra-plugin/common/http_api/log_views'; import { decodeOrThrow } from '@kbn/infra-plugin/common/runtime_types'; import { FtrProviderContext } from '../ftr_provider_context'; @@ -24,6 +24,7 @@ export function InfraLogViewsServiceProvider({ getService }: FtrProviderContext) .get(getLogViewUrl(logViewId)) .set({ 'kbn-xsrf': 'some-xsrf-token', + 'Elastic-Api-Version': '1', }) .send(); @@ -40,6 +41,7 @@ export function InfraLogViewsServiceProvider({ getService }: FtrProviderContext) .put(getLogViewUrl(logViewId)) .set({ 'kbn-xsrf': 'some-xsrf-token', + 'Elastic-Api-Version': '1', }) .send(putLogViewRequestPayloadRT.encode(payload)); diff --git a/x-pack/test/functional/apps/infra/hosts_view.ts b/x-pack/test/functional/apps/infra/hosts_view.ts index 796e0ac4f881b..e01b9939ecbf2 100644 --- a/x-pack/test/functional/apps/infra/hosts_view.ts +++ b/x-pack/test/functional/apps/infra/hosts_view.ts @@ -23,7 +23,6 @@ const timepickerFormat = 'MMM D, YYYY @ HH:mm:ss.SSS'; const tableEntries = [ { title: 'demo-stack-apache-01', - os: '-', cpuUsage: '1.2%', diskLatency: '1.6 ms', rx: '0 bit/s', @@ -33,7 +32,6 @@ const tableEntries = [ }, { title: 'demo-stack-client-01', - os: '-', cpuUsage: '0.5%', diskLatency: '8.7 ms', rx: '0 bit/s', @@ -43,7 +41,6 @@ const tableEntries = [ }, { title: 'demo-stack-haproxy-01', - os: '-', cpuUsage: '0.8%', diskLatency: '7 ms', rx: '0 bit/s', @@ -53,7 +50,6 @@ const tableEntries = [ }, { title: 'demo-stack-mysql-01', - os: '-', cpuUsage: '0.9%', diskLatency: '6.6 ms', rx: '0 bit/s', @@ -63,7 +59,6 @@ const tableEntries = [ }, { title: 'demo-stack-nginx-01', - os: '-', cpuUsage: '0.8%', diskLatency: '5.7 ms', rx: '0 bit/s', @@ -73,7 +68,6 @@ const tableEntries = [ }, { title: 'demo-stack-redis-01', - os: '-', cpuUsage: '0.8%', diskLatency: '6.3 ms', rx: '0 bit/s', diff --git a/x-pack/test/functional/page_objects/infra_hosts_view.ts b/x-pack/test/functional/page_objects/infra_hosts_view.ts index b4463b4d60541..cb137b404d2ac 100644 --- a/x-pack/test/functional/page_objects/infra_hosts_view.ts +++ b/x-pack/test/functional/page_objects/infra_hosts_view.ts @@ -90,11 +90,11 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) { const cells = await row.findAllByCssSelector('[data-test-subj*="hostsView-tableRow-"]'); // Retrieve content for each cell - const [title, os, cpuUsage, diskLatency, rx, tx, memoryTotal, memory] = await Promise.all( + const [title, cpuUsage, diskLatency, rx, tx, memoryTotal, memory] = await Promise.all( cells.map((cell) => this.getHostsCellContent(cell)) ); - return { title, os, cpuUsage, diskLatency, rx, tx, memoryTotal, memory }; + return { title, cpuUsage, diskLatency, rx, tx, memoryTotal, memory }; }, async getHostsCellContent(cell: WebElementWrapper) { @@ -285,7 +285,7 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) { // Sorting getDiskLatencyHeader() { - return testSubjects.find('tableHeaderCell_diskLatency_4'); + return testSubjects.find('tableHeaderCell_diskLatency_3'); }, getTitleHeader() { diff --git a/x-pack/test/session_view/basic/tests/get_total_io_bytes_route.ts b/x-pack/test/session_view/basic/tests/get_total_io_bytes_route.ts index ecc09ab719740..37dcc28b67aad 100644 --- a/x-pack/test/session_view/basic/tests/get_total_io_bytes_route.ts +++ b/x-pack/test/session_view/basic/tests/get_total_io_bytes_route.ts @@ -6,7 +6,10 @@ */ import expect from '@kbn/expect'; -import { GET_TOTAL_IO_BYTES_ROUTE } from '@kbn/session-view-plugin/common/constants'; +import { + CURRENT_API_VERSION, + GET_TOTAL_IO_BYTES_ROUTE, +} from '@kbn/session-view-plugin/common/constants'; import { FtrProviderContext } from '../../common/ftr_provider_context'; const MOCK_INDEX = 'logs-endpoint.events.process*'; @@ -20,6 +23,13 @@ export default function getTotalIOBytesTests({ getService }: FtrProviderContext) const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); + function getTestRoute() { + return supertest + .get(GET_TOTAL_IO_BYTES_ROUTE) + .set('kbn-xsrf', 'foo') + .set('Elastic-Api-Version', CURRENT_API_VERSION); + } + describe(`Session view - ${GET_TOTAL_IO_BYTES_ROUTE} - with a basic license`, () => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/session_view/process_events'); @@ -32,7 +42,7 @@ export default function getTotalIOBytesTests({ getService }: FtrProviderContext) }); it(`${GET_TOTAL_IO_BYTES_ROUTE} returns a page of IO events`, async () => { - const response = await supertest.get(GET_TOTAL_IO_BYTES_ROUTE).set('kbn-xsrf', 'foo').query({ + const response = await getTestRoute().query({ index: MOCK_INDEX, sessionEntityId: MOCK_SESSION_ENTITY_ID, sessionStartTime: MOCK_SESSION_START_TIME, @@ -42,7 +52,7 @@ export default function getTotalIOBytesTests({ getService }: FtrProviderContext) }); it(`${GET_TOTAL_IO_BYTES_ROUTE} returns 0 for invalid query`, async () => { - const response = await supertest.get(GET_TOTAL_IO_BYTES_ROUTE).set('kbn-xsrf', 'foo').query({ + const response = await getTestRoute().query({ index: MOCK_INDEX, sessionStartTime: MOCK_SESSION_START_TIME, sessionEntityId: 'xyz', diff --git a/x-pack/test/session_view/basic/tests/process_events_route.ts b/x-pack/test/session_view/basic/tests/process_events_route.ts index 7705ae145f697..9a8f5091a2b0a 100644 --- a/x-pack/test/session_view/basic/tests/process_events_route.ts +++ b/x-pack/test/session_view/basic/tests/process_events_route.ts @@ -54,8 +54,7 @@ export default function processEventsTests({ getService }: FtrProviderContext) { .set('Elastic-Api-Version', CURRENT_API_VERSION); } - // Failing: See https://github.com/elastic/kibana/issues/159275 - describe.skip(`Session view - ${PROCESS_EVENTS_ROUTE} - with a basic license`, () => { + describe(`Session view - ${PROCESS_EVENTS_ROUTE} - with a basic license`, () => { describe(`using typical process event data`, () => { before(async () => { await esArchiver.load('x-pack/test/functional/es_archives/session_view/process_events'); @@ -144,6 +143,7 @@ export default function processEventsTests({ getService }: FtrProviderContext) { .get(`${PROCESS_EVENTS_ROUTE}`) .auth(username, password) .set('kbn-xsrf', 'true') + .set('Elastic-Api-Version', CURRENT_API_VERSION) .query({ index: MOCK_INDEX, sessionEntityId: MOCK_SESSION_ENTITY_ID, @@ -167,6 +167,7 @@ export default function processEventsTests({ getService }: FtrProviderContext) { .get(`${PROCESS_EVENTS_ROUTE}`) .auth(username, password) .set('kbn-xsrf', 'true') + .set('Elastic-Api-Version', CURRENT_API_VERSION) .query({ index: MOCK_INDEX, sessionEntityId: MOCK_SESSION_ENTITY_ID,