Skip to content

Commit

Permalink
Addressed code feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Sep 4, 2020
1 parent 6f3e35f commit add24ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 30 deletions.
18 changes: 18 additions & 0 deletions x-pack/plugins/monitoring/server/alerts/alerts_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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,
],
};
};
54 changes: 24 additions & 30 deletions x-pack/plugins/monitoring/server/alerts/disk_usage_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit add24ff

Please sign in to comment.