diff --git a/x-pack/plugins/transform/common/constants.ts b/x-pack/plugins/transform/common/constants.ts index 3bf8d5c97cc07..0e8eb21c063bf 100644 --- a/x-pack/plugins/transform/common/constants.ts +++ b/x-pack/plugins/transform/common/constants.ts @@ -190,6 +190,17 @@ export const TRANSFORM_HEALTH_CHECK_NAMES: Record< } ), }, + healthCheck: { + name: i18n.translate('xpack.transform.alertTypes.transformHealth.healthCheckName', { + defaultMessage: 'Unhealthy transforms', + }), + description: i18n.translate( + 'xpack.transform.alertTypes.transformHealth.healthCheckDescription', + { + defaultMessage: 'Get alerts if a transform health status is not green.', + } + ), + }, }; // Transform API default values https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html diff --git a/x-pack/plugins/transform/common/types/alerting.ts b/x-pack/plugins/transform/common/types/alerting.ts index aa08db9a8ce13..4e4d5a7407c5f 100644 --- a/x-pack/plugins/transform/common/types/alerting.ts +++ b/x-pack/plugins/transform/common/types/alerting.ts @@ -14,9 +14,15 @@ export type TransformHealthRuleParams = { notStarted?: { enabled: boolean; } | null; + /** + * @deprecated replaced in favor of healthCheck in 8.8 + */ errorMessages?: { enabled: boolean; } | null; + healthCheck?: { + enabled: boolean; + } | null; } | null; } & RuleTypeParams; diff --git a/x-pack/plugins/transform/common/utils/alerts.ts b/x-pack/plugins/transform/common/utils/alerts.ts index 88c6fc64a35b2..1a4947db6ae2e 100644 --- a/x-pack/plugins/transform/common/utils/alerts.ts +++ b/x-pack/plugins/transform/common/utils/alerts.ts @@ -13,7 +13,10 @@ export function getResultTestConfig(config: TransformHealthRuleTestsConfig) { enabled: config?.notStarted?.enabled ?? true, }, errorMessages: { - enabled: config?.errorMessages?.enabled ?? true, + enabled: config?.errorMessages?.enabled ?? false, + }, + healthCheck: { + enabled: config?.healthCheck?.enabled ?? true, }, }; } diff --git a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts index dfbe7e3154bf1..47428c070cda6 100644 --- a/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts +++ b/x-pack/plugins/transform/public/alerting/transform_health_rule_type/register_transform_health_rule.ts @@ -67,13 +67,13 @@ export function getTransformHealthRuleType(): RuleTypeModel>([ + 'errorMessages', +]); + export const TestsSelectionControl: FC = React.memo( ({ config, onChange, errors }) => { const uiConfig = getResultTestConfig(config); + const initConfig = useMemo(() => { + return uiConfig; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + const updateCallback = useCallback( (update: Partial>) => { onChange({ @@ -43,35 +52,37 @@ export const TestsSelectionControl: FC = React.memo( Object.entries(uiConfig) as Array< [TransformHealthTests, typeof uiConfig[TransformHealthTests]] > - ).map(([name, conf], i) => { - return ( - {TRANSFORM_HEALTH_CHECK_NAMES[name]?.name}} - description={TRANSFORM_HEALTH_CHECK_NAMES[name]?.description} - fullWidth - gutterSize={'s'} - > - - - } - onChange={updateCallback.bind(null, { - [name]: { - ...uiConfig[name], - enabled: !uiConfig[name].enabled, - }, - })} - checked={uiConfig[name].enabled} - /> - - - ); - })} + ) + .filter(([name]) => !disabledChecks.has(name) || initConfig[name].enabled) + .map(([name, conf], i) => { + return ( + {TRANSFORM_HEALTH_CHECK_NAMES[name]?.name}} + description={TRANSFORM_HEALTH_CHECK_NAMES[name]?.description} + fullWidth + gutterSize={'s'} + > + + + } + onChange={updateCallback.bind(null, { + [name]: { + ...uiConfig[name], + enabled: !uiConfig[name].enabled, + }, + })} + checked={uiConfig[name].enabled} + /> + + + ); + })} diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts index e98d6edd294ac..5c487927c8461 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/schema.ts @@ -18,6 +18,11 @@ export const transformHealthRuleParams = schema.object({ }) ), errorMessages: schema.nullable( + schema.object({ + enabled: schema.boolean({ defaultValue: false }), + }) + ), + healthCheck: schema.nullable( schema.object({ enabled: schema.boolean({ defaultValue: true }), }) diff --git a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts index bdb2d6f1a68df..56963d717f164 100644 --- a/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts +++ b/x-pack/plugins/transform/server/lib/alerting/transform_health_rule_type/transform_health_service.ts @@ -309,6 +309,34 @@ export function transformHealthServiceProvider( }); } + if (testsConfig.healthCheck.enabled) { + const response = await this.getUnhealthyTransformsReport(transformIds); + const isHealthy = response.length === 0; + const count = response.length; + const transformsString = response.map((t) => t.transform_id).join(', '); + result.push({ + isHealthy, + name: TRANSFORM_HEALTH_CHECK_NAMES.healthCheck.name, + context: { + results: isHealthy ? [] : response, + message: isHealthy + ? i18n.translate( + 'xpack.transform.alertTypes.transformHealth.healthCheckRecoveryMessage', + { + defaultMessage: + '{count, plural, one {Transform} other {Transforms}} {transformsString} {count, plural, one {is} other {are}} healthy.', + values: { count, transformsString }, + } + ) + : i18n.translate('xpack.transform.alertTypes.transformHealth.healthCheckMessage', { + defaultMessage: + '{count, plural, one {Transform} other {Transforms}} {transformsString} {count, plural, one {is} other {are}} unhealthy.', + values: { count, transformsString }, + }), + }, + }); + } + return result; },