public void GetAlertConfigurationValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            Assert.That(() => adminClient.GetAlertConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.GetAlertConfigurationAsync(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.GetAlertConfigurationAsync("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));

            Assert.That(() => adminClient.GetAlertConfiguration(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.GetAlertConfiguration(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.GetAlertConfiguration("configId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
        }
        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 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}");
            }
        }
        public void GetAlertConfigurationRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            using var cancellationSource = new CancellationTokenSource();
            cancellationSource.Cancel();

            Assert.That(() => adminClient.GetAlertConfigurationAsync(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.GetAlertConfiguration(FakeGuid, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
Пример #5
0
        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));
                }
            }
        }