[Metrics UI] Fix passing space ID into anomaly alerts (#91222)
* [Metrics UI] Fix passing space ID into anomaly alerts * Fix jest
This commit is contained in:
parent
7a5526768c
commit
7537326aca
|
@ -51,6 +51,7 @@ export interface MetricAnomalyParams {
|
|||
metric: rt.TypeOf<typeof metricAnomalyMetricRT>;
|
||||
alertInterval?: string;
|
||||
sourceId?: string;
|
||||
spaceId?: string;
|
||||
threshold: Exclude<ANOMALY_THRESHOLD, ANOMALY_THRESHOLD.LOW>;
|
||||
influencerFilter: rt.TypeOf<typeof metricAnomalyInfluencerFilterRT> | undefined;
|
||||
}
|
||||
|
@ -112,6 +113,7 @@ const metricAnomalyAlertPreviewRequestParamsRT = rt.intersection([
|
|||
metric: metricAnomalyMetricRT,
|
||||
threshold: rt.number,
|
||||
alertType: rt.literal(METRIC_ANOMALY_ALERT_TYPE_ID),
|
||||
spaceId: rt.string,
|
||||
}),
|
||||
rt.partial({
|
||||
influencerFilter: metricAnomalyInfluencerFilterRT,
|
||||
|
|
|
@ -25,6 +25,12 @@ jest.mock('../../../hooks/use_kibana', () => ({
|
|||
}),
|
||||
}));
|
||||
|
||||
jest.mock('../../../hooks/use_kibana_space', () => ({
|
||||
useActiveKibanaSpace: () => ({
|
||||
space: { id: 'default' },
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('../../../containers/ml/infra_ml_capabilities', () => ({
|
||||
useInfraMLCapabilities: () => ({
|
||||
isLoading: false,
|
||||
|
|
|
@ -38,6 +38,7 @@ import { ANOMALY_THRESHOLD } from '../../../../common/infra_ml';
|
|||
import { validateMetricAnomaly } from './validation';
|
||||
import { InfluencerFilter } from './influencer_filter';
|
||||
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
|
||||
import { useActiveKibanaSpace } from '../../../hooks/use_kibana_space';
|
||||
|
||||
export interface AlertContextMeta {
|
||||
metric?: InfraWaffleMapOptions['metric'];
|
||||
|
@ -45,7 +46,7 @@ export interface AlertContextMeta {
|
|||
}
|
||||
|
||||
type AlertParams = AlertTypeParams &
|
||||
MetricAnomalyParams & { sourceId: string; hasInfraMLCapabilities: boolean };
|
||||
MetricAnomalyParams & { sourceId: string; spaceId: string; hasInfraMLCapabilities: boolean };
|
||||
|
||||
type Props = Omit<
|
||||
AlertTypeParamsExpressionProps<AlertParams, AlertContextMeta>,
|
||||
|
@ -62,6 +63,8 @@ export const defaultExpression = {
|
|||
export const Expression: React.FC<Props> = (props) => {
|
||||
const { hasInfraMLCapabilities, isLoading: isLoadingMLCapabilities } = useInfraMLCapabilities();
|
||||
const { http, notifications } = useKibanaContextForPlugin().services;
|
||||
const { space } = useActiveKibanaSpace();
|
||||
|
||||
const {
|
||||
setAlertParams,
|
||||
alertParams,
|
||||
|
@ -176,7 +179,11 @@ export const Expression: React.FC<Props> = (props) => {
|
|||
if (!alertParams.sourceId) {
|
||||
setAlertParams('sourceId', source?.id || 'default');
|
||||
}
|
||||
}, [metadata, derivedIndexPattern, defaultExpression, source]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
if (!alertParams.spaceId) {
|
||||
setAlertParams('spaceId', space?.id || 'default');
|
||||
}
|
||||
}, [metadata, derivedIndexPattern, defaultExpression, source, space]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
if (isLoadingMLCapabilities) return <EuiLoadingContent lines={10} />;
|
||||
if (!hasInfraMLCapabilities) return <SubscriptionSplashContent />;
|
||||
|
@ -263,6 +270,7 @@ export const Expression: React.FC<Props> = (props) => {
|
|||
'threshold',
|
||||
'nodeType',
|
||||
'sourceId',
|
||||
'spaceId',
|
||||
'influencerFilter'
|
||||
)}
|
||||
validate={validateMetricAnomaly}
|
||||
|
|
|
@ -51,6 +51,7 @@ export const createMetricAnomalyExecutor = (libs: InfraBackendLibs, ml?: MlPlugi
|
|||
alertInterval,
|
||||
influencerFilter,
|
||||
sourceId,
|
||||
spaceId,
|
||||
nodeType,
|
||||
threshold,
|
||||
} = params as MetricAnomalyParams;
|
||||
|
@ -67,7 +68,7 @@ export const createMetricAnomalyExecutor = (libs: InfraBackendLibs, ml?: MlPlugi
|
|||
|
||||
const { data } = await evaluateCondition({
|
||||
sourceId: sourceId ?? 'default',
|
||||
spaceId: 'default',
|
||||
spaceId: spaceId ?? 'default',
|
||||
mlSystem,
|
||||
mlAnomalyDetectors,
|
||||
startTime,
|
||||
|
|
|
@ -51,6 +51,7 @@ export const registerMetricAnomalyAlertType = (
|
|||
schema.string({ validate: validateIsStringElasticsearchJSONFilter })
|
||||
),
|
||||
sourceId: schema.string(),
|
||||
spaceId: schema.string(),
|
||||
},
|
||||
{ unknowns: 'allow' }
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue