public void GetDetectionConfigurationValidatesArguments() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); Assert.That(() => adminClient.GetDetectionConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.GetDetectionConfigurationAsync(""), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.GetDetectionConfigurationAsync("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); Assert.That(() => adminClient.GetDetectionConfiguration(null), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => adminClient.GetDetectionConfiguration(""), Throws.InstanceOf <ArgumentException>()); Assert.That(() => adminClient.GetDetectionConfiguration("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException))); }
public async Task UpdateDetectionConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; Response <AnomalyDetectionConfiguration> response = await adminClient.GetDetectionConfigurationAsync(detectionConfigurationId); AnomalyDetectionConfiguration detectionConfiguration = response.Value; string originalDescription = detectionConfiguration.Description; detectionConfiguration.Description = "This description was generated by a sample."; response = await adminClient.UpdateDetectionConfigurationAsync(detectionConfiguration); AnomalyDetectionConfiguration updatedDetectionConfiguration = response.Value; Console.WriteLine($"Updated description: {updatedDetectionConfiguration.Description}"); // Undo the changes to leave the detection configuration unaltered. Skip this step if you intend to keep // the changes. detectionConfiguration.Description = originalDescription; await adminClient.UpdateDetectionConfigurationAsync(detectionConfiguration); }
public async Task CreateAndGetDetectionConfigurationWithChangeAndSmartConditions() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string configName = Recording.GenerateAlphaNumericId("config"); var wholeConditions = new MetricWholeSeriesDetectionCondition() { CrossConditionsOperator = DetectionConditionsOperator.And, ChangeThresholdCondition = new (90.0, 5, true, AnomalyDetectorDirection.Both, new (1, 2.0)), SmartDetectionCondition = new (23.0, AnomalyDetectorDirection.Down, new (3, 4.0)) }; var configToCreate = new AnomalyDetectionConfiguration(MetricId, configName, wholeConditions); await using var disposableConfig = await DisposableDetectionConfiguration.CreateDetectionConfigurationAsync(adminClient, configToCreate); AnomalyDetectionConfiguration createdConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id); Assert.That(createdConfig.Id, Is.EqualTo(disposableConfig.Id)); Assert.That(createdConfig.MetricId, Is.EqualTo(MetricId)); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.Empty); Assert.That(createdConfig.SeriesGroupDetectionConditions, Is.Not.Null.And.Empty); Assert.That(createdConfig.SeriesDetectionConditions, Is.Not.Null.And.Empty); MetricWholeSeriesDetectionCondition createdWholeConditions = createdConfig.WholeSeriesDetectionConditions; Assert.That(createdWholeConditions, Is.Not.Null); Assert.That(createdWholeConditions.CrossConditionsOperator, Is.EqualTo(DetectionConditionsOperator.And)); Assert.That(createdWholeConditions.HardThresholdCondition, Is.Null); ValidateChangeThresholdCondition(createdWholeConditions.ChangeThresholdCondition, 90.0, 5, true, AnomalyDetectorDirection.Both, 1, 2.0); ValidateSmartDetectionCondition(createdWholeConditions.SmartDetectionCondition, 23.0, AnomalyDetectorDirection.Down, 3, 4.0); }
public void GetDetectionConfigurationRespectsTheCancellationToken() { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.That(() => adminClient.GetDetectionConfigurationAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); Assert.That(() => adminClient.GetDetectionConfiguration(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>()); }
public async Task CreateAndGetDetectionConfigurationWithHardCondition(bool useTokenCredential) { MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(useTokenCredential); string configName = Recording.GenerateAlphaNumericId("config"); var description = "This hook was created to test the .NET client."; var wholeConditions = new MetricWholeSeriesDetectionCondition() { HardThresholdCondition = new(AnomalyDetectorDirection.Up, new(1, 2.0)) { UpperBound = 10.0 } }; var configToCreate = new AnomalyDetectionConfiguration() { MetricId = MetricId, Name = configName, WholeSeriesDetectionConditions = wholeConditions, // This is the only test that validates description during creation. Please don't remove it! Description = description }; await using var disposableConfig = await DisposableDetectionConfiguration.CreateDetectionConfigurationAsync(adminClient, configToCreate); AnomalyDetectionConfiguration createdConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id); Assert.That(createdConfig.Id, Is.EqualTo(disposableConfig.Id)); Assert.That(createdConfig.MetricId, Is.EqualTo(MetricId)); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.EqualTo(description)); Assert.That(createdConfig.SeriesGroupDetectionConditions, Is.Not.Null.And.Empty); Assert.That(createdConfig.SeriesDetectionConditions, Is.Not.Null.And.Empty); MetricWholeSeriesDetectionCondition createdWholeConditions = createdConfig.WholeSeriesDetectionConditions; Assert.That(createdWholeConditions, Is.Not.Null); Assert.That(createdWholeConditions.CrossConditionsOperator, Is.Null); Assert.That(createdWholeConditions.ChangeThresholdCondition, Is.Null); Assert.That(createdWholeConditions.SmartDetectionCondition, Is.Null); ValidateHardThresholdCondition(createdWholeConditions.HardThresholdCondition, AnomalyDetectorDirection.Up, 10.0, null, 1, 2.0); }
public async Task GetDetectionConfigurationAsync() { string endpoint = MetricsAdvisorUri; string subscriptionKey = MetricsAdvisorSubscriptionKey; string apiKey = MetricsAdvisorApiKey; var credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey); var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential); string detectionConfigurationId = DetectionConfigurationId; Response <AnomalyDetectionConfiguration> response = await adminClient.GetDetectionConfigurationAsync(detectionConfigurationId); AnomalyDetectionConfiguration detectionConfiguration = response.Value; Console.WriteLine($"Detection configuration metric ID: {detectionConfiguration.MetricId}"); Console.WriteLine($"Detection configuration name: {detectionConfiguration.Name}"); Console.WriteLine($"Detection configuration description: {detectionConfiguration.Description}"); }
public async Task CreateAndGetDetectionConfigurationWithSeriesConditions() { // Set required parameters of the configuration to be created. MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient(); string configName = Recording.GenerateAlphaNumericId("config"); var wholeConditions = new MetricWholeSeriesDetectionCondition() { HardThresholdCondition = new(AnomalyDetectorDirection.Both, new(1, 2.0)) { UpperBound = 20.0, LowerBound = 10.0 } }; var configToCreate = new AnomalyDetectionConfiguration() { MetricId = MetricId, Name = configName, WholeSeriesDetectionConditions = wholeConditions }; // Set the series conditions and create the configuration. var seriesConditions0 = new MetricSingleSeriesDetectionCondition() { SmartDetectionCondition = new(30.0, AnomalyDetectorDirection.Both, new(3, 4.0)) }; seriesConditions0.SeriesKey.AddDimensionColumn("city", "Delhi"); seriesConditions0.SeriesKey.AddDimensionColumn("category", "Handmade"); var seriesConditions1 = new MetricSingleSeriesDetectionCondition() { ChangeThresholdCondition = new(40.0, 12, false, AnomalyDetectorDirection.Up, new(5, 6.0)) }; seriesConditions1.SeriesKey.AddDimensionColumn("city", "Koltaka"); seriesConditions1.SeriesKey.AddDimensionColumn("category", "Grocery & Gourmet Food"); configToCreate.SeriesDetectionConditions.Add(seriesConditions0); configToCreate.SeriesDetectionConditions.Add(seriesConditions1); await using var disposableConfig = await DisposableDetectionConfiguration.CreateDetectionConfigurationAsync(adminClient, configToCreate); // Get the created configuration and validate top-level members. AnomalyDetectionConfiguration createdConfig = await adminClient.GetDetectionConfigurationAsync(disposableConfig.Id); Assert.That(createdConfig.Id, Is.EqualTo(disposableConfig.Id)); Assert.That(createdConfig.MetricId, Is.EqualTo(MetricId)); Assert.That(createdConfig.Name, Is.EqualTo(configName)); Assert.That(createdConfig.Description, Is.Empty); Assert.That(createdConfig.SeriesGroupDetectionConditions, Is.Not.Null.And.Empty); // Validate whole series detection conditions. MetricWholeSeriesDetectionCondition createdWholeConditions = createdConfig.WholeSeriesDetectionConditions; Assert.That(createdWholeConditions, Is.Not.Null); Assert.That(createdWholeConditions.CrossConditionsOperator, Is.Null); Assert.That(createdWholeConditions.ChangeThresholdCondition, Is.Null); Assert.That(createdWholeConditions.SmartDetectionCondition, Is.Null); ValidateHardThresholdCondition(createdWholeConditions.HardThresholdCondition, AnomalyDetectorDirection.Both, 20.0, 10.0, 1, 2.0); // Start series conditions validation. Assert.That(createdConfig.SeriesDetectionConditions, Is.Not.Null); Assert.That(createdConfig.SeriesDetectionConditions.Count, Is.EqualTo(2)); // Validate first series conditions. var createdSeriesConditions0 = createdConfig.SeriesDetectionConditions[0]; Assert.That(createdSeriesConditions0, Is.Not.Null); ValidateSeriesKey(createdSeriesConditions0.SeriesKey); Dictionary <string, string> dimensionColumns = createdSeriesConditions0.SeriesKey.AsDictionary(); Assert.That(dimensionColumns["city"], Is.EqualTo("Delhi")); Assert.That(dimensionColumns["category"], Is.EqualTo("Handmade")); Assert.That(createdSeriesConditions0.CrossConditionsOperator, Is.Null); Assert.That(createdSeriesConditions0.HardThresholdCondition, Is.Null); Assert.That(createdSeriesConditions0.ChangeThresholdCondition, Is.Null); ValidateSmartDetectionCondition(createdSeriesConditions0.SmartDetectionCondition, 30.0, AnomalyDetectorDirection.Both, 3, 4.0); // Validate last series conditions. var createdSeriesConditions1 = createdConfig.SeriesDetectionConditions[1]; Assert.That(createdSeriesConditions1, Is.Not.Null); ValidateSeriesKey(createdSeriesConditions1.SeriesKey); dimensionColumns = createdSeriesConditions1.SeriesKey.AsDictionary(); Assert.That(dimensionColumns["city"], Is.EqualTo("Koltaka")); Assert.That(dimensionColumns["category"], Is.EqualTo("Grocery & Gourmet Food")); Assert.That(createdSeriesConditions1.CrossConditionsOperator, Is.Null); Assert.That(createdSeriesConditions1.HardThresholdCondition, Is.Null); Assert.That(createdSeriesConditions1.SmartDetectionCondition, Is.Null); ValidateChangeThresholdCondition(createdSeriesConditions1.ChangeThresholdCondition, 40.0, 12, false, AnomalyDetectorDirection.Up, 5, 6.0); }