@oneuptime/common 14.0.94 → 14.0.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Models/AnalyticsModels/ExceptionInstance.d.mts +2 -0
- package/Models/AnalyticsModels/ExceptionInstance.d.ts +2 -0
- package/Models/AnalyticsModels/ExceptionInstance.js +7 -0
- package/Models/AnalyticsModels/Log.d.mts +2 -0
- package/Models/AnalyticsModels/Log.d.ts +2 -0
- package/Models/AnalyticsModels/Log.js +7 -0
- package/Models/AnalyticsModels/SecurityEvent.d.mts +8 -0
- package/Models/AnalyticsModels/SecurityEvent.d.ts +8 -0
- package/Models/AnalyticsModels/SecurityEvent.js +55 -0
- package/Models/AnalyticsModels/Span.d.mts +4 -0
- package/Models/AnalyticsModels/Span.d.ts +4 -0
- package/Models/AnalyticsModels/Span.js +63 -0
- package/Models/DatabaseModels/CustomNotificationChannel.d.mts +16 -0
- package/Models/DatabaseModels/CustomNotificationChannel.d.ts +16 -0
- package/Models/DatabaseModels/CustomNotificationChannel.js +337 -0
- package/Models/DatabaseModels/CustomNotificationChannel.mjs +2 -0
- package/Models/DatabaseModels/DashboardPlaylist.d.mts +16 -0
- package/Models/DatabaseModels/DashboardPlaylist.d.ts +16 -0
- package/Models/DatabaseModels/DashboardPlaylist.js +314 -0
- package/Models/DatabaseModels/DashboardPlaylist.mjs +2 -0
- package/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel.js +14 -37
- package/Models/DatabaseModels/DatabaseBaseModel/OnCallRuleBaseModel.d.mts +1 -0
- package/Models/DatabaseModels/DatabaseBaseModel/OnCallRuleBaseModel.d.ts +1 -0
- package/Models/DatabaseModels/DatabaseBaseModel/OnCallRuleBaseModel.js +27 -3
- package/Models/DatabaseModels/DetectionRuleException.d.mts +25 -0
- package/Models/DatabaseModels/DetectionRuleException.d.ts +25 -0
- package/Models/DatabaseModels/DetectionRuleException.js +412 -0
- package/Models/DatabaseModels/DetectionRuleException.mjs +2 -0
- package/Models/DatabaseModels/GlobalConfig.d.mts +5 -0
- package/Models/DatabaseModels/GlobalConfig.d.ts +5 -0
- package/Models/DatabaseModels/GlobalConfig.js +107 -0
- package/Models/DatabaseModels/Index.js +8 -0
- package/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.d.mts +2 -0
- package/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.d.ts +2 -0
- package/Models/DatabaseModels/OnCallDutyPolicyExecutionLog.js +40 -0
- package/Models/DatabaseModels/SecurityTelemetrySource.d.mts +21 -0
- package/Models/DatabaseModels/SecurityTelemetrySource.d.ts +21 -0
- package/Models/DatabaseModels/SecurityTelemetrySource.js +357 -0
- package/Models/DatabaseModels/SecurityTelemetrySource.mjs +2 -0
- package/Models/DatabaseModels/TeamComplianceSetting.js +2 -2
- package/Models/DatabaseModels/TeamPermission.js +5 -7
- package/Models/DatabaseModels/UserNotificationRule.d.mts +3 -0
- package/Models/DatabaseModels/UserNotificationRule.d.ts +3 -0
- package/Models/DatabaseModels/UserNotificationRule.js +67 -0
- package/Models/DatabaseModels/UserNotificationSetting.d.mts +1 -0
- package/Models/DatabaseModels/UserNotificationSetting.d.ts +1 -0
- package/Models/DatabaseModels/UserNotificationSetting.js +26 -0
- package/Models/DatabaseModels/UserOnCallLogTimeline.d.mts +3 -0
- package/Models/DatabaseModels/UserOnCallLogTimeline.d.ts +3 -0
- package/Models/DatabaseModels/UserOnCallLogTimeline.js +53 -0
- package/Types/AI/AIChatPermissionMode.js +11 -5
- package/Types/AI/ResourceCardFacts.d.mts +11 -0
- package/Types/AI/ResourceCardFacts.d.ts +11 -0
- package/Types/AI/ResourceCardFacts.js +80 -0
- package/Types/AI/ResourceCardFacts.mjs +4 -0
- package/Types/AnalyticsDatabase/TableColumn.d.mts +4 -0
- package/Types/AnalyticsDatabase/TableColumn.d.ts +4 -0
- package/Types/AnalyticsDatabase/TableColumn.js +7 -0
- package/Types/AuditLog/Export/AuditLogExportDestinationCatalog.d.mts +2 -0
- package/Types/AuditLog/Export/AuditLogExportDestinationCatalog.d.ts +2 -0
- package/Types/AuditLog/Export/AuditLogExportDestinationCatalog.js +4 -0
- package/Types/Backup/BackupDestinationCatalog.d.mts +2 -0
- package/Types/Backup/BackupDestinationCatalog.d.ts +2 -0
- package/Types/Backup/BackupDestinationCatalog.js +8 -0
- package/Types/CallAndSMS/CallAndSmsGatewayPayload.d.mts +25 -0
- package/Types/CallAndSMS/CallAndSmsGatewayPayload.d.ts +25 -0
- package/Types/CallAndSMS/CallAndSmsGatewayPayload.js +86 -0
- package/Types/CallAndSMS/CallAndSmsGatewayPayload.mjs +6 -0
- package/Types/CallAndSMS/CallAndSmsProvider.d.mts +23 -0
- package/Types/CallAndSMS/CallAndSmsProvider.d.ts +23 -0
- package/Types/CallAndSMS/CallAndSmsProvider.js +107 -0
- package/Types/CallAndSMS/CallAndSmsProvider.mjs +7 -0
- package/Types/CloudConnection/CloudConnectionCatalog.d.mts +2 -0
- package/Types/CloudConnection/CloudConnectionCatalog.d.ts +2 -0
- package/Types/CloudConnection/CloudConnectionCatalog.js +4 -0
- package/Types/CustomNotificationChannel/CustomNotificationChannelPayload.d.mts +95 -0
- package/Types/CustomNotificationChannel/CustomNotificationChannelPayload.d.ts +95 -0
- package/Types/CustomNotificationChannel/CustomNotificationChannelPayload.js +236 -0
- package/Types/CustomNotificationChannel/CustomNotificationChannelPayload.mjs +16 -0
- package/Types/Dashboard/DashboardPlaylist.d.mts +21 -0
- package/Types/Dashboard/DashboardPlaylist.d.ts +21 -0
- package/Types/Dashboard/DashboardPlaylist.js +197 -0
- package/Types/Dashboard/DashboardPlaylist.mjs +19 -0
- package/Types/Database/TableColumn.d.mts +8 -0
- package/Types/Database/TableColumn.d.ts +8 -0
- package/Types/Database/TableColumn.js +69 -23
- package/Types/Database/TableColumn.mjs +1 -0
- package/Types/HeldPermissions.d.mts +2 -0
- package/Types/HeldPermissions.d.ts +2 -0
- package/Types/HeldPermissions.js +32 -8
- package/Types/Icon/IconProp.d.mts +3 -0
- package/Types/Icon/IconProp.d.ts +3 -0
- package/Types/Icon/IconProp.js +4 -0
- package/Types/JSONFunctions.js +16 -1
- package/Types/LlmObservability/LlmConnectionCatalog.d.mts +2 -0
- package/Types/LlmObservability/LlmConnectionCatalog.d.ts +2 -0
- package/Types/LlmObservability/LlmConnectionCatalog.js +8 -0
- package/Types/Monitor/MonitorType.js +5 -4
- package/Types/Monitor/TelemetryAlertRule.d.mts +111 -0
- package/Types/Monitor/TelemetryAlertRule.d.ts +111 -0
- package/Types/Monitor/TelemetryAlertRule.js +886 -0
- package/Types/Monitor/TelemetryAlertRule.mjs +5 -0
- package/Types/Monitor/TelemetryRulePreview.d.mts +57 -0
- package/Types/Monitor/TelemetryRulePreview.d.ts +57 -0
- package/Types/Monitor/TelemetryRulePreview.js +190 -0
- package/Types/Monitor/TelemetryRulePreview.mjs +6 -0
- package/Types/OnCallDutyPolicy/EveryNewEventRules.d.mts +23 -0
- package/Types/OnCallDutyPolicy/EveryNewEventRules.d.ts +23 -0
- package/Types/OnCallDutyPolicy/EveryNewEventRules.js +105 -0
- package/Types/OnCallDutyPolicy/EveryNewEventRules.mjs +9 -0
- package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunWait.d.mts +3 -0
- package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunWait.d.ts +3 -0
- package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunWait.js +23 -8
- package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunWait.mjs +2 -0
- package/Types/OnCallDutyPolicy/OnCallPolicyAiHold.d.mts +47 -0
- package/Types/OnCallDutyPolicy/OnCallPolicyAiHold.d.ts +47 -0
- package/Types/OnCallDutyPolicy/OnCallPolicyAiHold.js +122 -0
- package/Types/OnCallDutyPolicy/OnCallPolicyAiHold.mjs +12 -0
- package/Types/OnCallDutyPolicy/OnCallRuleWhenToPage.d.mts +2 -1
- package/Types/OnCallDutyPolicy/OnCallRuleWhenToPage.d.ts +2 -1
- package/Types/OnCallDutyPolicy/OnCallRuleWhenToPage.js +10 -1
- package/Types/Permission.d.mts +10 -0
- package/Types/Permission.d.ts +10 -0
- package/Types/Permission.js +83 -19
- package/Types/ProviderLogo/ProviderLogo.d.mts +87 -0
- package/Types/ProviderLogo/ProviderLogo.d.ts +87 -0
- package/Types/ProviderLogo/ProviderLogo.js +215 -0
- package/Types/ProviderLogo/ProviderLogo.mjs +6 -0
- package/Types/PushNotification/PushNotificationsTurnedOff.d.mts +3 -0
- package/Types/PushNotification/PushNotificationsTurnedOff.d.ts +3 -0
- package/Types/PushNotification/PushNotificationsTurnedOff.js +32 -0
- package/Types/PushNotification/PushNotificationsTurnedOff.mjs +4 -0
- package/Types/RollingTime/RollingTimeUtil.js +20 -10
- package/Types/Runbook/RunbookTriggerType.d.mts +2 -1
- package/Types/Runbook/RunbookTriggerType.d.ts +2 -1
- package/Types/Runbook/RunbookTriggerType.js +5 -1
- package/Types/SecurityCase/SecurityCaseContext.d.mts +188 -0
- package/Types/SecurityCase/SecurityCaseContext.d.ts +188 -0
- package/Types/SecurityCase/SecurityCaseContext.js +165 -0
- package/Types/SecurityCase/SecurityCaseContext.mjs +30 -0
- package/Types/SecurityCase/SecurityEntityRisk.d.mts +11 -0
- package/Types/SecurityCase/SecurityEntityRisk.d.ts +11 -0
- package/Types/SecurityCase/SecurityEntityRisk.js +9 -1
- package/Types/SecurityCase/SecurityEntityRisk.mjs +1 -0
- package/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.d.mts +2 -0
- package/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.d.ts +2 -0
- package/Types/SecurityEvent/Connectors/SecurityEventConnectorCatalog.js +9 -0
- package/Types/SecurityEvent/Destinations/SecurityEventDestinationCatalog.d.mts +2 -0
- package/Types/SecurityEvent/Destinations/SecurityEventDestinationCatalog.d.ts +2 -0
- package/Types/SecurityEvent/Destinations/SecurityEventDestinationCatalog.js +5 -0
- package/Types/SecurityEvent/DetectionRetrohunt.d.mts +38 -0
- package/Types/SecurityEvent/DetectionRetrohunt.d.ts +38 -0
- package/Types/SecurityEvent/DetectionRetrohunt.js +147 -0
- package/Types/SecurityEvent/DetectionRetrohunt.mjs +10 -0
- package/Types/SecurityEvent/DetectionRuleDataKind.d.mts +5 -1
- package/Types/SecurityEvent/DetectionRuleDataKind.d.ts +5 -1
- package/Types/SecurityEvent/DetectionRuleDataKind.js +42 -0
- package/Types/SecurityEvent/DetectionRuleException.d.mts +65 -0
- package/Types/SecurityEvent/DetectionRuleException.d.ts +65 -0
- package/Types/SecurityEvent/DetectionRuleException.js +441 -0
- package/Types/SecurityEvent/DetectionRuleException.mjs +24 -0
- package/Types/SecurityEvent/DetectionRuleLibrary.js +330 -0
- package/Types/SecurityEvent/NormalizedSecurityEvent.d.mts +5 -0
- package/Types/SecurityEvent/NormalizedSecurityEvent.d.ts +5 -0
- package/Types/SecurityEvent/SecurityAttackCampaign.d.mts +31 -0
- package/Types/SecurityEvent/SecurityAttackCampaign.d.ts +31 -0
- package/Types/SecurityEvent/SecurityAttackCampaign.js +81 -0
- package/Types/SecurityEvent/SecurityAttackCampaign.mjs +8 -0
- package/Types/SecurityEvent/SecurityEventRequestOutcome.d.mts +28 -0
- package/Types/SecurityEvent/SecurityEventRequestOutcome.d.ts +28 -0
- package/Types/SecurityEvent/SecurityEventRequestOutcome.js +78 -0
- package/Types/SecurityEvent/SecurityEventRequestOutcome.mjs +6 -0
- package/Types/SecurityEvent/SecurityTelemetrySource.d.mts +39 -0
- package/Types/SecurityEvent/SecurityTelemetrySource.d.ts +39 -0
- package/Types/SecurityEvent/SecurityTelemetrySource.js +127 -0
- package/Types/SecurityEvent/SecurityTelemetrySource.mjs +12 -0
- package/Types/SecurityEvent/TurnOnRecommended.d.mts +2 -0
- package/Types/SecurityEvent/TurnOnRecommended.d.ts +2 -0
- package/Types/SecurityEvent/TurnOnRecommended.js +7 -0
- package/Types/SecurityPlaybook/SecurityPlaybookAction.d.mts +7 -1
- package/Types/SecurityPlaybook/SecurityPlaybookAction.d.ts +7 -1
- package/Types/SecurityPlaybook/SecurityPlaybookAction.js +46 -0
- package/Types/SecurityPlaybook/SecurityPlaybookAction.mjs +1 -0
- package/Types/SecurityPlaybook/SecurityPlaybookStep.d.mts +10 -0
- package/Types/SecurityPlaybook/SecurityPlaybookStep.d.ts +10 -0
- package/Types/SecurityPlaybook/SecurityPlaybookStep.js +37 -1
- package/Types/SecurityPlaybook/SecurityPlaybookStep.mjs +1 -0
- package/Types/SecurityPlaybook/SecurityPlaybookTemplates.js +17 -0
- package/Types/Team/ComplianceNotificationChannel.d.mts +2 -1
- package/Types/Team/ComplianceNotificationChannel.d.ts +2 -1
- package/Types/Team/ComplianceNotificationChannel.js +10 -1
- package/Types/Team/ComplianceRule.d.mts +8 -3
- package/Types/Team/ComplianceRule.d.ts +8 -3
- package/Types/Team/ComplianceRule.js +34 -22
- package/Types/Team/TeamComplianceStatus.d.mts +1 -0
- package/Types/Team/TeamComplianceStatus.d.ts +1 -0
- package/Types/Telemetry/OpenTelemetryGuides.d.mts +52 -0
- package/Types/Telemetry/OpenTelemetryGuides.d.ts +52 -0
- package/Types/Telemetry/OpenTelemetryGuides.js +419 -0
- package/Types/Telemetry/OpenTelemetryGuides.mjs +17 -0
- package/Types/Telemetry/TelemetrySavedViewState.d.mts +1 -0
- package/Types/Telemetry/TelemetrySavedViewState.d.ts +1 -0
- package/Types/Telemetry/TraceHealth.d.mts +24 -0
- package/Types/Telemetry/TraceHealth.d.ts +24 -0
- package/Types/Telemetry/TraceHealth.js +97 -0
- package/Types/Telemetry/TraceHealth.mjs +4 -0
- package/Types/Telemetry/TraceSpanType.d.mts +90 -0
- package/Types/Telemetry/TraceSpanType.d.ts +90 -0
- package/Types/Telemetry/TraceSpanType.js +238 -0
- package/Types/Telemetry/TraceSpanType.mjs +19 -0
- package/Types/Theme/ThemePreference.d.mts +26 -0
- package/Types/Theme/ThemePreference.d.ts +26 -0
- package/Types/Theme/ThemePreference.js +104 -0
- package/Types/Theme/ThemePreference.mjs +12 -0
- package/Types/Workflow/Component.d.mts +3 -0
- package/Types/Workflow/Component.d.ts +3 -0
- package/Types/Workflow/Components/Discord.js +2 -0
- package/Types/Workflow/Components/Mattermost.js +2 -0
- package/Types/Workflow/Components/MicrosoftTeams.js +2 -0
- package/Types/Workflow/Components/Slack.js +2 -0
- package/Types/Workflow/Components/Telegram.js +2 -0
- package/Types/Workflow/Components.js +6 -0
- package/Types/Workflow/Templates.js +5 -3
- package/Utils/ColorContrast.d.mts +0 -3
- package/Utils/ColorContrast.d.ts +0 -3
- package/Utils/ColorContrast.js +3 -41
- package/Utils/ColorContrast.mjs +0 -2
- package/Utils/NameInitials.d.mts +5 -0
- package/Utils/NameInitials.d.ts +5 -0
- package/Utils/NameInitials.js +92 -0
- package/Utils/NameInitials.mjs +6 -0
- package/Utils/OldestKeyCursor.d.mts +7 -0
- package/Utils/OldestKeyCursor.d.ts +7 -0
- package/Utils/OldestKeyCursor.js +68 -0
- package/Utils/OldestKeyCursor.mjs +2 -0
- package/Utils/Schema/OpenApiMetadataRegistry.d.mts +4 -0
- package/Utils/Schema/OpenApiMetadataRegistry.d.ts +4 -0
- package/Utils/Schema/OpenApiMetadataRegistry.js +20 -0
- package/Utils/Schema/OpenApiMetadataRegistry.mjs +2 -0
- package/Utils/Schema/Zod.js +6 -0
- package/Utils/SecurityCase/SecurityCaseImpactFacts.d.mts +41 -0
- package/Utils/SecurityCase/SecurityCaseImpactFacts.d.ts +41 -0
- package/Utils/SecurityCase/SecurityCaseImpactFacts.js +215 -0
- package/Utils/SecurityCase/SecurityCaseImpactFacts.mjs +6 -0
- package/Utils/SecurityCase/SecurityCaseStoryItems.d.mts +46 -0
- package/Utils/SecurityCase/SecurityCaseStoryItems.d.ts +46 -0
- package/Utils/SecurityCase/SecurityCaseStoryItems.js +327 -0
- package/Utils/SecurityCase/SecurityCaseStoryItems.mjs +17 -0
- package/Utils/SecurityEvent/LogParsers/SecurityLogLine.d.mts +5 -0
- package/Utils/SecurityEvent/LogParsers/SecurityLogLine.d.ts +5 -0
- package/Utils/SecurityEvent/LogParsers/SecurityLogLine.js +22 -2
- package/Utils/SecurityEvent/LogParsers/SecurityLogLine.mjs +2 -0
- package/Utils/SecurityEvent/LogParsers/WebAttackLogParser.d.mts +20 -0
- package/Utils/SecurityEvent/LogParsers/WebAttackLogParser.d.ts +20 -0
- package/Utils/SecurityEvent/LogParsers/WebAttackLogParser.js +347 -31
- package/Utils/SecurityEvent/LogParsers/WebAttackLogParser.mjs +11 -0
- package/Utils/SecurityEvent/RequestFollowUp.d.mts +4 -0
- package/Utils/SecurityEvent/RequestFollowUp.d.ts +4 -0
- package/Utils/SecurityEvent/RequestFollowUp.js +127 -0
- package/Utils/SecurityEvent/RequestFollowUp.mjs +3 -0
- package/Utils/SecurityEvent/RequestOutcome.d.mts +80 -0
- package/Utils/SecurityEvent/RequestOutcome.d.ts +80 -0
- package/Utils/SecurityEvent/RequestOutcome.js +371 -0
- package/Utils/SecurityEvent/RequestOutcome.mjs +18 -0
- package/Utils/SecurityEvent/TelemetryScan/AuditLogSignals.d.mts +76 -0
- package/Utils/SecurityEvent/TelemetryScan/AuditLogSignals.d.ts +76 -0
- package/Utils/SecurityEvent/TelemetryScan/AuditLogSignals.js +348 -0
- package/Utils/SecurityEvent/TelemetryScan/AuditLogSignals.mjs +15 -0
- package/Utils/SecurityEvent/TelemetryScan/FlowSignals.d.mts +61 -0
- package/Utils/SecurityEvent/TelemetryScan/FlowSignals.d.ts +61 -0
- package/Utils/SecurityEvent/TelemetryScan/FlowSignals.js +260 -0
- package/Utils/SecurityEvent/TelemetryScan/FlowSignals.mjs +17 -0
- package/Utils/SecurityEvent/TelemetryScan/RumSignals.d.mts +30 -0
- package/Utils/SecurityEvent/TelemetryScan/RumSignals.d.ts +30 -0
- package/Utils/SecurityEvent/TelemetryScan/RumSignals.js +134 -0
- package/Utils/SecurityEvent/TelemetryScan/RumSignals.mjs +8 -0
- package/Utils/SecurityEvent/TelemetryScan/TelemetrySecurityEvent.d.mts +40 -0
- package/Utils/SecurityEvent/TelemetryScan/TelemetrySecurityEvent.d.ts +40 -0
- package/Utils/SecurityEvent/TelemetryScan/TelemetrySecurityEvent.js +190 -0
- package/Utils/SecurityEvent/TelemetryScan/TelemetrySecurityEvent.mjs +6 -0
- package/Utils/SecurityEvent/TelemetryScan/TraceSignals.d.mts +57 -0
- package/Utils/SecurityEvent/TelemetryScan/TraceSignals.d.ts +57 -0
- package/Utils/SecurityEvent/TelemetryScan/TraceSignals.js +491 -0
- package/Utils/SecurityEvent/TelemetryScan/TraceSignals.mjs +27 -0
- package/Utils/Telemetry/EntrySpan.d.mts +8 -0
- package/Utils/Telemetry/EntrySpan.d.ts +8 -0
- package/Utils/Telemetry/EntrySpan.js +53 -0
- package/Utils/Telemetry/EntrySpan.mjs +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,886 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TelemetryAlertRuleShapeProblem = exports.TelemetryAlertRuleRecovery = exports.TelemetryAlertRuleAction = void 0;
|
|
7
|
+
const FilterCondition_1 = __importDefault(require("../Filter/FilterCondition"));
|
|
8
|
+
const ObjectID_1 = __importDefault(require("../ObjectID"));
|
|
9
|
+
const RollingTime_1 = __importDefault(require("../RollingTime/RollingTime"));
|
|
10
|
+
const CriteriaFilter_1 = require("./CriteriaFilter");
|
|
11
|
+
const MonitorCriteria_1 = __importDefault(require("./MonitorCriteria"));
|
|
12
|
+
const MonitorCriteriaInstance_1 = __importDefault(require("./MonitorCriteriaInstance"));
|
|
13
|
+
const MonitorStep_1 = __importDefault(require("./MonitorStep"));
|
|
14
|
+
const MonitorStepExceptionMonitor_1 = require("./MonitorStepExceptionMonitor");
|
|
15
|
+
const MonitorStepLogMonitor_1 = require("./MonitorStepLogMonitor");
|
|
16
|
+
const MonitorStepMetricMonitor_1 = require("./MonitorStepMetricMonitor");
|
|
17
|
+
const MonitorStepTraceMonitor_1 = require("./MonitorStepTraceMonitor");
|
|
18
|
+
const MonitorType_1 = __importDefault(require("./MonitorType"));
|
|
19
|
+
const RecommendationCriteriaBuilder_1 = require("./Recommendation/RecommendationCriteriaBuilder");
|
|
20
|
+
/*
|
|
21
|
+
* A telemetry monitor's criteria, read as the one rule most people mean by
|
|
22
|
+
* them: "alert when there are more than 10 matching logs in 5 minutes",
|
|
23
|
+
* "alert when the average of a metric over 5 minutes is above 80".
|
|
24
|
+
*
|
|
25
|
+
* Telemetry monitors (Logs, Traces, Exceptions, Metrics) store their
|
|
26
|
+
* criteria in the same shape as every other monitor: criteria checked top
|
|
27
|
+
* to bottom, each with filters, a status to change to, and incidents and
|
|
28
|
+
* alerts to open. Most of them are one rule, often with its opposite beside
|
|
29
|
+
* it to set the healthy status again - which is how the out-of-the-box
|
|
30
|
+
* criteria, the recommendations, the AI insight monitors and the templates
|
|
31
|
+
* all write them. The monitor form reads such criteria as a rule, and edits
|
|
32
|
+
* the rule in plain words: a condition, a value, a window, and what
|
|
33
|
+
* happens. Criteria that are more than that (several rules, several
|
|
34
|
+
* filters, a disabled rule, grouped incidents) are not a rule: the form
|
|
35
|
+
* shows them in the full criteria editor, unchanged.
|
|
36
|
+
*
|
|
37
|
+
* Nothing new is stored. A rule is read from the criteria and written back
|
|
38
|
+
* onto them: every field the rule does not show (descriptions, owners,
|
|
39
|
+
* labels, roles, remediation notes, a retained incident row of a switched
|
|
40
|
+
* off action, the healthy criteria's name) is kept as it was, so reading a
|
|
41
|
+
* monitor and saving it unchanged saves exactly what was there.
|
|
42
|
+
*/
|
|
43
|
+
var TelemetryAlertRuleAction;
|
|
44
|
+
(function (TelemetryAlertRuleAction) {
|
|
45
|
+
TelemetryAlertRuleAction["Alert"] = "Alert";
|
|
46
|
+
TelemetryAlertRuleAction["Incident"] = "Incident";
|
|
47
|
+
TelemetryAlertRuleAction["AlertAndIncident"] = "AlertAndIncident";
|
|
48
|
+
// Only the monitor's status changes: nothing is opened.
|
|
49
|
+
TelemetryAlertRuleAction["StatusOnly"] = "StatusOnly";
|
|
50
|
+
})(TelemetryAlertRuleAction || (exports.TelemetryAlertRuleAction = TelemetryAlertRuleAction = {}));
|
|
51
|
+
/*
|
|
52
|
+
* How the monitor goes back to healthy once the rule stops matching.
|
|
53
|
+
*/
|
|
54
|
+
var TelemetryAlertRuleRecovery;
|
|
55
|
+
(function (TelemetryAlertRuleRecovery) {
|
|
56
|
+
/*
|
|
57
|
+
* No criteria of its own: when no criteria matches, the monitor returns to
|
|
58
|
+
* its default status, and the rule's incidents and alerts resolve.
|
|
59
|
+
*/
|
|
60
|
+
TelemetryAlertRuleRecovery["DefaultStatus"] = "DefaultStatus";
|
|
61
|
+
// A second criteria, the rule's exact opposite, sets the healthy status.
|
|
62
|
+
TelemetryAlertRuleRecovery["Opposite"] = "Opposite";
|
|
63
|
+
/*
|
|
64
|
+
* The opposite, a little past the threshold, as the recommendations write
|
|
65
|
+
* it (DefaultRecoveryMarginFraction), so a value sitting at the threshold
|
|
66
|
+
* does not flip the status on every check.
|
|
67
|
+
*/
|
|
68
|
+
TelemetryAlertRuleRecovery["OppositeWithMargin"] = "OppositeWithMargin";
|
|
69
|
+
/*
|
|
70
|
+
* A second criteria that sets the healthy status for some of the values
|
|
71
|
+
* the rule does not match, and never for one it does: the out-of-the-box
|
|
72
|
+
* Metrics criteria open an incident at exactly 0 and call anything above 0
|
|
73
|
+
* healthy. The values in neither return to the default status, which is
|
|
74
|
+
* the same healthy status, so it reads as the rule's recovery. A changed
|
|
75
|
+
* rule writes it as the rule's exact opposite.
|
|
76
|
+
*/
|
|
77
|
+
TelemetryAlertRuleRecovery["Disjoint"] = "Disjoint";
|
|
78
|
+
})(TelemetryAlertRuleRecovery || (exports.TelemetryAlertRuleRecovery = TelemetryAlertRuleRecovery = {}));
|
|
79
|
+
/*
|
|
80
|
+
* Why criteria are not read as a rule. Said to the reader above the full
|
|
81
|
+
* criteria editor, and pinned by tests.
|
|
82
|
+
*/
|
|
83
|
+
var TelemetryAlertRuleShapeProblem;
|
|
84
|
+
(function (TelemetryAlertRuleShapeProblem) {
|
|
85
|
+
TelemetryAlertRuleShapeProblem["NotARuleMonitorType"] = "NotARuleMonitorType";
|
|
86
|
+
TelemetryAlertRuleShapeProblem["NoCriteria"] = "NoCriteria";
|
|
87
|
+
TelemetryAlertRuleShapeProblem["SeveralRules"] = "SeveralRules";
|
|
88
|
+
TelemetryAlertRuleShapeProblem["DisabledRule"] = "DisabledRule";
|
|
89
|
+
TelemetryAlertRuleShapeProblem["SeveralFilters"] = "SeveralFilters";
|
|
90
|
+
TelemetryAlertRuleShapeProblem["OtherCheck"] = "OtherCheck";
|
|
91
|
+
TelemetryAlertRuleShapeProblem["UnsupportedCondition"] = "UnsupportedCondition";
|
|
92
|
+
TelemetryAlertRuleShapeProblem["SeveralIncidentsOrAlerts"] = "SeveralIncidentsOrAlerts";
|
|
93
|
+
TelemetryAlertRuleShapeProblem["GroupedIncidents"] = "GroupedIncidents";
|
|
94
|
+
TelemetryAlertRuleShapeProblem["UnknownMetric"] = "UnknownMetric";
|
|
95
|
+
})(TelemetryAlertRuleShapeProblem || (exports.TelemetryAlertRuleShapeProblem = TelemetryAlertRuleShapeProblem = {}));
|
|
96
|
+
/*
|
|
97
|
+
* The comparisons the rule editor offers, in the order it offers them. The
|
|
98
|
+
* same set the full criteria editor offers for these checks
|
|
99
|
+
* (CriteriaFilterUtil.getFilterTypeOptionsByCheckOn in the Dashboard), plus
|
|
100
|
+
* Not Equal To, which only an older or hand-written criteria holds: read,
|
|
101
|
+
* and offered back to such a rule, so it keeps meaning what it meant.
|
|
102
|
+
*/
|
|
103
|
+
const STATIC_COMPARISONS = [
|
|
104
|
+
CriteriaFilter_1.FilterType.GreaterThan,
|
|
105
|
+
CriteriaFilter_1.FilterType.GreaterThanOrEqualTo,
|
|
106
|
+
CriteriaFilter_1.FilterType.LessThan,
|
|
107
|
+
CriteriaFilter_1.FilterType.LessThanOrEqualTo,
|
|
108
|
+
CriteriaFilter_1.FilterType.EqualTo,
|
|
109
|
+
];
|
|
110
|
+
const ANOMALY_COMPARISONS = [
|
|
111
|
+
CriteriaFilter_1.FilterType.AnomalouslyHigh,
|
|
112
|
+
CriteriaFilter_1.FilterType.AnomalouslyLow,
|
|
113
|
+
CriteriaFilter_1.FilterType.Anomalous,
|
|
114
|
+
];
|
|
115
|
+
const READ_ONLY_COMPARISONS = [CriteriaFilter_1.FilterType.NotEqualTo];
|
|
116
|
+
/*
|
|
117
|
+
* A comparison of a count holds or not for every whole number. Read as the
|
|
118
|
+
* set of counts it matches, two filters are opposites when every count
|
|
119
|
+
* matches exactly one of them: "Equal To 0" and "Greater Than 0" are, as the
|
|
120
|
+
* out-of-the-box Logs criteria pair them, though Greater Than is not the
|
|
121
|
+
* formal opposite of Equal To.
|
|
122
|
+
*/
|
|
123
|
+
const LARGE_COUNT = 1000000000;
|
|
124
|
+
class TelemetryAlertRuleUtil {
|
|
125
|
+
static isRuleMonitorType(monitorType) {
|
|
126
|
+
return Boolean(monitorType &&
|
|
127
|
+
TelemetryAlertRuleUtil.RULE_MONITOR_TYPES.includes(monitorType));
|
|
128
|
+
}
|
|
129
|
+
// What a rule of this monitor type compares.
|
|
130
|
+
static getMeasureCheckOn(monitorType) {
|
|
131
|
+
switch (monitorType) {
|
|
132
|
+
case MonitorType_1.default.Logs:
|
|
133
|
+
return CriteriaFilter_1.CheckOn.LogCount;
|
|
134
|
+
case MonitorType_1.default.Traces:
|
|
135
|
+
return CriteriaFilter_1.CheckOn.SpanCount;
|
|
136
|
+
case MonitorType_1.default.Exceptions:
|
|
137
|
+
return CriteriaFilter_1.CheckOn.ExceptionCount;
|
|
138
|
+
case MonitorType_1.default.Metrics:
|
|
139
|
+
return CriteriaFilter_1.CheckOn.MetricValue;
|
|
140
|
+
default:
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Whether the measure is a count of things in the window (not a metric).
|
|
145
|
+
static isCountMonitorType(monitorType) {
|
|
146
|
+
return (monitorType === MonitorType_1.default.Logs ||
|
|
147
|
+
monitorType === MonitorType_1.default.Traces ||
|
|
148
|
+
monitorType === MonitorType_1.default.Exceptions);
|
|
149
|
+
}
|
|
150
|
+
/*
|
|
151
|
+
* The anomaly conditions are offered where the server judges them: log
|
|
152
|
+
* and span counts against their hourly baselines, metrics against theirs.
|
|
153
|
+
* Exceptions have no baseline.
|
|
154
|
+
*/
|
|
155
|
+
static supportsAnomaly(monitorType) {
|
|
156
|
+
return (monitorType === MonitorType_1.default.Logs ||
|
|
157
|
+
monitorType === MonitorType_1.default.Traces ||
|
|
158
|
+
monitorType === MonitorType_1.default.Metrics);
|
|
159
|
+
}
|
|
160
|
+
/*
|
|
161
|
+
* The comparisons to offer for a rule of this type. A comparison the rule
|
|
162
|
+
* already holds is always offered, so it can be kept.
|
|
163
|
+
*/
|
|
164
|
+
static getComparisons(data) {
|
|
165
|
+
const comparisons = [...STATIC_COMPARISONS];
|
|
166
|
+
if (TelemetryAlertRuleUtil.supportsAnomaly(data.monitorType)) {
|
|
167
|
+
comparisons.push(...ANOMALY_COMPARISONS);
|
|
168
|
+
}
|
|
169
|
+
if (data.current && !comparisons.includes(data.current)) {
|
|
170
|
+
if (TelemetryAlertRuleUtil.isReadableComparison(data)) {
|
|
171
|
+
comparisons.push(data.current);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return comparisons;
|
|
175
|
+
}
|
|
176
|
+
static isAnomaly(filterType) {
|
|
177
|
+
return CriteriaFilter_1.CriteriaFilterUtil.isAnomalyFilterType(filterType);
|
|
178
|
+
}
|
|
179
|
+
// The window of a count monitor, in seconds, as its step holds it.
|
|
180
|
+
static getWindowInSeconds(data) {
|
|
181
|
+
var _a, _b, _c, _d, _e, _f;
|
|
182
|
+
switch (data.monitorType) {
|
|
183
|
+
case MonitorType_1.default.Logs:
|
|
184
|
+
return (((_b = (_a = data.monitorStep.data) === null || _a === void 0 ? void 0 : _a.logMonitor) === null || _b === void 0 ? void 0 : _b.lastXSecondsOfLogs) ||
|
|
185
|
+
MonitorStepLogMonitor_1.MonitorStepLogMonitorUtil.getDefault().lastXSecondsOfLogs);
|
|
186
|
+
case MonitorType_1.default.Traces:
|
|
187
|
+
return (((_d = (_c = data.monitorStep.data) === null || _c === void 0 ? void 0 : _c.traceMonitor) === null || _d === void 0 ? void 0 : _d.lastXSecondsOfSpans) ||
|
|
188
|
+
MonitorStepTraceMonitor_1.MonitorStepTraceMonitorUtil.getDefault().lastXSecondsOfSpans);
|
|
189
|
+
case MonitorType_1.default.Exceptions:
|
|
190
|
+
return (((_f = (_e = data.monitorStep.data) === null || _e === void 0 ? void 0 : _e.exceptionMonitor) === null || _f === void 0 ? void 0 : _f.lastXSecondsOfExceptions) ||
|
|
191
|
+
MonitorStepExceptionMonitor_1.MonitorStepExceptionMonitorUtil.getDefault().lastXSecondsOfExceptions);
|
|
192
|
+
default:
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
static getRollingTime(monitorStep) {
|
|
197
|
+
var _a, _b;
|
|
198
|
+
return (((_b = (_a = monitorStep.data) === null || _a === void 0 ? void 0 : _a.metricMonitor) === null || _b === void 0 ? void 0 : _b.rollingTime) || RollingTime_1.default.Past1Minute);
|
|
199
|
+
}
|
|
200
|
+
/*
|
|
201
|
+
* The aliases a metric rule can compare: every query's and formula's
|
|
202
|
+
* variable, queries first - the order the evaluator resolves them in.
|
|
203
|
+
*/
|
|
204
|
+
static getMetricAliases(monitorStep) {
|
|
205
|
+
var _a, _b, _c;
|
|
206
|
+
const config = (_a = monitorStep.data) === null || _a === void 0 ? void 0 : _a.metricMonitor;
|
|
207
|
+
const viewConfig = MonitorStepMetricMonitor_1.MonitorStepMetricMonitorUtil.getMetricViewConfig(config);
|
|
208
|
+
const aliases = [];
|
|
209
|
+
for (const queryConfig of viewConfig.queryConfigs) {
|
|
210
|
+
const alias = (_b = queryConfig.metricAliasData) === null || _b === void 0 ? void 0 : _b.metricVariable;
|
|
211
|
+
if (alias && !aliases.includes(alias)) {
|
|
212
|
+
aliases.push(alias);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
for (const formulaConfig of viewConfig.formulaConfigs) {
|
|
216
|
+
const alias = (_c = formulaConfig.metricAliasData) === null || _c === void 0 ? void 0 : _c.metricVariable;
|
|
217
|
+
if (alias && !aliases.includes(alias)) {
|
|
218
|
+
aliases.push(alias);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return aliases;
|
|
222
|
+
}
|
|
223
|
+
/*
|
|
224
|
+
* Read the rule out of a step's criteria, or say why they are not one.
|
|
225
|
+
* `defaultMonitorStatusId` is the status the monitor shows when no
|
|
226
|
+
* criteria matches (MonitorSteps.defaultMonitorStatusId): a healthy
|
|
227
|
+
* criteria is only the rule's recovery when it sets that same status, so
|
|
228
|
+
* dropping it (when the rule becomes an anomaly) changes nothing.
|
|
229
|
+
*/
|
|
230
|
+
static read(data) {
|
|
231
|
+
var _a, _b, _c, _d, _e;
|
|
232
|
+
const measure = TelemetryAlertRuleUtil.getMeasureCheckOn(data.monitorType);
|
|
233
|
+
if (!measure) {
|
|
234
|
+
return {
|
|
235
|
+
rule: null,
|
|
236
|
+
problem: TelemetryAlertRuleShapeProblem.NotARuleMonitorType,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const instances = ((_c = (_b = (_a = data.monitorStep.data) === null || _a === void 0 ? void 0 : _a.monitorCriteria) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.monitorCriteriaInstanceArray) || [];
|
|
240
|
+
if (instances.length === 0) {
|
|
241
|
+
return { rule: null, problem: TelemetryAlertRuleShapeProblem.NoCriteria };
|
|
242
|
+
}
|
|
243
|
+
if (instances.length > 2) {
|
|
244
|
+
return {
|
|
245
|
+
rule: null,
|
|
246
|
+
problem: TelemetryAlertRuleShapeProblem.SeveralRules,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
let ruleInstance = undefined;
|
|
250
|
+
let recoveryInstance = undefined;
|
|
251
|
+
if (instances.length === 1) {
|
|
252
|
+
ruleInstance = instances[0];
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const recoveryCandidates = instances.filter((instance) => {
|
|
256
|
+
return TelemetryAlertRuleUtil.isRecoveryCandidate({
|
|
257
|
+
instance,
|
|
258
|
+
defaultMonitorStatusId: data.defaultMonitorStatusId,
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
if (recoveryCandidates.length !== 1) {
|
|
262
|
+
return {
|
|
263
|
+
rule: null,
|
|
264
|
+
problem: TelemetryAlertRuleShapeProblem.SeveralRules,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
recoveryInstance = recoveryCandidates[0];
|
|
268
|
+
ruleInstance = instances.find((instance) => {
|
|
269
|
+
return instance !== recoveryInstance;
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (!(ruleInstance === null || ruleInstance === void 0 ? void 0 : ruleInstance.data)) {
|
|
273
|
+
return { rule: null, problem: TelemetryAlertRuleShapeProblem.NoCriteria };
|
|
274
|
+
}
|
|
275
|
+
const problem = TelemetryAlertRuleUtil.getRuleInstanceProblem({
|
|
276
|
+
monitorType: data.monitorType,
|
|
277
|
+
monitorStep: data.monitorStep,
|
|
278
|
+
instance: ruleInstance,
|
|
279
|
+
measure,
|
|
280
|
+
});
|
|
281
|
+
if (problem) {
|
|
282
|
+
return { rule: null, problem };
|
|
283
|
+
}
|
|
284
|
+
const ruleFilter = ruleInstance.data.filters[0];
|
|
285
|
+
let recovery = TelemetryAlertRuleRecovery.DefaultStatus;
|
|
286
|
+
if (recoveryInstance) {
|
|
287
|
+
const recoveryFilter = ((_d = recoveryInstance.data) === null || _d === void 0 ? void 0 : _d.filters.length) === 1
|
|
288
|
+
? recoveryInstance.data.filters[0]
|
|
289
|
+
: undefined;
|
|
290
|
+
const matchedRecovery = recoveryFilter && ((_e = recoveryInstance.data) === null || _e === void 0 ? void 0 : _e.isEnabled) !== false
|
|
291
|
+
? TelemetryAlertRuleUtil.getRecoveryKind({
|
|
292
|
+
monitorType: data.monitorType,
|
|
293
|
+
ruleFilter,
|
|
294
|
+
recoveryFilter,
|
|
295
|
+
})
|
|
296
|
+
: null;
|
|
297
|
+
if (!matchedRecovery) {
|
|
298
|
+
return {
|
|
299
|
+
rule: null,
|
|
300
|
+
problem: TelemetryAlertRuleShapeProblem.SeveralRules,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
recovery = matchedRecovery;
|
|
304
|
+
}
|
|
305
|
+
const ruleData = ruleInstance.data;
|
|
306
|
+
const isMetric = data.monitorType === MonitorType_1.default.Metrics;
|
|
307
|
+
const metricOptions = ruleFilter.metricMonitorOptions;
|
|
308
|
+
const rule = {
|
|
309
|
+
filterType: ruleFilter.filterType,
|
|
310
|
+
threshold: TelemetryAlertRuleUtil.isAnomaly(ruleFilter.filterType)
|
|
311
|
+
? undefined
|
|
312
|
+
: TelemetryAlertRuleUtil.toNumber(ruleFilter.value),
|
|
313
|
+
windowInSeconds: TelemetryAlertRuleUtil.getWindowInSeconds({
|
|
314
|
+
monitorType: data.monitorType,
|
|
315
|
+
monitorStep: data.monitorStep,
|
|
316
|
+
}),
|
|
317
|
+
rollingTime: isMetric
|
|
318
|
+
? TelemetryAlertRuleUtil.getRollingTime(data.monitorStep)
|
|
319
|
+
: undefined,
|
|
320
|
+
metricAlias: isMetric ? metricOptions === null || metricOptions === void 0 ? void 0 : metricOptions.metricAlias : undefined,
|
|
321
|
+
metricAggregationType: isMetric
|
|
322
|
+
? metricOptions === null || metricOptions === void 0 ? void 0 : metricOptions.metricAggregationType
|
|
323
|
+
: undefined,
|
|
324
|
+
onNoDataPolicy: isMetric ? metricOptions === null || metricOptions === void 0 ? void 0 : metricOptions.onNoDataPolicy : undefined,
|
|
325
|
+
thresholdUnit: isMetric ? metricOptions === null || metricOptions === void 0 ? void 0 : metricOptions.thresholdUnit : undefined,
|
|
326
|
+
anomalyDetection: metricOptions === null || metricOptions === void 0 ? void 0 : metricOptions.anomalyDetection,
|
|
327
|
+
action: TelemetryAlertRuleUtil.getAction(ruleInstance),
|
|
328
|
+
monitorStatusId: ruleData.changeMonitorStatus
|
|
329
|
+
? ruleData.monitorStatusId
|
|
330
|
+
: undefined,
|
|
331
|
+
incident: ruleData.incidents[0],
|
|
332
|
+
alert: ruleData.alerts[0],
|
|
333
|
+
name: ruleData.name || "",
|
|
334
|
+
ruleCriteriaId: ruleData.id,
|
|
335
|
+
recovery,
|
|
336
|
+
};
|
|
337
|
+
return { rule, problem: null };
|
|
338
|
+
}
|
|
339
|
+
/*
|
|
340
|
+
* Write a rule back onto a step: the rule criteria, its recovery criteria
|
|
341
|
+
* (kept the opposite of the rule) and the window. Returns a new step; the
|
|
342
|
+
* one handed in is not changed.
|
|
343
|
+
*/
|
|
344
|
+
static write(data) {
|
|
345
|
+
var _a, _b, _c, _d;
|
|
346
|
+
const { monitorType, rule } = data;
|
|
347
|
+
const step = MonitorStep_1.default.clone(data.monitorStep);
|
|
348
|
+
const measure = TelemetryAlertRuleUtil.getMeasureCheckOn(monitorType);
|
|
349
|
+
if (!measure || !step.data) {
|
|
350
|
+
return step;
|
|
351
|
+
}
|
|
352
|
+
TelemetryAlertRuleUtil.writeWindow({
|
|
353
|
+
monitorType,
|
|
354
|
+
monitorStep: step,
|
|
355
|
+
rule,
|
|
356
|
+
});
|
|
357
|
+
const instances = (((_b = (_a = step.data.monitorCriteria) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.monitorCriteriaInstanceArray) || []).map((instance) => {
|
|
358
|
+
return MonitorCriteriaInstance_1.default.clone(instance);
|
|
359
|
+
});
|
|
360
|
+
const ruleInstance = instances.find((instance) => {
|
|
361
|
+
var _a;
|
|
362
|
+
return ((_a = instance.data) === null || _a === void 0 ? void 0 : _a.id) === rule.ruleCriteriaId;
|
|
363
|
+
});
|
|
364
|
+
/*
|
|
365
|
+
* A rule that is not one of these criteria is a new one (a recipe): it
|
|
366
|
+
* takes the criteria's place.
|
|
367
|
+
*/
|
|
368
|
+
if (!ruleInstance) {
|
|
369
|
+
step.setMonitorCriteria(TelemetryAlertRuleUtil.buildCriteria({ monitorType, rule }));
|
|
370
|
+
return step;
|
|
371
|
+
}
|
|
372
|
+
const previousRuleFilter = (_c = ruleInstance.data) === null || _c === void 0 ? void 0 : _c.filters[0];
|
|
373
|
+
const ruleFilter = TelemetryAlertRuleUtil.buildRuleFilter({
|
|
374
|
+
monitorType,
|
|
375
|
+
measure,
|
|
376
|
+
rule,
|
|
377
|
+
previous: previousRuleFilter,
|
|
378
|
+
});
|
|
379
|
+
TelemetryAlertRuleUtil.applyRuleToInstance({
|
|
380
|
+
instance: ruleInstance,
|
|
381
|
+
rule,
|
|
382
|
+
filter: ruleFilter,
|
|
383
|
+
});
|
|
384
|
+
const recoveryIndex = instances.findIndex((instance) => {
|
|
385
|
+
return instance !== ruleInstance;
|
|
386
|
+
});
|
|
387
|
+
if (recoveryIndex >= 0) {
|
|
388
|
+
const recoveryInstance = instances[recoveryIndex];
|
|
389
|
+
/*
|
|
390
|
+
* An anomaly has no opposite to write: the monitor is healthy again
|
|
391
|
+
* when no criteria matches, and its default status is the one this
|
|
392
|
+
* criteria set (read() requires that), so dropping it changes nothing.
|
|
393
|
+
*/
|
|
394
|
+
if (TelemetryAlertRuleUtil.isAnomaly(rule.filterType) ||
|
|
395
|
+
rule.recovery === TelemetryAlertRuleRecovery.DefaultStatus) {
|
|
396
|
+
instances.splice(recoveryIndex, 1);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
const ruleChanged = !TelemetryAlertRuleUtil.isSameComparison(previousRuleFilter, ruleFilter);
|
|
400
|
+
const previousRecoveryFilter = (_d = recoveryInstance.data) === null || _d === void 0 ? void 0 : _d.filters[0];
|
|
401
|
+
if (recoveryInstance.data && previousRecoveryFilter) {
|
|
402
|
+
recoveryInstance.data.filters = [
|
|
403
|
+
TelemetryAlertRuleUtil.buildRecoveryFilter({
|
|
404
|
+
monitorType,
|
|
405
|
+
ruleFilter,
|
|
406
|
+
previousRecoveryFilter,
|
|
407
|
+
recovery: rule.recovery,
|
|
408
|
+
ruleChanged,
|
|
409
|
+
}),
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const criteria = new MonitorCriteria_1.default();
|
|
415
|
+
criteria.data = { monitorCriteriaInstanceArray: instances };
|
|
416
|
+
step.setMonitorCriteria(criteria);
|
|
417
|
+
return step;
|
|
418
|
+
}
|
|
419
|
+
/*
|
|
420
|
+
* The criteria for a new rule: the rule alone. When it stops matching, no
|
|
421
|
+
* criteria matches, and the monitor returns to its default status and
|
|
422
|
+
* resolves what the rule opened (MonitorResource, "No criteria met").
|
|
423
|
+
*/
|
|
424
|
+
static buildCriteria(data) {
|
|
425
|
+
const measure = TelemetryAlertRuleUtil.getMeasureCheckOn(data.monitorType);
|
|
426
|
+
const instance = TelemetryAlertRuleUtil.newRuleInstance(data.rule);
|
|
427
|
+
if (measure) {
|
|
428
|
+
TelemetryAlertRuleUtil.applyRuleToInstance({
|
|
429
|
+
instance,
|
|
430
|
+
rule: data.rule,
|
|
431
|
+
filter: TelemetryAlertRuleUtil.buildRuleFilter({
|
|
432
|
+
monitorType: data.monitorType,
|
|
433
|
+
measure,
|
|
434
|
+
rule: data.rule,
|
|
435
|
+
previous: undefined,
|
|
436
|
+
}),
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
const criteria = new MonitorCriteria_1.default();
|
|
440
|
+
criteria.data = { monitorCriteriaInstanceArray: [instance] };
|
|
441
|
+
return criteria;
|
|
442
|
+
}
|
|
443
|
+
/*
|
|
444
|
+
* The window, written where the step's sub-configuration keeps it. A step
|
|
445
|
+
* without the sub-configuration gets its type's defaults with the window.
|
|
446
|
+
*/
|
|
447
|
+
static writeWindow(data) {
|
|
448
|
+
const { monitorType, monitorStep, rule } = data;
|
|
449
|
+
if (!monitorStep.data) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (monitorType === MonitorType_1.default.Logs && rule.windowInSeconds) {
|
|
453
|
+
const logMonitor = monitorStep.data.logMonitor || MonitorStepLogMonitor_1.MonitorStepLogMonitorUtil.getDefault();
|
|
454
|
+
monitorStep.setLogMonitor(Object.assign(Object.assign({}, logMonitor), { lastXSecondsOfLogs: rule.windowInSeconds }));
|
|
455
|
+
}
|
|
456
|
+
if (monitorType === MonitorType_1.default.Traces && rule.windowInSeconds) {
|
|
457
|
+
const traceMonitor = monitorStep.data.traceMonitor ||
|
|
458
|
+
MonitorStepTraceMonitor_1.MonitorStepTraceMonitorUtil.getDefault();
|
|
459
|
+
monitorStep.setTraceMonitor(Object.assign(Object.assign({}, traceMonitor), { lastXSecondsOfSpans: rule.windowInSeconds }));
|
|
460
|
+
}
|
|
461
|
+
if (monitorType === MonitorType_1.default.Exceptions && rule.windowInSeconds) {
|
|
462
|
+
const exceptionMonitor = monitorStep.data.exceptionMonitor ||
|
|
463
|
+
MonitorStepExceptionMonitor_1.MonitorStepExceptionMonitorUtil.getDefault();
|
|
464
|
+
monitorStep.setExceptionMonitor(Object.assign(Object.assign({}, exceptionMonitor), { lastXSecondsOfExceptions: rule.windowInSeconds }));
|
|
465
|
+
}
|
|
466
|
+
if (monitorType === MonitorType_1.default.Metrics && rule.rollingTime) {
|
|
467
|
+
const metricMonitor = monitorStep.data.metricMonitor ||
|
|
468
|
+
MonitorStepMetricMonitor_1.MonitorStepMetricMonitorUtil.getDefault();
|
|
469
|
+
monitorStep.setMetricMonitor(Object.assign(Object.assign({}, metricMonitor), { rollingTime: rule.rollingTime }));
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/*
|
|
473
|
+
* Whether a value matches a comparison, the way the server compares one
|
|
474
|
+
* number (CompareCriteria.compareCriteriaNumbers). The rule editor's
|
|
475
|
+
* preview marks the windows a rule would have matched with it.
|
|
476
|
+
*/
|
|
477
|
+
static matches(data) {
|
|
478
|
+
switch (data.filterType) {
|
|
479
|
+
case CriteriaFilter_1.FilterType.GreaterThan:
|
|
480
|
+
return data.value > data.threshold;
|
|
481
|
+
case CriteriaFilter_1.FilterType.GreaterThanOrEqualTo:
|
|
482
|
+
return data.value >= data.threshold;
|
|
483
|
+
case CriteriaFilter_1.FilterType.LessThan:
|
|
484
|
+
return data.value < data.threshold;
|
|
485
|
+
case CriteriaFilter_1.FilterType.LessThanOrEqualTo:
|
|
486
|
+
return data.value <= data.threshold;
|
|
487
|
+
case CriteriaFilter_1.FilterType.EqualTo:
|
|
488
|
+
return data.value === data.threshold;
|
|
489
|
+
case CriteriaFilter_1.FilterType.NotEqualTo:
|
|
490
|
+
return data.value !== data.threshold;
|
|
491
|
+
default:
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// ---- private ----
|
|
496
|
+
static isReadableComparison(data) {
|
|
497
|
+
if (!data.current) {
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
if (STATIC_COMPARISONS.includes(data.current)) {
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
if (READ_ONLY_COMPARISONS.includes(data.current)) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
return (ANOMALY_COMPARISONS.includes(data.current) &&
|
|
507
|
+
TelemetryAlertRuleUtil.supportsAnomaly(data.monitorType));
|
|
508
|
+
}
|
|
509
|
+
static getRuleInstanceProblem(data) {
|
|
510
|
+
var _a;
|
|
511
|
+
const instanceData = data.instance.data;
|
|
512
|
+
if (!instanceData) {
|
|
513
|
+
return TelemetryAlertRuleShapeProblem.NoCriteria;
|
|
514
|
+
}
|
|
515
|
+
if (instanceData.isEnabled === false) {
|
|
516
|
+
return TelemetryAlertRuleShapeProblem.DisabledRule;
|
|
517
|
+
}
|
|
518
|
+
if (instanceData.filters.length !== 1) {
|
|
519
|
+
return TelemetryAlertRuleShapeProblem.SeveralFilters;
|
|
520
|
+
}
|
|
521
|
+
const filter = instanceData.filters[0];
|
|
522
|
+
if (filter.checkOn !== data.measure) {
|
|
523
|
+
return TelemetryAlertRuleShapeProblem.OtherCheck;
|
|
524
|
+
}
|
|
525
|
+
if (filter.evaluateOverTime ||
|
|
526
|
+
!TelemetryAlertRuleUtil.isReadableComparison({
|
|
527
|
+
monitorType: data.monitorType,
|
|
528
|
+
current: filter.filterType,
|
|
529
|
+
})) {
|
|
530
|
+
return TelemetryAlertRuleShapeProblem.UnsupportedCondition;
|
|
531
|
+
}
|
|
532
|
+
/*
|
|
533
|
+
* A rule without a value is still a rule: a new Metrics monitor starts
|
|
534
|
+
* on "above a value" and asks for the value, and the criteria cannot be
|
|
535
|
+
* saved until it has one (MonitorCriteriaInstance.getValidationError).
|
|
536
|
+
*/
|
|
537
|
+
if (instanceData.incidents.length > 1 || instanceData.alerts.length > 1) {
|
|
538
|
+
return TelemetryAlertRuleShapeProblem.SeveralIncidentsOrAlerts;
|
|
539
|
+
}
|
|
540
|
+
if ((instanceData.createIncidents && instanceData.incidents.length !== 1) ||
|
|
541
|
+
(instanceData.createAlerts && instanceData.alerts.length !== 1)) {
|
|
542
|
+
return TelemetryAlertRuleShapeProblem.SeveralIncidentsOrAlerts;
|
|
543
|
+
}
|
|
544
|
+
if (instanceData.incidentGrouping || instanceData.openForEveryEmail) {
|
|
545
|
+
return TelemetryAlertRuleShapeProblem.GroupedIncidents;
|
|
546
|
+
}
|
|
547
|
+
if (data.monitorType === MonitorType_1.default.Metrics) {
|
|
548
|
+
const alias = (_a = filter.metricMonitorOptions) === null || _a === void 0 ? void 0 : _a.metricAlias;
|
|
549
|
+
if (alias &&
|
|
550
|
+
!TelemetryAlertRuleUtil.getMetricAliases(data.monitorStep).includes(alias)) {
|
|
551
|
+
return TelemetryAlertRuleShapeProblem.UnknownMetric;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
/*
|
|
557
|
+
* A criteria that can be the rule's recovery: on, opening nothing, and
|
|
558
|
+
* setting the monitor's default status.
|
|
559
|
+
*/
|
|
560
|
+
static isRecoveryCandidate(data) {
|
|
561
|
+
var _a;
|
|
562
|
+
const instanceData = data.instance.data;
|
|
563
|
+
if (!instanceData || !data.defaultMonitorStatusId) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
return (instanceData.isEnabled !== false &&
|
|
567
|
+
!instanceData.createIncidents &&
|
|
568
|
+
!instanceData.createAlerts &&
|
|
569
|
+
Boolean(instanceData.changeMonitorStatus) &&
|
|
570
|
+
((_a = instanceData.monitorStatusId) === null || _a === void 0 ? void 0 : _a.toString()) ===
|
|
571
|
+
data.defaultMonitorStatusId.toString() &&
|
|
572
|
+
!instanceData.incidentGrouping &&
|
|
573
|
+
!instanceData.openForEveryEmail);
|
|
574
|
+
}
|
|
575
|
+
static getRecoveryKind(data) {
|
|
576
|
+
const { ruleFilter, recoveryFilter } = data;
|
|
577
|
+
if (recoveryFilter.checkOn !== ruleFilter.checkOn ||
|
|
578
|
+
recoveryFilter.evaluateOverTime ||
|
|
579
|
+
TelemetryAlertRuleUtil.isAnomaly(ruleFilter.filterType) ||
|
|
580
|
+
TelemetryAlertRuleUtil.isAnomaly(recoveryFilter.filterType)) {
|
|
581
|
+
return null;
|
|
582
|
+
}
|
|
583
|
+
const ruleValue = TelemetryAlertRuleUtil.toNumber(ruleFilter.value);
|
|
584
|
+
const recoveryValue = TelemetryAlertRuleUtil.toNumber(recoveryFilter.value);
|
|
585
|
+
if (ruleValue === undefined ||
|
|
586
|
+
recoveryValue === undefined ||
|
|
587
|
+
!ruleFilter.filterType ||
|
|
588
|
+
!recoveryFilter.filterType) {
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
const isMetric = data.monitorType === MonitorType_1.default.Metrics;
|
|
592
|
+
/*
|
|
593
|
+
* A metric's recovery must read the same number the rule reads: the
|
|
594
|
+
* same query, in the same unit, taken from its window the same way.
|
|
595
|
+
*/
|
|
596
|
+
if (isMetric) {
|
|
597
|
+
const ruleOptions = ruleFilter.metricMonitorOptions;
|
|
598
|
+
const recoveryOptions = recoveryFilter.metricMonitorOptions;
|
|
599
|
+
if (((ruleOptions === null || ruleOptions === void 0 ? void 0 : ruleOptions.metricAlias) || "") !==
|
|
600
|
+
((recoveryOptions === null || recoveryOptions === void 0 ? void 0 : recoveryOptions.metricAlias) || "") ||
|
|
601
|
+
((ruleOptions === null || ruleOptions === void 0 ? void 0 : ruleOptions.thresholdUnit) || "") !==
|
|
602
|
+
((recoveryOptions === null || recoveryOptions === void 0 ? void 0 : recoveryOptions.thresholdUnit) || "") ||
|
|
603
|
+
((ruleOptions === null || ruleOptions === void 0 ? void 0 : ruleOptions.metricAggregationType) || "") !==
|
|
604
|
+
((recoveryOptions === null || recoveryOptions === void 0 ? void 0 : recoveryOptions.metricAggregationType) || "")) {
|
|
605
|
+
return null;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const comparison = TelemetryAlertRuleUtil.compareFilterSets({
|
|
609
|
+
isCount: !isMetric,
|
|
610
|
+
rule: { filterType: ruleFilter.filterType, value: ruleValue },
|
|
611
|
+
recovery: {
|
|
612
|
+
filterType: recoveryFilter.filterType,
|
|
613
|
+
value: recoveryValue,
|
|
614
|
+
},
|
|
615
|
+
});
|
|
616
|
+
if (comparison.isOpposite) {
|
|
617
|
+
return TelemetryAlertRuleRecovery.Opposite;
|
|
618
|
+
}
|
|
619
|
+
if (comparison.overlaps) {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
if (isMetric &&
|
|
623
|
+
recoveryFilter.filterType === (0, RecommendationCriteriaBuilder_1.getRecoveryFilterType)(ruleFilter.filterType)) {
|
|
624
|
+
const withMargin = (0, RecommendationCriteriaBuilder_1.getRecoveryThreshold)({
|
|
625
|
+
filterType: ruleFilter.filterType,
|
|
626
|
+
value: ruleValue,
|
|
627
|
+
});
|
|
628
|
+
if (withMargin !== undefined &&
|
|
629
|
+
TelemetryAlertRuleUtil.isSameNumber(withMargin, recoveryValue)) {
|
|
630
|
+
return TelemetryAlertRuleRecovery.OppositeWithMargin;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return TelemetryAlertRuleRecovery.Disjoint;
|
|
634
|
+
}
|
|
635
|
+
/*
|
|
636
|
+
* How the values two comparisons match relate: whether every value
|
|
637
|
+
* matches exactly one of them (opposites), and whether any value matches
|
|
638
|
+
* both. A comparison changes its answer only at its own value, so a few
|
|
639
|
+
* values on each side of the two thresholds, and far beyond them, decide
|
|
640
|
+
* it: whole numbers from 0 for a count, any number for a metric.
|
|
641
|
+
*/
|
|
642
|
+
static compareFilterSets(data) {
|
|
643
|
+
const thresholds = [data.rule.value, data.recovery.value];
|
|
644
|
+
const candidates = [];
|
|
645
|
+
if (data.isCount) {
|
|
646
|
+
candidates.push(0, LARGE_COUNT);
|
|
647
|
+
for (const threshold of thresholds) {
|
|
648
|
+
for (const near of [
|
|
649
|
+
Math.floor(threshold) - 1,
|
|
650
|
+
Math.floor(threshold),
|
|
651
|
+
Math.ceil(threshold),
|
|
652
|
+
Math.ceil(threshold) + 1,
|
|
653
|
+
]) {
|
|
654
|
+
if (near >= 0) {
|
|
655
|
+
candidates.push(near);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
const lowest = Math.min(...thresholds);
|
|
662
|
+
const highest = Math.max(...thresholds);
|
|
663
|
+
const gap = highest - lowest;
|
|
664
|
+
const step = gap > 0 ? gap / 4 : Math.max(1, Math.abs(lowest)) * 1e-6;
|
|
665
|
+
candidates.push(-LARGE_COUNT, LARGE_COUNT, (lowest + highest) / 2);
|
|
666
|
+
for (const threshold of thresholds) {
|
|
667
|
+
candidates.push(threshold - step, threshold, threshold + step);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
let isOpposite = true;
|
|
671
|
+
let overlaps = false;
|
|
672
|
+
for (const candidate of candidates) {
|
|
673
|
+
const ruleMatches = TelemetryAlertRuleUtil.matches({
|
|
674
|
+
filterType: data.rule.filterType,
|
|
675
|
+
threshold: data.rule.value,
|
|
676
|
+
value: candidate,
|
|
677
|
+
});
|
|
678
|
+
const recoveryMatches = TelemetryAlertRuleUtil.matches({
|
|
679
|
+
filterType: data.recovery.filterType,
|
|
680
|
+
threshold: data.recovery.value,
|
|
681
|
+
value: candidate,
|
|
682
|
+
});
|
|
683
|
+
if (ruleMatches === recoveryMatches) {
|
|
684
|
+
isOpposite = false;
|
|
685
|
+
}
|
|
686
|
+
if (ruleMatches && recoveryMatches) {
|
|
687
|
+
overlaps = true;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return { isOpposite, overlaps };
|
|
691
|
+
}
|
|
692
|
+
static getAction(instance) {
|
|
693
|
+
var _a, _b;
|
|
694
|
+
const createIncidents = Boolean((_a = instance.data) === null || _a === void 0 ? void 0 : _a.createIncidents);
|
|
695
|
+
const createAlerts = Boolean((_b = instance.data) === null || _b === void 0 ? void 0 : _b.createAlerts);
|
|
696
|
+
if (createIncidents && createAlerts) {
|
|
697
|
+
return TelemetryAlertRuleAction.AlertAndIncident;
|
|
698
|
+
}
|
|
699
|
+
if (createIncidents) {
|
|
700
|
+
return TelemetryAlertRuleAction.Incident;
|
|
701
|
+
}
|
|
702
|
+
if (createAlerts) {
|
|
703
|
+
return TelemetryAlertRuleAction.Alert;
|
|
704
|
+
}
|
|
705
|
+
return TelemetryAlertRuleAction.StatusOnly;
|
|
706
|
+
}
|
|
707
|
+
static newRuleInstance(rule) {
|
|
708
|
+
const instance = new MonitorCriteriaInstance_1.default();
|
|
709
|
+
instance.data = {
|
|
710
|
+
id: rule.ruleCriteriaId || ObjectID_1.default.generate().toString(),
|
|
711
|
+
monitorStatusId: undefined,
|
|
712
|
+
filterCondition: FilterCondition_1.default.Any,
|
|
713
|
+
filters: [],
|
|
714
|
+
incidents: [],
|
|
715
|
+
alerts: [],
|
|
716
|
+
changeMonitorStatus: false,
|
|
717
|
+
createIncidents: false,
|
|
718
|
+
createAlerts: false,
|
|
719
|
+
isEnabled: true,
|
|
720
|
+
name: "",
|
|
721
|
+
description: "",
|
|
722
|
+
};
|
|
723
|
+
return instance;
|
|
724
|
+
}
|
|
725
|
+
static buildRuleFilter(data) {
|
|
726
|
+
var _a, _b, _c;
|
|
727
|
+
const { rule } = data;
|
|
728
|
+
const isAnomaly = TelemetryAlertRuleUtil.isAnomaly(rule.filterType);
|
|
729
|
+
/*
|
|
730
|
+
* The value as it was stored when it is still the same number: the API
|
|
731
|
+
* and Terraform may have written it as text ("10"), and a rule saved
|
|
732
|
+
* unchanged must save what was there.
|
|
733
|
+
*/
|
|
734
|
+
const previousValue = (_a = data.previous) === null || _a === void 0 ? void 0 : _a.value;
|
|
735
|
+
const value = isAnomaly
|
|
736
|
+
? undefined
|
|
737
|
+
: previousValue !== undefined &&
|
|
738
|
+
TelemetryAlertRuleUtil.toNumber(previousValue) === rule.threshold
|
|
739
|
+
? previousValue
|
|
740
|
+
: rule.threshold;
|
|
741
|
+
const filter = Object.assign(Object.assign({}, (data.previous || {})), { checkOn: data.measure, filterType: rule.filterType, value: value });
|
|
742
|
+
if (data.monitorType === MonitorType_1.default.Metrics) {
|
|
743
|
+
const options = Object.assign({}, (((_b = data.previous) === null || _b === void 0 ? void 0 : _b.metricMonitorOptions) || {}));
|
|
744
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "metricAlias", rule.metricAlias);
|
|
745
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "metricAggregationType", rule.metricAggregationType);
|
|
746
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "onNoDataPolicy", rule.onNoDataPolicy);
|
|
747
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "thresholdUnit", rule.thresholdUnit);
|
|
748
|
+
/*
|
|
749
|
+
* Kept whichever comparison the rule makes, as the full editor keeps
|
|
750
|
+
* it: a threshold condition ignores it, and a rule switched back to an
|
|
751
|
+
* anomaly finds its sensitivity again.
|
|
752
|
+
*/
|
|
753
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "anomalyDetection", rule.anomalyDetection);
|
|
754
|
+
filter.metricMonitorOptions = options;
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
/*
|
|
758
|
+
* A count's anomaly conditions read their sensitivity and baseline
|
|
759
|
+
* from the same options a metric's do (LogMonitorCriteria,
|
|
760
|
+
* TraceMonitorCriteria).
|
|
761
|
+
*/
|
|
762
|
+
const options = Object.assign({}, (((_c = data.previous) === null || _c === void 0 ? void 0 : _c.metricMonitorOptions) || {}));
|
|
763
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "anomalyDetection", rule.anomalyDetection);
|
|
764
|
+
if (Object.keys(options).length > 0) {
|
|
765
|
+
filter.metricMonitorOptions = options;
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
delete filter.metricMonitorOptions;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return filter;
|
|
772
|
+
}
|
|
773
|
+
static buildRecoveryFilter(data) {
|
|
774
|
+
var _a, _b, _c, _d;
|
|
775
|
+
const { ruleFilter, previousRecoveryFilter } = data;
|
|
776
|
+
const recoveryFilter = Object.assign({}, previousRecoveryFilter);
|
|
777
|
+
/*
|
|
778
|
+
* A metric's recovery reads the same query, unit and aggregation as the
|
|
779
|
+
* rule; the other options (a no-data policy of its own) stay its own.
|
|
780
|
+
*/
|
|
781
|
+
if (data.monitorType === MonitorType_1.default.Metrics) {
|
|
782
|
+
const options = Object.assign({}, (previousRecoveryFilter.metricMonitorOptions || {}));
|
|
783
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "metricAlias", (_a = ruleFilter.metricMonitorOptions) === null || _a === void 0 ? void 0 : _a.metricAlias);
|
|
784
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "metricAggregationType", (_b = ruleFilter.metricMonitorOptions) === null || _b === void 0 ? void 0 : _b.metricAggregationType);
|
|
785
|
+
TelemetryAlertRuleUtil.setOrDelete(options, "thresholdUnit", (_c = ruleFilter.metricMonitorOptions) === null || _c === void 0 ? void 0 : _c.thresholdUnit);
|
|
786
|
+
recoveryFilter.metricMonitorOptions = options;
|
|
787
|
+
}
|
|
788
|
+
// Unchanged comparison: the recovery keeps its own wording of it.
|
|
789
|
+
if (!data.ruleChanged) {
|
|
790
|
+
return recoveryFilter;
|
|
791
|
+
}
|
|
792
|
+
const ruleValue = TelemetryAlertRuleUtil.toNumber(ruleFilter.value);
|
|
793
|
+
recoveryFilter.filterType = TelemetryAlertRuleUtil.getOppositeFilterType({
|
|
794
|
+
monitorType: data.monitorType,
|
|
795
|
+
filterType: ruleFilter.filterType,
|
|
796
|
+
value: ruleValue,
|
|
797
|
+
});
|
|
798
|
+
recoveryFilter.value =
|
|
799
|
+
data.recovery === TelemetryAlertRuleRecovery.OppositeWithMargin
|
|
800
|
+
? (_d = (0, RecommendationCriteriaBuilder_1.getRecoveryThreshold)({
|
|
801
|
+
filterType: ruleFilter.filterType,
|
|
802
|
+
value: ruleValue,
|
|
803
|
+
})) !== null && _d !== void 0 ? _d : ruleValue
|
|
804
|
+
: ruleValue;
|
|
805
|
+
return recoveryFilter;
|
|
806
|
+
}
|
|
807
|
+
/*
|
|
808
|
+
* The opposite of a comparison. For a count, "is 0" is written as its
|
|
809
|
+
* opposite "more than 0", as the out-of-the-box criteria write it.
|
|
810
|
+
*/
|
|
811
|
+
static getOppositeFilterType(data) {
|
|
812
|
+
if (TelemetryAlertRuleUtil.isCountMonitorType(data.monitorType) &&
|
|
813
|
+
data.filterType === CriteriaFilter_1.FilterType.EqualTo &&
|
|
814
|
+
data.value === 0) {
|
|
815
|
+
return CriteriaFilter_1.FilterType.GreaterThan;
|
|
816
|
+
}
|
|
817
|
+
return (0, RecommendationCriteriaBuilder_1.getRecoveryFilterType)(data.filterType);
|
|
818
|
+
}
|
|
819
|
+
static applyRuleToInstance(data) {
|
|
820
|
+
const { instance, rule } = data;
|
|
821
|
+
if (!instance.data) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
instance.data.filters = [data.filter];
|
|
825
|
+
instance.data.name = rule.name;
|
|
826
|
+
const opensIncident = rule.action === TelemetryAlertRuleAction.Incident ||
|
|
827
|
+
rule.action === TelemetryAlertRuleAction.AlertAndIncident;
|
|
828
|
+
const opensAlert = rule.action === TelemetryAlertRuleAction.Alert ||
|
|
829
|
+
rule.action === TelemetryAlertRuleAction.AlertAndIncident;
|
|
830
|
+
instance.data.createIncidents = opensIncident;
|
|
831
|
+
instance.data.createAlerts = opensAlert;
|
|
832
|
+
/*
|
|
833
|
+
* The rows of an action that is off stay, as the full editor keeps them
|
|
834
|
+
* (MonitorCriteriaInstance.getValidationError): turning it back on
|
|
835
|
+
* brings back what was typed. Only the first row is the rule's.
|
|
836
|
+
*/
|
|
837
|
+
if (rule.incident) {
|
|
838
|
+
instance.data.incidents = [
|
|
839
|
+
rule.incident,
|
|
840
|
+
...instance.data.incidents.slice(1),
|
|
841
|
+
];
|
|
842
|
+
}
|
|
843
|
+
if (rule.alert) {
|
|
844
|
+
instance.data.alerts = [rule.alert, ...instance.data.alerts.slice(1)];
|
|
845
|
+
}
|
|
846
|
+
instance.data.changeMonitorStatus = Boolean(rule.monitorStatusId);
|
|
847
|
+
instance.data.monitorStatusId = rule.monitorStatusId;
|
|
848
|
+
}
|
|
849
|
+
static isSameComparison(previous, next) {
|
|
850
|
+
if (!previous) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
return (previous.filterType === next.filterType &&
|
|
854
|
+
TelemetryAlertRuleUtil.toNumber(previous.value) ===
|
|
855
|
+
TelemetryAlertRuleUtil.toNumber(next.value));
|
|
856
|
+
}
|
|
857
|
+
// A stored value as a number: numbers, and numeric text (the API's).
|
|
858
|
+
static toNumber(value) {
|
|
859
|
+
if (typeof value === "number") {
|
|
860
|
+
return Number.isFinite(value) ? value : undefined;
|
|
861
|
+
}
|
|
862
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
863
|
+
const parsed = Number(value.trim());
|
|
864
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
865
|
+
}
|
|
866
|
+
return undefined;
|
|
867
|
+
}
|
|
868
|
+
static isSameNumber(a, b) {
|
|
869
|
+
const scale = Math.max(1, Math.abs(a), Math.abs(b));
|
|
870
|
+
return Math.abs(a - b) <= scale * 1e-9;
|
|
871
|
+
}
|
|
872
|
+
static setOrDelete(target, key, value) {
|
|
873
|
+
if (value === undefined) {
|
|
874
|
+
delete target[key];
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
target[key] = value;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
TelemetryAlertRuleUtil.RULE_MONITOR_TYPES = [
|
|
881
|
+
MonitorType_1.default.Logs,
|
|
882
|
+
MonitorType_1.default.Traces,
|
|
883
|
+
MonitorType_1.default.Exceptions,
|
|
884
|
+
MonitorType_1.default.Metrics,
|
|
885
|
+
];
|
|
886
|
+
exports.default = TelemetryAlertRuleUtil;
|