Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.15] [ML] AIOps Fixing runtime mappings in pattern analysis (#188530) #188759

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
QueryDslQueryContainer,
AggregationsCustomCategorizeTextAnalyzer,
} from '@elastic/elasticsearch/lib/api/types';
import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { isPopulatedObject } from '@kbn/ml-is-populated-object/src/is_populated_object';

import type { createRandomSamplerWrapper } from '@kbn/ml-random-sampler-utils';

Expand All @@ -29,6 +31,7 @@ export function createCategoryRequest(
timeField: string,
timeRange: { from: number; to: number } | undefined,
queryIn: QueryDslQueryContainer,
runtimeMappings: MappingRuntimeFields | undefined,
wrap: ReturnType<typeof createRandomSamplerWrapper>['wrap'],
intervalMs?: number,
additionalFilter?: CategorizationAdditionalFilter,
Expand Down Expand Up @@ -113,6 +116,7 @@ export function createCategoryRequest(
body: {
query,
aggs: wrap(aggs),
...(isPopulatedObject(runtimeMappings) ? { runtime_mappings: runtimeMappings } : {}),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"@kbn/es-query",
"@kbn/saved-search-plugin",
"@kbn/data-views-plugin",
"@kbn/ml-is-populated-object",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const getCategoryRequest = (
timeFieldName,
undefined,
query,
undefined,
wrap,
undefined,
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,30 +247,41 @@ export const LogCategorizationEmbeddable: FC<LogCategorizationEmbeddableProps> =
from: earliest,
to: latest,
};
const runtimeMappings = dataView.getRuntimeMappings();

try {
const timeRange = await getMinimumTimeRange(
index,
timeField,
additionalFilter,
minimumTimeRangeOption,
searchQuery
searchQuery,
runtimeMappings
);

if (mounted.current !== true) {
return;
}

const [validationResult, categorizationResult] = await Promise.all([
runValidateFieldRequest(index, selectedField.name, timeField, timeRange, searchQuery, {
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}),
runValidateFieldRequest(
index,
selectedField.name,
timeField,
timeRange,
searchQuery,
runtimeMappings,
{
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}
),
runCategorizeRequest(
index,
selectedField.name,
timeField,
{ to: timeRange.to, from: timeRange.from },
searchQuery,
runtimeMappings,
intervalMs,
timeRange.useSubAgg ? additionalFilter : undefined
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { HttpFetchOptions } from '@kbn/core/public';
import { getTimeFieldRange } from '@kbn/ml-date-picker';
import moment from 'moment';
import { useStorage } from '@kbn/ml-local-storage';
import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { useAiopsAppContext } from '../../../hooks/use_aiops_app_context';
import type { MinimumTimeRangeOption } from './minimum_time_range';
import { MINIMUM_TIME_RANGE } from './minimum_time_range';
Expand All @@ -29,6 +30,7 @@ export function useMinimumTimeRange() {
timeRange: { from: number; to: number },
minimumTimeRangeOption: MinimumTimeRangeOption,
queryIn: QueryDslQueryContainer,
runtimeMappings: MappingRuntimeFields | undefined,
headers?: HttpFetchOptions['headers']
) => {
const minimumTimeRange = MINIMUM_TIME_RANGE[minimumTimeRangeOption];
Expand All @@ -47,6 +49,7 @@ export function useMinimumTimeRange() {
index,
timeFieldName: timeField,
query: queryIn,
runtimeMappings,
path: '/internal/file_upload/time_field_range',
signal: abortController.current.signal,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,28 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
to: latest,
};

const runtimeMappings = dataView.getRuntimeMappings();

try {
const [validationResult, categorizationResult] = await Promise.all([
runValidateFieldRequest(index, selectedField.name, timeField, timeRange, searchQuery, {
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}),
runValidateFieldRequest(
index,
selectedField.name,
timeField,
timeRange,
searchQuery,
runtimeMappings,
{
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}
),
runCategorizeRequest(
index,
selectedField.name,
timeField,
timeRange,
searchQuery,
runtimeMappings,
intervalMs,
additionalFilter
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,31 @@ export const LogCategorizationPage: FC<LogCategorizationPageProps> = ({ embeddin
to: latest,
};

const runtimeMappings = dataView.getRuntimeMappings();

try {
const [validationResult, categorizationResult] = await Promise.all([
runValidateFieldRequest(index, selectedField, timeField, timeRange, searchQuery, {
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}),

runCategorizeRequest(index, selectedField, timeField, timeRange, searchQuery, intervalMs),
runValidateFieldRequest(
index,
selectedField,
timeField,
timeRange,
searchQuery,
runtimeMappings,
{
[AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin,
}
),

runCategorizeRequest(
index,
selectedField,
timeField,
timeRange,
searchQuery,
runtimeMappings,
intervalMs
),
]);

setFieldValidationResult(validationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { processCategoryResults } from '@kbn/aiops-log-pattern-analysis/process_category_results';
import type { CatResponse } from '@kbn/aiops-log-pattern-analysis/types';

import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import {
type AiOpsKey,
Expand Down Expand Up @@ -69,6 +70,7 @@ export function useCategorizeRequest() {
timeField: string,
timeRange: { from: number; to: number },
query: QueryDslQueryContainer,
runtimeMappings: MappingRuntimeFields | undefined,
intervalMs?: number,
additionalFilter?: CategorizationAdditionalFilter
): Promise<ReturnType<typeof processCategoryResults>> => {
Expand All @@ -83,6 +85,7 @@ export function useCategorizeRequest() {
timeField,
timeRange,
query,
runtimeMappings,
wrap,
intervalMs,
additionalFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { useRef, useCallback } from 'react';

import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import type { FieldValidationResults } from '@kbn/ml-category-validator';
import type { HttpFetchOptions } from '@kbn/core/public';
Expand All @@ -28,6 +29,7 @@ export function useValidateFieldRequest() {
timeField: string,
timeRange: { from: number; to: number },
queryIn: QueryDslQueryContainer,
runtimeMappings: MappingRuntimeFields | undefined,
headers?: HttpFetchOptions['headers']
) => {
const query = createCategorizeQuery(queryIn, timeField, timeRange);
Expand All @@ -42,10 +44,7 @@ export function useValidateFieldRequest() {
timeField,
start: timeRange.from,
end: timeRange.to,
// only text fields are supported in pattern analysis,
// and it is not possible to create a text runtime field
// so runtimeMappings are not needed
runtimeMappings: undefined,
runtimeMappings,
indicesOptions: undefined,
includeExamples: false,
}),
Expand Down