Beispiel #1
0
        public void GetAllFeedbackValidatesArguments()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            Assert.That(() => client.GetAllFeedbackAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetAllFeedbackAsync(""), Throws.InstanceOf <ArgumentException>());

            Assert.That(() => client.GetAllFeedback(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetAllFeedback(""), Throws.InstanceOf <ArgumentException>());
        }
        public void GetAllFeedbackValidatesArguments()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            Assert.That(() => client.GetAllFeedbackAsync(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetAllFeedbackAsync(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetAllFeedbackAsync("metricId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));

            Assert.That(() => client.GetAllFeedback(null), Throws.InstanceOf <ArgumentNullException>());
            Assert.That(() => client.GetAllFeedback(""), Throws.InstanceOf <ArgumentException>());
            Assert.That(() => client.GetAllFeedback("metricId"), Throws.InstanceOf <ArgumentException>().With.InnerException.TypeOf(typeof(FormatException)));
        }
Beispiel #3
0
        public async Task GetAllFeedbackAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var client = new MetricsAdvisorClient(new Uri(endpoint), credential);

            string metricId = MetricId;

            var options = new GetAllFeedbackOptions()
            {
                StartTime   = DateTimeOffset.Parse("2020-01-01T00:00:00Z"),
                EndTime     = DateTimeOffset.Parse("2020-09-09T00:00:00Z"),
                TimeMode    = FeedbackQueryTimeMode.MetricTimestamp,
                MaxPageSize = 5
            };

            int feedbackCount = 0;

            await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(metricId, options))
            {
                Console.WriteLine($"Feedback ID: {feedback.Id}");
                Console.WriteLine($"Metric ID: {feedback.MetricId}");
                Console.WriteLine($"Feedback type: {feedback.Type}");
                Console.WriteLine();

                // Print at most 5 feedback entries.
                if (++feedbackCount >= 5)
                {
                    break;
                }
            }
        }
        public async Task MetricsAdvisorKeyCredentialSendsSecretInMetricsAdvisorClient()
        {
            MockResponse response = new MockResponse(200);

            response.SetContent("{}");

            MockTransport mockTransport = new MockTransport(response);

            string expectedSubscriptionKey         = "fakeSubscriptionKey";
            string expectedApiKey                  = "fakeApiKey";
            MetricsAdvisorKeyCredential credential = new MetricsAdvisorKeyCredential(expectedSubscriptionKey, expectedApiKey);

            MetricsAdvisorClient client = CreateInstrumentedClient(mockTransport, credential);

            IAsyncEnumerator <MetricFeedback> asyncEnumerator = client.GetAllFeedbackAsync(FakeGuid).GetAsyncEnumerator();
            await asyncEnumerator.MoveNextAsync();

            MockRequest request = mockTransport.Requests.First();

            Assert.That(request.Headers.TryGetValue(Constants.SubscriptionAuthorizationHeader, out string subscriptionKey));
            Assert.That(request.Headers.TryGetValue(Constants.ApiAuthorizationHeader, out string apiKey));

            Assert.That(subscriptionKey, Is.EqualTo(expectedSubscriptionKey));
            Assert.That(apiKey, Is.EqualTo(expectedApiKey));
        }
Beispiel #5
0
        public async Task GetAllFeedbackWithOptionalFeedbackFilter()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            // The sampling time range was chosen in a way to make sure there'll be feedback returned by the
            // service call. Changing these values can make this test fail.

            DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2020-12-01T00:00:00Z");
            DateTimeOffset feedbackSamplingEndTime   = DateTimeOffset.Parse("2020-12-31T00:00:00Z");

            var options = new GetAllFeedbackOptions()
            {
                TimeMode     = FeedbackQueryTimeMode.FeedbackCreatedTime,
                StartTime    = feedbackSamplingStartTime,
                EndTime      = feedbackSamplingEndTime,
                FeedbackType = FeedbackType.Comment,
            };

            options.Filter.AddDimensionColumn("city", "Delhi");

            var feedbackCount = 0;

            await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(MetricId, options))
            {
                Assert.That(feedback, Is.Not.Null);
                Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.MetricId, Is.EqualTo(MetricId));
                Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.CreatedTime, Is.Not.Null);
                Assert.That(feedback.CreatedTime, Is.GreaterThanOrEqualTo(feedbackSamplingStartTime));
                Assert.That(feedback.CreatedTime, Is.LessThanOrEqualTo(feedbackSamplingEndTime));

                Assert.That(feedback.DimensionFilter, Is.Not.Null);
                Assert.That(feedback.DimensionFilter.DimensionFilter, Is.Not.Null);

                ValidateGroupKey(feedback.DimensionFilter.DimensionFilter);

                Dictionary <string, string> dimensionColumns = feedback.DimensionFilter.DimensionFilter.AsDictionary();

                Assert.That(dimensionColumns.ContainsKey("city"));
                Assert.That(dimensionColumns["city"], Is.EqualTo("Delhi"));

                Assert.That(feedback.Type, Is.EqualTo(FeedbackType.Comment));

                var commentFeedback = feedback as MetricCommentFeedback;

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

                if (++feedbackCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(feedbackCount, Is.GreaterThan(0));
        }
        public void GetAllFeedbackRespectsTheCancellationToken()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

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

            IAsyncEnumerator <MetricFeedback> asyncEnumerator = client.GetAllFeedbackAsync(FakeGuid, cancellationToken: cancellationSource.Token).GetAsyncEnumerator();

            Assert.That(async() => await asyncEnumerator.MoveNextAsync(), Throws.InstanceOf <OperationCanceledException>());

            IEnumerator <MetricFeedback> enumerator = client.GetAllFeedback(FakeGuid, cancellationToken: cancellationSource.Token).GetEnumerator();

            Assert.That(() => enumerator.MoveNext(), Throws.InstanceOf <OperationCanceledException>());
        }
