From a79d2011cc6f018aa52607d77081873b1e66eaeb Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Fri, 26 Apr 2024 23:05:51 +0200 Subject: [PATCH] [ML] AIOps: Remove v1 of log rate analysis API. (#181803) ## Summary Follow up to #170274. Part of #181111 and #181603. We had v1 and v2 of the log rate analysis API for a while now (Nov 23). Originally we did this to practice API versioning for serverless. Enough time has passed so we can remove v1 which this PR does. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../ml/aiops_log_rate_analysis/api/actions.ts | 115 +++++------------- .../ml/aiops_log_rate_analysis/api/schema.ts | 9 +- .../aiops_log_rate_analysis/api/schema_v1.ts | 42 ------- .../api/stream_reducer.test.ts | 37 +++--- .../api/stream_reducer.ts | 4 +- .../analysis_handlers/grouping_handler.ts | 27 ++-- .../analysis_handlers/histogram_handler.ts | 52 +++----- .../significant_items_handler.ts | 45 ++----- .../analysis_handlers/top_items_handler.ts | 45 ++----- .../routes/log_rate_analysis/define_route.ts | 12 -- .../response_stream_factory.ts | 6 +- .../stream_end_with_updated_loading_state.ts | 5 +- .../stream_push_error.ts | 5 +- .../stream_push_ping_with_timeout.ts | 5 +- .../aiops/log_rate_analysis_full_analysis.ts | 8 +- .../aiops/log_rate_analysis_groups_only.ts | 33 ++--- .../api_integration/apis/aiops/test_data.ts | 2 +- .../apis/aiops/test_helpers.ts | 34 ++---- .../apis/aiops/permissions.ts | 2 +- 19 files changed, 129 insertions(+), 359 deletions(-) delete mode 100644 x-pack/packages/ml/aiops_log_rate_analysis/api/schema_v1.ts diff --git a/x-pack/packages/ml/aiops_log_rate_analysis/api/actions.ts b/x-pack/packages/ml/aiops_log_rate_analysis/api/actions.ts index 2348b32c32f8dc..4c17f28c932b3f 100644 --- a/x-pack/packages/ml/aiops_log_rate_analysis/api/actions.ts +++ b/x-pack/packages/ml/aiops_log_rate_analysis/api/actions.ts @@ -12,8 +12,6 @@ import type { SignificantItemGroupHistogram, } from '@kbn/ml-agg-utils'; -import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from './schema'; - export const API_ACTION_NAME = { /** @since API v2 */ ADD_SIGNIFICANT_ITEMS: 'add_significant_items', @@ -23,13 +21,6 @@ export const API_ACTION_NAME = { ADD_SIGNIFICANT_ITEMS_GROUP: 'add_significant_items_group', /** @since API v2 */ ADD_SIGNIFICANT_ITEMS_GROUP_HISTOGRAM: 'add_significant_items_group_histogram', - /** @deprecated since API v2 */ - ADD_SIGNIFICANT_TERMS: 'add_significant_terms', - /** @deprecated since API v2 */ - ADD_SIGNIFICANT_TERMS_HISTOGRAM: 'add_significant_terms_histogram', - /** @deprecated since API v2 */ - ADD_SIGNIFICANT_TERMS_GROUP: 'add_significant_terms_group', - /** @deprecated since API v2 */ ADD_SIGNIFICANT_TERMS_GROUP_HISTOGRAM: 'add_significant_terms_group_histogram', ADD_ERROR: 'add_error', PING: 'ping', @@ -41,108 +32,60 @@ export const API_ACTION_NAME = { } as const; export type ApiActionName = typeof API_ACTION_NAME[keyof typeof API_ACTION_NAME]; -interface ApiActionAddSignificantItems { - type: T extends '1' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_TERMS - : T extends '2' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS - : never; +interface ApiActionAddSignificantItems { + type: typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS; payload: SignificantItem[]; } -export function addSignificantItemsAction( - payload: ApiActionAddSignificantItems['payload'], - version: T -): ApiActionAddSignificantItems { - if (version === '1') { - return { - type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS, - payload, - } as ApiActionAddSignificantItems; - } - +export function addSignificantItemsAction( + payload: ApiActionAddSignificantItems['payload'] +): ApiActionAddSignificantItems { return { type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS, payload, - } as ApiActionAddSignificantItems; + }; } -interface ApiActionAddSignificantItemsHistogram { - type: T extends '1' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_HISTOGRAM - : T extends '2' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_HISTOGRAM - : never; +interface ApiActionAddSignificantItemsHistogram { + type: typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_HISTOGRAM; payload: SignificantItemHistogram[]; } -export function addSignificantItemsHistogramAction( - payload: ApiActionAddSignificantItemsHistogram['payload'], - version: T -): ApiActionAddSignificantItemsHistogram { - if (version === '1') { - return { - type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_HISTOGRAM, - payload, - } as ApiActionAddSignificantItemsHistogram; - } - +export function addSignificantItemsHistogramAction( + payload: ApiActionAddSignificantItemsHistogram['payload'] +): ApiActionAddSignificantItemsHistogram { return { type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_HISTOGRAM, payload, - } as ApiActionAddSignificantItemsHistogram; + }; } -interface ApiActionAddSignificantItemsGroup { - type: T extends '1' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP - : T extends '2' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP - : never; +interface ApiActionAddSignificantItemsGroup { + type: typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP; payload: SignificantItemGroup[]; } -export function addSignificantItemsGroupAction( - payload: ApiActionAddSignificantItemsGroup['payload'], - version: T -): ApiActionAddSignificantItemsGroup { - if (version === '1') { - return { - type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP, - payload, - } as ApiActionAddSignificantItemsGroup; - } - +export function addSignificantItemsGroupAction( + payload: ApiActionAddSignificantItemsGroup['payload'] +): ApiActionAddSignificantItemsGroup { return { type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP, payload, - } as ApiActionAddSignificantItemsGroup; + }; } -interface ApiActionAddSignificantItemsGroupHistogram { - type: T extends '1' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP_HISTOGRAM - : T extends '2' - ? typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP_HISTOGRAM - : never; +interface ApiActionAddSignificantItemsGroupHistogram { + type: typeof API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP_HISTOGRAM; payload: SignificantItemGroupHistogram[]; } -export function addSignificantItemsGroupHistogramAction( - payload: ApiActionAddSignificantItemsGroupHistogram['payload'], - version: T -): ApiActionAddSignificantItemsGroupHistogram { - if (version === '1') { - return { - type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP_HISTOGRAM, - payload, - } as ApiActionAddSignificantItemsGroupHistogram; - } - +export function addSignificantItemsGroupHistogramAction( + payload: ApiActionAddSignificantItemsGroupHistogram['payload'] +): ApiActionAddSignificantItemsGroupHistogram { return { type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP_HISTOGRAM, payload, - } as ApiActionAddSignificantItemsGroupHistogram; + }; } interface ApiActionAddError { @@ -225,11 +168,11 @@ export function setZeroDocsFallback( }; } -export type AiopsLogRateAnalysisApiAction = - | ApiActionAddSignificantItems - | ApiActionAddSignificantItemsGroup - | ApiActionAddSignificantItemsHistogram - | ApiActionAddSignificantItemsGroupHistogram +export type AiopsLogRateAnalysisApiAction = + | ApiActionAddSignificantItems + | ApiActionAddSignificantItemsGroup + | ApiActionAddSignificantItemsHistogram + | ApiActionAddSignificantItemsGroupHistogram | ApiActionAddError | ApiActionPing | ApiActionResetAll diff --git a/x-pack/packages/ml/aiops_log_rate_analysis/api/schema.ts b/x-pack/packages/ml/aiops_log_rate_analysis/api/schema.ts index a7fbcfd303b553..fae5d17c67fdba 100644 --- a/x-pack/packages/ml/aiops_log_rate_analysis/api/schema.ts +++ b/x-pack/packages/ml/aiops_log_rate_analysis/api/schema.ts @@ -5,17 +5,12 @@ * 2.0. */ -import type { AiopsLogRateAnalysisSchemaV1 } from './schema_v1'; import type { AiopsLogRateAnalysisSchemaV2 } from './schema_v2'; -export type AiopsLogRateAnalysisApiVersion = '1' | '2'; +export type AiopsLogRateAnalysisApiVersion = '2'; const LATEST_API_VERSION: AiopsLogRateAnalysisApiVersion = '2'; export type AiopsLogRateAnalysisSchema< T extends AiopsLogRateAnalysisApiVersion = typeof LATEST_API_VERSION -> = T extends '1' - ? AiopsLogRateAnalysisSchemaV1 - : T extends '2' - ? AiopsLogRateAnalysisSchemaV2 - : never; +> = T extends '2' ? AiopsLogRateAnalysisSchemaV2 : never; diff --git a/x-pack/packages/ml/aiops_log_rate_analysis/api/schema_v1.ts b/x-pack/packages/ml/aiops_log_rate_analysis/api/schema_v1.ts deleted file mode 100644 index de059bca1235ee..00000000000000 --- a/x-pack/packages/ml/aiops_log_rate_analysis/api/schema_v1.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { TypeOf } from '@kbn/config-schema'; -import { schema } from '@kbn/config-schema'; - -export const aiopsLogRateAnalysisSchemaV1 = schema.object({ - start: schema.number(), - end: schema.number(), - searchQuery: schema.string(), - timeFieldName: schema.string(), - includeFrozen: schema.maybe(schema.boolean()), - grouping: schema.maybe(schema.boolean()), - /** Analysis selection time ranges */ - baselineMin: schema.number(), - baselineMax: schema.number(), - deviationMin: schema.number(), - deviationMax: schema.number(), - /** The index to query for log rate analysis */ - index: schema.string(), - /** Settings to override headers derived compression and flush fix */ - compressResponse: schema.maybe(schema.boolean()), - flushFix: schema.maybe(schema.boolean()), - /** Overrides to skip steps of the analysis with existing data */ - overrides: schema.maybe( - schema.object({ - loaded: schema.maybe(schema.number()), - remainingFieldCandidates: schema.maybe(schema.arrayOf(schema.string())), - // TODO Improve schema - significantTerms: schema.maybe(schema.arrayOf(schema.any())), - regroupOnly: schema.maybe(schema.boolean()), - }) - ), - /** Probability used for the random sampler aggregations */ - sampleProbability: schema.maybe(schema.number()), -}); - -export type AiopsLogRateAnalysisSchemaV1 = TypeOf; diff --git a/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.test.ts b/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.test.ts index bd318e6de0875b..ea1c33e569fce7 100644 --- a/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.test.ts +++ b/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.test.ts @@ -38,24 +38,21 @@ describe('streamReducer', () => { it('adds significant item, then resets all state again', () => { const state1 = streamReducer( initialState, - addSignificantItemsAction( - [ - { - key: 'the-field-name:the-field-value', - type: 'keyword', - fieldName: 'the-field-name', - fieldValue: 'the-field-value', - doc_count: 10, - bg_count: 100, - total_doc_count: 1000, - total_bg_count: 10000, - score: 0.1, - pValue: 0.01, - normalizedScore: 0.123, - }, - ], - '2' - ) + addSignificantItemsAction([ + { + key: 'the-field-name:the-field-value', + type: 'keyword', + fieldName: 'the-field-name', + fieldValue: 'the-field-value', + doc_count: 10, + bg_count: 100, + total_doc_count: 1000, + total_bg_count: 10000, + score: 0.1, + pValue: 0.01, + normalizedScore: 0.123, + }, + ]) ); expect(state1.significantItems).toHaveLength(1); @@ -66,14 +63,14 @@ describe('streamReducer', () => { }); it('adds significant items and groups, then resets groups only', () => { - const state1 = streamReducer(initialState, addSignificantItemsAction(significantTerms, '2')); + const state1 = streamReducer(initialState, addSignificantItemsAction(significantTerms)); expect(state1.significantItems).toHaveLength(4); expect(state1.significantItemsGroups).toHaveLength(0); const state2 = streamReducer( state1, - addSignificantItemsGroupAction(finalSignificantItemGroups, '2') + addSignificantItemsGroupAction(finalSignificantItemGroups) ); expect(state2.significantItems).toHaveLength(4); diff --git a/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.ts b/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.ts index 2e3117b4326e8b..ca6148c133ccad 100644 --- a/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.ts +++ b/x-pack/packages/ml/aiops_log_rate_analysis/api/stream_reducer.ts @@ -10,7 +10,7 @@ import type { SignificantItem, SignificantItemGroup } from '@kbn/ml-agg-utils'; import type { AiopsLogRateAnalysisApiAction } from './actions'; import { API_ACTION_NAME } from './actions'; -interface StreamState { +export interface StreamState { ccsWarning: boolean; significantItems: SignificantItem[]; significantItemsGroups: SignificantItemGroup[]; @@ -34,7 +34,7 @@ export const initialState: StreamState = { export function streamReducer( state: StreamState, - action: AiopsLogRateAnalysisApiAction<'2'> | Array> + action: AiopsLogRateAnalysisApiAction | AiopsLogRateAnalysisApiAction[] ): StreamState { if (Array.isArray(action)) { return action.reduce(streamReducer, state); diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/grouping_handler.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/grouping_handler.ts index 233aa62985befc..5266858e6d3bc2 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/grouping_handler.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/grouping_handler.ts @@ -46,7 +46,6 @@ export const groupingHandlerFactory = logDebugMessage, logger, stateHandler, - version, }: ResponseStreamFetchOptions) => async ( significantCategories: SignificantItem[], @@ -134,7 +133,7 @@ export const groupingHandlerFactory = const maxItems = Math.max(...significantItemGroups.map((g) => g.group.length)); if (maxItems > 1) { - responseStream.push(addSignificantItemsGroupAction(significantItemGroups, version)); + responseStream.push(addSignificantItemsGroupAction(significantItemGroups)); } stateHandler.loaded(PROGRESS_STEP_GROUPING, false); @@ -203,15 +202,6 @@ export const groupingHandlerFactory = doc_count: 0, }; - if (version === '1') { - return { - key: o.key, - key_as_string: o.key_as_string ?? '', - doc_count_significant_term: current.doc_count, - doc_count_overall: Math.max(0, o.doc_count - current.doc_count), - }; - } - return { key: o.key, key_as_string: o.key_as_string ?? '', @@ -221,15 +211,12 @@ export const groupingHandlerFactory = }) ?? []; responseStream.push( - addSignificantItemsGroupHistogramAction( - [ - { - id: cpg.id, - histogram, - }, - ], - version - ) + addSignificantItemsGroupHistogramAction([ + { + id: cpg.id, + histogram, + }, + ]) ); } }, MAX_CONCURRENT_QUERIES); diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/histogram_handler.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/histogram_handler.ts index 077c2162a30fd6..1a61edde6864bc 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/histogram_handler.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/histogram_handler.ts @@ -41,7 +41,6 @@ export const histogramHandlerFactory = requestBody, responseStream, stateHandler, - version, }: ResponseStreamFetchOptions) => async ( fieldValuePairsCount: number, @@ -132,14 +131,6 @@ export const histogramHandlerFactory = ) ?? { doc_count: 0, }; - if (version === '1') { - return { - key: o.key, - key_as_string: o.key_as_string ?? '', - doc_count_significant_term: current.doc_count, - doc_count_overall: Math.max(0, o.doc_count - current.doc_count), - }; - } return { key: o.key, @@ -154,16 +145,13 @@ export const histogramHandlerFactory = stateHandler.loaded((1 / fieldValuePairsCount) * PROGRESS_STEP_HISTOGRAMS, false); pushHistogramDataLoadingState(); responseStream.push( - addSignificantItemsHistogramAction( - [ - { - fieldName, - fieldValue, - histogram, - }, - ], - version - ) + addSignificantItemsHistogramAction([ + { + fieldName, + fieldValue, + histogram, + }, + ]) ); } }, MAX_CONCURRENT_QUERIES); @@ -237,15 +225,6 @@ export const histogramHandlerFactory = doc_count: 0, }; - if (version === '1') { - return { - key: o.key, - key_as_string: o.key_as_string ?? '', - doc_count_significant_term: current.doc_count, - doc_count_overall: Math.max(0, o.doc_count - current.doc_count), - }; - } - return { key: o.key, key_as_string: o.key_as_string ?? '', @@ -259,16 +238,13 @@ export const histogramHandlerFactory = stateHandler.loaded((1 / fieldValuePairsCount) * PROGRESS_STEP_HISTOGRAMS, false); pushHistogramDataLoadingState(); responseStream.push( - addSignificantItemsHistogramAction( - [ - { - fieldName, - fieldValue, - histogram, - }, - ], - version - ) + addSignificantItemsHistogramAction([ + { + fieldName, + fieldValue, + histogram, + }, + ]) ); } } diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/significant_items_handler.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/significant_items_handler.ts index 6fb9f97cde4eff..aa2aa1944e64a5 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/significant_items_handler.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/significant_items_handler.ts @@ -38,7 +38,6 @@ export const significantItemsHandlerFactory = requestBody, responseStream, stateHandler, - version, }: ResponseStreamFetchOptions) => async ({ fieldCandidates, @@ -54,21 +53,11 @@ export const significantItemsHandlerFactory = const significantCategories: SignificantItem[] = []; - if (version === '1') { - significantCategories.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'1'>).overrides?.significantTerms?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN - ) ?? []) - ); - } - - if (version === '2') { - significantCategories.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN - ) ?? []) - ); - } + significantCategories.push( + ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( + (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN + ) ?? []) + ); // Get significant categories of text fields if (textFieldCandidates.length > 0) { @@ -85,27 +74,17 @@ export const significantItemsHandlerFactory = ); if (significantCategories.length > 0) { - responseStream.push(addSignificantItemsAction(significantCategories, version)); + responseStream.push(addSignificantItemsAction(significantCategories)); } } const significantTerms: SignificantItem[] = []; - if (version === '1') { - significantTerms.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'1'>).overrides?.significantTerms?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD - ) ?? []) - ); - } - - if (version === '2') { - significantTerms.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD - ) ?? []) - ); - } + significantTerms.push( + ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( + (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD + ) ?? []) + ); const fieldsToSample = new Set(); @@ -157,7 +136,7 @@ export const significantItemsHandlerFactory = }); significantTerms.push(...pValues); - responseStream.push(addSignificantItemsAction(pValues, version)); + responseStream.push(addSignificantItemsAction(pValues)); } responseStream.push( diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/top_items_handler.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/top_items_handler.ts index cc15c8b6169957..f29b372116f48f 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/top_items_handler.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/analysis_handlers/top_items_handler.ts @@ -39,7 +39,6 @@ export const topItemsHandlerFactory = requestBody, responseStream, stateHandler, - version, }: ResponseStreamFetchOptions) => async ({ fieldCandidates, @@ -55,21 +54,11 @@ export const topItemsHandlerFactory = const topCategories: SignificantItem[] = []; - if (version === '1') { - topCategories.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'1'>).overrides?.significantTerms?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN - ) ?? []) - ); - } - - if (version === '2') { - topCategories.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN - ) ?? []) - ); - } + topCategories.push( + ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( + (d) => d.type === SIGNIFICANT_ITEM_TYPE.LOG_PATTERN + ) ?? []) + ); // Get categories of text fields if (textFieldCandidates.length > 0) { @@ -86,27 +75,17 @@ export const topItemsHandlerFactory = ); if (topCategories.length > 0) { - responseStream.push(addSignificantItemsAction(topCategories, version)); + responseStream.push(addSignificantItemsAction(topCategories)); } } const topTerms: SignificantItem[] = []; - if (version === '1') { - topTerms.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'1'>).overrides?.significantTerms?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD - ) ?? []) - ); - } - - if (version === '2') { - topTerms.push( - ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( - (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD - ) ?? []) - ); - } + topTerms.push( + ...((requestBody as AiopsLogRateAnalysisSchema<'2'>).overrides?.significantItems?.filter( + (d) => d.type === SIGNIFICANT_ITEM_TYPE.KEYWORD + ) ?? []) + ); const fieldsToSample = new Set(); @@ -158,7 +137,7 @@ export const topItemsHandlerFactory = }); topTerms.push(...fetchedTopTerms); - responseStream.push(addSignificantItemsAction(fetchedTopTerms, version)); + responseStream.push(addSignificantItemsAction(fetchedTopTerms)); } responseStream.push( diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/define_route.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/define_route.ts index de9df4aa5bdab2..77fedfafb18966 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/define_route.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/define_route.ts @@ -9,7 +9,6 @@ import type { CoreStart, IRouter } from '@kbn/core/server'; import type { Logger } from '@kbn/logging'; import type { DataRequestHandlerContext } from '@kbn/data-plugin/server'; import type { UsageCounter } from '@kbn/usage-collection-plugin/server'; -import { aiopsLogRateAnalysisSchemaV1 } from '@kbn/aiops-log-rate-analysis/api/schema_v1'; import { aiopsLogRateAnalysisSchemaV2 } from '@kbn/aiops-log-rate-analysis/api/schema_v2'; import { AIOPS_API_ENDPOINT } from '@kbn/aiops-common/constants'; @@ -35,17 +34,6 @@ export const defineRoute = ( path: AIOPS_API_ENDPOINT.LOG_RATE_ANALYSIS, access: 'internal', }) - .addVersion( - { - version: '1', - validate: { - request: { - body: aiopsLogRateAnalysisSchemaV1, - }, - }, - }, - routeHandlerFactory('1', license, logger, coreStart, usageCounter) - ) .addVersion( { version: '2', diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_factory.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_factory.ts index b676836adfa968..57e97ade7fb126 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_factory.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_factory.ts @@ -56,7 +56,7 @@ export interface ResponseStreamFetchOptions extends Respon responseStream: { end: () => void; endWithUpdatedLoadingState: () => void; - push: StreamFactoryReturnType>['push']; + push: StreamFactoryReturnType['push']; pushPingWithTimeout: () => void; pushError: (msg: string) => void; }; @@ -97,14 +97,14 @@ export const responseStreamFactory = (options: ResponseStr end: streamEnd, push, responseWithHeaders, - } = streamFactory>( + } = streamFactory( headers, logger, requestBody.compressResponse, requestBody.flushFix ); - const pushPingWithTimeout = streamPushPingWithTimeoutFactory(state, push, logDebugMessage); + const pushPingWithTimeout = streamPushPingWithTimeoutFactory(state, push, logDebugMessage); const end = streamEndFactory(state, streamEnd, logDebugMessage); const endWithUpdatedLoadingState = streamEndWithUpdatedLoadingStateFactory(end, push); const pushError = streamPushErrorFactory(push, logDebugMessage); diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_end_with_updated_loading_state.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_end_with_updated_loading_state.ts index 3ecb08fba480b0..7765f6679d38d9 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_end_with_updated_loading_state.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_end_with_updated_loading_state.ts @@ -13,7 +13,6 @@ import { updateLoadingStateAction, type AiopsLogRateAnalysisApiAction, } from '@kbn/aiops-log-rate-analysis/api/actions'; -import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from '@kbn/aiops-log-rate-analysis/api/schema'; /** * Helper function that will push a message to the stream that it's done and @@ -21,9 +20,9 @@ import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from '@kbn/aiops-lo * This is implemented as a factory that receives the necessary dependencies * which then returns the actual helper function. */ -export const streamEndWithUpdatedLoadingStateFactory = ( +export const streamEndWithUpdatedLoadingStateFactory = ( streamEndCallback: () => void, - push: StreamFactoryReturnType>['push'] + push: StreamFactoryReturnType['push'] ) => { return function endWithUpdatedLoadingState() { push( diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_error.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_error.ts index 87978b2561a357..92c3fb3661ae82 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_error.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_error.ts @@ -7,7 +7,6 @@ import type { StreamFactoryReturnType } from '@kbn/ml-response-stream/server'; -import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from '@kbn/aiops-log-rate-analysis/api/schema'; import { addErrorAction, type AiopsLogRateAnalysisApiAction, @@ -20,8 +19,8 @@ import type { LogDebugMessage } from './log_debug_message'; * This is implemented as a factory that receives the necessary dependencies * which then returns the actual helper function. */ -export const streamPushErrorFactory = ( - push: StreamFactoryReturnType>['push'], +export const streamPushErrorFactory = ( + push: StreamFactoryReturnType['push'], logDebugMessage: LogDebugMessage ) => { return function pushError(m: string) { diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_ping_with_timeout.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_ping_with_timeout.ts index d570da39f277e6..bcedc82d5f5c4f 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_ping_with_timeout.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/response_stream_utils/stream_push_ping_with_timeout.ts @@ -11,7 +11,6 @@ import { pingAction, type AiopsLogRateAnalysisApiAction, } from '@kbn/aiops-log-rate-analysis/api/actions'; -import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from '@kbn/aiops-log-rate-analysis/api/schema'; import type { LogDebugMessage } from './log_debug_message'; import type { StateHandler } from './state_handler'; @@ -24,9 +23,9 @@ const PING_FREQUENCY = 10000; * This is implemented as a factory that receives the necessary dependencies * which then returns the actual helper function. */ -export const streamPushPingWithTimeoutFactory = ( +export const streamPushPingWithTimeoutFactory = ( stateHandler: StateHandler, - push: StreamFactoryReturnType>['push'], + push: StreamFactoryReturnType['push'], logDebugMessage: LogDebugMessage ) => { return function pushPingWithTimeout() { diff --git a/x-pack/test/api_integration/apis/aiops/log_rate_analysis_full_analysis.ts b/x-pack/test/api_integration/apis/aiops/log_rate_analysis_full_analysis.ts index 02086bbfe8b1c2..b1a9fe2effb498 100644 --- a/x-pack/test/api_integration/apis/aiops/log_rate_analysis_full_analysis.ts +++ b/x-pack/test/api_integration/apis/aiops/log_rate_analysis_full_analysis.ts @@ -56,7 +56,7 @@ export default ({ getService }: FtrProviderContext) => { expect(typeof d.type).to.be('string'); }); - const addSignificantItemsActions = getAddSignificationItemsActions(data, apiVersion); + const addSignificantItemsActions = getAddSignificationItemsActions(data); expect(addSignificantItemsActions.length).to.greaterThan( 0, 'Expected significant items actions to be greater than 0.' @@ -73,7 +73,7 @@ export default ({ getService }: FtrProviderContext) => { 'Significant items do not match expected values.' ); - const histogramActions = getHistogramActions(data, apiVersion); + const histogramActions = getHistogramActions(data); const histograms = histogramActions.flatMap((d) => d.payload); // for each significant term we should get a histogram expect(histogramActions.length).to.be(significantItems.length); @@ -85,7 +85,7 @@ export default ({ getService }: FtrProviderContext) => { ); }); - const groupActions = getGroupActions(data, apiVersion); + const groupActions = getGroupActions(data); const groups = groupActions.flatMap((d) => d.payload); const actualGroups = orderBy(groups, ['docCount'], ['desc']); @@ -98,7 +98,7 @@ export default ({ getService }: FtrProviderContext) => { )}, got ${JSON.stringify(actualGroups)}` ); - const groupHistogramActions = getGroupHistogramActions(data, apiVersion); + const groupHistogramActions = getGroupHistogramActions(data); const groupHistograms = groupHistogramActions.flatMap((d) => d.payload); // for each significant terms group we should get a histogram expect(groupHistograms.length).to.be(groups.length); diff --git a/x-pack/test/api_integration/apis/aiops/log_rate_analysis_groups_only.ts b/x-pack/test/api_integration/apis/aiops/log_rate_analysis_groups_only.ts index 340f450a5f7179..d3a7aaed19a407 100644 --- a/x-pack/test/api_integration/apis/aiops/log_rate_analysis_groups_only.ts +++ b/x-pack/test/api_integration/apis/aiops/log_rate_analysis_groups_only.ts @@ -37,24 +37,13 @@ export default ({ getService }: FtrProviderContext) => { getLogRateAnalysisTestData().forEach((testData) => { let overrides: AiopsLogRateAnalysisSchema['overrides'] = {}; - if (apiVersion === '1') { - overrides = { - loaded: 0, - remainingFieldCandidates: [], - significantTerms: testData.expected.significantItems, - regroupOnly: true, - } as AiopsLogRateAnalysisSchema['overrides']; - } - - if (apiVersion === '2') { - overrides = { - loaded: 0, - remainingFieldCandidates: [], - significantItems: testData.expected - .significantItems as AiopsLogRateAnalysisSchemaSignificantItem[], - regroupOnly: true, - } as AiopsLogRateAnalysisSchema['overrides']; - } + overrides = { + loaded: 0, + remainingFieldCandidates: [], + significantItems: testData.expected + .significantItems as AiopsLogRateAnalysisSchemaSignificantItem[], + regroupOnly: true, + } as AiopsLogRateAnalysisSchema['overrides']; describe(`with v${apiVersion} - ${testData.testName}`, () => { before(async () => { @@ -78,13 +67,13 @@ export default ({ getService }: FtrProviderContext) => { expect(typeof d.type).to.be('string'); }); - const addSignificantItemsActions = getAddSignificationItemsActions(data, apiVersion); + const addSignificantItemsActions = getAddSignificationItemsActions(data); expect(addSignificantItemsActions.length).to.eql( 0, `Expected significant items actions to be 0, got ${addSignificantItemsActions.length}` ); - const histogramActions = getHistogramActions(data, apiVersion); + const histogramActions = getHistogramActions(data); // for each significant item we should get a histogram expect(histogramActions.length).to.eql( @@ -92,7 +81,7 @@ export default ({ getService }: FtrProviderContext) => { `Expected histogram actions to be 0, got ${histogramActions.length}` ); - const groupActions = getGroupActions(data, apiVersion); + const groupActions = getGroupActions(data); const groups = groupActions.flatMap((d) => d.payload); expect(orderBy(groups, ['docCount'], ['desc'])).to.eql( @@ -102,7 +91,7 @@ export default ({ getService }: FtrProviderContext) => { )}, got ${JSON.stringify(groups)}` ); - const groupHistogramActions = getGroupHistogramActions(data, apiVersion); + const groupHistogramActions = getGroupHistogramActions(data); const groupHistograms = groupHistogramActions.flatMap((d) => d.payload); // for each significant items group we should get a histogram expect(groupHistograms.length).to.be(groups.length); diff --git a/x-pack/test/api_integration/apis/aiops/test_data.ts b/x-pack/test/api_integration/apis/aiops/test_data.ts index 63bf9940d959c9..21f628d832c7d2 100644 --- a/x-pack/test/api_integration/apis/aiops/test_data.ts +++ b/x-pack/test/api_integration/apis/aiops/test_data.ts @@ -25,7 +25,7 @@ import { import type { TestData } from './types'; -export const API_VERSIONS: ApiVersion[] = ['1', '2']; +export const API_VERSIONS: ApiVersion[] = ['2']; export const getLogRateAnalysisTestData = (): Array> => [ { diff --git a/x-pack/test/api_integration/apis/aiops/test_helpers.ts b/x-pack/test/api_integration/apis/aiops/test_helpers.ts index 5252d14fbb7f76..cf5f1d41ebbcec 100644 --- a/x-pack/test/api_integration/apis/aiops/test_helpers.ts +++ b/x-pack/test/api_integration/apis/aiops/test_helpers.ts @@ -5,34 +5,16 @@ * 2.0. */ -import type { AiopsLogRateAnalysisApiVersion as ApiVersion } from '@kbn/aiops-log-rate-analysis/api/schema'; +export const getAddSignificationItemsActions = (data: any[]) => + data.filter((d) => d.type === 'add_significant_items'); -export const getAddSignificationItemsActions = (data: any[], apiVersion: ApiVersion) => - data.filter( - (d) => d.type === (apiVersion === '1' ? 'add_significant_terms' : 'add_significant_items') - ); +export const getHistogramActions = (data: any[]) => + data.filter((d) => d.type === 'add_significant_items_histogram'); -export const getHistogramActions = (data: any[], apiVersion: ApiVersion) => - data.filter( - (d) => - d.type === - (apiVersion === '1' ? 'add_significant_terms_histogram' : 'add_significant_items_histogram') - ); +export const getGroupActions = (data: any[]) => + data.filter((d) => d.type === 'add_significant_items_group'); -export const getGroupActions = (data: any[], apiVersion: ApiVersion) => - data.filter( - (d) => - d.type === - (apiVersion === '1' ? 'add_significant_terms_group' : 'add_significant_items_group') - ); - -export const getGroupHistogramActions = (data: any[], apiVersion: ApiVersion) => - data.filter( - (d) => - d.type === - (apiVersion === '1' - ? 'add_significant_terms_group_histogram' - : 'add_significant_items_group_histogram') - ); +export const getGroupHistogramActions = (data: any[]) => + data.filter((d) => d.type === 'add_significant_items_group_histogram'); export const getErrorActions = (data: any[]) => data.filter((d) => d.type === 'add_error'); diff --git a/x-pack/test/api_integration_basic/apis/aiops/permissions.ts b/x-pack/test/api_integration_basic/apis/aiops/permissions.ts index ed25731ffd5e36..239696215c7593 100644 --- a/x-pack/test/api_integration_basic/apis/aiops/permissions.ts +++ b/x-pack/test/api_integration_basic/apis/aiops/permissions.ts @@ -17,7 +17,7 @@ import type { import type { FtrProviderContext } from '../../ftr_provider_context'; -const API_VERSIONS: ApiVersion[] = ['1', '2']; +const API_VERSIONS: ApiVersion[] = ['2']; export default ({ getService }: FtrProviderContext) => { const supertest = getService('supertest');