"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigValidator = void 0; var _react = _interopRequireDefault(require("react")); var _i18nReact = require("@kbn/i18n-react"); var _eui = require("@elastic/eui"); var _parse_interval = require("../../common/util/parse_interval"); var _states = require("../../common/constants/states"); var _alerts = require("../../common/constants/alerts"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ /** * Validated alert configuration */ const ConfigValidator = /*#__PURE__*/_react.default.memo(({ jobConfigs = [], alertInterval, alertParams, alertNotifyWhen, maxNumberOfBuckets }) => { var _parseInterval, _alertParams$topNBuck; if (jobConfigs.length === 0) return null; const alertIntervalInSeconds = (0, _parse_interval.parseInterval)(alertInterval).asSeconds(); const lookbackIntervalInSeconds = !!alertParams.lookbackInterval && ((_parseInterval = (0, _parse_interval.parseInterval)(alertParams.lookbackInterval)) === null || _parseInterval === void 0 ? void 0 : _parseInterval.asSeconds()); const isAlertIntervalTooHigh = lookbackIntervalInSeconds && lookbackIntervalInSeconds < alertIntervalInSeconds; const jobWithoutStartedDatafeed = jobConfigs.filter(job => job.datafeed_config.state !== _states.DATAFEED_STATE.STARTED).map(job => job.job_id); const configContainsIssues = isAlertIntervalTooHigh || jobWithoutStartedDatafeed.length > 0; const notifyWhenWarning = alertNotifyWhen === 'onActiveAlert' && lookbackIntervalInSeconds && alertIntervalInSeconds < lookbackIntervalInSeconds; const bucketSpanDuration = (0, _parse_interval.parseInterval)(jobConfigs[0].analysis_config.bucket_span); const notificationDuration = bucketSpanDuration ? Math.ceil(bucketSpanDuration.asMinutes()) * Math.min((_alertParams$topNBuck = alertParams.topNBuckets) !== null && _alertParams$topNBuck !== void 0 ? _alertParams$topNBuck : _alerts.TOP_N_BUCKETS_COUNT, maxNumberOfBuckets !== null && maxNumberOfBuckets !== void 0 ? maxNumberOfBuckets : _alerts.TOP_N_BUCKETS_COUNT) : undefined; return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, { size: 'm' }), configContainsIssues ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiCallOut, { title: /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.ml.alertConditionValidation.title", defaultMessage: "Alert condition contains the following issues:" }), color: "warning", size: 's' }, /*#__PURE__*/_react.default.createElement("ul", null, isAlertIntervalTooHigh ? /*#__PURE__*/_react.default.createElement("li", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.ml.alertConditionValidation.alertIntervalTooHighMessage", defaultMessage: "The check interval is greater than the lookback interval. Reduce it to {lookbackInterval} to avoid potentially missing notifications.", values: { lookbackInterval: alertParams.lookbackInterval } })) : null, jobWithoutStartedDatafeed.length > 0 ? /*#__PURE__*/_react.default.createElement("li", null, /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.ml.alertConditionValidation.stoppedDatafeedJobsMessage", defaultMessage: "The datafeed is not started for the following {count, plural, one {job} other {jobs}}: {jobIds}.", values: { count: jobWithoutStartedDatafeed.length, jobIds: jobWithoutStartedDatafeed.join(', ') } })) : null)), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, { size: 'm' })) : null, notifyWhenWarning ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_eui.EuiCallOut, { title: /*#__PURE__*/_react.default.createElement(_i18nReact.FormattedMessage, { id: "xpack.ml.alertConditionValidation.notifyWhenWarning", defaultMessage: "Expect to receive duplicate notifications about the same anomaly for up to {notificationDuration, plural, one {# minute} other {# minutes}}. Increase the check interval or switch to notify only on status change to avoid duplicate notifications.", values: { notificationDuration } }), color: "warning", size: 's' }), /*#__PURE__*/_react.default.createElement(_eui.EuiSpacer, { size: 'm' })) : null); }); exports.ConfigValidator = ConfigValidator;