diff --git a/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs b/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs index 5362e85f9..b6132114a 100644 --- a/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs +++ b/src/Promitor.Scraper.Tests.Unit/Builders/Metrics/v1/MetricsDeclarationBuilder.cs @@ -2,32 +2,32 @@ using AutoMapper; using Microsoft.Azure.Management.Monitor.Fluent.Models; using Microsoft.Extensions.Logging.Abstractions; -using Promitor.Core.Scraping.Configuration.Model; -using Promitor.Core.Scraping.Configuration.Model.Metrics; -using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; +using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; +using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.Metrics; +using Promitor.Core.Scraping.Configuration.Serialization.v1.Model.Metrics.ResourceTypes; using Promitor.Integrations.AzureStorage; namespace Promitor.Scraper.Tests.Unit.Builders.Metrics.v1 { public class MetricsDeclarationBuilder { - private readonly AzureMetadata _azureMetadata; - private readonly List _metrics = new List(); - private MetricDefaults _metricDefaults = new MetricDefaults + private readonly AzureMetadataV1 _azureMetadata; + private readonly List _metrics = new List(); + private MetricDefaultsV1 _metricDefaults = new MetricDefaultsV1 { - Scraping = new Scraping { Schedule = @"0 * * ? * *" } + Scraping = new ScrapingV1 { Schedule = @"0 * * ? * *" } }; - public MetricsDeclarationBuilder(AzureMetadata azureMetadata) + public MetricsDeclarationBuilder(AzureMetadataV1 azureMetadata) { _azureMetadata = azureMetadata; } public static MetricsDeclarationBuilder WithMetadata(string tenantId = "tenantId", string subscriptionId = "subscriptionId", string resourceGroupName = "resourceGroupName") { - var azureMetadata = new AzureMetadata + var azureMetadata = new AzureMetadataV1 { TenantId = tenantId, SubscriptionId = subscriptionId, @@ -42,7 +42,7 @@ public static MetricsDeclarationBuilder WithoutMetadata() return new MetricsDeclarationBuilder(azureMetadata: null); } - public MetricsDeclarationBuilder WithDefaults(MetricDefaults defaults) + public MetricsDeclarationBuilder WithDefaults(MetricDefaultsV1 defaults) { _metricDefaults = defaults; @@ -51,7 +51,7 @@ public MetricsDeclarationBuilder WithDefaults(MetricDefaults defaults) public string Build(IMapper mapper) { - var metricsDeclaration = new MetricsDeclaration + var metricsDeclaration = new MetricsDeclarationV1 { Version = SpecVersion.v1.ToString(), AzureMetadata = _azureMetadata, @@ -66,7 +66,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithServiceBusMetric(string metricName = "promitor-service-bus", string metricDescription = "Description for a metric", string queueName = "promitor-queue", string serviceBusNamespace = "promitor-namespace", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new ServiceBusQueueMetricDefinition + var metric = new ServiceBusQueueMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -82,7 +82,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithContainerInstanceMetric(string metricName = "promitor-container-instance", string metricDescription = "Description for a metric", string containerGroup = "promitor-group", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new ContainerInstanceMetricDefinition + var metric = new ContainerInstanceMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -98,7 +98,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithContainerRegistryMetric(string metricName = "promitor-container-registry", string metricDescription = "Description for a metric", string registryName = "promitor-container-registry", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new ContainerRegistryMetricDefinition + var metric = new ContainerRegistryMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -113,7 +113,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithCosmosDbMetric(string metricName = "promitor-cosmosdb", string metricDescription = "Description for a metric", string dbName = "promitor-cosmosdb", string azureMetricName = "TotalRequests") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new CosmosDbMetricDefinition + var metric = new CosmosDbMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -128,12 +128,12 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithAzureStorageQueueMetric(string metricName = "promitor", string metricDescription = "Description for a metric", string queueName = "promitor-queue", string accountName = "promitor-account", string sasToken = "?sig=promitor", string azureMetricName = AzureStorageConstants.Queues.Metrics.MessageCount) { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var secret = new Secret + var secret = new SecretV1 { RawValue = sasToken }; - var metric = new StorageQueueMetricDefinition + var metric = new StorageQueueMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -150,7 +150,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithVirtualMachineMetric(string metricName = "promitor-virtual-machine", string metricDescription = "Description for a metric", string virtualMachineName = "promitor-virtual-machine-name", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new VirtualMachineMetricDefinition + var metric = new VirtualMachineMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -166,7 +166,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithNetworkInterfaceMetric(string metricName = "promitor-network-interface", string metricDescription = "Description for a metric", string networkInterfaceName = "promitor-network-interface-name", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new NetworkInterfaceMetricDefinition + var metric = new NetworkInterfaceMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -182,7 +182,7 @@ public string Build(IMapper mapper) public MetricsDeclarationBuilder WithGenericMetric(string metricName = "foo", string metricDescription = "Description for a metric", string resourceUri = "Microsoft.ServiceBus/namespaces/promitor-messaging", string filter = "EntityName eq \'orders\'", string azureMetricName = "Total") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new GenericAzureMetricDefinition + var metric = new GenericAzureMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -195,12 +195,12 @@ public string Build(IMapper mapper) return this; } - private AzureMetricConfiguration CreateAzureMetricConfiguration(string azureMetricName) + private AzureMetricConfigurationV1 CreateAzureMetricConfiguration(string azureMetricName) { - return new AzureMetricConfiguration + return new AzureMetricConfigurationV1 { MetricName = azureMetricName, - Aggregation = new MetricAggregation + Aggregation = new MetricAggregationV1 { Type = AggregationType.Average } @@ -210,7 +210,7 @@ private AzureMetricConfiguration CreateAzureMetricConfiguration(string azureMetr public MetricsDeclarationBuilder WithRedisCacheMetric(string metricName = "promitor-redis", string metricDescription = "Description for a metric", string cacheName = "promitor-redis", string azureMetricName = "CacheHits") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new RedisCacheMetricDefinition + var metric = new RedisCacheMetricDefinitionV1 { Name = metricName, Description = metricDescription, @@ -225,7 +225,7 @@ private AzureMetricConfiguration CreateAzureMetricConfiguration(string azureMetr public MetricsDeclarationBuilder WithPostgreSqlMetric(string metricName = "promitor-postgresql", string metricDescription = "Description for a metric", string serverName = "promitor-postgresql", string azureMetricName = "cpu_percent") { var azureMetricConfiguration = CreateAzureMetricConfiguration(azureMetricName); - var metric = new PostgreSqlMetricDefinition + var metric = new PostgreSqlMetricDefinitionV1 { Name = metricName, Description = metricDescription, diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithAzureStorageQueueYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithAzureStorageQueueYamlSerializationTests.cs index db51e7dba..5e19f61a9 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithAzureStorageQueueYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithAzureStorageQueueYamlSerializationTests.cs @@ -50,23 +50,24 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForAzureStorageQ Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, azureStorageQueueMetricDefinition); - var deserializedAzureStorageQueueMetricDefinition = deserializedMetricDefinition as StorageQueueMetricDefinition; - AssertAzureStorageQueueMetricDefinition(deserializedAzureStorageQueueMetricDefinition, azureStorageQueueMetricDefinition, deserializedMetricDefinition); + AssertAzureStorageQueueMetricDefinition(deserializedMetricDefinition, azureStorageQueueMetricDefinition); } - private static void AssertAzureStorageQueueMetricDefinition(StorageQueueMetricDefinition deserializedStorageQueueMetricDefinition, StorageQueueMetricDefinitionV1 storageQueueMetricDefinition, MetricDefinition deserializedMetricDefinition) + private static void AssertAzureStorageQueueMetricDefinition(MetricDefinition deserializedStorageQueueMetricDefinition, StorageQueueMetricDefinitionV1 storageQueueMetricDefinition) { - Assert.NotNull(deserializedStorageQueueMetricDefinition); - Assert.Equal(storageQueueMetricDefinition.AccountName, deserializedStorageQueueMetricDefinition.AccountName); - Assert.Equal(storageQueueMetricDefinition.QueueName, deserializedStorageQueueMetricDefinition.QueueName); - Assert.NotNull(deserializedStorageQueueMetricDefinition.SasToken); - Assert.Equal(storageQueueMetricDefinition.SasToken.RawValue, deserializedStorageQueueMetricDefinition.SasToken.RawValue); - Assert.Equal(storageQueueMetricDefinition.SasToken.EnvironmentVariable, deserializedStorageQueueMetricDefinition.SasToken.EnvironmentVariable); - Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration); - Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.MetricName, deserializedMetricDefinition.AzureMetricConfiguration.MetricName); - Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration.Aggregation); - Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Type, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Type); - Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Interval, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Interval); + var deserializedResource = deserializedStorageQueueMetricDefinition.Resources.Single() as StorageQueueMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(storageQueueMetricDefinition.AccountName, deserializedResource.AccountName); + Assert.Equal(storageQueueMetricDefinition.QueueName, deserializedResource.QueueName); + Assert.NotNull(deserializedResource.SasToken); + Assert.Equal(storageQueueMetricDefinition.SasToken.RawValue, deserializedResource.SasToken.RawValue); + Assert.Equal(storageQueueMetricDefinition.SasToken.EnvironmentVariable, deserializedResource.SasToken.EnvironmentVariable); + Assert.NotNull(deserializedStorageQueueMetricDefinition.AzureMetricConfiguration); + Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.MetricName, deserializedStorageQueueMetricDefinition.AzureMetricConfiguration.MetricName); + Assert.NotNull(deserializedStorageQueueMetricDefinition.AzureMetricConfiguration.Aggregation); + Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Type, deserializedStorageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Type); + Assert.Equal(storageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Interval, deserializedStorageQueueMetricDefinition.AzureMetricConfiguration.Aggregation.Interval); } private StorageQueueMetricDefinitionV1 GenerateBogusAzureStorageQueueMetricDefinition(string resourceGroupName, string metricScrapingInterval, string sasTokenRawValue, string sasTokenEnvironmentVariable) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerInstanceYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerInstanceYamlSerializationTests.cs index 80041c49c..c267eff7e 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerInstanceYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerInstanceYamlSerializationTests.cs @@ -51,19 +51,20 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForContainerInst Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, containerInstanceMetricDefinition); - var deserializedServiceBusMetricDefinition = deserializedMetricDefinition as ContainerInstanceMetricDefinition; - AssertContainerInstanceMetricDefinition(deserializedServiceBusMetricDefinition, containerInstanceMetricDefinition, deserializedMetricDefinition); + AssertContainerInstanceMetricDefinition(deserializedMetricDefinition, containerInstanceMetricDefinition); } - private static void AssertContainerInstanceMetricDefinition(ContainerInstanceMetricDefinition deserializedContainerInstanceMetricDefinition, ContainerInstanceMetricDefinitionV1 containerInstanceMetricDefinition, MetricDefinition deserializedMetricDefinition) + private static void AssertContainerInstanceMetricDefinition(MetricDefinition deserializedContainerInstanceMetricDefinition, ContainerInstanceMetricDefinitionV1 containerInstanceMetricDefinition) { - Assert.NotNull(deserializedContainerInstanceMetricDefinition); - Assert.Equal(containerInstanceMetricDefinition.ContainerGroup, deserializedContainerInstanceMetricDefinition.ContainerGroup); - Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration); - Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.MetricName, deserializedMetricDefinition.AzureMetricConfiguration.MetricName); - Assert.NotNull(deserializedMetricDefinition.AzureMetricConfiguration.Aggregation); - Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Type, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Type); - Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Interval, deserializedMetricDefinition.AzureMetricConfiguration.Aggregation.Interval); + var deserializedResource = deserializedContainerInstanceMetricDefinition.Resources.Single() as ContainerInstanceMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(containerInstanceMetricDefinition.ContainerGroup, deserializedResource.ContainerGroup); + Assert.NotNull(deserializedContainerInstanceMetricDefinition.AzureMetricConfiguration); + Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.MetricName, deserializedContainerInstanceMetricDefinition.AzureMetricConfiguration.MetricName); + Assert.NotNull(deserializedContainerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation); + Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Type, deserializedContainerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Type); + Assert.Equal(containerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Interval, deserializedContainerInstanceMetricDefinition.AzureMetricConfiguration.Aggregation.Interval); } private ContainerInstanceMetricDefinitionV1 GenerateBogusContainerInstanceMetricDefinition(string resourceGroupName, string metricScrapingInterval) { diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerRegistryYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerRegistryYamlSerializationTests.cs index c32b16477..d942b3496 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerRegistryYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithContainerRegistryYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForContainerRegi Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, containerRegistryMetricDefinition); - var deserializedContainerRegistryMetricDefinition = deserializedMetricDefinition as ContainerRegistryMetricDefinition; - AssertContainerRegistryMetricDefinition(deserializedContainerRegistryMetricDefinition, containerRegistryMetricDefinition); + AssertContainerRegistryMetricDefinition(deserializedMetricDefinition, containerRegistryMetricDefinition); } - private static void AssertContainerRegistryMetricDefinition(ContainerRegistryMetricDefinition deserializedServiceBusMetricDefinition, ContainerRegistryMetricDefinitionV1 serviceBusMetricDefinition) + private static void AssertContainerRegistryMetricDefinition(MetricDefinition deserializedContainerRegistryMetricDefinition, ContainerRegistryMetricDefinitionV1 containerRegistryMetricDefinition) { - Assert.NotNull(deserializedServiceBusMetricDefinition); - Assert.Equal(serviceBusMetricDefinition.RegistryName, deserializedServiceBusMetricDefinition.RegistryName); + var deserializedResource = deserializedContainerRegistryMetricDefinition.Resources.Single() as ContainerRegistryMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(containerRegistryMetricDefinition.RegistryName, deserializedResource.RegistryName); } private ContainerRegistryMetricDefinitionV1 GenerateBogusContainerRegistryMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithCosmosDbYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithCosmosDbYamlSerializationTests.cs index fc32d40b9..aed982cc6 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithCosmosDbYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithCosmosDbYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForCosmosDb_Succ Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, cosmosDbMetricDefinition); - var deserializedCosmosDbMetricDefinition = deserializedMetricDefinition as CosmosDbMetricDefinition; - AssertCosmosDbMetricDefinition(deserializedCosmosDbMetricDefinition, cosmosDbMetricDefinition); + AssertCosmosDbMetricDefinition(deserializedMetricDefinition, cosmosDbMetricDefinition); } - private static void AssertCosmosDbMetricDefinition(CosmosDbMetricDefinition deserializedCosmosDbMetricDefinition, CosmosDbMetricDefinitionV1 cosmosDbMetricDefinition) + private static void AssertCosmosDbMetricDefinition(MetricDefinition deserializedCosmosDbMetricDefinition, CosmosDbMetricDefinitionV1 cosmosDbMetricDefinition) { - Assert.NotNull(deserializedCosmosDbMetricDefinition); - Assert.Equal(cosmosDbMetricDefinition.DbName, deserializedCosmosDbMetricDefinition.DbName); + var deserializedResource = deserializedCosmosDbMetricDefinition.Resources.Single() as CosmosDbMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(cosmosDbMetricDefinition.DbName, deserializedResource.DbName); } private CosmosDbMetricDefinitionV1 GenerateBogusCosmosDbMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithNetworkInterfaceYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithNetworkInterfaceYamlSerializationTests.cs index 78a0660cc..57a1be197 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithNetworkInterfaceYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithNetworkInterfaceYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForNetworkInterf Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, networkInterfaceMetricDefinition); - var deserializedNetworkInterfaceMetricDefinition = deserializedMetricDefinition as NetworkInterfaceMetricDefinition; - AssertNetworkInterfaceMetricDefinition(deserializedNetworkInterfaceMetricDefinition, networkInterfaceMetricDefinition); + AssertNetworkInterfaceMetricDefinition(deserializedMetricDefinition, networkInterfaceMetricDefinition); } - private static void AssertNetworkInterfaceMetricDefinition(NetworkInterfaceMetricDefinition deserializedNetworkInterfaceMetricDefinition, NetworkInterfaceMetricDefinitionV1 networkInterfaceMetricDefinition) + private static void AssertNetworkInterfaceMetricDefinition(MetricDefinition deserializedNetworkInterfaceMetricDefinition, NetworkInterfaceMetricDefinitionV1 networkInterfaceMetricDefinition) { - Assert.NotNull(deserializedNetworkInterfaceMetricDefinition); - Assert.Equal(networkInterfaceMetricDefinition.NetworkInterfaceName, deserializedNetworkInterfaceMetricDefinition.NetworkInterfaceName); + var deserializedResource = deserializedNetworkInterfaceMetricDefinition.Resources.Single() as NetworkInterfaceMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(networkInterfaceMetricDefinition.NetworkInterfaceName, deserializedResource.NetworkInterfaceName); } private NetworkInterfaceMetricDefinitionV1 GenerateBogusNetworkInterfaceMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithPostgreSqlYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithPostgreSqlYamlSerializationTests.cs index 6f18069ce..e21f74546 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithPostgreSqlYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithPostgreSqlYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeConfigForPostgreSql_Succeed Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, postgreSqlMetricDefinition); - var deserializedPostgreSqlMetricDefinition = deserializedMetricDefinition as PostgreSqlMetricDefinition; - AssertPostgreSqlMetricDefinition(deserializedPostgreSqlMetricDefinition, postgreSqlMetricDefinition); + AssertPostgreSqlMetricDefinition(deserializedMetricDefinition, postgreSqlMetricDefinition); } - private static void AssertPostgreSqlMetricDefinition(PostgreSqlMetricDefinition deserializedPostgreSqlMetricDefinition, PostgreSqlMetricDefinitionV1 postgreSqlMetricDefinition) + private static void AssertPostgreSqlMetricDefinition(MetricDefinition deserializedPostgreSqlMetricDefinition, PostgreSqlMetricDefinitionV1 postgreSqlMetricDefinition) { - Assert.NotNull(deserializedPostgreSqlMetricDefinition); - Assert.Equal(postgreSqlMetricDefinition.ServerName, deserializedPostgreSqlMetricDefinition.ServerName); + var deserializedResource = deserializedPostgreSqlMetricDefinition.Resources.Single() as PostgreSqlMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(postgreSqlMetricDefinition.ServerName, deserializedResource.ServerName); } private PostgreSqlMetricDefinitionV1 GenerateBogusPostgreSqlMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithRedisCacheYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithRedisCacheYamlSerializationTests.cs index 444b7c05d..c8cd1c08c 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithRedisCacheYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithRedisCacheYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeConfigForRedisCache_Succeed Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, redisCacheMetricDefinition); - var deserializedRedisCacheMetricDefinition = deserializedMetricDefinition as RedisCacheMetricDefinition; - AssertRedisCacheMetricDefinition(deserializedRedisCacheMetricDefinition, redisCacheMetricDefinition); + AssertRedisCacheMetricDefinition(deserializedMetricDefinition, redisCacheMetricDefinition); } - private static void AssertRedisCacheMetricDefinition(RedisCacheMetricDefinition deserializedRedisCacheMetricDefinition, RedisCacheMetricDefinitionV1 redisCacheMetricDefinition) + private static void AssertRedisCacheMetricDefinition(MetricDefinition deserializedRedisCacheMetricDefinition, RedisCacheMetricDefinitionV1 redisCacheMetricDefinition) { - Assert.NotNull(deserializedRedisCacheMetricDefinition); - Assert.Equal(redisCacheMetricDefinition.CacheName, deserializedRedisCacheMetricDefinition.CacheName); + var deserializedResource = deserializedRedisCacheMetricDefinition.Resources.Single() as RedisCacheMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(redisCacheMetricDefinition.CacheName, deserializedResource.CacheName); } private RedisCacheMetricDefinitionV1 GenerateBogusRedisCacheMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithServiceBusQueueYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithServiceBusQueueYamlSerializationTests.cs index bfa874a48..953af8c7b 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithServiceBusQueueYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithServiceBusQueueYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,15 +51,16 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForServiceBus_Su Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, serviceBusMetricDefinition); - var deserializedServiceBusMetricDefinition = deserializedMetricDefinition as ServiceBusQueueMetricDefinition; - AssertServiceBusQueueMetricDefinition(deserializedServiceBusMetricDefinition, serviceBusMetricDefinition); + AssertServiceBusQueueMetricDefinition(deserializedMetricDefinition, serviceBusMetricDefinition); } - private static void AssertServiceBusQueueMetricDefinition(ServiceBusQueueMetricDefinition deserializedServiceBusMetricDefinition, ServiceBusQueueMetricDefinitionV1 serviceBusMetricDefinition) + private static void AssertServiceBusQueueMetricDefinition(MetricDefinition deserializedServiceBusMetricDefinition, ServiceBusQueueMetricDefinitionV1 serviceBusMetricDefinition) { - Assert.NotNull(deserializedServiceBusMetricDefinition); - Assert.Equal(serviceBusMetricDefinition.Namespace, deserializedServiceBusMetricDefinition.Namespace); - Assert.Equal(serviceBusMetricDefinition.QueueName, deserializedServiceBusMetricDefinition.QueueName); + var deserializedResource = deserializedServiceBusMetricDefinition.Resources.Single() as ServiceBusQueueMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(serviceBusMetricDefinition.Namespace, deserializedResource.Namespace); + Assert.Equal(serviceBusMetricDefinition.QueueName, deserializedResource.QueueName); } private ServiceBusQueueMetricDefinitionV1 GenerateBogusServiceBusMetricDefinition(string resourceGroupName, string metricScrapingInterval) diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithVirtualMachineYamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithVirtualMachineYamlSerializationTests.cs index f6831c3bf..4a68783ba 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithVirtualMachineYamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/MetricsDeclarationWithVirtualMachineYamlSerializationTests.cs @@ -4,6 +4,7 @@ using Bogus; using Microsoft.Extensions.Logging.Abstractions; using Promitor.Core.Scraping.Configuration.Model; +using Promitor.Core.Scraping.Configuration.Model.Metrics; using Promitor.Core.Scraping.Configuration.Model.Metrics.ResourceTypes; using Promitor.Core.Scraping.Configuration.Serialization; using Promitor.Core.Scraping.Configuration.Serialization.Enum; @@ -50,14 +51,15 @@ public void YamlSerialization_SerializeAndDeserializeValidConfigForVirtualMachin Assert.Single(deserializedConfiguration.Metrics); var deserializedMetricDefinition = deserializedConfiguration.Metrics.FirstOrDefault(); AssertMetricDefinition(deserializedMetricDefinition, virtualMachineMetricDefinition); - var deserializedVirtualMachineMetricDefinition = deserializedMetricDefinition as VirtualMachineMetricDefinition; - AssertVirtualMachineMetricDefinition(deserializedVirtualMachineMetricDefinition, virtualMachineMetricDefinition); + AssertVirtualMachineMetricDefinition(deserializedMetricDefinition, virtualMachineMetricDefinition); } - private static void AssertVirtualMachineMetricDefinition(VirtualMachineMetricDefinition deserializedVirtualMachineMetricDefinition, VirtualMachineMetricDefinitionV1 virtualMachineMetricDefinition) + private static void AssertVirtualMachineMetricDefinition(MetricDefinition deserializedVirtualMachineMetricDefinition, VirtualMachineMetricDefinitionV1 virtualMachineMetricDefinition) { - Assert.NotNull(deserializedVirtualMachineMetricDefinition); - Assert.Equal(virtualMachineMetricDefinition.VirtualMachineName, deserializedVirtualMachineMetricDefinition.VirtualMachineName); + var deserializedResource = deserializedVirtualMachineMetricDefinition.Resources.Single() as VirtualMachineMetricDefinition; + + Assert.NotNull(deserializedResource); + Assert.Equal(virtualMachineMetricDefinition.VirtualMachineName, deserializedResource.VirtualMachineName); Assert.NotNull(deserializedVirtualMachineMetricDefinition.AzureMetricConfiguration); Assert.Equal(virtualMachineMetricDefinition.AzureMetricConfiguration.MetricName, deserializedVirtualMachineMetricDefinition.AzureMetricConfiguration.MetricName); Assert.NotNull(deserializedVirtualMachineMetricDefinition.AzureMetricConfiguration.Aggregation); diff --git a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/YamlSerializationTests.cs b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/YamlSerializationTests.cs index f3ee3d3fe..74650d81b 100644 --- a/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/YamlSerializationTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Serialization/v1/MetricsDeclaration/YamlSerializationTests.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Linq; using AutoMapper; using Bogus; using Promitor.Core.Scraping.Configuration.Model.Metrics; @@ -24,16 +25,16 @@ public YamlSerializationTests() protected void AssertMetricDefinition(MetricDefinition deserializedMetricDefinition, MetricDefinitionV1 metricDefinition) { Assert.NotNull(deserializedMetricDefinition); - Assert.Equal(metricDefinition.Name, deserializedMetricDefinition.Name); - Assert.Equal(metricDefinition.Description, deserializedMetricDefinition.Description); + Assert.Equal(metricDefinition.Name, deserializedMetricDefinition.PrometheusMetricDefinition.Name); + Assert.Equal(metricDefinition.Description, deserializedMetricDefinition.PrometheusMetricDefinition.Description); Assert.Equal(metricDefinition.ResourceType, deserializedMetricDefinition.ResourceType); - Assert.NotNull(deserializedMetricDefinition.Labels); - Assert.Equal(deserializedMetricDefinition.Labels, metricDefinition.Labels); - Assert.Equal(deserializedMetricDefinition.ResourceGroupName, metricDefinition.ResourceGroupName); + Assert.NotNull(deserializedMetricDefinition.PrometheusMetricDefinition.Labels); + Assert.Equal(metricDefinition.Labels, deserializedMetricDefinition.PrometheusMetricDefinition.Labels); + Assert.Equal(deserializedMetricDefinition.Resources.Single().ResourceGroupName, metricDefinition.ResourceGroupName); foreach (var label in metricDefinition.Labels) { - var deserializedLabel = deserializedMetricDefinition.Labels[label.Key]; + var deserializedLabel = deserializedMetricDefinition.PrometheusMetricDefinition.Labels[label.Key]; Assert.NotNull(deserializedLabel); Assert.Equal(label.Value, deserializedLabel); } diff --git a/src/Promitor.Scraper.Tests.Unit/Validation/Metrics/GeneralMetricsDeclarationValidationStepTests.cs b/src/Promitor.Scraper.Tests.Unit/Validation/Metrics/GeneralMetricsDeclarationValidationStepTests.cs index 5acb3f85d..815d6e055 100644 --- a/src/Promitor.Scraper.Tests.Unit/Validation/Metrics/GeneralMetricsDeclarationValidationStepTests.cs +++ b/src/Promitor.Scraper.Tests.Unit/Validation/Metrics/GeneralMetricsDeclarationValidationStepTests.cs @@ -1,10 +1,11 @@ using System.ComponentModel; using AutoMapper; +using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping; using Promitor.Scraper.Host.Validation.Steps; -using Promitor.Scraper.Tests.Unit.Builders.Metrics.v1; using Promitor.Scraper.Tests.Unit.Stubs; using Xunit; +using MetricsDeclarationBuilder = Promitor.Scraper.Tests.Unit.Builders.Metrics.v1.MetricsDeclarationBuilder; namespace Promitor.Scraper.Tests.Unit.Validation.Metrics { @@ -107,7 +108,7 @@ public void MetricsDeclaration_WithoutDefaultScrapingSchedule_Fails() { // Arrange var rawDeclaration = MetricsDeclarationBuilder.WithMetadata() - .WithDefaults(new Core.Scraping.Configuration.Model.MetricDefaults()) + .WithDefaults(new MetricDefaultsV1()) .Build(_mapper); var metricsDeclarationProvider = new MetricsDeclarationProviderStub(rawDeclaration, _mapper);