[ML] AIOps: Adds execution context to client side data.search requests (#154891)

Part of https://github.com/elastic/kibana/issues/147378. This PR adds
context information to data.search requests so that they appear in the
search slow log.
This commit is contained in:
Walter Rafelsberger 2023-04-19 15:51:31 +02:00 committed by GitHub
parent d1dff0b2c7
commit 0283b7abd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 2 deletions

View file

@ -6,6 +6,7 @@
*/
import type { CoreStart } from '@kbn/core/server';
import type { KibanaExecutionContext } from '@kbn/core-execution-context-common';
/**
* Creates an execution context to be passed on as part of ES queries.
@ -22,7 +23,7 @@ export function createExecutionContext(
name: string,
id?: string,
type = 'application'
) {
): KibanaExecutionContext {
const labels = coreStart.executionContext.getAsLabels();
const page = labels.page as string;
return {

View file

@ -17,5 +17,6 @@
],
"kbn_references": [
"@kbn/core",
"@kbn/core-execution-context-common",
]
}

View file

@ -114,6 +114,7 @@ export const ExplainLogRateSpikesPage: FC = () => {
{ selectedDataView: dataView, selectedSavedSearch },
aiopsListState,
setGlobalState,
'explain_log_rage_spikes',
currentSelectedSignificantTerm,
currentSelectedGroup
);

View file

@ -111,6 +111,7 @@ export const LogCategorizationPage: FC = () => {
{ selectedDataView: dataView, selectedSavedSearch },
aiopsListState,
setGlobalState,
'log_categorization',
undefined,
undefined,
BAR_TARGET

View file

@ -8,7 +8,6 @@
import { createContext, useContext } from 'react';
import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import type { ChartsPluginStart } from '@kbn/charts-plugin/public';
@ -17,6 +16,7 @@ import type { SharePluginStart } from '@kbn/share-plugin/public';
import type {
CoreStart,
CoreSetup,
ExecutionContextStart,
HttpStart,
IUiSettingsClient,
ThemeServiceStart,
@ -26,6 +26,7 @@ import type { LensPublicStart } from '@kbn/lens-plugin/public';
export interface AiopsAppDependencies {
application: CoreStart['application'];
data: DataPublicPluginStart;
executionContext: ExecutionContextStart;
charts: ChartsPluginStart;
fieldFormats: FieldFormatsStart;
http: HttpStart;

View file

@ -8,12 +8,15 @@
import { useEffect, useMemo, useState } from 'react';
import { merge } from 'rxjs';
import { useExecutionContext } from '@kbn/kibana-react-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { SignificantTerm } from '@kbn/ml-agg-utils';
import type { SavedSearch } from '@kbn/discover-plugin/public';
import type { Dictionary } from '@kbn/ml-url-state';
import { mlTimefilterRefresh$, useTimefilter } from '@kbn/ml-date-picker';
import { PLUGIN_ID } from '../../common';
import type { DocumentStatsSearchStrategyParams } from '../get_document_stats';
import type { AiOpsIndexBasedAppState } from '../components/explain_log_rate_spikes/explain_log_rate_spikes_app_state';
import { getEsQueryFromSavedSearch } from '../application/utils/search_utils';
@ -33,17 +36,25 @@ export const useData = (
}: { selectedDataView: DataView; selectedSavedSearch: SavedSearch | null },
aiopsListState: AiOpsIndexBasedAppState,
onUpdate: (params: Dictionary<unknown>) => void,
contextId: string,
selectedSignificantTerm?: SignificantTerm,
selectedGroup?: GroupTableItem | null,
barTarget: number = DEFAULT_BAR_TARGET
) => {
const {
executionContext,
uiSettings,
data: {
query: { filterManager },
},
} = useAiopsAppContext();
useExecutionContext(executionContext, {
name: PLUGIN_ID,
type: 'application',
id: contextId,
});
const [lastRefresh, setLastRefresh] = useState(0);
/** Prepare required params to pass to search strategy **/

View file

@ -49,6 +49,7 @@ export const ChangePointDetectionPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',

View file

@ -49,6 +49,7 @@ export const ExplainLogRateSpikesPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',

View file

@ -49,6 +49,7 @@ export const LogCategorizationPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',