public async Task UpdateAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string alertConfigurationId = AlertConfigurationId; Response <AnomalyAlertConfiguration> response = await adminClient.GetAlertConfigurationAsync(alertConfigurationId); AnomalyAlertConfiguration alertConfiguration = response.Value; string originalDescription = alertConfiguration.Description; alertConfiguration.Description = "This description was generated by a sample."; await adminClient.UpdateAlertConfigurationAsync(alertConfigurationId, alertConfiguration); // Undo the changes to leave the alert configuration unaltered. Skip this step if you intend to keep // the changes. alertConfiguration.Description = originalDescription; await adminClient.UpdateAlertConfigurationAsync(alertConfigurationId, alertConfiguration); }
public async Task UpdateRootLevelMembersWithNullSetsToDefault() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); var detectionConfigId = disposableDetectionConfig.Configuration.Id; string configName = Recording.GenerateAlphaNumericId("config"); var configToCreate = new AnomalyAlertConfiguration() { Name = configName, Description = "description", MetricAlertConfigurations = { new MetricAlertConfiguration(detectionConfigId, MetricAnomalyAlertScope.CreateScopeForWholeSeries()) } }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); AnomalyAlertConfiguration configToUpdate = disposableConfig.Configuration; configToUpdate.Description = null; AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate); Assert.That(updatedConfig.Description, Is.Empty); }
public async Task GetAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string alertConfigurationId = AlertConfigurationId; Response <AnomalyAlertConfiguration> response = await adminClient.GetAlertConfigurationAsync(alertConfigurationId); AnomalyAlertConfiguration alertConfiguration = response.Value; Console.WriteLine($"Alert configuration name: {alertConfiguration.Name}"); Console.WriteLine($"Alert configuration description: {alertConfiguration.Description}"); Console.WriteLine(); Console.WriteLine($"IDs of hooks to alert:"); foreach (string hookId in alertConfiguration.IdsOfHooksToAlert) { Console.WriteLine($" - {hookId}"); } Console.WriteLine(); Console.WriteLine("Metric anomaly alert configurations:"); foreach (MetricAnomalyAlertConfiguration metricAlertConfiguration in alertConfiguration.MetricAlertConfigurations) { Console.Write($" Scope type: {metricAlertConfiguration.AlertScope.ScopeType}, "); Console.WriteLine($"Anomaly detection configuration ID: {metricAlertConfiguration.DetectionConfigurationId}"); } }
/// <summary> /// Creates an alert configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>. /// A <see cref="DisposableAlertConfiguration"/> instance is returned, from which the ID of the created /// configuration can be obtained. Upon disposal, the associated configuration will be deleted. /// </summary> /// <param name="adminClient">The client to use for creating and for deleting the configuration.</param> /// <param name="hook">Specifies how the created <see cref="AnomalyAlertConfiguration"/> should be configured.</param> /// <returns>A <see cref="DisposableAlertConfiguration"/> instance from which the ID of the created configuration can be obtained.</returns> public static async Task <DisposableAlertConfiguration> CreateAlertConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyAlertConfiguration alertConfiguration) { AnomalyAlertConfiguration createdConfig = await adminClient.CreateAlertConfigurationAsync(alertConfiguration); Assert.That(createdConfig, Is.Not.Null); Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty); return(new DisposableAlertConfiguration(adminClient, createdConfig.Id)); }
public async Task CreateAndGetAlertConfigurationWithSeriesGroupScope() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); var dimensions = new Dictionary <string, string>() { { TempDataFeedDimensionNameA, "Delhi" } }; DimensionKey groupKey = new DimensionKey(dimensions); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.CreateScopeForSeriesGroup(groupKey); var metricAlertConfig = new MetricAlertConfiguration(detectionConfigId, scope); string configName = Recording.GenerateAlphaNumericId("config"); var configToCreate = new AnomalyAlertConfiguration() { Name = configName, MetricAlertConfigurations = { metricAlertConfig } }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); AnomalyAlertConfiguration createdConfig = disposableConfig.Configuration; Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.Empty); Assert.That(createdConfig.CrossMetricsOperator, Is.Null); Assert.That(createdConfig.IdsOfHooksToAlert, Is.Not.Null.And.Empty); Assert.That(createdConfig.DimensionsToSplitAlert, Is.Not.Null.And.Empty); Assert.That(createdConfig.MetricAlertConfigurations, Is.Not.Null); MetricAlertConfiguration createdMetricAlertConfig = createdConfig.MetricAlertConfigurations.Single(); Assert.That(createdMetricAlertConfig.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(createdMetricAlertConfig.AlertScope, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.SeriesGroup)); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope, Is.Null); ValidateTempDataFeedDimensionKey(createdMetricAlertConfig.AlertScope.SeriesGroupInScope, "Delhi"); Assert.That(createdMetricAlertConfig.AlertConditions, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition, Is.Null); Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition, Is.Null); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition, Is.Null); Assert.That(createdMetricAlertConfig.UseDetectionResultToFilterAnomalies, Is.False); }
public async Task CreateAndGetAlertConfigurationWithTopNScope() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var topNGroup = new TopNGroupScope(30, 20, 10); var scope = MetricAnomalyAlertScope.GetScopeForTopNGroup(topNGroup); var metricAlertConfig = new MetricAnomalyAlertConfiguration(detectionConfigId, scope); string configName = Recording.GenerateAlphaNumericId("config"); var configToCreate = new AnomalyAlertConfiguration() { Name = configName, MetricAlertConfigurations = { metricAlertConfig } }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); AnomalyAlertConfiguration createdConfig = disposableConfig.Configuration; Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.Empty); Assert.That(createdConfig.CrossMetricsOperator, Is.Null); Assert.That(createdConfig.IdsOfHooksToAlert, Is.Not.Null.And.Empty); Assert.That(createdConfig.MetricAlertConfigurations, Is.Not.Null); MetricAnomalyAlertConfiguration createdMetricAlertConfig = createdConfig.MetricAlertConfigurations.Single(); Assert.That(createdMetricAlertConfig.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(createdMetricAlertConfig.AlertScope, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.TopN)); Assert.That(createdMetricAlertConfig.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope.Top, Is.EqualTo(30)); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope.Period, Is.EqualTo(20)); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope.MinimumTopCount, Is.EqualTo(10)); Assert.That(createdMetricAlertConfig.AlertConditions, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition, Is.Null); Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition, Is.Null); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition, Is.Null); Assert.That(createdMetricAlertConfig.UseDetectionResultToFilterAnomalies, Is.False); }
public void UpdateAlertConfigurationRespectsTheCancellationToken() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var config = new AnomalyAlertConfiguration(); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(FakeGuid, config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(FakeGuid, config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); }
public void UpdateAlertConfigurationValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var config = new AnomalyAlertConfiguration(); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(null), Throws.InstanceOf <ArgumentNullException>()); var configurationWithNullId = new AnomalyAlertConfiguration(); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(configurationWithNullId), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(configurationWithNullId), Throws.InstanceOf <ArgumentNullException>()); }
public void UpdateAlertConfigurationRespectsTheCancellationToken() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var metricConfigs = new List <MetricAnomalyAlertConfiguration>() { new MetricAnomalyAlertConfiguration(FakeGuid, MetricAnomalyAlertScope.GetScopeForWholeSeries()) }; var config = new AnomalyAlertConfiguration("configName", new List <string>(), metricConfigs); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(FakeGuid, config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(FakeGuid, config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); }
public void UpdateAlertConfigurationValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var config = new AnomalyAlertConfiguration(); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(null, config), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfigurationAsync("", config), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.UpdateAlertConfigurationAsync("configId", config), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(null, config), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration("", config), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.UpdateAlertConfiguration("configId", config), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.UpdateAlertConfiguration(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>()); }
public async Task CreateAndDeleteAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); #region Snippet:CreateAlertConfigurationAsync #if SNIPPET string hookId = "<hookId>"; string anomalyDetectionConfigurationId = "<anomalyDetectionConfigurationId>"; string configurationName = "<configurationName>"; #else string hookId = HookId; string anomalyDetectionConfigurationId = DetectionConfigurationId; string configurationName = GetUniqueName(); #endif AnomalyAlertConfiguration alertConfiguration = new AnomalyAlertConfiguration() { Name = configurationName }; alertConfiguration.IdsOfHooksToAlert.Add(hookId); var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfiguration = new MetricAnomalyAlertConfiguration(anomalyDetectionConfigurationId, scope); alertConfiguration.MetricAlertConfigurations.Add(metricAlertConfiguration); Response <AnomalyAlertConfiguration> response = await adminClient.CreateAlertConfigurationAsync(alertConfiguration); AnomalyAlertConfiguration createdAlertConfiguration = response.Value; Console.WriteLine($"Alert configuration ID: {createdAlertConfiguration.Id}"); #endregion // Delete the anomaly alert configuration to clean up the Metrics Advisor resource. Do not // perform this step if you intend to keep using the configuration. await adminClient.DeleteAlertConfigurationAsync(createdAlertConfiguration.Id); }
public void CreateAlertConfigurationValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var config = new AnomalyAlertConfiguration() { Name = null }; Assert.That(() => adminClient.CreateAlertConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateAlertConfiguration(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateAlertConfigurationAsync(config), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.CreateAlertConfiguration(config), Throws.InstanceOf <ArgumentNullException>()); config.Name = ""; Assert.That(() => adminClient.CreateAlertConfigurationAsync(config), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.CreateAlertConfiguration(config), Throws.InstanceOf <ArgumentException>()); }
public async Task AnomalyAlertConfigurationOperations() { var adminClient = GetMetricsAdvisorAdministrationClient(); // Create a Detection Configuration DataFeed feed = await GetFirstDataFeed(adminClient); MetricAnomalyDetectionConfiguration detectionConfig = await CreateMetricAnomalyDetectionConfiguration(adminClient).ConfigureAwait(false); MetricAnomalyDetectionConfiguration createdAnomalyDetectionConfiguration = await adminClient.CreateMetricAnomalyDetectionConfigurationAsync(detectionConfig).ConfigureAwait(false); AnomalyAlertConfiguration createdAlertConfig = await adminClient.CreateAnomalyAlertConfigurationAsync( new AnomalyAlertConfiguration( Recording.GenerateAlphaNumericId("test"), new List <string>(), new List <MetricAnomalyAlertConfiguration> { new MetricAnomalyAlertConfiguration( createdAnomalyDetectionConfiguration.Id, new MetricAnomalyAlertScope( MetricAnomalyAlertScopeType.TopN, new DimensionKey(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("test", "test2") }), new TopNGroupScope(8, 4, 2))) }) ).ConfigureAwait(false); Assert.That(createdAlertConfig.Id, Is.Not.Null); // Validate that we can Get the newly created config AnomalyAlertConfiguration getAlertConfig = await adminClient.GetAnomalyAlertConfigurationAsync(createdAlertConfig.Id).ConfigureAwait(false); Response <IReadOnlyList <AnomalyAlertConfiguration> > getAlertConfigs = await adminClient.GetAnomalyAlertConfigurationsAsync(createdAnomalyDetectionConfiguration.Id).ConfigureAwait(false); Assert.That(getAlertConfig.Id, Is.EqualTo(createdAlertConfig.Id)); Assert.That(getAlertConfigs.Value.Any(c => c.Id == createdAlertConfig.Id)); // Cleanup await adminClient.DeleteAnomalyAlertConfigurationAsync(createdAlertConfig.Id).ConfigureAwait(false); }
public async Task CreateAndDeleteAlertConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string hookId = HookId; string anomalyDetectionConfigurationId = DetectionConfigurationId; #region Snippet:CreateAlertConfigurationAsync //@@ string hookId = "<hookId>"; //@@ string anomalyDetectionConfigurationId = "<anomalyDetectionConfigurationId>"; string configurationName = "Sample anomaly alert configuration"; var idsOfHooksToAlert = new List <string>() { hookId }; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfigurations = new List <MetricAnomalyAlertConfiguration>() { new MetricAnomalyAlertConfiguration(anomalyDetectionConfigurationId, scope) }; AnomalyAlertConfiguration alertConfiguration = new AnomalyAlertConfiguration(configurationName, idsOfHooksToAlert, metricAlertConfigurations); Response <string> response = await adminClient.CreateAlertConfigurationAsync(alertConfiguration); string alertConfigurationId = response.Value; Console.WriteLine($"Alert configuration ID: {alertConfigurationId}"); #endregion // Delete the anomaly alert configuration to clean up the Metrics Advisor resource. Do not // perform this step if you intend to keep using the configuration. await adminClient.DeleteAlertConfigurationAsync(alertConfigurationId); }
public void UpdateAlertConfigurationValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); var metricConfigs = new List <MetricAnomalyAlertConfiguration>() { new MetricAnomalyAlertConfiguration(FakeGuid, MetricAnomalyAlertScope.GetScopeForWholeSeries()) }; var config = new AnomalyAlertConfiguration("configName", new List <string>(), metricConfigs); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(null, config), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfigurationAsync("", config), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.UpdateAlertConfigurationAsync("configId", config), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.UpdateAlertConfigurationAsync(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration(null, config), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.UpdateAlertConfiguration("", config), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.UpdateAlertConfiguration("configId", config), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.UpdateAlertConfiguration(FakeGuid, null), Throws.InstanceOf <ArgumentNullException>()); }
public async Task DeleteAlertConfiguration(bool useTokenCredential) { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); string configName = Recording.GenerateAlphaNumericId("config"); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var configToCreate = new AnomalyAlertConfiguration() { Name = configName, MetricAlertConfigurations = { new(detectionConfigId, scope) } }; string configId = null; try { AnomalyAlertConfiguration createdConfig = await adminClient.CreateAlertConfigurationAsync(configToCreate); configId = createdConfig.Id; Assert.That(configId, Is.Not.Null.And.Not.Empty); } finally { if (configId != null) { await adminClient.DeleteAlertConfigurationAsync(configId); var errorCause = "Not Found"; Assert.That(async() => await adminClient.GetAlertConfigurationAsync(configId), Throws.InstanceOf <RequestFailedException>().With.Message.Contains(errorCause)); } } }
/// <summary> /// Initializes a new instance of the <see cref="DisposableAlertConfiguration"/> class. /// </summary> /// <param name="adminClient">The client to use for deleting the configuration upon disposal.</param> /// <param name="configuration">The alert configuration this instance is associated with.</param> private DisposableAlertConfiguration(MetricsAdvisorAdministrationClient adminClient, AnomalyAlertConfiguration configuration) { _adminClient = adminClient; Configuration = configuration; }
/// <summary> /// Creates an alert configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>. /// A <see cref="DisposableAlertConfiguration"/> instance is returned, from which the created configuration /// can be obtained. Upon disposal, the associated configuration will be deleted. /// </summary> /// <param name="adminClient">The client to use for creating and for deleting the configuration.</param> /// <param name="configuration">Specifies how the created <see cref="AnomalyAlertConfiguration"/> should be configured.</param> /// <returns>A <see cref="DisposableAlertConfiguration"/> instance from which the created configuration can be obtained.</returns> public static async Task <DisposableAlertConfiguration> CreateAlertConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyAlertConfiguration alertConfiguration) { AnomalyAlertConfiguration createdConfig = await adminClient.CreateAlertConfigurationAsync(alertConfiguration); return(new DisposableAlertConfiguration(adminClient, createdConfig)); }
public async Task UpdateAlertConfigurationWithEveryMember() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); // Configure the Metric Anomaly Alert Configurations to be used. string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new EmailNotificationHook(hookName) { EmailsToAlert = { "*****@*****.**" } }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfig0 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true), AlertConditions = new MetricAnomalyAlertConditions() { MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both) { UpperBound = 20.0, LowerBound = 10.0, CompanionMetricId = metricId, ShouldAlertIfDataPointMissing = true }, SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium) } }; var metricAlertConfig1 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { UseDetectionResultToFilterAnomalies = true }; // Create the Anomaly Alert Configuration. string configName = Recording.GenerateAlphaNumericId("config"); var description = "This hook was created to test the .NET client."; var hookIds = new List <string>() { disposableHook.Hook.Id }; var metricAlertConfigs = new List <MetricAnomalyAlertConfiguration>() { metricAlertConfig0, metricAlertConfig1 }; var configToCreate = new AnomalyAlertConfiguration() { Name = configName, IdsOfHooksToAlert = { disposableHook.Hook.Id }, MetricAlertConfigurations = { metricAlertConfig0, metricAlertConfig1 }, CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Xor }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); // Update the created configuration. AnomalyAlertConfiguration configToUpdate = disposableConfig.Configuration; configToUpdate.Description = description; configToUpdate.IdsOfHooksToAlert.Clear(); configToUpdate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.And; configToUpdate.MetricAlertConfigurations.RemoveAt(1); var newScope = MetricAnomalyAlertScope.GetScopeForTopNGroup(new TopNGroupScope(50, 40, 30)); var newMetricAlertConfig = new MetricAnomalyAlertConfiguration(detectionConfigId, newScope) { AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(4, SnoozeScope.Metric, true), UseDetectionResultToFilterAnomalies = true }; configToUpdate.MetricAlertConfigurations.Add(newMetricAlertConfig); MetricAnomalyAlertConfiguration metricAlertConfigToUpdate = configToUpdate.MetricAlertConfigurations[0]; metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.UpperBound = 15.0; metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.LowerBound = 5.0; metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.CompanionMetricId = null; metricAlertConfigToUpdate.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing = false; metricAlertConfigToUpdate.AlertConditions.SeverityCondition = new SeverityCondition(AnomalySeverity.Medium, AnomalySeverity.High); metricAlertConfigToUpdate.AlertSnoozeCondition = null; AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate); // Validate top-level members. Assert.That(updatedConfig.Id, Is.EqualTo(configToUpdate.Id)); Assert.That(updatedConfig.Name, Is.EqualTo(configName)); Assert.That(updatedConfig.Description, Is.EqualTo(description)); Assert.That(updatedConfig.CrossMetricsOperator, Is.EqualTo(MetricAnomalyAlertConfigurationsOperator.And)); Assert.That(updatedConfig.IdsOfHooksToAlert, Is.Not.Null.And.Empty); Assert.That(updatedConfig.MetricAlertConfigurations, Is.Not.Null); // Validate the first Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration updatedMetricAlertConfig0 = updatedConfig.MetricAlertConfigurations[0]; Assert.That(updatedMetricAlertConfig0.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(updatedMetricAlertConfig0.AlertScope, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(updatedMetricAlertConfig0.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig0.AlertScope.TopNGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(15.0)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(5.0)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.False); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium)); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.High)); Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition, Is.Null); Assert.That(updatedMetricAlertConfig0.UseDetectionResultToFilterAnomalies, Is.False); // Validate the second Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration updatedMetricAlertConfig1 = updatedConfig.MetricAlertConfigurations[1]; Assert.That(updatedMetricAlertConfig1.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(updatedMetricAlertConfig1.AlertScope, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.TopN)); Assert.That(updatedMetricAlertConfig1.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.Top, Is.EqualTo(50)); Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.Period, Is.EqualTo(40)); Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope.MinimumTopCount, Is.EqualTo(30)); Assert.That(updatedMetricAlertConfig1.AlertConditions, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertConditions.MetricBoundaryCondition, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertConditions.SeverityCondition, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(4)); Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Metric)); Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True); Assert.That(updatedMetricAlertConfig1.UseDetectionResultToFilterAnomalies, Is.True); }
public async Task UpdateAlertConfigurationWithMinimumSetup(bool useTokenCrendential) { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCrendential); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); // Configure the Metric Anomaly Alert Configurations to be used. string hookName = Recording.GenerateAlphaNumericId("hook"); var hookToCreate = new EmailNotificationHook(hookName) { EmailsToAlert = { "*****@*****.**" } }; await using var disposableHook = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfig0 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true), AlertConditions = new MetricAnomalyAlertConditions() { MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both) { UpperBound = 20.0, LowerBound = 10.0, CompanionMetricId = metricId, ShouldAlertIfDataPointMissing = true }, SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium) } }; var metricAlertConfig1 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { UseDetectionResultToFilterAnomalies = true }; // Create the Anomaly Alert Configuration. string configName = Recording.GenerateAlphaNumericId("config"); var hookIds = new List <string>() { disposableHook.Hook.Id }; var configToCreate = new AnomalyAlertConfiguration() { Name = configName, IdsOfHooksToAlert = { disposableHook.Hook.Id }, MetricAlertConfigurations = { metricAlertConfig0, metricAlertConfig1 }, CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Xor }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); // Update the created configuration. AnomalyAlertConfiguration configToUpdate = disposableConfig.Configuration; configToUpdate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Or; AnomalyAlertConfiguration updatedConfig = await adminClient.UpdateAlertConfigurationAsync(configToUpdate); // Validate top-level members. Assert.That(updatedConfig.Id, Is.EqualTo(configToUpdate.Id)); Assert.That(updatedConfig.Name, Is.EqualTo(configName)); Assert.That(updatedConfig.Description, Is.Empty); Assert.That(updatedConfig.CrossMetricsOperator, Is.EqualTo(MetricAnomalyAlertConfigurationsOperator.Or)); Assert.That(updatedConfig.IdsOfHooksToAlert, Is.EqualTo(hookIds)); Assert.That(updatedConfig.MetricAlertConfigurations, Is.Not.Null); Assert.That(updatedConfig.MetricAlertConfigurations.Count, Is.EqualTo(2)); // Validate the first Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration updatedMetricAlertConfig0 = updatedConfig.MetricAlertConfigurations[0]; Assert.That(updatedMetricAlertConfig0.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(updatedMetricAlertConfig0.AlertScope, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(updatedMetricAlertConfig0.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig0.AlertScope.TopNGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(20.0)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(10.0)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.EqualTo(metricId)); Assert.That(updatedMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.True); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Low)); Assert.That(updatedMetricAlertConfig0.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium)); Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition, Is.Not.Null); Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(12)); Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Series)); Assert.That(updatedMetricAlertConfig0.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True); Assert.That(updatedMetricAlertConfig0.UseDetectionResultToFilterAnomalies, Is.False); // Validate the second Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration updatedMetricAlertConfig1 = updatedConfig.MetricAlertConfigurations[1]; Assert.That(updatedMetricAlertConfig1.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(updatedMetricAlertConfig1.AlertScope, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(updatedMetricAlertConfig1.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertScope.TopNGroupInScope, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertConditions, Is.Not.Null); Assert.That(updatedMetricAlertConfig1.AlertConditions.MetricBoundaryCondition, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertConditions.SeverityCondition, Is.Null); Assert.That(updatedMetricAlertConfig1.AlertSnoozeCondition, Is.Null); Assert.That(updatedMetricAlertConfig1.UseDetectionResultToFilterAnomalies, Is.True); }
public async Task AnomalyAlertConfigurationOperations() { var adminClient = GetMetricsAdvisorAdministrationClient(); // Create a Detection Configuration DataFeed feed = await GetFirstDataFeed(adminClient); string createdAnomalyDetectionConfigurationId = await CreateDetectionConfiguration(adminClient).ConfigureAwait(false); var alertConfigToCreate = new AnomalyAlertConfiguration( Recording.GenerateAlphaNumericId("test"), new List <string>(), new List <MetricAnomalyAlertConfiguration> { new MetricAnomalyAlertConfiguration( createdAnomalyDetectionConfigurationId, new MetricAnomalyAlertScope( MetricAnomalyAlertScopeType.TopN, new DimensionKey(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("test", "test2") }), new TopNGroupScope(8, 4, 2))) }); string createdAlertConfigId = await adminClient.CreateAlertConfigurationAsync(alertConfigToCreate).ConfigureAwait(false); Assert.That(createdAlertConfigId, Is.Not.Null); // Validate that we can Get the newly created config AnomalyAlertConfiguration getAlertConfig = await adminClient.GetAlertConfigurationAsync(createdAlertConfigId).ConfigureAwait(false); List <AnomalyAlertConfiguration> getAlertConfigs = new List <AnomalyAlertConfiguration>(); await foreach (var config in adminClient.GetAlertConfigurationsAsync(createdAnomalyDetectionConfigurationId)) { getAlertConfigs.Add(config); } Assert.That(getAlertConfig.Id, Is.EqualTo(createdAlertConfigId)); Assert.That(getAlertConfigs.Any(c => c.Id == createdAlertConfigId)); getAlertConfig.Description = "Updated"; getAlertConfig.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.And; await adminClient.UpdateAlertConfigurationAsync(getAlertConfig.Id, getAlertConfig).ConfigureAwait(false); // Validate that the update succeeded. getAlertConfig = await adminClient.GetAlertConfigurationAsync(createdAlertConfigId).ConfigureAwait(false); Assert.That(getAlertConfig.Description, Is.EqualTo(getAlertConfig.Description)); // Update again starting with our locally created model. alertConfigToCreate.Description = "updated again!"; alertConfigToCreate.CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.And; await adminClient.UpdateAlertConfigurationAsync(getAlertConfig.Id, alertConfigToCreate).ConfigureAwait(false); // Validate that the update succeeded. getAlertConfig = await adminClient.GetAlertConfigurationAsync(createdAlertConfigId).ConfigureAwait(false); Assert.That(getAlertConfig.Description, Is.EqualTo(alertConfigToCreate.Description)); // Cleanup await adminClient.DeleteAlertConfigurationAsync(createdAlertConfigId).ConfigureAwait(false); }
public async Task CreateAndGetAlertConfigurationWithOptionalSingleMetricConfigurationMembers() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); string hookName0 = Recording.GenerateAlphaNumericId("hook"); string hookName1 = Recording.GenerateAlphaNumericId("hook"); var hookToCreate0 = new EmailNotificationHook(hookName0); var hookToCreate1 = new EmailNotificationHook(hookName1); hookToCreate0.EmailsToAlert.Add("*****@*****.**"); hookToCreate1.EmailsToAlert.Add("*****@*****.**"); await using var disposableHook0 = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate0); await using var disposableHook1 = await DisposableNotificationHook.CreateHookAsync(adminClient, hookToCreate1); var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfig = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { AlertSnoozeCondition = new MetricAnomalyAlertSnoozeCondition(12, SnoozeScope.Series, true), AlertConditions = new MetricAnomalyAlertConditions() { MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Both) { UpperBound = 20.0, LowerBound = 10.0, CompanionMetricId = metricId, ShouldAlertIfDataPointMissing = true }, SeverityCondition = new SeverityCondition(AnomalySeverity.Low, AnomalySeverity.Medium) } }; string configName = Recording.GenerateAlphaNumericId("config"); var description = "This hook was created to test the .NET client."; var configToCreate = new AnomalyAlertConfiguration() { Name = configName, IdsOfHooksToAlert = { disposableHook0.Hook.Id, disposableHook1.Hook.Id }, MetricAlertConfigurations = { metricAlertConfig }, Description = description }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); AnomalyAlertConfiguration createdConfig = disposableConfig.Configuration; Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.EqualTo(description)); Assert.That(createdConfig.CrossMetricsOperator, Is.Null); Assert.That(createdConfig.IdsOfHooksToAlert.Count, Is.EqualTo(2)); Assert.That(createdConfig.IdsOfHooksToAlert.Contains(disposableHook0.Hook.Id)); Assert.That(createdConfig.IdsOfHooksToAlert.Contains(disposableHook1.Hook.Id)); Assert.That(createdConfig.MetricAlertConfigurations, Is.Not.Null); MetricAnomalyAlertConfiguration createdMetricAlertConfig = createdConfig.MetricAlertConfigurations.Single(); Assert.That(createdMetricAlertConfig.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(createdMetricAlertConfig.AlertScope, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(createdMetricAlertConfig.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig.AlertScope.TopNGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig.AlertConditions, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Both)); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(20.0)); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(10.0)); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.EqualTo(metricId)); Assert.That(createdMetricAlertConfig.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.True); Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition.MinimumAlertSeverity, Is.EqualTo(AnomalySeverity.Low)); Assert.That(createdMetricAlertConfig.AlertConditions.SeverityCondition.MaximumAlertSeverity, Is.EqualTo(AnomalySeverity.Medium)); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition, Is.Not.Null); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.AutoSnooze, Is.EqualTo(12)); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.SnoozeScope, Is.EqualTo(SnoozeScope.Series)); Assert.That(createdMetricAlertConfig.AlertSnoozeCondition.IsOnlyForSuccessive, Is.True); Assert.That(createdMetricAlertConfig.UseDetectionResultToFilterAnomalies, Is.False); }
public async Task CreateAndGetAlertConfigurationWithMultipleMetricConfigurations() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); await using DisposableDataFeed disposableDataFeed = await CreateTempDataFeedAsync(adminClient); string metricId = disposableDataFeed.DataFeed.MetricIds[TempDataFeedMetricName]; await using DisposableDetectionConfiguration disposableDetectionConfig = await CreateTempDetectionConfigurationAsync(adminClient, metricId); // Configure the Metric Anomaly Alert Configurations to be used. var detectionConfigId = disposableDetectionConfig.Configuration.Id; var scope = MetricAnomalyAlertScope.GetScopeForWholeSeries(); var metricAlertConfig0 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { AlertConditions = new MetricAnomalyAlertConditions() { MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Up) { UpperBound = 20.0 } }, UseDetectionResultToFilterAnomalies = true }; var metricAlertConfig1 = new MetricAnomalyAlertConfiguration(detectionConfigId, scope) { AlertConditions = new MetricAnomalyAlertConditions() { MetricBoundaryCondition = new MetricBoundaryCondition(BoundaryDirection.Down) { LowerBound = 10.0 } } }; // Create the Anomaly Alert Configuration. string configName = Recording.GenerateAlphaNumericId("config"); var configToCreate = new AnomalyAlertConfiguration() { Name = configName, MetricAlertConfigurations = { metricAlertConfig0, metricAlertConfig1 }, CrossMetricsOperator = MetricAnomalyAlertConfigurationsOperator.Xor }; await using var disposableConfig = await DisposableAlertConfiguration.CreateAlertConfigurationAsync(adminClient, configToCreate); // Get the created configuration and validate top-level members. AnomalyAlertConfiguration createdConfig = disposableConfig.Configuration; Assert.That(createdConfig.Id, Is.Not.Null.And.Not.Empty); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.Empty); Assert.That(createdConfig.CrossMetricsOperator, Is.EqualTo(MetricAnomalyAlertConfigurationsOperator.Xor)); Assert.That(createdConfig.IdsOfHooksToAlert, Is.Not.Null.And.Empty); Assert.That(createdConfig.MetricAlertConfigurations, Is.Not.Null); Assert.That(createdConfig.MetricAlertConfigurations.Count, Is.EqualTo(2)); // Validate the first Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration createdMetricAlertConfig0 = createdConfig.MetricAlertConfigurations[0]; Assert.That(createdMetricAlertConfig0.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(createdMetricAlertConfig0.AlertScope, Is.Not.Null); Assert.That(createdMetricAlertConfig0.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(createdMetricAlertConfig0.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig0.AlertScope.TopNGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig0.AlertConditions, Is.Not.Null); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition, Is.Not.Null); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Up)); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.UpperBound, Is.EqualTo(20.0)); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.LowerBound, Is.Null); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.Null); Assert.That(createdMetricAlertConfig0.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.False); Assert.That(createdMetricAlertConfig0.AlertConditions.SeverityCondition, Is.Null); Assert.That(createdMetricAlertConfig0.AlertSnoozeCondition, Is.Null); Assert.That(createdMetricAlertConfig0.UseDetectionResultToFilterAnomalies, Is.True); // Validate the second Metric Anomaly Alert Configuration. MetricAnomalyAlertConfiguration createdMetricAlertConfig1 = createdConfig.MetricAlertConfigurations[1]; Assert.That(createdMetricAlertConfig1.DetectionConfigurationId, Is.EqualTo(detectionConfigId)); Assert.That(createdMetricAlertConfig1.AlertScope, Is.Not.Null); Assert.That(createdMetricAlertConfig1.AlertScope.ScopeType, Is.EqualTo(MetricAnomalyAlertScopeType.WholeSeries)); Assert.That(createdMetricAlertConfig1.AlertScope.SeriesGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig1.AlertScope.TopNGroupInScope, Is.Null); Assert.That(createdMetricAlertConfig1.AlertConditions, Is.Not.Null); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition, Is.Not.Null); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition.Direction, Is.EqualTo(BoundaryDirection.Down)); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition.UpperBound, Is.Null); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition.LowerBound, Is.EqualTo(10.0)); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition.CompanionMetricId, Is.Null); Assert.That(createdMetricAlertConfig1.AlertConditions.MetricBoundaryCondition.ShouldAlertIfDataPointMissing, Is.False); Assert.That(createdMetricAlertConfig1.AlertConditions.SeverityCondition, Is.Null); Assert.That(createdMetricAlertConfig1.AlertSnoozeCondition, Is.Null); Assert.That(createdMetricAlertConfig1.UseDetectionResultToFilterAnomalies, Is.False); }