Example #1
0
        public void WhenCreatingContractsAlertThenMetricChartPropertiesAreConvertedCorrectly()
        {
            ContractsAlert contractsAlert = CreateContractsAlert <TestAlert>();

            Assert.AreEqual(1, contractsAlert.AlertProperties.Count);

            MetricChartAlertProperty alertProperty = (MetricChartAlertProperty)contractsAlert.AlertProperties[0];

            Assert.AreEqual(string.Empty, alertProperty.ResourceId);
            Assert.AreEqual("someMetric", alertProperty.MetricName);
            Assert.AreEqual("namespace", alertProperty.MetricNamespace);
            Assert.AreEqual(2, alertProperty.MetricDimensions.Count);
            Assert.AreEqual("val1", alertProperty.MetricDimensions["dim1"]);
            Assert.AreEqual("val2", alertProperty.MetricDimensions["dim2"]);
            Assert.AreEqual(new DateTime(1972, 6, 6), alertProperty.StartTimeUtc);
            Assert.AreEqual(new DateTime(1972, 6, 7), alertProperty.EndTimeUtc);
            Assert.AreEqual(TimeSpan.FromHours(1), alertProperty.TimeGrain);
            Assert.AreEqual(ContractsAggregationType.Average, alertProperty.AggregationType);
            Assert.AreEqual(ContractsThresholdType.LessThan, alertProperty.ThresholdType);
            Assert.AreEqual(0.1, alertProperty.StaticThreshold.LowerThreshold);
            Assert.AreEqual(0.5, alertProperty.StaticThreshold.UpperThreshold);
            Assert.AreEqual((uint)5, alertProperty.DynamicThreshold.FailingPeriodsSettings.ConsecutivePeriods);
            Assert.AreEqual((uint)3, alertProperty.DynamicThreshold.FailingPeriodsSettings.ConsecutiveViolations);
            Assert.AreEqual(DynamicThreshold.MediumSensitivity, alertProperty.DynamicThreshold.Sensitivity);
            Assert.AreEqual(new DateTime(1972, 6, 6), alertProperty.DynamicThreshold.IgnoreDataBefore);
        }
        public void WhenConvertingMetricChartAlertPropertyToMetricChartPropertyControlViewModelThenTheResultIsAsExpected()
        {
            var metricChartAlertProperty = new MetricChartAlertProperty("propertyName", "displayName", 5, "metric1", TimeSpan.FromMinutes(15), AggregationType.Maximum);

            object result = this.converter.Convert(metricChartAlertProperty, typeof(MetricChartPropertyControlViewModel), null, new CultureInfo("en-us"));

            Assert.IsInstanceOfType(result, typeof(MetricChartPropertyControlViewModel));
        }
Example #3
0
        public void TestInitialize()
        {
            // Create property
            this.resource = new ResourceIdentifier(ResourceType.AzureStorage, "subscriptionId", "resourceGroupName", "storage1");
            this.property = new MetricChartAlertProperty(
                propertyName: "metric",
                displayName: "metric display",
                order: 1,
                metricName: "metric1",
                timeGrain: TimeSpan.FromMinutes(5),
                aggregationType: AggregationType.Sum)
            {
                StartTimeUtc    = new DateTime(2019, 4, 1, 10, 0, 0),
                EndTimeUtc      = new DateTime(2019, 4, 1, 12, 0, 0),
                MetricNamespace = "nameSpace",
                ResourceId      = this.resource.ToResourceId()
            };

            // Create metric data
            this.values     = Enumerable.Range(0, (int)((this.property.EndTimeUtc - this.property.StartTimeUtc).Value.Ticks / this.property.TimeGrain.Ticks)).Select(n => (double)n).ToList();
            this.timestamps = this.values.Select(n => new DateTime((long)(this.property.StartTimeUtc.Value.Ticks + (this.property.TimeGrain.Ticks * n)))).ToList();
            MetricQueryResult metricQueryResult = new MetricQueryResult("name", "unit", new List <MetricTimeSeries>()
            {
                new MetricTimeSeries(
                    this.timestamps.Zip(this.values, (t, v) => new MetricValues(t, v, v, v, v, 1)).ToList(),
                    new List <KeyValuePair <string, string> >()
                {
                })
            });

            // Mock metric client result
            this.metricClientMock = new Mock <IMetricClient>();
            this.metricClientMock
            .Setup(x => x.GetResourceMetricsAsync(this.resource.ToResourceId(), It.IsAny <QueryParameters>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((string resourceId, QueryParameters queryParameters, CancellationToken ct) =>
            {
                // Verify the query parameters
                Assert.AreEqual(Aggregation.Total, queryParameters.Aggregations.Single());
                Assert.AreEqual(TimeSpan.FromMinutes(5), queryParameters.Interval);
                Assert.AreEqual(new DateTime(2019, 4, 1, 10, 0, 0), queryParameters.StartTime);
                Assert.AreEqual(new DateTime(2019, 4, 1, 12, 0, 0), queryParameters.EndTime);
                Assert.AreEqual("metric1", queryParameters.MetricNames.Single());
                Assert.AreEqual("nameSpace", queryParameters.MetricNamespace);

                return(new[] { metricQueryResult });
            });

            this.analysisServicesFactoryMock = new Mock <IAnalysisServicesFactory>();
            this.analysisServicesFactoryMock
            .Setup(x => x.CreateMetricClientAsync(this.resource.SubscriptionId, It.IsAny <CancellationToken>()))
            .ReturnsAsync(this.metricClientMock.Object);

            this.tracerMock = new Mock <ITracer>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MetricChartPropertyControlViewModel"/> class.
        /// </summary>
        /// <param name="metricChartAlertProperty">The metric chart alert property that should be displayed.</param>
        /// <param name="analysisServicesFactory">The analysis services factory</param>
        /// <param name="tracer">The tracer</param>
        public MetricChartPropertyControlViewModel(
            MetricChartAlertProperty metricChartAlertProperty,
            IAnalysisServicesFactory analysisServicesFactory,
            ITracer tracer)
        {
            this.metricChartAlertProperty = metricChartAlertProperty;

            this.Title = metricChartAlertProperty.DisplayName;
            this.analysisServicesFactory = analysisServicesFactory;
            this.tracer = tracer;

            // Set X/Y axis formatters
            this.XAxisFormatter = value => (value >= 0 ? new DateTime((long)(value * TimeSpan.FromHours(1).Ticks)) : DateTime.MinValue).ToString(CultureInfo.InvariantCulture);
            this.YAxisFormatter = value => value.ToString(CultureInfo.InvariantCulture);

            // Start a task to read the metric values
            this.ReadChartValuesTask = new ObservableTask <ChartValues <DateTimePoint> >(
                this.ReadChartValuesAsync(),
                tracer);
        }