From 3d25c55abf24bb770ca37805d7d0d7b60835148b Mon Sep 17 00:00:00 2001 From: Brandon H Date: Thu, 28 Mar 2019 13:20:33 -0700 Subject: [PATCH] fixing resharper warnings --- .../Configuration/Model/Scraping.cs | 4 +--- .../Providers/MetricsDeclarationProvider.cs | 14 +++++++++++--- .../Core/MetricDefaultsDeserializer.cs | 7 +++---- .../Factories/MetricScraperFactory.cs | 1 - src/Promitor.Core.Scraping/Scraper.cs | 4 ++-- .../Steps/MetricsDeclarationValidationStep.cs | 6 +++--- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Promitor.Core.Scraping/Configuration/Model/Scraping.cs b/src/Promitor.Core.Scraping/Configuration/Model/Scraping.cs index bbd8f2109..2f29b1b5b 100644 --- a/src/Promitor.Core.Scraping/Configuration/Model/Scraping.cs +++ b/src/Promitor.Core.Scraping/Configuration/Model/Scraping.cs @@ -1,6 +1,4 @@ -using System; - -namespace Promitor.Core.Scraping.Configuration.Model +namespace Promitor.Core.Scraping.Configuration.Model { public class Scraping { diff --git a/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs b/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs index 673b47ae3..27bc39c9d 100644 --- a/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs +++ b/src/Promitor.Core.Scraping/Configuration/Providers/MetricsDeclarationProvider.cs @@ -33,17 +33,25 @@ public virtual MetricsDeclaration Get(bool applyDefaults = false) } // Apply the default aggregation interval if none is specified - if (metric.AzureMetricConfiguration?.Aggregation?.Interval == null) + if (metric.AzureMetricConfiguration == null) + { + metric.AzureMetricConfiguration = new AzureMetricConfiguration(); + } + if (metric.AzureMetricConfiguration?.Aggregation == null) + { + metric.AzureMetricConfiguration.Aggregation = new MetricAggregation(); + } + if (metric.AzureMetricConfiguration?.Aggregation.Interval == null) { metric.AzureMetricConfiguration.Aggregation.Interval = config.MetricDefaults.Aggregation.Interval; } // Apply the default scraping interval if none is specified - if (metric.Scraping?.Schedule == null) + if (metric.Scraping == null) { metric.Scraping = config.MetricDefaults.Scraping; } - + // Apply the default scraping interval if none is specified if (metric.Scraping.Schedule == null) { diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/Core/MetricDefaultsDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/Core/MetricDefaultsDeserializer.cs index f582c4755..5df83e5d1 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/Core/MetricDefaultsDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/Core/MetricDefaultsDeserializer.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using GuardNet; +using GuardNet; using Microsoft.Extensions.Logging; using Promitor.Core.Scraping.Configuration.Model; using YamlDotNet.RepresentationModel; @@ -21,7 +20,7 @@ internal override MetricDefaults Deserialize(YamlMappingNode node) if (node.Children.ContainsKey("aggregation")) { var metricDefaultsNode = (YamlMappingNode)node.Children[new YamlScalarNode("aggregation")]; - var metricDefaultsSerializer = new AggregationDeserializer(this.Logger); + var metricDefaultsSerializer = new AggregationDeserializer(Logger); var aggregation = metricDefaultsSerializer.Deserialize(metricDefaultsNode); metricDefaults.Aggregation = aggregation; } @@ -29,7 +28,7 @@ internal override MetricDefaults Deserialize(YamlMappingNode node) if (node.Children.ContainsKey(@"scraping")) { var metricDefaultsNode = (YamlMappingNode)node.Children[new YamlScalarNode("scraping")]; - var metricDefaultsSerializer = new ScrapingDeserializer(this.Logger); + var metricDefaultsSerializer = new ScrapingDeserializer(Logger); var scraping = metricDefaultsSerializer.Deserialize(metricDefaultsNode); metricDefaults.Scraping = scraping; } diff --git a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs index 889fef02d..7d5c67499 100644 --- a/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs +++ b/src/Promitor.Core.Scraping/Factories/MetricScraperFactory.cs @@ -16,7 +16,6 @@ public class MetricScraperFactory /// /// Metadata concerning the Azure resources /// Resource type to scrape - /// Default configuration for metrics /// General logger /// Tracker used to log exceptions public static IScraper CreateScraper(ResourceType metricDefinitionResourceType, AzureMetadata azureMetadata, diff --git a/src/Promitor.Core.Scraping/Scraper.cs b/src/Promitor.Core.Scraping/Scraper.cs index 25e3718a1..36a61adb1 100644 --- a/src/Promitor.Core.Scraping/Scraper.cs +++ b/src/Promitor.Core.Scraping/Scraper.cs @@ -42,8 +42,8 @@ protected Scraper(AzureMetadata azureMetadata, AzureMonitorClient azureMonitorCl _logger = logger; _exceptionTracker = exceptionTracker; - this.AzureMetadata = azureMetadata; - this.AzureMonitorClient = azureMonitorClient; + AzureMetadata = azureMetadata; + AzureMonitorClient = azureMonitorClient; } /// diff --git a/src/Promitor.Scraper.Host/Validation/Steps/MetricsDeclarationValidationStep.cs b/src/Promitor.Scraper.Host/Validation/Steps/MetricsDeclarationValidationStep.cs index d44d63782..692b7e360 100644 --- a/src/Promitor.Scraper.Host/Validation/Steps/MetricsDeclarationValidationStep.cs +++ b/src/Promitor.Scraper.Host/Validation/Steps/MetricsDeclarationValidationStep.cs @@ -28,7 +28,7 @@ public MetricsDeclarationValidationStep(IMetricsDeclarationProvider metricsDecla public ValidationResult Run() { var rawMetricsConfiguration = _metricsDeclarationProvider.ReadRawDeclaration(); - this.Logger.LogInformation("Following metrics configuration was configured:\n{Configuration}", rawMetricsConfiguration); + Logger.LogInformation("Following metrics configuration was configured:\n{Configuration}", rawMetricsConfiguration); MetricsDeclaration metricsDeclaration = null; try @@ -42,7 +42,7 @@ public ValidationResult Run() if (metricsDeclaration == null) { - return ValidationResult.Failure(this.ComponentName, "Unable to deserialize configured metrics declaration"); + return ValidationResult.Failure(ComponentName, "Unable to deserialize configured metrics declaration"); } var validationErrors = new List(); @@ -55,7 +55,7 @@ public ValidationResult Run() var metricsErrorMessages = ValidateMetrics(metricsDeclaration.Metrics, metricsDeclaration.MetricDefaults); validationErrors.AddRange(metricsErrorMessages); - return validationErrors.Any() ? ValidationResult.Failure(this.ComponentName, validationErrors) : ValidationResult.Successful(this.ComponentName); + return validationErrors.Any() ? ValidationResult.Failure(ComponentName, validationErrors) : ValidationResult.Successful(ComponentName); } private static IEnumerable ValidateMetricDefaults(MetricDefaults metricDefaults)