From 2a96594ad7fca1ff5c4e0d5c1f929ab5a2d21827 Mon Sep 17 00:00:00 2001 From: Jayendran Arumugam <25414541+jayendranarumugam@users.noreply.github.com> Date: Sun, 1 Dec 2024 06:20:34 +0000 Subject: [PATCH] Code quality fix InconsistentNaming --- .../StubResourceDiscoveryRepository.cs | 8 +- .../v1/Core/AggregationDeserializer.cs | 4 +- .../Serialization/Yaml/YamlSerialization.cs | 4 +- .../OpenTelemetryCollectorMetricSink.cs | 4 +- .../ScrapeDefinitionBatchPropertiesTest.cs | 100 ++++++++--------- .../AzureResourceDefinitionBatchingTests.cs | 102 +++++++++--------- .../Generators/ScrapeResultGenerator.cs | 10 +- .../DeserializerTests/DeserializationTests.cs | 6 +- 8 files changed, 119 insertions(+), 119 deletions(-) diff --git a/src/Promitor.Agents.Scraper/Discovery/StubResourceDiscoveryRepository.cs b/src/Promitor.Agents.Scraper/Discovery/StubResourceDiscoveryRepository.cs index 0295f8d6e..0327ec7ab 100644 --- a/src/Promitor.Agents.Scraper/Discovery/StubResourceDiscoveryRepository.cs +++ b/src/Promitor.Agents.Scraper/Discovery/StubResourceDiscoveryRepository.cs @@ -8,17 +8,17 @@ namespace Promitor.Agents.Scraper.Discovery { public class StubResourceDiscoveryRepository : IResourceDiscoveryRepository { - private static readonly List emptyResourceDefinitions = new(); - private static readonly AgentHealthReport healthReport = new(); + private static readonly List EmptyResourceDefinitions = new(); + private static readonly AgentHealthReport HealthReport = new(); public Task> GetResourceDiscoveryGroupAsync(string resourceDiscoveryGroupName) { - return Task.FromResult(emptyResourceDefinitions); + return Task.FromResult(EmptyResourceDefinitions); } public Task GetHealthAsync() { - return Task.FromResult(healthReport); + return Task.FromResult(HealthReport); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs index 0d3d66481..02b8b9f20 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs @@ -6,12 +6,12 @@ namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Core { public class AggregationDeserializer : Deserializer { - private static readonly TimeSpan defaultAggregationInterval = TimeSpan.FromMinutes(5); + private static readonly TimeSpan DefaultAggregationInterval = TimeSpan.FromMinutes(5); public AggregationDeserializer(ILogger logger) : base(logger) { Map(aggregation => aggregation.Interval) - .WithDefault(defaultAggregationInterval); + .WithDefault(DefaultAggregationInterval); } } } diff --git a/src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs b/src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs index 74b391243..2638d24f6 100644 --- a/src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs +++ b/src/Promitor.Core/Serialization/Yaml/YamlSerialization.cs @@ -5,12 +5,12 @@ namespace Promitor.Core.Serialization.Yaml { public static class YamlSerialization { - private static readonly INamingConvention namingConvention = CamelCaseNamingConvention.Instance; + private static readonly INamingConvention NamingConvention = CamelCaseNamingConvention.Instance; public static ISerializer CreateSerializer() { var builder = new SerializerBuilder(); - builder.WithNamingConvention(namingConvention); + builder.WithNamingConvention(NamingConvention); builder.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults); return builder.Build(); diff --git a/src/Promitor.Integrations.Sinks.OpenTelemetry/OpenTelemetryCollectorMetricSink.cs b/src/Promitor.Integrations.Sinks.OpenTelemetry/OpenTelemetryCollectorMetricSink.cs index cba785007..b0bd3d5be 100644 --- a/src/Promitor.Integrations.Sinks.OpenTelemetry/OpenTelemetryCollectorMetricSink.cs +++ b/src/Promitor.Integrations.Sinks.OpenTelemetry/OpenTelemetryCollectorMetricSink.cs @@ -17,7 +17,7 @@ namespace Promitor.Integrations.Sinks.OpenTelemetry public class OpenTelemetryCollectorMetricSink : MetricSink, IMetricSink { private readonly ILogger _logger; - private static readonly Meter azureMonitorMeter = new Meter("Promitor.Scraper.Metrics.AzureMonitor", "1.0"); + private static readonly Meter AzureMonitorMeter = new Meter("Promitor.Scraper.Metrics.AzureMonitor", "1.0"); public MetricSinkType Type => MetricSinkType.OpenTelemetryCollector; @@ -74,7 +74,7 @@ public Task ReportMetricAsync(string metricName, string metricDescription, doubl private void InitializeNewMetric(string metricName, string metricDescription) { - var gauge = azureMonitorMeter.CreateObservableGauge(metricName, description: metricDescription, observeValues: () => ReportMeasurementsForMetric(metricName)); + var gauge = AzureMonitorMeter.CreateObservableGauge(metricName, description: metricDescription, observeValues: () => ReportMeasurementsForMetric(metricName)); _gauges.TryAdd(metricName, gauge); _measurements.TryAdd(metricName, []); diff --git a/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs b/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs index c95cc4479..bb49d9112 100644 --- a/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs +++ b/src/Promitor.Tests.Unit/Core/Metrics/ScrapeDefinitionBatchPropertiesTest.cs @@ -15,19 +15,19 @@ namespace Promitor.Tests.Unit.Core.Metrics public class ScrapeDefinitionBatchPropertiesTest { private readonly IMapper _mapper; // to model instantiation happen - private readonly static string azureMetricNameBase = "promitor_batch_test_metric"; - private readonly static PrometheusMetricDefinition prometheusMetricDefinition = + private readonly static string AzureMetricNameBase = "promitor_batch_test_metric"; + private readonly static PrometheusMetricDefinition PrometheusMetricDefinition = new("promitor_batch_test", "test", new Dictionary()); - private readonly static string subscriptionId = "subscription"; - private readonly static AzureMetricConfigurationV1 azureMetricConfigurationBase = new AzureMetricConfigurationV1 + private readonly static string SubscriptionId = "subscription"; + private readonly static AzureMetricConfigurationV1 AzureMetricConfigurationBase = new AzureMetricConfigurationV1 { - MetricName = azureMetricNameBase, + MetricName = AzureMetricNameBase, Aggregation = new MetricAggregationV1 { Type = PromitorMetricAggregationType.Average }, }; - private readonly static LogAnalyticsConfigurationV1 logAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 + private readonly static LogAnalyticsConfigurationV1 LogAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 { Query = "A eq B", Aggregation = new AggregationV1 @@ -35,7 +35,7 @@ public class ScrapeDefinitionBatchPropertiesTest Interval = TimeSpan.FromMinutes(60) }, }; - private readonly static ScrapingV1 scrapingBase = new ScrapingV1 + private readonly static ScrapingV1 ScrapingBase = new ScrapingV1 { Schedule = "5 4 3 2 1" }; @@ -49,12 +49,12 @@ public ScrapeDefinitionBatchPropertiesTest() [Fact] public void BuildBatchHashKeySameResultNoDimensions() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var scraping = _mapper.Map(scrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); + var scraping = _mapper.Map(ScrapingBase); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -64,14 +64,14 @@ public void BuildBatchHashKeySameResultNoDimensions() [Fact] public void BuildBatchHashKeySameResultIdenticalDimensions() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var scraping = _mapper.Map(ScrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -81,16 +81,16 @@ public void BuildBatchHashKeySameResultIdenticalDimensions() [Fact] public void BuildBatchHashKeyDifferentResultDifferentDimensions() { - var azureMetricConfiguration1 = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration1 = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration1.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; - var azureMetricConfiguration2 = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration2 = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration2.Dimensions = [new MetricDimension{Name = "DiffDimension1"}, new MetricDimension{Name = "DiffDimension2"}]; - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var scraping = _mapper.Map(ScrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -100,17 +100,17 @@ public void BuildBatchHashKeyDifferentResultDifferentDimensions() [Fact] public void BuildBatchHashKeyDifferentResultDifferentMetricName() { - var azureMetricConfiguration1 = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration1 = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration1.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; - var azureMetricConfiguration2 = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration2 = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration2.Dimensions = [new MetricDimension{Name = "Dimension1"}, new MetricDimension{Name = "Dimension2"}]; azureMetricConfiguration2.MetricName = "diffName"; - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var scraping = _mapper.Map(ScrapingBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -120,13 +120,13 @@ public void BuildBatchHashKeyDifferentResultDifferentMetricName() [Fact] public void BuildBatchHashKeyDifferentResultDifferentSubscription() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: "subscription2"); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -136,12 +136,12 @@ public void BuildBatchHashKeyDifferentResultDifferentSubscription() [Fact] public void BuildBatchHashKeyDifferentResultDifferentResourceType() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.LoadBalancer, scraping: scraping, subscriptionId: "subscription2"); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.LoadBalancer, scraping: scraping, SubscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -151,15 +151,15 @@ public void BuildBatchHashKeyDifferentResultDifferentResourceType() [Fact] public void BuildBatchHashKeyDifferentResultDifferentSchedule() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping1 = _mapper.Map(scrapingBase); - var scraping2 = _mapper.Map(scrapingBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping1 = _mapper.Map(ScrapingBase); + var scraping2 = _mapper.Map(ScrapingBase); scraping2.Schedule = "6 4 3 2 1"; - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping1, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping2, subscriptionId: "subscription2"); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping1, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.StorageAccount, scraping: scraping2, SubscriptionId: "subscription2"); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); @@ -189,13 +189,13 @@ public void BuildBatchHashKeyTest() var azureMetricConfiguration1 = _mapper.Map(azureMetricConfigurationTest1); var azureMetricConfiguration2 = _mapper.Map(azureMetricConfigurationTest2); - var scraping1 = _mapper.Map(scrapingBase); - var scraping2 = _mapper.Map(scrapingBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var scraping1 = _mapper.Map(ScrapingBase); + var scraping2 = _mapper.Map(ScrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); - var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.ApplicationInsights, scraping: scraping1, subscriptionId: subscriptionId); - var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.ApplicationInsights, scraping: scraping2, subscriptionId: subscriptionId); + var batchProperties = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration1, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.ApplicationInsights, scraping: scraping1, SubscriptionId: SubscriptionId); + var batchProperties2 = new ScrapeDefinitionBatchProperties(azureMetricConfiguration: azureMetricConfiguration2, logAnalyticsConfiguration: logAnalyticsConfiguration, PrometheusMetricDefinition: PrometheusMetricDefinition, resourceType: Promitor.Core.Contracts.ResourceType.ApplicationInsights, scraping: scraping2, SubscriptionId: SubscriptionId); var hashCode1 = batchProperties.GetHashCode(); var hashCode2 = batchProperties2.GetHashCode(); diff --git a/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs b/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs index a23989993..519c39299 100644 --- a/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs +++ b/src/Promitor.Tests.Unit/Core/Scraping/Batching/AzureResourceDefinitionBatchingTests.cs @@ -17,19 +17,19 @@ namespace Promitor.Tests.Unit.Core.Scraping.Batching public class AzureResourceDefinitionBatchingTests { private readonly IMapper _mapper; // to model instantiation happen - private readonly static string azureMetricNameBase = "promitor_batch_test_metric"; - private readonly static PrometheusMetricDefinition prometheusMetricDefinitionTest = + private readonly static string AzureMetricNameBase = "promitor_batch_test_metric"; + private readonly static PrometheusMetricDefinition PrometheusMetricDefinitionTest = new("promitor_batch_test", "test", new Dictionary()); - private readonly static string subscriptionIdTest = "subscription"; - private readonly static AzureMetricConfigurationV1 azureMetricConfigurationBase = new AzureMetricConfigurationV1 + private readonly static string SubscriptionIdTest = "subscription"; + private readonly static AzureMetricConfigurationV1 AzureMetricConfigurationBase = new AzureMetricConfigurationV1 { - MetricName = azureMetricNameBase, + MetricName = AzureMetricNameBase, Aggregation = new MetricAggregationV1 { Type = PromitorMetricAggregationType.Average }, }; - private readonly static LogAnalyticsConfigurationV1 logAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 + private readonly static LogAnalyticsConfigurationV1 LogAnalyticsConfigurationBase = new LogAnalyticsConfigurationV1 { Query = "A eq B", Aggregation = new AggregationV1 @@ -37,12 +37,12 @@ public class AzureResourceDefinitionBatchingTests Interval = TimeSpan.FromMinutes(60) }, }; - private readonly static ScrapingV1 scrapingBase = new ScrapingV1 + private readonly static ScrapingV1 ScrapingBase = new ScrapingV1 { Schedule = "5 4 3 2 1" }; - private readonly static string resourceGroupNameTest = "batch_test_group"; - private readonly static int batchSize = 50; + private readonly static string ResourceGroupNameTest = "batch_test_group"; + private readonly static int BatchSize = 50; public AzureResourceDefinitionBatchingTests() { @@ -53,14 +53,14 @@ public AzureResourceDefinitionBatchingTests() [Fact] public void IdenticalBatchPropertiesShouldBatchTogether() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); var scrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); - var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions(scrapeDefinitions, maxBatchSize: batchSize); + var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions(scrapeDefinitions, maxBatchSize: BatchSize); // expect one batch of 10 Assert.Single(groupedScrapeDefinitions); Assert.Equal(10, groupedScrapeDefinitions[0].ScrapeDefinitions.Count); @@ -69,14 +69,14 @@ public void IdenticalBatchPropertiesShouldBatchTogether() [Fact] public void BatchShouldSplitAccordingToConfiguredBatchSize() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); var testBatchSize = 10; - var scraping = _mapper.Map(scrapingBase); + var scraping = _mapper.Map(ScrapingBase); var scrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 25 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 25 ); var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions(scrapeDefinitions, maxBatchSize: testBatchSize); // expect three batches adding up to total size @@ -87,18 +87,18 @@ public void BatchShouldSplitAccordingToConfiguredBatchSize() [Fact] public void DifferentBatchPropertiesShouldBatchSeparately() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); var scrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); var differentScrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.BlobStorage, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.BlobStorage, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); - var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: batchSize); + var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: BatchSize); // expect two batch of 10 each Assert.Equal(2, groupedScrapeDefinitions.Count); Assert.Equal(10, groupedScrapeDefinitions[0].ScrapeDefinitions.Count); @@ -108,21 +108,21 @@ public void DifferentBatchPropertiesShouldBatchSeparately() [Fact] public void DifferentAggregationIntervalsShouldBatchSeparately() { - var azureMetricConfiguration5MInterval = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration5MInterval = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration5MInterval.Aggregation.Interval = TimeSpan.FromMinutes(5); - var azureMetricConfiguration2MInterval = _mapper.Map(azureMetricConfigurationBase); + var azureMetricConfiguration2MInterval = _mapper.Map(AzureMetricConfigurationBase); azureMetricConfiguration5MInterval.Aggregation.Interval = TimeSpan.FromMinutes(2); - var logAnalyticsConfiguration = _mapper.Map(logAnalyticsConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var logAnalyticsConfiguration = _mapper.Map(LogAnalyticsConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); var scrapeDefinitions5M = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration5MInterval, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration5MInterval, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); var differentScrapeDefinitions2M = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration2MInterval, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.BlobStorage, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration2MInterval, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.BlobStorage, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); - var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions5M, .. differentScrapeDefinitions2M], maxBatchSize: batchSize); + var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions5M, .. differentScrapeDefinitions2M], maxBatchSize: BatchSize); // expect two batch of 10 each Assert.Equal(2, groupedScrapeDefinitions.Count); Assert.Equal(10, groupedScrapeDefinitions[0].ScrapeDefinitions.Count); @@ -133,18 +133,18 @@ public void DifferentAggregationIntervalsShouldBatchSeparately() [Fact] public void MixedBatchShouldSplitAccordingToConfiguredBatchSize() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); var scrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 130 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 130 ); var differentScrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.BlobStorage, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 120 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.BlobStorage, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 120 ); - var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: batchSize); + var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: BatchSize); // expect two batch of 10 each Assert.Equal(6, groupedScrapeDefinitions.Count); Assert.Equal(250, CountTotalScrapeDefinitions(groupedScrapeDefinitions)); @@ -153,18 +153,18 @@ public void MixedBatchShouldSplitAccordingToConfiguredBatchSize() [Fact] public void BatchConstructionShouldBeAgnosticToResourceGroup() { - var azureMetricConfiguration = _mapper.Map(azureMetricConfigurationBase); - var scraping = _mapper.Map(scrapingBase); + var azureMetricConfiguration = _mapper.Map(AzureMetricConfigurationBase); + var scraping = _mapper.Map(ScrapingBase); var logAnalyticsConfiguration = new LogAnalyticsConfiguration(); var scrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: resourceGroupNameTest, 10 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: ResourceGroupNameTest, 10 ); var differentScrapeDefinitions = BuildScrapeDefinitionBatch( - azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: prometheusMetricDefinitionTest, scraping: scraping, - resourceType: ResourceType.StorageAccount, subscriptionId: subscriptionIdTest, resourceGroupName: "group2", 10 + azureMetricConfiguration: azureMetricConfiguration, logAnalyticsConfiguration: logAnalyticsConfiguration, prometheusMetricDefinition: PrometheusMetricDefinitionTest, scraping: scraping, + resourceType: ResourceType.StorageAccount, subscriptionId: SubscriptionIdTest, resourceGroupName: "group2", 10 ); - var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: batchSize); + var groupedScrapeDefinitions = AzureResourceDefinitionBatching.GroupScrapeDefinitions([.. scrapeDefinitions, .. differentScrapeDefinitions], maxBatchSize: BatchSize); // expect two batch of 10 each Assert.Single(groupedScrapeDefinitions); Assert.Equal(20, groupedScrapeDefinitions[0].ScrapeDefinitions.Count); diff --git a/src/Promitor.Tests.Unit/Generators/ScrapeResultGenerator.cs b/src/Promitor.Tests.Unit/Generators/ScrapeResultGenerator.cs index 9248c0723..cf27d6878 100644 --- a/src/Promitor.Tests.Unit/Generators/ScrapeResultGenerator.cs +++ b/src/Promitor.Tests.Unit/Generators/ScrapeResultGenerator.cs @@ -7,14 +7,14 @@ namespace Promitor.Tests.Unit.Generators { public class ScrapeResultGenerator { - private static readonly Faker bogus = new(); + private static readonly Faker Bogus = new(); public static ScrapeResult GenerateFromMetric(MeasuredMetric measuredMetric) { - var subscriptionId = bogus.Name.FirstName(); - var resourceGroupName = bogus.Name.FirstName(); - var instanceName = bogus.Name.FirstName(); - var resourceUri = bogus.Internet.Url(); + var subscriptionId = Bogus.Name.FirstName(); + var resourceGroupName = Bogus.Name.FirstName(); + var instanceName = Bogus.Name.FirstName(); + var resourceUri = Bogus.Internet.Url(); return new ScrapeResult(subscriptionId, resourceGroupName, instanceName, resourceUri, new List {measuredMetric}); } diff --git a/src/Promitor.Tests.Unit/Serialization/DeserializerTests/DeserializationTests.cs b/src/Promitor.Tests.Unit/Serialization/DeserializerTests/DeserializationTests.cs index 14c3e9869..afeb55da8 100644 --- a/src/Promitor.Tests.Unit/Serialization/DeserializerTests/DeserializationTests.cs +++ b/src/Promitor.Tests.Unit/Serialization/DeserializerTests/DeserializationTests.cs @@ -10,7 +10,7 @@ namespace Promitor.Tests.Unit.Serialization.DeserializerTests { public class DeserializationTests : UnitTest { - private static readonly TimeSpan defaultInterval = TimeSpan.FromMinutes(5); + private static readonly TimeSpan DefaultInterval = TimeSpan.FromMinutes(5); private readonly Mock _errorReporter = new(); private readonly Mock> _childDeserializer = new(); @@ -171,7 +171,7 @@ public void Deserialize_MapOptional_CanSpecifyDefaultValue() var result = _deserializer.Deserialize(node, _errorReporter.Object); // Assert - Assert.Equal(defaultInterval, result.DefaultedInterval); + Assert.Equal(DefaultInterval, result.DefaultedInterval); } [Fact] @@ -268,7 +268,7 @@ public RegistrationConfigDeserializer(IDeserializer childDeserializer) : Map(t => t.Classes).IsRequired(); Map(t => t.Town); Map(t => t.Interval); - Map(t => t.DefaultedInterval).WithDefault(defaultInterval); + Map(t => t.DefaultedInterval).WithDefault(DefaultInterval); Map(t => t.NullableInterval); Map(t => t.InvertedProperty) .MapUsing(InvertBooleanString);