Skip to content

Commit

Permalink
[ML] AIOps: Tweak function API for fetchTopCategories/fetchTopTerms (#…
Browse files Browse the repository at this point in the history
…189863)

## Summary

Follow up to #187669.
Part of #187684.
Fixes #176387. (Ran the flaky test runner on AIOps functional tests)

- Fixes the `size: 0` option to be properly nested for
`createCategoryRequest()`.
- Changes the arguments structure for `fetchTopCategories` and
`fetchTopTerms` from individual arguments to an options object to be
more in line with the other functions used for log rate analysis.
- Adds jest unit test for `fetchTopCategories` and `fetchTopTerms`.

### 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] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [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)
  • Loading branch information
walterra authored Aug 7, 2024
1 parent d3d5a7c commit 0a01fdd
Show file tree
Hide file tree
Showing 13 changed files with 1,872 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ export function createCategoryRequest(
return {
params: {
index,
size: 0,
body: {
query,
aggs: wrap(aggs),
...(isPopulatedObject(runtimeMappings) ? { runtime_mappings: runtimeMappings } : {}),
size: 0,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.
*/

export const topCategoriesResultMock = [
{
bg_count: 0,
doc_count: 1642,
fieldName: 'message',
fieldValue:
'71.231.222.196 - - [2018-08-13T05:04:08.731Z] "GET /kibana/kibana-6.3.2-windows-x86_64.zip HTTP/1.1" 200 15139 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1"',
key: 'GET HTTP/1.1 Mozilla/5.0 X11 Linux x86_64 rv Gecko/20110421 Firefox/6.0a1',
normalizedScore: 0,
pValue: 1,
score: 0,
total_bg_count: 0,
total_doc_count: 0,
type: 'log_pattern',
},
{
bg_count: 0,
doc_count: 1488,
fieldName: 'message',
fieldValue:
'7.210.210.41 - - [2018-08-13T04:20:49.558Z] "GET /elasticsearch/elasticsearch-6.3.2.deb HTTP/1.1" 404 6699 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24"',
key: 'GET HTTP/1.1 Mozilla/5.0 X11 Linux i686 AppleWebKit/534.24 KHTML like Gecko Chrome/11.0.696.50 Safari/534.24',
normalizedScore: 0,
pValue: 1,
score: 0,
total_bg_count: 0,
total_doc_count: 0,
type: 'log_pattern',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.
*/

export const topCategoriesSearchResponseMock = {
took: 98,
responses: [
{
took: 98,
timed_out: false,
_shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
hits: { total: { value: 4413, relation: 'eq' }, max_score: null, hits: [] },
aggregations: {
categories: {
buckets: [
{
doc_count: 1642,
key: 'GET HTTP/1.1 Mozilla/5.0 X11 Linux x86_64 rv Gecko/20110421 Firefox/6.0a1',
regex:
'.*?GET.+?HTTP/1\\.1.+?Mozilla/5\\.0.+?X11.+?Linux.+?x86_64.+?rv.+?Gecko/20110421.+?Firefox/6\\.0a1.*?',
max_matching_length: 233,
examples: {
hits: {
total: { value: 1642, relation: 'eq' },
max_score: null,
hits: [
{
_index: '.ds-kibana_sample_data_logs-2024.07.08-000001',
_id: 'zpkLk5AB4oRN3GwDmOW1',
_score: null,
_source: {
message:
'71.231.222.196 - - [2018-08-13T05:04:08.731Z] "GET /kibana/kibana-6.3.2-windows-x86_64.zip HTTP/1.1" 200 15139 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1"',
},
sort: [1721624648731],
},
],
},
},
},
{
doc_count: 1488,
key: 'GET HTTP/1.1 Mozilla/5.0 X11 Linux i686 AppleWebKit/534.24 KHTML like Gecko Chrome/11.0.696.50 Safari/534.24',
regex:
'.*?GET.+?HTTP/1\\.1.+?Mozilla/5\\.0.+?X11.+?Linux.+?i686.+?AppleWebKit/534\\.24.+?KHTML.+?like.+?Gecko.+?Chrome/11\\.0\\.696\\.50.+?Safari/534\\.24.*?',
max_matching_length: 266,
examples: {
hits: {
total: { value: 1488, relation: 'eq' },
max_score: null,
hits: [
{
_index: '.ds-kibana_sample_data_logs-2024.07.08-000001',
_id: 'VpkLk5AB4oRN3GwDmOW1',
_score: null,
_source: {
message:
'7.210.210.41 - - [2018-08-13T04:20:49.558Z] "GET /elasticsearch/elasticsearch-6.3.2.deb HTTP/1.1" 404 6699 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.50 Safari/534.24"',
},
sort: [1721622049558],
},
],
},
},
},
],
},
},
status: 200,
},
],
};
Loading

0 comments on commit 0a01fdd

Please sign in to comment.