Skip to content

Commit

Permalink
fix types/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Oct 3, 2023
1 parent 6ad57d9 commit a8bb5cf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,54 @@ const selectedGroupMock: GroupTableItem = {
pValue: 2.2250738585072626e-308,
uniqueItemsCount: 3,
groupItemsSortedByUniqueness: [
{ fieldName: 'error.message', fieldValue: 'rate limit exceeded', docCount: 10, pValue: 0.05 },
{ fieldName: 'message', fieldValue: 'too many requests', docCount: 10, pValue: 0.05 },
{
key: 'error.message:rate limit exceeded',
type: 'keyword',
fieldName: 'error.message',
fieldValue: 'rate limit exceeded',
docCount: 10,
pValue: 0.05,
},
{
key: 'message:too many requests',
type: 'keyword',
fieldName: 'message',
fieldValue: 'too many requests',
docCount: 10,
pValue: 0.05,
},
{
key: 'user_agent.original.keyword:Mozilla/5.0',
type: 'keyword',
fieldName: 'user_agent.original.keyword',
fieldValue: 'Mozilla/5.0',
docCount: 10,
pValue: 0.05,
},
{
key: 'beat.hostname.keyword:ip-192-168-1-1',
type: 'keyword',
fieldName: 'beat.hostname.keyword',
fieldValue: 'ip-192-168-1-1',
docCount: 10,
pValue: 0.05,
},
{ fieldName: 'beat.name.keyword', fieldValue: 'i-1234', docCount: 10, pValue: 0.05 },
{ fieldName: 'docker.container.id.keyword', fieldValue: 'asdf', docCount: 10, pValue: 0.05 },
{
key: 'beat.name.keyword:i-1234',
type: 'keyword',
fieldName: 'beat.name.keyword',
fieldValue: 'i-1234',
docCount: 10,
pValue: 0.05,
},
{
key: 'docker.container.id.keyword:asdf',
type: 'keyword',
fieldName: 'docker.container.id.keyword',
fieldValue: 'asdf',
docCount: 10,
pValue: 0.05,
},
],
histogram: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import type { Query } from '@kbn/es-query';
import type { SignificantTerm } from '@kbn/ml-agg-utils';
import { type SignificantTerm, SIGNIFICANT_TERM_TYPE } from '@kbn/ml-agg-utils';

import { buildBaseFilterCriteria } from '@kbn/ml-query-utils';

Expand Down Expand Up @@ -40,8 +40,20 @@ export function buildExtendedBaseFilterCriteria(
if (selectedGroup) {
const allItems = selectedGroup.groupItemsSortedByUniqueness;
for (const item of allItems) {
const { fieldName, fieldValue } = item;
groupFilter.push({ term: { [fieldName]: fieldValue } });
const { fieldName, fieldValue, key, type, docCount } = item;
if (type === SIGNIFICANT_TERM_TYPE.KEYWORD) {
groupFilter.push({ term: { [fieldName]: fieldValue } });
} else {
groupFilter.push(
getCategoryQuery(fieldName, [
{
key,
count: docCount,
examples: [],
},
])
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@ export function getGroupTableItems(
const dedupedGroup: GroupTableItemGroup[] = [];

sortedGroup.forEach((pair) => {
const { fieldName, fieldValue, docCount: pairDocCount, pValue: pairPValue, duplicate } = pair;
const {
key,
type,
fieldName,
fieldValue,
docCount: pairDocCount,
pValue: pairPValue,
duplicate,
} = pair;
if ((duplicate ?? 0) <= 1) {
dedupedGroup.push({ fieldName, fieldValue, docCount: pairDocCount, pValue: pairPValue });
dedupedGroup.push({
key,
type,
fieldName,
fieldValue,
docCount: pairDocCount,
pValue: pairPValue,
});
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { SignificantTerm, SignificantTermGroupItem } from '@kbn/ml-agg-util

export type GroupTableItemGroup = Pick<
SignificantTermGroupItem,
'fieldName' | 'fieldValue' | 'docCount' | 'pValue' | 'duplicate'
'key' | 'type' | 'fieldName' | 'fieldValue' | 'docCount' | 'pValue' | 'duplicate'
>;

export interface GroupTableItem {
Expand Down

0 comments on commit a8bb5cf

Please sign in to comment.