Skip to content

Commit

Permalink
[ML][AIOps] Telemetry: Track change point detection runs (#169158)
Browse files Browse the repository at this point in the history
## Summary

This PR adds UI tracking for Change Point Detection for AIOps.

- tracks type of analysis and source (where the analysis is being run
from)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Quynh Nguyen (Quinn) <43350163+qn895@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 25, 2023
1 parent 13d1792 commit 7e97dd9
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/aiops/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export const AIOPS_TELEMETRY_ID = {
AIOPS_DEFAULT_SOURCE: 'ml_aiops_labs',
AIOPS_ANALYSIS_RUN_ORIGIN: 'aiops-analysis-run-origin',
} as const;

export const EMBEDDABLE_ORIGIN = 'embeddable';
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from './change_point_detection_context';
import { timeSeriesDataViewWarning } from '../../application/utils/time_series_dataview_check';
import { ReloadContextProvider } from '../../hooks/use_reload';
import { AIOPS_TELEMETRY_ID } from '../../../common/constants';

const localStorage = new Storage(window.localStorage);

Expand Down Expand Up @@ -76,6 +77,8 @@ export const ChangePointDetectionAppState: FC<ChangePointDetectionAppStateProps>
return <>{warning}</>;
}

appDependencies.embeddingOrigin = AIOPS_TELEMETRY_ID.AIOPS_DEFAULT_SOURCE;

const PresentationContextProvider =
appDependencies.presentationUtil?.ContextProvider ?? React.Fragment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ export const EXCLUDED_CHANGE_POINT_TYPES = new Set<ChangePointType>([
]);

export const MAX_CHANGE_POINT_CONFIGS = 6;

