From 021b102dcbd67bc21705b8a62857ec8ce191b5e1 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Fri, 23 Feb 2024 08:58:33 +0100 Subject: [PATCH] fix tests --- .../final_significant_item_groups.ts | 35 +++++++++-- .../artificial_logs/frequent_item_sets.ts | 2 +- .../aiops/common/api/stream_reducer.test.ts | 2 +- .../get_group_table_items.test.ts | 59 +++++++++++++------ .../queries/get_value_counts.test.ts | 2 +- .../aiops/log_rate_analysis_groups_only.ts | 4 +- .../api_integration/apis/aiops/test_data.ts | 2 +- 7 files changed, 78 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/aiops/common/__mocks__/artificial_logs/final_significant_item_groups.ts b/x-pack/plugins/aiops/common/__mocks__/artificial_logs/final_significant_item_groups.ts index 4ed2a8337a8ff..7fcf5ea425afe 100644 --- a/x-pack/plugins/aiops/common/__mocks__/artificial_logs/final_significant_item_groups.ts +++ b/x-pack/plugins/aiops/common/__mocks__/artificial_logs/final_significant_item_groups.ts @@ -52,14 +52,14 @@ export const finalSignificantItemGroups: SignificantItemGroup[] = [ fieldValue: 'login.php', docCount: 790, pValue: 0.012783309213417932, - duplicate: 1, + duplicate: 2, }, ], docCount: 790, pValue: 0.012783309213417932, }, { - id: '1807570559', + id: '2091742187', group: [ { key: 'url:home.php', @@ -67,7 +67,7 @@ export const finalSignificantItemGroups: SignificantItemGroup[] = [ fieldName: 'url', fieldValue: 'home.php', docCount: 792, - pValue: 0.012783309213417932, + pValue: 0.00974308761016614, duplicate: 2, }, { @@ -76,11 +76,36 @@ export const finalSignificantItemGroups: SignificantItemGroup[] = [ fieldName: 'user', fieldValue: 'Peter', docCount: 636, - pValue: 0.012783309213417932, - duplicate: 1, + pValue: 0.00974308761016614, + duplicate: 2, }, ], docCount: 636, + pValue: 0.00974308761016614, + }, + { + id: '1937394803', + group: [ + { + key: 'url:login.php', + type: 'keyword', + fieldName: 'url', + fieldValue: 'login.php', + docCount: 790, + pValue: 0.012783309213417932, + duplicate: 2, + }, + { + key: 'user:Peter', + type: 'keyword', + fieldName: 'user', + fieldValue: 'Peter', + docCount: 632, + pValue: 0.012783309213417932, + duplicate: 2, + }, + ], + docCount: 632, pValue: 0.012783309213417932, }, ]; diff --git a/x-pack/plugins/aiops/common/__mocks__/artificial_logs/frequent_item_sets.ts b/x-pack/plugins/aiops/common/__mocks__/artificial_logs/frequent_item_sets.ts index 1e8a2ed9d3fe9..791512e6bffbc 100644 --- a/x-pack/plugins/aiops/common/__mocks__/artificial_logs/frequent_item_sets.ts +++ b/x-pack/plugins/aiops/common/__mocks__/artificial_logs/frequent_item_sets.ts @@ -44,7 +44,7 @@ export const frequentItemSets: ItemSet[] = [ { set: [ { fieldName: 'user', fieldValue: 'Peter' }, - { fieldName: 'url', fieldValue: 'home.php' }, + { fieldName: 'url', fieldValue: 'login.php' }, ], size: 2, maxPValue: 0.012783309213417932, diff --git a/x-pack/plugins/aiops/common/api/stream_reducer.test.ts b/x-pack/plugins/aiops/common/api/stream_reducer.test.ts index 53dcc5142b962..5344d2448463c 100644 --- a/x-pack/plugins/aiops/common/api/stream_reducer.test.ts +++ b/x-pack/plugins/aiops/common/api/stream_reducer.test.ts @@ -77,7 +77,7 @@ describe('streamReducer', () => { ); expect(state2.significantItems).toHaveLength(4); - expect(state2.significantItemsGroups).toHaveLength(3); + expect(state2.significantItemsGroups).toHaveLength(4); const state3 = streamReducer(state2, resetGroupsAction()); diff --git a/x-pack/plugins/aiops/public/components/log_rate_analysis_results_table/get_group_table_items.test.ts b/x-pack/plugins/aiops/public/components/log_rate_analysis_results_table/get_group_table_items.test.ts index a2ff91d3d05f9..0976382377245 100644 --- a/x-pack/plugins/aiops/public/components/log_rate_analysis_results_table/get_group_table_items.test.ts +++ b/x-pack/plugins/aiops/public/components/log_rate_analysis_results_table/get_group_table_items.test.ts @@ -15,7 +15,10 @@ describe('getGroupTableItems', () => { expect(groupTableItems).toEqual([ { + id: '2675980076', docCount: 792, + pValue: 0.00974308761016614, + uniqueItemsCount: 0, groupItemsSortedByUniqueness: [ { key: 'response_code:500', @@ -23,8 +26,8 @@ describe('getGroupTableItems', () => { fieldName: 'response_code', fieldValue: '500', docCount: 792, - duplicate: 2, pValue: 0.012783309213417932, + duplicate: 2, }, { key: 'url:home.php', @@ -32,17 +35,16 @@ describe('getGroupTableItems', () => { fieldName: 'url', fieldValue: 'home.php', docCount: 792, - duplicate: 2, pValue: 0.00974308761016614, + duplicate: 2, }, ], - histogram: undefined, - id: '2675980076', - pValue: 0.00974308761016614, - uniqueItemsCount: 0, }, { + id: '3819687732', docCount: 790, + pValue: 0.012783309213417932, + uniqueItemsCount: 0, groupItemsSortedByUniqueness: [ { key: 'url:login.php', @@ -50,8 +52,8 @@ describe('getGroupTableItems', () => { fieldName: 'url', fieldValue: 'login.php', docCount: 790, - duplicate: 1, pValue: 0.012783309213417932, + duplicate: 2, }, { key: 'response_code:500', @@ -59,17 +61,16 @@ describe('getGroupTableItems', () => { fieldName: 'response_code', fieldValue: '500', docCount: 792, - duplicate: 2, pValue: 0.012783309213417932, + duplicate: 2, }, ], - histogram: undefined, - id: '3819687732', - pValue: 0.012783309213417932, - uniqueItemsCount: 1, }, { + id: '2091742187', docCount: 636, + pValue: 0.00974308761016614, + uniqueItemsCount: 0, groupItemsSortedByUniqueness: [ { key: 'user:Peter', @@ -77,8 +78,8 @@ describe('getGroupTableItems', () => { fieldName: 'user', fieldValue: 'Peter', docCount: 636, - duplicate: 1, - pValue: 0.012783309213417932, + pValue: 0.00974308761016614, + duplicate: 2, }, { key: 'url:home.php', @@ -86,14 +87,36 @@ describe('getGroupTableItems', () => { fieldName: 'url', fieldValue: 'home.php', docCount: 792, + pValue: 0.00974308761016614, duplicate: 2, - pValue: 0.012783309213417932, }, ], - histogram: undefined, - id: '1807570559', + }, + { + id: '1937394803', + docCount: 632, pValue: 0.012783309213417932, - uniqueItemsCount: 1, + uniqueItemsCount: 0, + groupItemsSortedByUniqueness: [ + { + key: 'user:Peter', + type: 'keyword', + fieldName: 'user', + fieldValue: 'Peter', + docCount: 632, + pValue: 0.012783309213417932, + duplicate: 2, + }, + { + key: 'url:login.php', + type: 'keyword', + fieldName: 'url', + fieldValue: 'login.php', + docCount: 790, + pValue: 0.012783309213417932, + duplicate: 2, + }, + ], }, ]); }); diff --git a/x-pack/plugins/aiops/server/routes/log_rate_analysis/queries/get_value_counts.test.ts b/x-pack/plugins/aiops/server/routes/log_rate_analysis/queries/get_value_counts.test.ts index 0c09136ce75eb..9187ed7c0eaab 100644 --- a/x-pack/plugins/aiops/server/routes/log_rate_analysis/queries/get_value_counts.test.ts +++ b/x-pack/plugins/aiops/server/routes/log_rate_analysis/queries/get_value_counts.test.ts @@ -16,7 +16,7 @@ describe('getValueCounts', () => { }); it('get value counts for field url', () => { - expect(getValueCounts(frequentItemSets, 'url')).toEqual({ 'home.php': 3, 'login.php': 1 }); + expect(getValueCounts(frequentItemSets, 'url')).toEqual({ 'home.php': 2, 'login.php': 2 }); }); it('get value counts for field user', () => { 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 78344782beaf4..f3aeeed8d067c 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 @@ -97,7 +97,9 @@ export default ({ getService }: FtrProviderContext) => { expect(orderBy(groups, ['docCount'], ['desc'])).to.eql( orderBy(testData.expected.groups, ['docCount'], ['desc']), - 'Grouping result does not match expected values.' + `Grouping result does not match expected values. Expected ${JSON.stringify( + testData.expected.groups + )}, got ${JSON.stringify(groups)}` ); const groupHistogramActions = getGroupHistogramActions(data, apiVersion); 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 692543084a08e..455574e4c7e76 100644 --- a/x-pack/test/api_integration/apis/aiops/test_data.ts +++ b/x-pack/test/api_integration/apis/aiops/test_data.ts @@ -38,7 +38,7 @@ export const getLogRateAnalysisTestData = (): Array