예제 #1
0
 private static IEnumerable <string> ValidateMetricDefaults(MetricDefaults metricDefaults)
 {
     if (string.IsNullOrWhiteSpace(metricDefaults.Scraping?.Schedule))
     {
         yield return(@"No default metric scraping schedule is defined.");
     }
 }
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefaults metricDefaults, MetricDefinition metricDefinitionDefinition)
        {
            _logger.LogInformation("Scraping '{MetricName}' for resource type '{ResourceType}'", metricDefinitionDefinition.Name, metricDefinitionDefinition.ResourceType);

            var scraper = MetricScraperFactory.CreateScraper(metricDefinitionDefinition.ResourceType, azureMetadata, metricDefaults, _logger, _exceptionTracker);
            await scraper.ScrapeAsync(metricDefinitionDefinition);
        }
예제 #3
0
        /// <summary>
        ///     Creates a scraper that is capable of scraping a specific resource type
        /// </summary>
        /// <param name="azureMetadata">Metadata concerning the Azure resources</param>
        /// <param name="metricDefinitionResourceType">Resource type to scrape</param>
        /// <param name="metricDefaults">Default configuration for metrics</param>
        /// <param name="logger">General logger</param>
        /// <param name="exceptionTracker">Tracker used to log exceptions</param>
        public static IScraper <MetricDefinition> CreateScraper(ResourceType metricDefinitionResourceType, AzureMetadata azureMetadata,
                                                                MetricDefaults metricDefaults, ILogger logger, IExceptionTracker exceptionTracker)
        {
            var azureCredentials   = DetermineAzureCredentials();
            var azureMonitorClient = CreateAzureMonitorClient(azureMetadata, azureCredentials, logger);

            switch (metricDefinitionResourceType)
            {
            case ResourceType.ServiceBusQueue:
                return(new ServiceBusQueueScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            case ResourceType.Generic:
                return(new GenericScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            case ResourceType.StorageQueue:
                return(new StorageQueueScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            case ResourceType.ContainerInstance:
                return(new ContainerInstanceScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            case ResourceType.VirtualMachine:
                return(new VirtualMachineScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            case ResourceType.ContainerRegistry:
                return(new ContainerRegistryScraper(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private List <string> ValidateMetrics(List <MetricDefinition> metrics, MetricDefaults metricDefaults)
        {
            var errorMessages = new List <string>();

            if (metrics == null)
            {
                errorMessages.Add("No metrics are configured");
                return(errorMessages);
            }

            var metricsValidator    = new MetricsValidator(metricDefaults);
            var metricErrorMessages = metricsValidator.Validate(metrics);

            errorMessages.AddRange(metricErrorMessages);

            // Detect duplicate metric names
            var duplicateMetricNames = DetectDuplicateMetrics(metrics);

            foreach (var duplicateMetricName in duplicateMetricNames)
            {
                errorMessages.Add($"Metric name '{duplicateMetricName}' is declared multiple times");
            }

            return(errorMessages);
        }
        protected MetricDefaults GenerateBogusMetricDefaults()
        {
            var bogusAggregationGenerator = new Faker <Aggregation>()
                                            .StrictMode(ensureRulesForAllProperties: true)
                                            .RuleFor(aggregation => aggregation.Interval, faker => TimeSpan.FromMinutes(faker.Random.Int()));

            var generatedAggregation = bogusAggregationGenerator.Generate();
            var metricDefaults       = new MetricDefaults
            {
                Aggregation = generatedAggregation
            };

            return(metricDefaults);
        }
예제 #6
0
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="azureMetadata">Metadata concerning the Azure resources</param>
        /// <param name="azureMonitorClient">Client to communicate with Azure Monitor</param>
        /// <param name="metricDefaults">Default configuration for metrics</param>
        /// <param name="logger">General logger</param>
        /// <param name="exceptionTracker">Exception tracker</param>
        protected Scraper(AzureMetadata azureMetadata, MetricDefaults metricDefaults, AzureMonitorClient azureMonitorClient,
                          ILogger logger, IExceptionTracker exceptionTracker)
        {
            Guard.NotNull(exceptionTracker, nameof(exceptionTracker));
            Guard.NotNull(azureMetadata, nameof(azureMetadata));
            Guard.NotNull(metricDefaults, nameof(metricDefaults));
            Guard.NotNull(azureMonitorClient, nameof(azureMonitorClient));

            _logger           = logger;
            _exceptionTracker = exceptionTracker;

            AzureMetadata      = azureMetadata;
            MetricDefaults     = metricDefaults;
            AzureMonitorClient = azureMonitorClient;
        }
        private static IEnumerable <string> ValidateMetricDefaults(MetricDefaults metricDefaults)
        {
            if (string.IsNullOrWhiteSpace(metricDefaults.Scraping?.Schedule))
            {
                yield return(@"No default metric scraping schedule is defined.");
            }

            if (metricDefaults.Limit > Promitor.Core.Defaults.MetricDefaults.Limit)
            {
                yield return($"Limit cannot be higher than {Promitor.Core.Defaults.MetricDefaults.Limit}");
            }

            if (metricDefaults.Limit <= 0)
            {
                yield return(@"Limit has to be at least 1");
            }
        }
예제 #8
0
        protected MetricDefaults GenerateBogusMetricDefaults(string defaultScrapingInterval)
        {
            var bogusAggregationGenerator = new Faker <Aggregation>()
                                            .StrictMode(ensureRulesForAllProperties: true)
                                            .RuleFor(aggregation => aggregation.Interval, faker => TimeSpan.FromMinutes(faker.Random.Int()));

            var generatedAggregation = bogusAggregationGenerator.Generate();
            var metricDefaults       = new MetricDefaults
            {
                Aggregation = generatedAggregation,
            };

            if (!string.IsNullOrWhiteSpace(defaultScrapingInterval))
            {
                metricDefaults.Scraping.Interval = TimeSpan.Parse(defaultScrapingInterval);
            }

            return(metricDefaults);
        }
        private MetricsDeclaration InterpretYamlStream(YamlStream metricsDeclarationYamlStream)
        {
            var document = metricsDeclarationYamlStream.Documents.First();
            var rootNode = (YamlMappingNode)document.RootNode;

            AzureMetadata azureMetadata = null;

            if (rootNode.Children.ContainsKey("azureMetadata"))
            {
                var azureMetadataNode       = (YamlMappingNode)rootNode.Children[new YamlScalarNode("azureMetadata")];
                var azureMetadataSerializer = new AzureMetadataDeserializer(_logger);
                azureMetadata = azureMetadataSerializer.Deserialize(azureMetadataNode);
            }

            MetricDefaults metricDefaults = null;

            if (rootNode.Children.ContainsKey("metricDefaults"))
            {
                var metricDefaultsNode       = (YamlMappingNode)rootNode.Children[new YamlScalarNode("metricDefaults")];
                var metricDefaultsSerializer = new MetricDefaultsDeserializer(_logger);
                metricDefaults = metricDefaultsSerializer.Deserialize(metricDefaultsNode);
            }

            List <MetricDefinition> metrics = null;

            if (rootNode.Children.ContainsKey("metrics"))
            {
                var metricsNode         = (YamlSequenceNode)rootNode.Children[new YamlScalarNode("metrics")];
                var metricsDeserializer = new MetricsDeserializer(_logger);
                metrics = metricsDeserializer.Deserialize(metricsNode);
            }

            var metricsDeclaration = new MetricsDeclaration
            {
                AzureMetadata  = azureMetadata,
                MetricDefaults = metricDefaults,
                Metrics        = metrics
            };

            return(metricsDeclaration);
        }
예제 #10
0
        public JsonResult GetMetricDefaults()
        {
            var service           = new MetricsService();
            var supportMetricList = new List <Metric>()
            {
                new Metric {
                    Name = "Analysis", DefaultPercentage = 20, RateCode = "DT"
                },
                new Metric {
                    Name = "Test", DefaultPercentage = 60, RateCode = "DT"
                },
                new Metric {
                    Name = "CodeReview", DefaultPercentage = 30, RateCode = "DT"
                },
                new Metric {
                    Name = "Project Management", DefaultPercentage = 30, RateCode = "PM"
                }
            };
            var supportMetricDefaults = new MetricDefaults("Sprint Story", supportMetricList);


            var projectMetricList = new List <Metric>()
            {
                new Metric {
                    Name = "Analysis", DefaultPercentage = 20, RateCode = "DT"
                },
                new Metric {
                    Name = "Test", DefaultPercentage = 60, RateCode = "DT"
                },
                new Metric {
                    Name = "Project Management", DefaultPercentage = 30, RateCode = "PM"
                }
            };
            var projectMetricDefaults = new MetricDefaults("Support IR", projectMetricList);

            return(Json(new [] { supportMetricDefaults, projectMetricDefaults }));
        }
예제 #11
0
 public StorageQueueScraper(AzureMetadata azureMetadata, MetricDefaults metricDefaults, AzureMonitorClient azureMonitorClient, ILogger logger, IExceptionTracker exceptionTracker)
     : base(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker)
 {
     _azureStorageQueueClient = new AzureStorageQueueClient(logger);
 }
예제 #12
0
        protected void AssertMetricDefaults(Core.Scraping.Configuration.Model.MetricsDeclaration deserializedConfiguration, MetricDefaults metricDefaults)
        {
            var deserializedMetricDefaults = deserializedConfiguration.MetricDefaults;

            Assert.NotNull(deserializedMetricDefaults);
            Assert.NotNull(deserializedMetricDefaults.Aggregation);
            Assert.Equal(metricDefaults.Aggregation.Interval, deserializedMetricDefaults.Aggregation.Interval);
        }
예제 #13
0
 public MetricAggregationValidator(MetricDefaults metricDefaults)
 {
     _metricDefaults = metricDefaults;
 }
예제 #14
0
 public MetricsValidator(MetricDefaults metricDefaults)
 {
     _metricDefaults = metricDefaults;
 }
예제 #15
0
        public MetricsDeclarationBuilder WithDefaults(MetricDefaults defaults)
        {
            _metricDefaults = defaults;

            return(this);
        }
예제 #16
0
 public GenericScraper(AzureMetadata azureMetadata, MetricDefaults metricDefaults, AzureMonitorClient azureMonitorClient, ILogger logger, IExceptionTracker exceptionTracker)
     : base(azureMetadata, metricDefaults, azureMonitorClient, logger, exceptionTracker)
 {
 }
예제 #17
0
 public AzureMetricConfigurationValidator(MetricDefaults metricDefaults)
 {
     this._metricDefaults = metricDefaults;
 }
예제 #18
0
 public MetricScrapingValidator(MetricDefaults metricDefaults)
 {
     _metricDefaults = metricDefaults;
 }