export const CHANGE_POINT_DETECTION_EVENT = {
RUN: 'ran_aiops_change_point_detection',
SUCCESS: 'aiops_change_point_detection_success',
ERROR: 'aiops_change_point_detection_error',
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
MappingRuntimeFields,
SearchRequest,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { METRIC_TYPE } from '@kbn/analytics';
import { useReload } from '../../hooks/use_reload';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import {
Expand All @@ -28,6 +29,7 @@ import {
COMPOSITE_AGG_SIZE,
EXCLUDED_CHANGE_POINT_TYPES,
SPLIT_FIELD_CARDINALITY_LIMIT,
CHANGE_POINT_DETECTION_EVENT,
} from './constants';

interface RequestOptions {
Expand Down Expand Up @@ -122,6 +124,8 @@ export function useChangePointResults(
) {
const {
notifications: { toasts },
usageCollection,
embeddingOrigin,
} = useAiopsAppContext();

const { dataView } = useDataSource();
Expand Down Expand Up @@ -187,11 +191,27 @@ export function useChangePointResults(
runtimeMappings
);

if (usageCollection?.reportUiCounter && embeddingOrigin) {
usageCollection.reportUiCounter(
embeddingOrigin,
METRIC_TYPE.COUNT,
CHANGE_POINT_DETECTION_EVENT.RUN
);
}

const result = await runRequest<
{ params: SearchRequest },
{ rawResponse: ChangePointAggResponse }
>({ params: requestPayload });

if (usageCollection?.reportUiCounter && embeddingOrigin) {
usageCollection.reportUiCounter(
embeddingOrigin,
METRIC_TYPE.COUNT,
CHANGE_POINT_DETECTION_EVENT.SUCCESS
);
}

if (result === null) {
setProgress(null);
return;
Expand Down Expand Up @@ -257,6 +277,13 @@ export function useChangePointResults(
);
}
} catch (e) {
if (usageCollection?.reportUiCounter && embeddingOrigin) {
usageCollection.reportUiCounter(
embeddingOrigin,
METRIC_TYPE.COUNT,
CHANGE_POINT_DETECTION_EVENT.ERROR
);
}
toasts.addError(e, {
title: i18n.translate('xpack.aiops.changePointDetection.fetchErrorTitle', {
defaultMessage: 'Failed to fetch change points',
Expand All @@ -265,6 +292,7 @@ export function useChangePointResults(
}
},
[
embeddingOrigin,
isSingleMetric,
totalAggPages,
dataView,
Expand All @@ -278,6 +306,7 @@ export function useChangePointResults(
splitFieldsOptions,
runRequest,
toasts,
usageCollection,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import { DatePickerContextProvider } from '@kbn/ml-date-picker';
import { pick } from 'lodash';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import { Subject } from 'rxjs';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/common';
import { EmbeddableInputTracker } from './embeddable_chart_component_wrapper';
import { EMBEDDABLE_CHANGE_POINT_CHART_TYPE } from '../../common/constants';
import { EMBEDDABLE_CHANGE_POINT_CHART_TYPE, EMBEDDABLE_ORIGIN } from '../../common/constants';
import { AiopsAppContext, type AiopsAppDependencies } from '../hooks/use_aiops_app_context';

import { EmbeddableChangePointChartProps } from './embeddable_change_point_chart_component';
Expand All @@ -40,6 +41,7 @@ export interface EmbeddableChangePointChartDeps {
notifications: CoreStart['notifications'];
i18n: CoreStart['i18n'];
lens: LensPublicStart;
usageCollection: UsageCollectionSetup;
}

export type IEmbeddableChangePointChart = typeof EmbeddableChangePointChart;
Expand Down Expand Up @@ -121,10 +123,15 @@ export class EmbeddableChangePointChart extends AbstractEmbeddable<
const input = this.getInput();
const input$ = this.getInput$();

const aiopsAppContextValue = {
...this.deps,
embeddingOrigin: this.parent?.type ?? EMBEDDABLE_ORIGIN,
} as unknown as AiopsAppDependencies;

ReactDOM.render(
<I18nContext>
<KibanaThemeProvider theme$={this.deps.theme.theme$}>
<AiopsAppContext.Provider value={this.deps as unknown as AiopsAppDependencies}>
<AiopsAppContext.Provider value={aiopsAppContextValue}>
<DatePickerContextProvider {...datePickerDeps}>
<Suspense fallback={null}>
<EmbeddableInputTracker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export interface EmbeddableChangePointChartProps {
*/
lastReloadRequestTime?: number;
}

export function getEmbeddableChangePointChart(core: CoreStart, plugins: AiopsPluginStartDeps) {
const { embeddable: embeddableStart } = plugins;
const factory = embeddableStart.getEmbeddableFactory<EmbeddableChangePointChartInput>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export class EmbeddableChangePointChartFactory implements EmbeddableFactoryDefin

async create(input: EmbeddableChangePointChartInput, parent?: IContainer) {
try {
const [{ i18n: i18nService, theme, http, uiSettings, notifications }, { lens, data }] =
await this.getStartServices();
const [
{ i18n: i18nService, theme, http, uiSettings, notifications },
{ lens, data, usageCollection },
] = await this.getStartServices();

return new EmbeddableChangePointChart(
{
Expand All @@ -83,6 +85,7 @@ export class EmbeddableChangePointChartFactory implements EmbeddableFactoryDefin
data,
notifications,
lens,
usageCollection,
},
input,
parent
Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/aiops/public/hooks/use_aiops_app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker';
import type { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public';
import type { EmbeddableStart } from '@kbn/embeddable-plugin/public';
import type { CasesUiStart } from '@kbn/cases-plugin/public';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';

/**
* AIOps App Dependencies to be provided via React context.
Expand Down Expand Up @@ -84,6 +85,10 @@ export interface AiopsAppDependencies {
* Unified search.
*/
unifiedSearch: UnifiedSearchPublicPluginStart;
/**
* Usage collection.
*/
usageCollection?: UsageCollectionSetup;
/**
* Used to create deep links to other plugins.
*/
Expand Down Expand Up @@ -115,6 +120,8 @@ export interface AiopsAppDependencies {
embeddable?: EmbeddableStart;
cases?: CasesUiStart;
isServerless?: boolean;
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin?: string;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/aiops/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/
import type { EmbeddableSetup, EmbeddableStart } from '@kbn/embeddable-plugin/public';
import type { CasesUiSetup } from '@kbn/cases-plugin/public';
import type { LicensingPluginSetup } from '@kbn/licensing-plugin/public';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import type { EmbeddableChangePointChartInput } from './embeddable/embeddable_change_point_chart';

export interface AiopsPluginSetupDeps {
Expand All @@ -40,6 +41,7 @@ export interface AiopsPluginStartDeps {
licensing: LicensingPluginStart;
executionContext: ExecutionContextStart;
embeddable: EmbeddableStart;
usageCollection: UsageCollectionSetup;
}

export type AiopsPluginSetup = void;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/aiops/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@kbn/react-kibana-mount",
"@kbn/ml-chi2test",
"@kbn/usage-collection-plugin",
"@kbn/analytics",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const ChangePointDetectionPage: FC = () => {
'embeddable',
'cases',
'i18n',
'usageCollection',
]),
fieldStats: { useFieldStatsTrigger, FieldStatsFlyoutProvider },
}}
Expand Down

0 comments on commit 7e97dd9

Please sign in to comment.