Skip to content

Commit

Permalink
disable errorMessages check
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 1, 2023
1 parent 93dd0e7 commit 18bb3d5
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 33 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/transform/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/transform/common/types/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/transform/common/utils/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export function getTransformHealthRuleType(): RuleTypeModel<TransformHealthRuleP
Transform ID: \\{\\{transform_id\\}\\}
\\{\\{#description\\}\\}Transform description: \\{\\{description\\}\\}
\\{\\{/description\\}\\}\\{\\{#transform_state\\}\\}Transform state: \\{\\{transform_state\\}\\}
\\{\\{/transform_state\\}\\}\\{\\{#failure_reason\\}\\}Failure reason: \\{\\{failure_reason\\}\\}
\\{\\{/transform_state\\}\\}\\{\\{#health\\}\\}Transform health: \\{\\{health\\}\\}
\\{\\{/health\\}\\}\\{\\{#failure_reason\\}\\}Failure reason: \\{\\{failure_reason\\}\\}
\\{\\{/failure_reason\\}\\}\\{\\{#notification_message\\}\\}Notification message: \\{\\{notification_message\\}\\}
\\{\\{/notification_message\\}\\}\\{\\{#node_name\\}\\}Node name: \\{\\{node_name\\}\\}
\\{\\{/node_name\\}\\}\\{\\{#timestamp\\}\\}Timestamp: \\{\\{timestamp\\}\\}
\\{\\{/timestamp\\}\\}\\{\\{#error_messages\\}\\}Error message: \\{\\{message\\}\\}
\\{\\{/error_messages\\}\\}
\\{\\{/context.results\\}\\}
`,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FC, useCallback } from 'react';
import React, { FC, useCallback, useMemo } from 'react';
import { EuiDescribedFormGroup, EuiForm, EuiFormRow, EuiSpacer, EuiSwitch } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

Expand All @@ -22,10 +22,19 @@ interface TestsSelectionControlProps {
errors?: string[];
}

const disabledChecks = new Set<keyof Exclude<TransformHealthRuleTestsConfig, null | undefined>>([
'errorMessages',
]);

export const TestsSelectionControl: FC<TestsSelectionControlProps> = 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<Exclude<TransformHealthRuleTestsConfig, undefined>>) => {
onChange({
Expand All @@ -43,35 +52,37 @@ export const TestsSelectionControl: FC<TestsSelectionControlProps> = React.memo(
Object.entries(uiConfig) as Array<
[TransformHealthTests, typeof uiConfig[TransformHealthTests]]
>
).map(([name, conf], i) => {
return (
<EuiDescribedFormGroup
key={name}
title={<h4>{TRANSFORM_HEALTH_CHECK_NAMES[name]?.name}</h4>}
description={TRANSFORM_HEALTH_CHECK_NAMES[name]?.description}
fullWidth
gutterSize={'s'}
>
<EuiFormRow>
<EuiSwitch
label={
<FormattedMessage
id="xpack.transform.alertTypes.transformHealth.testsSelection.enableTestLabel"
defaultMessage="Enable"
/>
}
onChange={updateCallback.bind(null, {
[name]: {
...uiConfig[name],
enabled: !uiConfig[name].enabled,
},
})}
checked={uiConfig[name].enabled}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
);
})}
)
.filter(([name]) => !disabledChecks.has(name) || initConfig[name].enabled)
.map(([name, conf], i) => {
return (
<EuiDescribedFormGroup
key={name}
title={<h4>{TRANSFORM_HEALTH_CHECK_NAMES[name]?.name}</h4>}
description={TRANSFORM_HEALTH_CHECK_NAMES[name]?.description}
fullWidth
gutterSize={'s'}
>
<EuiFormRow>
<EuiSwitch
label={
<FormattedMessage
id="xpack.transform.alertTypes.transformHealth.testsSelection.enableTestLabel"
defaultMessage="Enable"
/>
}
onChange={updateCallback.bind(null, {
[name]: {
...uiConfig[name],
enabled: !uiConfig[name].enabled,
},
})}
checked={uiConfig[name].enabled}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
);
})}
</EuiForm>
<EuiSpacer size="l" />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

Expand Down

0 comments on commit 18bb3d5

Please sign in to comment.