Skip to content

Commit

Permalink
[ML] AIOps: Adds execution context to client side data.search reque…
Browse files Browse the repository at this point in the history
…sts (#154891)

Part of #147378. This PR adds
context information to data.search requests so that they appear in the
search slow log.
  • Loading branch information
walterra committed Apr 19, 2023
1 parent d1dff0b commit 0283b7a
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions x-pack/packages/ml/route_utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
],
"kbn_references": [
"@kbn/core",
"@kbn/core-execution-context-common",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const ExplainLogRateSpikesPage: FC = () => {
{ selectedDataView: dataView, selectedSavedSearch },
aiopsListState,
setGlobalState,
'explain_log_rage_spikes',
currentSelectedSignificantTerm,
currentSelectedGroup
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const LogCategorizationPage: FC = () => {
{ selectedDataView: dataView, selectedSavedSearch },
aiopsListState,
setGlobalState,
'log_categorization',
undefined,
undefined,
BAR_TARGET
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/aiops/public/hooks/use_aiops_app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,6 +16,7 @@ import type { SharePluginStart } from '@kbn/share-plugin/public';
import type {
CoreStart,
CoreSetup,
ExecutionContextStart,
HttpStart,
IUiSettingsClient,
ThemeServiceStart,
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/aiops/public/hooks/use_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ChangePointDetectionPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const ExplainLogRateSpikesPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const LogCategorizationPage: FC = () => {
appDependencies={pick(services, [
'application',
'data',
'executionContext',
'charts',
'fieldFormats',
'http',
Expand Down

0 comments on commit 0283b7a

Please sign in to comment.