[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)
This commit is contained in:
Walter Rafelsberger 2024-04-26 23:05:51 +02:00 committed by GitHub
parent 0de746796c
commit a79d2011cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 129 additions and 359 deletions

View file

@ -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<T extends ApiVersion> {
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<T extends ApiVersion>(
payload: ApiActionAddSignificantItems<T>['payload'],
version: T
): ApiActionAddSignificantItems<T> {
if (version === '1') {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS,
payload,
} as ApiActionAddSignificantItems<T>;
}
export function addSignificantItemsAction(
payload: ApiActionAddSignificantItems['payload']
): ApiActionAddSignificantItems {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS,
payload,
} as ApiActionAddSignificantItems<T>;
};
}
interface ApiActionAddSignificantItemsHistogram<T extends ApiVersion> {
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<T extends ApiVersion>(
payload: ApiActionAddSignificantItemsHistogram<T>['payload'],
version: T
): ApiActionAddSignificantItemsHistogram<T> {
if (version === '1') {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_HISTOGRAM,
payload,
} as ApiActionAddSignificantItemsHistogram<T>;
}
export function addSignificantItemsHistogramAction(
payload: ApiActionAddSignificantItemsHistogram['payload']
): ApiActionAddSignificantItemsHistogram {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_HISTOGRAM,
payload,
} as ApiActionAddSignificantItemsHistogram<T>;
};
}
interface ApiActionAddSignificantItemsGroup<T extends ApiVersion> {
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<T extends ApiVersion>(
payload: ApiActionAddSignificantItemsGroup<T>['payload'],
version: T
): ApiActionAddSignificantItemsGroup<T> {
if (version === '1') {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP,
payload,
} as ApiActionAddSignificantItemsGroup<T>;
}
export function addSignificantItemsGroupAction(
payload: ApiActionAddSignificantItemsGroup['payload']
): ApiActionAddSignificantItemsGroup {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP,
payload,
} as ApiActionAddSignificantItemsGroup<T>;
};
}
interface ApiActionAddSignificantItemsGroupHistogram<T extends ApiVersion> {
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<T extends ApiVersion>(
payload: ApiActionAddSignificantItemsGroupHistogram<T>['payload'],
version: T
): ApiActionAddSignificantItemsGroupHistogram<T> {
if (version === '1') {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_TERMS_GROUP_HISTOGRAM,
payload,
} as ApiActionAddSignificantItemsGroupHistogram<T>;
}
export function addSignificantItemsGroupHistogramAction(
payload: ApiActionAddSignificantItemsGroupHistogram['payload']
): ApiActionAddSignificantItemsGroupHistogram {
return {
type: API_ACTION_NAME.ADD_SIGNIFICANT_ITEMS_GROUP_HISTOGRAM,
payload,
} as ApiActionAddSignificantItemsGroupHistogram<T>;
};
}
interface ApiActionAddError {
@ -225,11 +168,11 @@ export function setZeroDocsFallback(
};
}
export type AiopsLogRateAnalysisApiAction<T extends ApiVersion> =
| ApiActionAddSignificantItems<T>
| ApiActionAddSignificantItemsGroup<T>
| ApiActionAddSignificantItemsHistogram<T>
| ApiActionAddSignificantItemsGroupHistogram<T>
export type AiopsLogRateAnalysisApiAction =
| ApiActionAddSignificantItems
| ApiActionAddSignificantItemsGroup
| ApiActionAddSignificantItemsHistogram
| ApiActionAddSignificantItemsGroupHistogram
| ApiActionAddError
| ApiActionPing
| ApiActionResetAll

View file

@ -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;

View file

@ -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<typeof aiopsLogRateAnalysisSchemaV1>;

View file

@ -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);

View file

@ -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<AiopsLogRateAnalysisApiAction<'2'>>
action: AiopsLogRateAnalysisApiAction | AiopsLogRateAnalysisApiAction[]
): StreamState {
if (Array.isArray(action)) {
return action.reduce(streamReducer, state);

View file

@ -46,7 +46,6 @@ export const groupingHandlerFactory =
logDebugMessage,
logger,
stateHandler,
version,
}: ResponseStreamFetchOptions<T>) =>
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);

View file

