Skip to content

Commit

Permalink
Merge branch 'main' into ai_err
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Sep 29, 2023
2 parents 6efc31c + b888ecb commit 8e5ccbb
Show file tree
Hide file tree
Showing 94 changed files with 2,229 additions and 1,023 deletions.
2 changes: 1 addition & 1 deletion src/plugins/ui_actions/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface VisualizeFieldContext {
export interface CategorizeFieldContext {
field: DataViewField;
dataView: DataView;
originatingApp?: string;
originatingApp: string;
}

export const ACTION_VISUALIZE_FIELD = 'ACTION_VISUALIZE_FIELD';
Expand Down
6 changes: 4 additions & 2 deletions x-pack/packages/ml/response_stream/client/fetch_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import startsWith from 'lodash/startsWith';
import type { Reducer, ReducerAction } from 'react';

import type { HttpSetup } from '@kbn/core/public';
import type { HttpSetup, HttpFetchOptions } from '@kbn/core/public';

type GeneratorError = string | null;

Expand Down Expand Up @@ -42,7 +42,8 @@ export async function* fetchStream<B extends object, R extends Reducer<any, any>
apiVersion: string | undefined,
abortCtrl: React.MutableRefObject<AbortController>,
body?: B,
ndjson = true
ndjson = true,
headers?: HttpFetchOptions['headers']
): AsyncGenerator<[GeneratorError, ReducerAction<R> | Array<ReducerAction<R>> | undefined]> {
let stream: Readonly<Response> | undefined;

Expand All @@ -52,6 +53,7 @@ export async function* fetchStream<B extends object, R extends Reducer<any, any>
version: apiVersion,
asResponse: true,
rawResponse: true,
headers,
...(body && Object.keys(body).length > 0 ? { body: JSON.stringify(body) } : {}),
});

Expand Down
8 changes: 5 additions & 3 deletions x-pack/packages/ml/response_stream/client/use_fetch_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'react';
import useThrottle from 'react-use/lib/useThrottle';

import type { HttpSetup } from '@kbn/core/public';
import type { HttpSetup, HttpFetchOptions } from '@kbn/core/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';

