From add24ff595dd696506ce6906f54aec1df53d542c Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Fri, 4 Sep 2020 10:01:16 -0400 Subject: [PATCH] Addressed code feedback --- .../monitoring/server/alerts/alerts_common.ts | 18 +++++++ .../server/alerts/disk_usage_alert.ts | 54 +++++++++---------- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/x-pack/plugins/monitoring/server/alerts/alerts_common.ts b/x-pack/plugins/monitoring/server/alerts/alerts_common.ts index 538f5a4a041b4..c284f9108bac3 100644 --- a/x-pack/plugins/monitoring/server/alerts/alerts_common.ts +++ b/x-pack/plugins/monitoring/server/alerts/alerts_common.ts @@ -5,6 +5,8 @@ */ import { i18n } from '@kbn/i18n'; +import { AlertMessageDocLinkToken } from './types'; +import { AlertMessageTokenType } from '../../common/enums'; export class AlertingDefaults { public static readonly ALERT_STATE = { @@ -59,3 +61,19 @@ export class AlertingDefaults { }, }; } + +export const createDocLink = (translateStr: string, linkText: string, linkURL: string) => { + return { + text: i18n.translate(translateStr, { + defaultMessage: `#start_link${linkText}#end_link`, + }), + tokens: [ + { + startToken: '#start_link', + endToken: '#end_link', + type: AlertMessageTokenType.DocLink, + partialUrl: linkURL, + } as AlertMessageDocLinkToken, + ], + }; +}; diff --git a/x-pack/plugins/monitoring/server/alerts/disk_usage_alert.ts b/x-pack/plugins/monitoring/server/alerts/disk_usage_alert.ts index 64d985bf1e1c8..889f2e4ba3167 100644 --- a/x-pack/plugins/monitoring/server/alerts/disk_usage_alert.ts +++ b/x-pack/plugins/monitoring/server/alerts/disk_usage_alert.ts @@ -24,7 +24,7 @@ import { getCcsIndexPattern } from '../lib/alerts/get_ccs_index_pattern'; import { AlertMessageTokenType, AlertSeverity, AlertParamType } from '../../common/enums'; import { RawAlertInstance } from '../../../alerts/common'; import { CommonAlertFilter, CommonAlertParams, CommonAlertParamDetail } from '../../common/types'; -import { AlertingDefaults } from './alerts_common'; +import { AlertingDefaults, createDocLink } from './alerts_common'; interface ParamDetails { [key: string]: CommonAlertParamDetail; @@ -110,7 +110,7 @@ export class DiskUsageAlert extends BaseAlert { protected filterAlertInstance(alertInstance: RawAlertInstance, filters: CommonAlertFilter[]) { const alertInstanceStates = alertInstance.state?.alertStates as AlertDiskUsageState[]; - const nodeUuid = filters.find((filter) => filter.nodeUuid); + const nodeUuid = filters?.find((filter) => filter.nodeUuid); if (!filters || !filters.length || !alertInstanceStates?.length || !nodeUuid) { return true; @@ -153,36 +153,30 @@ export class DiskUsageAlert extends BaseAlert { defaultMessage: `Node #start_link{nodeName}#end_link is reporting disk usage of {diskUsage}% at #absolute`, values: { nodeName: stat.nodeName, - diskUsage: stat.diskUsage.toFixed(2), + diskUsage: stat.diskUsage, }, }), nextSteps: [ - { - text: i18n.translate('xpack.monitoring.alerts.diskUsage.ui.nextSteps.hotThreads', { - defaultMessage: `#start_linkCheck hot threads#end_link`, - }), - tokens: [ - { - startToken: '#start_link', - endToken: '#end_link', - type: AlertMessageTokenType.DocLink, - partialUrl: `{elasticWebsiteUrl}/guide/en/elasticsearch/reference/{docLinkVersion}/cluster-nodes-hot-threads.html`, - } as AlertMessageDocLinkToken, - ], - }, - { - text: i18n.translate('xpack.monitoring.alerts.diskUsage.ui.nextSteps.runningTasks', { - defaultMessage: `#start_linkCheck long running tasks#end_link`, - }), - tokens: [ - { - startToken: '#start_link', - endToken: '#end_link', - type: AlertMessageTokenType.DocLink, - partialUrl: `{elasticWebsiteUrl}/guide/en/elasticsearch/reference/{docLinkVersion}/tasks.html`, - } as AlertMessageDocLinkToken, - ], - }, + createDocLink( + 'xpack.monitoring.alerts.diskUsage.ui.nextSteps.tuneDisk', + 'Tune for disk usage', + `{elasticWebsiteUrl}/guide/en/elasticsearch/reference/{docLinkVersion}/tune-for-disk-usage.html` + ), + createDocLink( + 'xpack.monitoring.alerts.diskUsage.ui.nextSteps.ilmPolicies', + 'Implement ILM policies', + `{elasticWebsiteUrl}/guide/en/elasticsearch/reference/{docLinkVersion}/index-lifecycle-management.html` + ), + createDocLink( + 'xpack.monitoring.alerts.diskUsage.ui.nextSteps.addMoreNodes', + 'Add more data nodes', + `{elasticWebsiteUrl}/guide/en/elasticsearch/reference/{docLinkVersion}/add-elasticsearch-nodes.html` + ), + createDocLink( + 'xpack.monitoring.alerts.diskUsage.ui.nextSteps.resizeYourDeployment', + 'Resize your deployment (ECE)', + `{elasticWebsiteUrl}/guide/en/cloud-enterprise/{docLinkVersion}/ece-resize-deployment.html` + ), ], tokens: [ { @@ -354,7 +348,7 @@ export class DiskUsageAlert extends BaseAlert { if (indexInState < 0) { alertInstanceState.alertStates.push(nodeState); } else { - alertInstanceState.alertStates.splice(indexInState, 0, nodeState); + alertInstanceState.alertStates[indexInState] = nodeState; } }