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

            Assert.That(() => adminClient.CreateAlertConfigurationAsync(null), Throws.InstanceOf <ArgumentNullException>());

            Assert.That(() => adminClient.CreateAlertConfiguration(null), Throws.InstanceOf <ArgumentNullException>());
        }
        /// <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)
        {
            string configId = await adminClient.CreateAlertConfigurationAsync(alertConfiguration);

            Assert.That(configId, Is.Not.Null.And.Not.Empty);

            return(new DisposableAlertConfiguration(adminClient, configId));
        }
        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 void CreateAlertConfigurationRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var config = new AnomalyAlertConfiguration()
            {
                Name = "configName"
            };

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

            Assert.That(() => adminClient.CreateAlertConfigurationAsync(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateAlertConfiguration(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
        public void CreateAlertConfigurationRespectsTheCancellationToken()
        {
            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.CreateAlertConfigurationAsync(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateAlertConfiguration(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
        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 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);
        }
Example #8
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));
                }
            }
        }
Example #9
0
        /// <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));
        }