From c262c6ac2db79c80e49af17730614687d27a08a3 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Thu, 1 Oct 2020 09:22:38 -0400 Subject: [PATCH] PR feedback --- .../alerts/missing_monitoring_data_alert.ts | 76 ++----------------- .../fetch_missing_monitoring_data.test.ts | 20 ++++- .../alerts/fetch_missing_monitoring_data.ts | 1 - 3 files changed, 25 insertions(+), 72 deletions(-) diff --git a/x-pack/plugins/monitoring/server/alerts/missing_monitoring_data_alert.ts b/x-pack/plugins/monitoring/server/alerts/missing_monitoring_data_alert.ts index d9c1f38210b96..6017314f332e6 100644 --- a/x-pack/plugins/monitoring/server/alerts/missing_monitoring_data_alert.ts +++ b/x-pack/plugins/monitoring/server/alerts/missing_monitoring_data_alert.ts @@ -16,7 +16,6 @@ import { AlertMissingData, AlertMessageTimeToken, AlertInstanceState, - AlertMessageLinkToken, } from './types'; import { AlertInstance, AlertServices } from '../../../alerts/server'; import { @@ -42,6 +41,7 @@ import { getListingLinkForStackProduct } from '../lib/alerts/get_listing_link_fo import { getStackProductLabel } from '../lib/alerts/get_stack_product_label'; import { fetchClusters } from '../lib/alerts/fetch_clusters'; import { fetchAvailableCcs } from '../lib/alerts/fetch_available_ccs'; +import { AlertingDefaults, createLink } from './alerts_common'; const RESOLVED = i18n.translate('xpack.monitoring.alerts.missingData.resolved', { defaultMessage: 'resolved', @@ -88,30 +88,6 @@ export class MissingMonitoringDataAlert extends BaseAlert { }; protected actionVariables = [ - { - name: 'internalShortMessage', - description: i18n.translate( - 'xpack.monitoring.alerts.missingData.actionVariables.internalShortMessage', - { - defaultMessage: 'The short internal message generated by Elastic.', - } - ), - }, - { - name: 'internalFullMessage', - description: i18n.translate( - 'xpack.monitoring.alerts.missingData.actionVariables.internalFullMessage', - { - defaultMessage: 'The full internal message generated by Elastic.', - } - ), - }, - { - name: 'state', - description: i18n.translate('xpack.monitoring.alerts.missingData.actionVariables.state', { - defaultMessage: 'The current state of the alert.', - }), - }, { name: 'stackProducts', description: i18n.translate( @@ -127,30 +103,7 @@ export class MissingMonitoringDataAlert extends BaseAlert { defaultMessage: 'The number of stack products missing monitoring data.', }), }, - { - name: 'clusterName', - description: i18n.translate( - 'xpack.monitoring.alerts.missingData.actionVariables.clusterName', - { - defaultMessage: 'The cluster to which the stack products belong.', - } - ), - }, - { - name: 'action', - description: i18n.translate('xpack.monitoring.alerts.missingData.actionVariables.action', { - defaultMessage: 'The recommended action for this alert.', - }), - }, - { - name: 'actionPlain', - description: i18n.translate( - 'xpack.monitoring.alerts.missingData.actionVariables.actionPlain', - { - defaultMessage: 'The recommended action for this alert, without any markdown.', - } - ), - }, + ...Object.values(AlertingDefaults.ALERT_TYPE.context), ]; protected async fetchClusters( @@ -197,7 +150,6 @@ export class MissingMonitoringDataAlert extends BaseAlert { callCluster, clusters, indexPattern, - limit, this.config.ui.max_bucket_size, now, now - limit - LIMIT_BUFFER @@ -271,10 +223,6 @@ export class MissingMonitoringDataAlert extends BaseAlert { protected getUiMessage(alertState: AlertState, item: AlertData): AlertMessage { const { missing, limit } = item.meta as { missing: AlertMissingData; limit: number }; - const globalState = [`cluster_uuid:${item.clusterUuid}`]; - if (item.ccs) { - globalState.push(`ccs:${item.ccs}`); - } if (!alertState.ui.isFiring) { if (missing.gapDuration > limit) { return { @@ -319,27 +267,19 @@ export class MissingMonitoringDataAlert extends BaseAlert { }, }), nextSteps: [ - { - text: i18n.translate('xpack.monitoring.alerts.missingData.ui.nextSteps.hotThreads', { + createLink( + i18n.translate('xpack.monitoring.alerts.missingData.ui.nextSteps.viewAll', { defaultMessage: `#start_linkView all {stackProduct} {type}#end_link`, values: { type: getTypeLabelForStackProduct(missing.stackProduct), stackProduct: getStackProductLabel(missing.stackProduct), }, }), - tokens: [ - { - startToken: '#start_link', - endToken: '#end_link', - type: AlertMessageTokenType.Link, - url: `${getListingLinkForStackProduct(missing.stackProduct)}?_g=(${globalState.join( - ',' - )})`, - } as AlertMessageLinkToken, - ], - }, + getListingLinkForStackProduct(missing.stackProduct), + AlertMessageTokenType.Link + ), { - text: i18n.translate('xpack.monitoring.alerts.missingData.ui.nextSteps.runningTasks', { + text: i18n.translate('xpack.monitoring.alerts.missingData.ui.nextSteps.verifySettings', { defaultMessage: `Verify monitoring settings on the {type}`, values: { type: getTypeLabelForStackProduct(missing.stackProduct, false), diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts index 750ec33d028cf..b09f5a88dba9c 100644 --- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts +++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts @@ -38,7 +38,7 @@ function getResponse( describe('fetchMissingMonitoringData', () => { let callCluster = jest.fn(); const index = '.monitoring-*'; - const limit = 100; + const startMs = 100; const size = 10; it('fetch as expected', async () => { @@ -137,7 +137,14 @@ describe('fetchMissingMonitoringData', () => { }, }; }); - const result = await fetchMissingMonitoringData(callCluster, clusters, index, limit, size, now); + const result = await fetchMissingMonitoringData( + callCluster, + clusters, + index, + size, + now, + startMs + ); expect(result).toEqual([ { stackProduct: 'elasticsearch', @@ -220,7 +227,14 @@ describe('fetchMissingMonitoringData', () => { }, }; }); - const result = await fetchMissingMonitoringData(callCluster, clusters, index, limit, size, now); + const result = await fetchMissingMonitoringData( + callCluster, + clusters, + index, + size, + now, + startMs + ); expect(result).toEqual([ { stackProduct: 'elasticsearch', diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.ts index ee7297b1e5a77..91fc05137a8c1 100644 --- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.ts +++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.ts @@ -90,7 +90,6 @@ export async function fetchMissingMonitoringData( callCluster: any, clusters: AlertCluster[], index: string, - limit: number, size: number, nowInMs: number, startMs: number