@ -41,7 +41,6 @@ export const histogramHandlerFactory =
requestBody,
responseStream,
stateHandler,
version,
}: ResponseStreamFetchOptions<T>) =>
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,
},
])
);
}
}

View file

@ -38,7 +38,6 @@ export const significantItemsHandlerFactory =
requestBody,
responseStream,
stateHandler,
version,
}: ResponseStreamFetchOptions<T>) =>
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<string>();
@ -157,7 +136,7 @@ export const significantItemsHandlerFactory =
});
significantTerms.push(...pValues);
responseStream.push(addSignificantItemsAction(pValues, version));
responseStream.push(addSignificantItemsAction(pValues));
}
responseStream.push(

View file

@ -39,7 +39,6 @@ export const topItemsHandlerFactory =
requestBody,
responseStream,
stateHandler,
version,
}: ResponseStreamFetchOptions<T>) =>
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<string>();
@ -158,7 +137,7 @@ export const topItemsHandlerFactory =
});
topTerms.push(...fetchedTopTerms);
responseStream.push(addSignificantItemsAction(fetchedTopTerms, version));
responseStream.push(addSignificantItemsAction(fetchedTopTerms));
}
responseStream.push(

View file

@ -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',

View file

@ -56,7 +56,7 @@ export interface ResponseStreamFetchOptions<T extends ApiVersion> extends Respon
responseStream: {
end: () => void;
endWithUpdatedLoadingState: () => void;
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction<T>>['push'];
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction>['push'];
pushPingWithTimeout: () => void;
pushError: (msg: string) => void;
};
@ -97,14 +97,14 @@ export const responseStreamFactory = <T extends ApiVersion>(options: ResponseStr
end: streamEnd,
push,
responseWithHeaders,
} = streamFactory<AiopsLogRateAnalysisApiAction<T>>(
} = streamFactory<AiopsLogRateAnalysisApiAction>(
headers,
logger,
requestBody.compressResponse,
requestBody.flushFix
);
const pushPingWithTimeout = streamPushPingWithTimeoutFactory<T>(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);

View file

@ -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 = <T extends ApiVersion>(
export const streamEndWithUpdatedLoadingStateFactory = (
streamEndCallback: () => void,
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction<T>>['push']
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction>['push']
) => {
return function endWithUpdatedLoadingState() {
push(

View file

@ -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 = <T extends ApiVersion>(
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction<T>>['push'],
export const streamPushErrorFactory = (
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction>['push'],
logDebugMessage: LogDebugMessage
) => {
return function pushError(m: string) {

View file

@ -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 = <T extends ApiVersion>(
export const streamPushPingWithTimeoutFactory = (
stateHandler: StateHandler,
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction<T>>['push'],
push: StreamFactoryReturnType<AiopsLogRateAnalysisApiAction>['push'],
logDebugMessage: LogDebugMessage
) => {
return function pushPingWithTimeout() {

View file

@ -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);

View file

@ -37,24 +37,13 @@ export default ({ getService }: FtrProviderContext) => {
getLogRateAnalysisTestData<typeof apiVersion>().forEach((testData) => {
let overrides: AiopsLogRateAnalysisSchema<typeof apiVersion>['overrides'] = {};
if (apiVersion === '1') {
overrides = {
loaded: 0,
remainingFieldCandidates: [],
significantTerms: testData.expected.significantItems,
regroupOnly: true,
} as AiopsLogRateAnalysisSchema<typeof apiVersion>['overrides'];
}
if (apiVersion === '2') {
overrides = {
loaded: 0,
remainingFieldCandidates: [],
significantItems: testData.expected
.significantItems as AiopsLogRateAnalysisSchemaSignificantItem[],
regroupOnly: true,
} as AiopsLogRateAnalysisSchema<typeof apiVersion>['overrides'];
}
overrides = {
loaded: 0,
remainingFieldCandidates: [],
significantItems: testData.expected
.significantItems as AiopsLogRateAnalysisSchemaSignificantItem[],
regroupOnly: true,
} as AiopsLogRateAnalysisSchema<typeof apiVersion>['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);

View file

@ -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 = <T extends ApiVersion>(): Array<TestData<T>> => [
{

View file

@ -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');

View file

@ -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');