Beispiel #7
0
        public async Task GetAllFeedbackWithMinimumSetup(bool useTokenCredential)
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);

            var feedbackCount = 0;

            await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(MetricId))
            {
                Assert.That(feedback, Is.Not.Null);
                Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.MetricId, Is.EqualTo(MetricId));
                Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.CreatedTime, Is.Not.Null);

                Assert.That(feedback.DimensionFilter, Is.Not.Null);
                Assert.That(feedback.DimensionFilter.DimensionFilter, Is.Not.Null);

                ValidateGroupKey(feedback.DimensionFilter.DimensionFilter);

                if (feedback.Type == FeedbackType.Anomaly)
                {
                    var anomalyFeedback = feedback as MetricAnomalyFeedback;

                    Assert.That(anomalyFeedback, Is.Not.Null);
                    Assert.That(anomalyFeedback.AnomalyValue, Is.Not.EqualTo(default(AnomalyFeedbackValue)));

                    if (anomalyFeedback.AnomalyDetectionConfigurationId != null)
                    {
                        // TODO: Add snapshot validation (https://github.com/azure/azure-sdk-for-net/issues/15915).
                    }
                }
                else if (feedback.Type == FeedbackType.ChangePoint)
                {
                    var changePointFeedback = feedback as MetricChangePointFeedback;

                    Assert.That(changePointFeedback, Is.Not.Null);
                    Assert.That(changePointFeedback.ChangePointValue, Is.Not.EqualTo(default(ChangePointValue)));
                }
                else if (feedback.Type == FeedbackType.Comment)
                {
                    var commentFeedback = feedback as MetricCommentFeedback;

                    Assert.That(commentFeedback, Is.Not.Null);
                    Assert.That(commentFeedback.Comment, Is.Not.Null.And.Not.Empty);
                }
                else
                {
                    Assert.That(feedback.Type, Is.EqualTo(FeedbackType.Period));

                    var periodFeedback = feedback as MetricPeriodFeedback;

                    Assert.That(periodFeedback, Is.Not.Null);
                    Assert.That(periodFeedback.PeriodType, Is.Not.EqualTo(default(PeriodType)));
                }

                if (++feedbackCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(feedbackCount, Is.GreaterThan(0));
        }
        public async Task GetAllFeedbackWithOptionalFeedbackFilter()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            // The sampling time range was chosen in a way to make sure there'll be feedback returned by the
            // service call. Changing these values can make this test fail.

            DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2021-10-01T00:00:00Z");
            DateTimeOffset feedbackSamplingEndTime   = DateTimeOffset.Parse("2021-11-20T00:00:00Z");

            var dimensions = new Dictionary <string, string>()
            {
                { "region", "Karachi" }
            };
            var options = new GetAllFeedbackOptions()
            {
                Filter = new FeedbackFilter()
                {
                    DimensionKey = new DimensionKey(dimensions),
                    TimeMode     = FeedbackQueryTimeMode.FeedbackCreatedOn,
                    StartsOn     = feedbackSamplingStartTime,
                    EndsOn       = feedbackSamplingEndTime,
                    FeedbackKind = MetricFeedbackKind.Anomaly
                }
            };

            var feedbackCount = 0;

            await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(MetricId, options))
            {
                Assert.That(feedback, Is.Not.Null);
                Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.MetricId, Is.EqualTo(MetricId));
                Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.CreatedOn, Is.Not.Null);
                Assert.That(feedback.CreatedOn, Is.GreaterThanOrEqualTo(feedbackSamplingStartTime));
                Assert.That(feedback.CreatedOn, Is.LessThanOrEqualTo(feedbackSamplingEndTime));

                Assert.That(feedback.DimensionFilter, Is.Not.Null);

                DimensionKey dimensionKeyFilter = feedback.DimensionFilter.DimensionKey;

                Assert.That(dimensionKeyFilter, Is.Not.Null);

                ValidateGroupKey(dimensionKeyFilter);

                Assert.That(dimensionKeyFilter.TryGetValue("region", out string region));
                Assert.That(region, Is.EqualTo("Karachi"));

                Assert.That(feedback.FeedbackKind, Is.EqualTo(MetricFeedbackKind.Anomaly));

                var anomalyFeedback = feedback as MetricAnomalyFeedback;

                Assert.That(anomalyFeedback, Is.Not.Null);
                Assert.That(anomalyFeedback.AnomalyValue, Is.Not.EqualTo(default(AnomalyValue)));

                if (++feedbackCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(feedbackCount, Is.GreaterThan(0));
        }
        public async Task GetAllFeedback(bool populateOptionalMembers)
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            // The sampling time range was chosen in a way to make sure there'll be feedback returned by the
            // service call. Changing these values can make this test fail.

            DateTimeOffset feedbackSamplingStartTime = DateTimeOffset.Parse("2020-12-01T00:00:00Z");
            DateTimeOffset feedbackSamplingEndTime   = DateTimeOffset.Parse("2020-12-31T00:00:00Z");

            var options = new GetAllFeedbackOptions();

            if (populateOptionalMembers)
            {
                options.TimeMode     = FeedbackQueryTimeMode.FeedbackCreatedTime;
                options.StartTime    = feedbackSamplingStartTime;
                options.EndTime      = feedbackSamplingEndTime;
                options.FeedbackType = FeedbackType.Comment;

                options.Filter.AddDimensionColumn("city", "Delhi");
            }

            var feedbackCount = 0;

            await foreach (MetricFeedback feedback in client.GetAllFeedbackAsync(MetricId, options))
            {
                Assert.That(feedback, Is.Not.Null);
                Assert.That(feedback.Id, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.MetricId, Is.EqualTo(MetricId));
                Assert.That(feedback.UserPrincipal, Is.Not.Null.And.Not.Empty);
                Assert.That(feedback.CreatedTime, Is.Not.Null);

                Assert.That(feedback.DimensionFilter, Is.Not.Null);
                Assert.That(feedback.DimensionFilter.DimensionFilter, Is.Not.Null);

                ValidateGroupKey(feedback.DimensionFilter.DimensionFilter);

                if (populateOptionalMembers)
                {
                    Assert.That(feedback.CreatedTime, Is.GreaterThanOrEqualTo(feedbackSamplingStartTime));
                    Assert.That(feedback.CreatedTime, Is.LessThanOrEqualTo(feedbackSamplingEndTime));
                    Assert.That(feedback.Type, Is.EqualTo(FeedbackType.Comment));

                    Dictionary <string, string> dimensionColumns = feedback.DimensionFilter.DimensionFilter.AsDictionary();

                    Assert.That(dimensionColumns.ContainsKey("city"));
                    Assert.That(dimensionColumns["city"], Is.EqualTo("Delhi"));
                }

                if (feedback.Type == FeedbackType.Anomaly)
                {
                    var anomalyFeedback = feedback as MetricAnomalyFeedback;

                    Assert.That(anomalyFeedback, Is.Not.Null);
                    Assert.That(anomalyFeedback.AnomalyValue, Is.Not.EqualTo(default(AnomalyFeedbackValue)));

                    if (anomalyFeedback.AnomalyDetectionConfigurationId != null)
                    {
                        // TODO: Add snapshot validation (https://github.com/azure/azure-sdk-for-net/issues/15915).
                    }
                }
                else if (feedback.Type == FeedbackType.ChangePoint)
                {
                    var changePointFeedback = feedback as MetricChangePointFeedback;

                    Assert.That(changePointFeedback, Is.Not.Null);
                    Assert.That(changePointFeedback.ChangePointValue, Is.Not.EqualTo(default(ChangePointValue)));
                }
                else if (feedback.Type == FeedbackType.Comment)
                {
                    var commentFeedback = feedback as MetricCommentFeedback;

                    Assert.That(commentFeedback, Is.Not.Null);
                    Assert.That(commentFeedback.Comment, Is.Not.Null.And.Not.Empty);
                }
                else
                {
                    Assert.That(feedback.Type, Is.EqualTo(FeedbackType.Period));

                    var periodFeedback = feedback as MetricPeriodFeedback;

                    Assert.That(periodFeedback, Is.Not.Null);
                    Assert.That(periodFeedback.PeriodType, Is.Not.EqualTo(default(PeriodType)));
                }

                if (++feedbackCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(feedbackCount, Is.GreaterThan(0));
        }