import { fetchStream } from './fetch_stream';
Expand Down Expand Up @@ -64,7 +64,8 @@ export function useFetchStream<B extends object, R extends Reducer<any, any>>(
endpoint: string,
apiVersion?: string,
body?: B,
customReducer?: FetchStreamCustomReducer<R>
customReducer?: FetchStreamCustomReducer<R>,
headers?: HttpFetchOptions['headers']
) {
const [errors, setErrors] = useState<string[]>([]);
const [isCancelled, setIsCancelled] = useState(false);
Expand Down Expand Up @@ -104,7 +105,8 @@ export function useFetchStream<B extends object, R extends Reducer<any, any>>(
apiVersion,
abortCtrl,
body,
customReducer !== undefined
customReducer !== undefined,
headers
)) {
if (fetchStreamError !== null) {
addError(fetchStreamError);
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/aiops/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ export const RANDOM_SAMPLER_SEED = 3867412;
export const CASES_ATTACHMENT_CHANGE_POINT_CHART = 'aiopsChangePointChart';

export const EMBEDDABLE_CHANGE_POINT_CHART_TYPE = 'aiopsChangePointChart' as const;

export const AIOPS_TELEMETRY_ID = {
AIOPS_DEFAULT_SOURCE: 'ml_aiops_labs',
AIOPS_ANALYSIS_RUN_ORIGIN: 'aiops-analysis-run-origin',
} as const;
3 changes: 2 additions & 1 deletion x-pack/plugins/aiops/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"unifiedSearch"
],
"optionalPlugins": [
"cases"
"cases",
"usageCollection"
],
"requiredBundles": [
"fieldFormats",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const categorizeFieldAction = (coreStart: CoreStart, plugins: AiopsPlugin
return field.esTypes?.includes('text') === true;
},
execute: async (context: CategorizeFieldContext) => {
const { field, dataView } = context;
showCategorizeFlyout(field, dataView, coreStart, plugins);
const { field, dataView, originatingApp } = context;
showCategorizeFlyout(field, dataView, coreStart, plugins, originatingApp);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Storage } from '@kbn/kibana-utils-plugin/public';
import { DatePickerContextProvider, type DatePickerDependencies } from '@kbn/ml-date-picker';
import { UI_SETTINGS } from '@kbn/data-plugin/common';

import { AIOPS_TELEMETRY_ID } from '../../../common/constants';
import { DataSourceContext } from '../../hooks/use_data_source';
import type { AiopsAppDependencies } from '../../hooks/use_aiops_app_context';
import { AIOPS_STORAGE_KEYS } from '../../types/storage';
Expand Down Expand Up @@ -65,7 +66,7 @@ export const LogCategorizationAppState: FC<LogCategorizationAppStateProps> = ({
<DataSourceContext.Provider value={{ dataView, savedSearch }}>
<StorageContextProvider storage={localStorage} storageKeys={AIOPS_STORAGE_KEYS}>
<DatePickerContextProvider {...datePickerDeps}>
<LogCategorizationPage />
<LogCategorizationPage embeddingOrigin={AIOPS_TELEMETRY_ID.AIOPS_DEFAULT_SOURCE} />
</DatePickerContextProvider>
</StorageContextProvider>
</DataSourceContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { buildEmptyFilter, Filter } from '@kbn/es-query';
import { usePageUrlState } from '@kbn/ml-url-state';
import type { FieldValidationResults } from '@kbn/ml-category-validator';
import { AIOPS_TELEMETRY_ID } from '../../../common/constants';

import type { Category, SparkLinesPerCategory } from '../../../common/api/log_categorization/types';

Expand Down Expand Up @@ -49,6 +50,8 @@ export interface LogCategorizationPageProps {
savedSearch: SavedSearch | null;
selectedField: DataViewField;
onClose: () => void;
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin: string;
}

const BAR_TARGET = 20;
Expand All @@ -58,6 +61,7 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
savedSearch,
selectedField,
onClose,
embeddingOrigin,
}) => {
const {
notifications: { toasts },
Expand Down Expand Up @@ -151,7 +155,8 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
timeField,
earliest,
latest,
searchQuery
searchQuery,
{ [AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin }
),
runCategorizeRequest(
index,
Expand Down Expand Up @@ -193,6 +198,7 @@ export const LogCategorizationFlyout: FC<LogCategorizationPageProps> = ({
runCategorizeRequest,
intervalMs,
toasts,
embeddingOrigin,
]);

const onAddFilter = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { usePageUrlState, useUrlState } from '@kbn/ml-url-state';
import type { FieldValidationResults } from '@kbn/ml-category-validator';
import type { SearchQueryLanguage } from '@kbn/ml-query-utils';
import { AIOPS_TELEMETRY_ID } from '../../../common/constants';

import type { Category, SparkLinesPerCategory } from '../../../common/api/log_categorization/types';

Expand Down Expand Up @@ -53,7 +54,12 @@ import { FieldValidationCallout } from './category_validation_callout';
const BAR_TARGET = 20;
const DEFAULT_SELECTED_FIELD = 'message';

export const LogCategorizationPage: FC = () => {
interface LogCategorizationPageProps {
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin: string;
}

export const LogCategorizationPage: FC<LogCategorizationPageProps> = ({ embeddingOrigin }) => {
const {
notifications: { toasts },
} = useAiopsAppContext();
Expand Down Expand Up @@ -208,7 +214,10 @@ export const LogCategorizationPage: FC = () => {

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

runCategorizeRequest(
index,
selectedField,
Expand Down Expand Up @@ -245,6 +254,7 @@ export const LogCategorizationPage: FC = () => {
runCategorizeRequest,
intervalMs,
toasts,
embeddingOrigin,
]);

useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export async function showCategorizeFlyout(
field: DataViewField,
dataView: DataView,
coreStart: CoreStart,
plugins: AiopsPluginStartDeps
plugins: AiopsPluginStartDeps,
originatingApp: string
): Promise<void> {
const { http, theme, overlays, application, notifications, uiSettings, i18n } = coreStart;

Expand Down Expand Up @@ -70,6 +71,7 @@ export async function showCategorizeFlyout(
savedSearch={null}
selectedField={field}
onClose={onFlyoutClose}
embeddingOrigin={originatingApp}
/>
</StorageContextProvider>
</DatePickerContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/type

import type { FieldValidationResults } from '@kbn/ml-category-validator';

import type { HttpFetchOptions } from '@kbn/core/public';

import { AIOPS_API_ENDPOINT } from '../../../common/api';
import { createCategorizeQuery } from '../../../common/api/log_categorization/create_categorize_query';

Expand All @@ -27,7 +29,8 @@ export function useValidateFieldRequest() {
timeField: string,
start: number | undefined,
end: number | undefined,
queryIn: QueryDslQueryContainer
queryIn: QueryDslQueryContainer,
headers?: HttpFetchOptions['headers']
) => {
const query = createCategorizeQuery(queryIn, timeField, start, end);
const resp = await http.post<FieldValidationResults>(
Expand All @@ -48,6 +51,7 @@ export function useValidateFieldRequest() {
indicesOptions: undefined,
includeExamples: false,
}),
headers,
version: '1',
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export interface LogRateAnalysisContentProps {
barHighlightColorOverride?: string;
/** Optional callback that exposes data of the completed analysis */
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin: string;
}

export const LogRateAnalysisContent: FC<LogRateAnalysisContentProps> = ({
Expand All @@ -76,6 +78,7 @@ export const LogRateAnalysisContent: FC<LogRateAnalysisContentProps> = ({
barColorOverride,
barHighlightColorOverride,
onAnalysisCompleted,
embeddingOrigin,
}) => {
const [windowParameters, setWindowParameters] = useState<WindowParameters | undefined>();
const [initialAnalysisStart, setInitialAnalysisStart] = useState<
Expand Down Expand Up @@ -172,6 +175,7 @@ export const LogRateAnalysisContent: FC<LogRateAnalysisContentProps> = ({
barColorOverride={barColorOverride}
barHighlightColorOverride={barHighlightColorOverride}
onAnalysisCompleted={onAnalysisCompleted}
embeddingOrigin={embeddingOrigin}
/>
)}
{windowParameters === undefined && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export interface LogRateAnalysisContentWrapperProps {
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Optional flag to indicate whether kibana is running in serverless */
showFrozenDataTierChoice?: boolean;
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin: string;
}

export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProps> = ({
Expand All @@ -73,6 +75,7 @@ export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProp
barHighlightColorOverride,
onAnalysisCompleted,
showFrozenDataTierChoice = true,
embeddingOrigin,
}) => {
if (!dataView) return null;

Expand Down Expand Up @@ -105,6 +108,7 @@ export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProp
barColorOverride={barColorOverride}
barHighlightColorOverride={barHighlightColorOverride}
onAnalysisCompleted={onAnalysisCompleted}
embeddingOrigin={embeddingOrigin}
/>
</DatePickerContextProvider>
</StorageContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
getDefaultAiOpsListState,
type AiOpsPageUrlState,
} from '../../application/utils/url_state';
import { AIOPS_TELEMETRY_ID } from '../../../common/constants';

import { SearchPanel } from '../search_panel';
import { useLogRateAnalysisResultsTableRowContext } from '../log_rate_analysis_results_table/log_rate_analysis_results_table_row_provider';
Expand Down Expand Up @@ -151,6 +152,7 @@ export const LogRateAnalysisPage: FC<Props> = ({ stickyHistogram }) => {
setGlobalState={setGlobalState}
esSearchQuery={searchQuery}
stickyHistogram={stickyHistogram}
embeddingOrigin={AIOPS_TELEMETRY_ID.AIOPS_DEFAULT_SOURCE}
/>
</EuiFlexGroup>
</EuiPageSection>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import type { SignificantTerm, SignificantTermGroup } from '@kbn/ml-agg-utils';
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import { initialState, streamReducer } from '../../../common/api/stream_reducer';
import type { AiopsApiLogRateAnalysis } from '../../../common/api';
import { AIOPS_TELEMETRY_ID } from '../../../common/constants';
import {
getGroupTableItems,
LogRateAnalysisResultsTable,
Expand Down Expand Up @@ -113,6 +114,8 @@ interface LogRateAnalysisResultsProps {
barHighlightColorOverride?: string;
/** Optional callback that exposes data of the completed analysis */
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Identifier to indicate the plugin utilizing the component */
embeddingOrigin: string;
}

export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
Expand All @@ -129,6 +132,7 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
barColorOverride,
barHighlightColorOverride,
onAnalysisCompleted,
embeddingOrigin,
}) => {
const { http } = useAiopsAppContext();

Expand Down Expand Up @@ -198,7 +202,8 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
overrides,
sampleProbability,
},
{ reducer: streamReducer, initialState }
{ reducer: streamReducer, initialState },
{ [AIOPS_TELEMETRY_ID.AIOPS_ANALYSIS_RUN_ORIGIN]: embeddingOrigin }
);

const { significantTerms } = data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { EuiLoadingChart } from '@elastic/eui';
import { EMBEDDABLE_CHANGE_POINT_CHART_TYPE } from '../../common/constants';
import type { AiopsPluginStartDeps } from '../types';
import type { EmbeddableChangePointChartInput } from './embeddable_change_point_chart';
import type { ChangePointAnnotation } from '../components/change_point_detection/change_point_detection_context';

export interface EmbeddableChangePointChartProps {
dataViewId: string;
Expand All @@ -27,6 +28,18 @@ export interface EmbeddableChangePointChartProps {
splitField?: string;
partitions?: string[];
maxSeriesToPlot?: number;
/**
* Component to render if there are no change points found
*/
emptyState?: React.ReactElement;
/**
* Outputs the most recent change point data
*/
onChange?: (changePointData: ChangePointAnnotation[]) => void;
/**
* Last reload request time, can be used for manual reload
*/
lastReloadRequestTime?: number;
}

export function getEmbeddableChangePointChart(core: CoreStart, plugins: AiopsPluginStartDeps) {
Expand Down
Loading

0 comments on commit 8e5ccbb

Please sign in to comment.