internal async Task <string> CreateDetectionConfiguration(MetricsAdvisorAdministrationClient adminClient)
        {
            DataFeed feed = await GetFirstDataFeed(adminClient).ConfigureAwait(false);

            AnomalyDetectionConfiguration config = PopulateMetricAnomalyDetectionConfiguration(feed.MetricIds.First().Value);

            return(await adminClient.CreateDetectionConfigurationAsync(config).ConfigureAwait(false));
        }
        /// <summary>
        /// Creates a detection configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
        /// A <see cref="DisposableDetectionConfiguration"/> 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="AnomalyDetectionConfiguration"/> should be configured.</param>
        /// <returns>A <see cref="DisposableDetectionConfiguration"/> instance from which the ID of the created configuration can be obtained.</returns>
        public static async Task <DisposableDetectionConfiguration> CreateDetectionConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyDetectionConfiguration detectionConfiguration)
        {
            string configId = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

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

            return(new DisposableDetectionConfiguration(adminClient, configId));
        }
        public void CreateDetectionConfigurationValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

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

            Assert.That(() => adminClient.CreateDetectionConfiguration(null), Throws.InstanceOf <ArgumentNullException>());
        }
        public void CreateDetectionConfigurationRespectsTheCancellationToken()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var config = new AnomalyDetectionConfiguration(FakeGuid, "configName", new ());

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

            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config, cancellationSource.Token), Throws.InstanceOf <OperationCanceledException>());
        }
        public async Task CreateAndDeleteDetectionConfigurationAsync()
        {
            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:CreateDetectionConfigurationAsync
#if SNIPPET
            string metricId          = "<metricId>";
            string configurationName = "<configurationName>";
#else
            string metricId          = MetricId;
            string configurationName = GetUniqueName();
#endif

            var detectionConfiguration = new AnomalyDetectionConfiguration()
            {
                MetricId = metricId,
                Name     = configurationName,
                WholeSeriesDetectionConditions = new MetricWholeSeriesDetectionCondition()
            };

            var detectCondition = detectionConfiguration.WholeSeriesDetectionConditions;

            var hardSuppress = new SuppressCondition(1, 100);
            detectCondition.HardThresholdCondition = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardSuppress)
            {
                LowerBound = 5.0
            };

            var smartSuppress = new SuppressCondition(4, 50);
            detectCondition.SmartDetectionCondition = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartSuppress);

            detectCondition.CrossConditionsOperator = DetectionConditionsOperator.Or;

            Response <AnomalyDetectionConfiguration> response = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

            AnomalyDetectionConfiguration createdDetectionConfiguration = response.Value;

            Console.WriteLine($"Anomaly detection configuration ID: {createdDetectionConfiguration.Id}");
            #endregion

            // Delete the created anomaly detection configuration to clean up the Metrics Advisor resource.
            // Do not perform this step if you intend to keep using the configuration.

            await adminClient.DeleteDetectionConfigurationAsync(createdDetectionConfiguration.Id);
        }
        public async Task CreateAndDeleteDetectionConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            string metricId = MetricId;

            #region Snippet:CreateDetectionConfigurationAsync
            //@@ string metricId = "<metricId>";
            string configurationName = "Sample anomaly detection configuration";

            var hardThresholdSuppressCondition = new SuppressCondition(1, 100);
            var hardThresholdCondition         = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardThresholdSuppressCondition)
            {
                LowerBound = 5.0
            };

            var smartDetectionSuppressCondition = new SuppressCondition(4, 50);
            var smartDetectionCondition         = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartDetectionSuppressCondition);

            var detectionCondition = new MetricWholeSeriesDetectionCondition()
            {
                HardThresholdCondition  = hardThresholdCondition,
                SmartDetectionCondition = smartDetectionCondition,
                CrossConditionsOperator = DetectionConditionsOperator.Or
            };

            var detectionConfiguration = new AnomalyDetectionConfiguration(metricId, configurationName, detectionCondition);

            Response <string> response = await adminClient.CreateDetectionConfigurationAsync(detectionConfiguration);

            string detectionConfigurationId = response.Value;

            Console.WriteLine($"Anomaly detection configuration ID: {detectionConfigurationId}");
            #endregion

            // Delete the created anomaly detection configuration to clean up the Metrics Advisor resource.
            // Do not perform this step if you intend to keep using the configuration.

            await adminClient.DeleteDetectionConfigurationAsync(detectionConfigurationId);
        }
        public void CreateDetectionConfigurationValidatesArguments()
        {
            MetricsAdvisorAdministrationClient adminClient = GetMetricsAdvisorAdministrationClient();

            var metricId   = "metricId";
            var name       = "configName";
            var conditions = new MetricWholeSeriesDetectionCondition();

            var config = new AnomalyDetectionConfiguration()
            {
                MetricId = null,
                Name     = name,
                WholeSeriesDetectionConditions = conditions
            };

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

            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config), Throws.InstanceOf <ArgumentNullException>());

            config.MetricId = "";
            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config), Throws.InstanceOf <ArgumentException>());

            config.MetricId = metricId;
            config.Name     = null;
            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config), Throws.InstanceOf <ArgumentNullException>());

            config.Name = "";
            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config), Throws.InstanceOf <ArgumentException>());

            config.Name = name;
            config.WholeSeriesDetectionConditions = null;
            Assert.That(() => adminClient.CreateDetectionConfigurationAsync(config), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => adminClient.CreateDetectionConfiguration(config), Throws.InstanceOf <ArgumentNullException>());
        }
Example #8
0
        /// <summary>
        /// Creates a detection configuration using the specified <see cref="MetricsAdvisorAdministrationClient"/>.
        /// A <see cref="DisposableDetectionConfiguration"/> 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="AnomalyDetectionConfiguration"/> should be configured.</param>
        /// <returns>A <see cref="DisposableDetectionConfiguration"/> instance from which the created configuration can be obtained.</returns>
        public static async Task <DisposableDetectionConfiguration> CreateDetectionConfigurationAsync(MetricsAdvisorAdministrationClient adminClient, AnomalyDetectionConfiguration configuration)
        {
            AnomalyDetectionConfiguration createdConfig = await adminClient.CreateDetectionConfigurationAsync(configuration);

            return(new DisposableDetectionConfiguration(adminClient, createdConfig));
        }