예제 #1
0
        private IList <string> Validate(MetricDefinition metric)
        {
            Guard.NotNull(metric, nameof(metric));

            var errorMessages = new List <string>();

            if (metric == null)
            {
                errorMessages.Add("Invalid metric is configured");
                return(errorMessages);
            }

            if (metric.ResourceType == ResourceType.NotSpecified)
            {
                errorMessages.Add($"{metric.ResourceType} '{nameof(ResourceType.NotSpecified)}' is not supported");
            }

            if (string.IsNullOrWhiteSpace(metric.Name))
            {
                errorMessages.Add("No metric name is configured");
            }

            var metricDefinitionValidationErrors = MetricValidatorFactory
                                                   .GetValidatorFor(metric.ResourceType)
                                                   .Validate(metric);

            errorMessages.AddRange(metricDefinitionValidationErrors);

            var metricAggregationValidator        = new AzureMetricConfigurationValidator(_metricDefaults);
            var metricsConfigurationErrorMessages = metricAggregationValidator.Validate(metric.AzureMetricConfiguration);

            errorMessages.AddRange(metricsConfigurationErrorMessages);

            return(errorMessages);
        }
예제 #2
0
        private IEnumerable <string> Validate(MetricDefinition metric)
        {
            Guard.NotNull(metric, nameof(metric));

            var errorMessages = new List <string>();

            if (metric == null)
            {
                errorMessages.Add("Invalid metric is configured");
                return(errorMessages);
            }

            if (metric.ResourceType == ResourceType.NotSpecified)
            {
                errorMessages.Add($"{metric.ResourceType} '{nameof(ResourceType.NotSpecified)}' is not supported");
            }

            if (string.IsNullOrWhiteSpace(metric.PrometheusMetricDefinition?.Name))
            {
                errorMessages.Add("No metric name is configured");
            }

            if (metric.Resources?.Any() == false && metric.ResourceDiscoveryGroups?.Any() == false)
            {
                errorMessages.Add("No resource or resource collection is configured to be scraped");
            }
            else
            {
                var metricDefinitionValidationErrors = MetricValidatorFactory
                                                       .GetValidatorFor(metric.ResourceType)
                                                       .Validate(metric);

                errorMessages.AddRange(metricDefinitionValidationErrors);
            }

            var metricAggregationValidator        = new AzureMetricConfigurationValidator(_metricDefaults);
            var metricsConfigurationErrorMessages = metricAggregationValidator.Validate(metric.AzureMetricConfiguration);

            errorMessages.AddRange(metricsConfigurationErrorMessages);

            var metricScrapingScheduleValidator = new MetricScrapingValidator(_metricDefaults);
            var metricScrapingErrorMessages     = metricScrapingScheduleValidator.Validate(metric.Scraping);

            errorMessages.AddRange(metricScrapingErrorMessages);

            return(errorMessages);
        }