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 a6bd6b1c1..0d3d66481 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs @@ -10,7 +10,8 @@ public class AggregationDeserializer : Deserializer public AggregationDeserializer(ILogger logger) : base(logger) { - MapOptional(aggregation => aggregation.Interval, defaultAggregationInterval); + Map(aggregation => aggregation.Interval) + .WithDefault(defaultAggregationInterval); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs index 130199f81..7123588c5 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureMetricConfigurationDeserializer.cs @@ -8,9 +8,13 @@ public class AzureMetricConfigurationDeserializer : Deserializer dimensionDeserializer, IDeserializer aggregationDeserializer, ILogger logger) : base(logger) { - MapRequired(config => config.MetricName); - MapOptional(config => config.Dimension, dimensionDeserializer); - MapRequired(config => config.Aggregation, aggregationDeserializer); + Map(config => config.MetricName) + .IsRequired(); + Map(config => config.Dimension) + .MapUsingDeserializer(dimensionDeserializer); + Map(config => config.Aggregation) + .IsRequired() + .MapUsingDeserializer(aggregationDeserializer); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceCollectionDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceCollectionDeserializer.cs index 296989508..e0d57244b 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceCollectionDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AzureResourceCollectionDeserializer.cs @@ -7,7 +7,8 @@ public class AzureResourceCollectionDeserializer : Deserializer logger) : base(logger) { - MapRequired(metadata => metadata.Name); + Map(metadata => metadata.Name) + .IsRequired(); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs index ed05637fa..571ffab1a 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricAggregationDeserializer.cs @@ -7,8 +7,9 @@ public class MetricAggregationDeserializer : Deserializer { public MetricAggregationDeserializer(ILogger logger) : base(logger) { - MapRequired(aggregation => aggregation.Type); - MapOptional(aggregation => aggregation.Interval); + Map(aggregation => aggregation.Type) + .IsRequired(); + Map(aggregation => aggregation.Interval); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs index 68e3fcfd3..8bb767207 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefaultsDeserializer.cs @@ -10,8 +10,11 @@ public MetricDefaultsDeserializer( IDeserializer scrapingDeserializer, ILogger logger) : base(logger) { - MapOptional(defaults => defaults.Aggregation, aggregationDeserializer); - MapRequired(defaults => defaults.Scraping, scrapingDeserializer); + Map(defaults => defaults.Aggregation) + .MapUsingDeserializer(aggregationDeserializer); + Map(defaults => defaults.Scraping) + .IsRequired() + .MapUsingDeserializer(scrapingDeserializer); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs index 5915e6c59..633e4d1be 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDefinitionDeserializer.cs @@ -21,12 +21,18 @@ public MetricDefinitionDeserializer(IDeserializer az _azureResourceCollectionDeserializer = azureResourceCollectionDeserializer; _azureResourceDeserializerFactory = azureResourceDeserializerFactory; - MapRequired(definition => definition.Name); - MapRequired(definition => definition.Description); - MapRequired(definition => definition.ResourceType); - MapRequired(definition => definition.AzureMetricConfiguration, azureMetricConfigurationDeserializer); - MapOptional(definition => definition.Labels); - MapOptional(definition => definition.Scraping, scrapingDeserializer); + Map(definition => definition.Name) + .IsRequired(); + Map(definition => definition.Description) + .IsRequired(); + Map(definition => definition.ResourceType) + .IsRequired(); + Map(definition => definition.AzureMetricConfiguration) + .IsRequired() + .MapUsingDeserializer(azureMetricConfigurationDeserializer); + Map(definition => definition.Labels); + Map(definition => definition.Scraping) + .MapUsingDeserializer(scrapingDeserializer); IgnoreField(ResourceCollectionsTag); IgnoreField(ResourcesTag); } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDimensionDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDimensionDeserializer.cs index 93bfe2cd1..51173178d 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDimensionDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/MetricDimensionDeserializer.cs @@ -1,24 +1,14 @@ using Microsoft.Extensions.Logging; using Promitor.Core.Scraping.Configuration.Serialization.v1.Model; -using YamlDotNet.RepresentationModel; namespace Promitor.Core.Scraping.Configuration.Serialization.v1.Core { public class MetricDimensionDeserializer : Deserializer { - private const string NameTag = "name"; - public MetricDimensionDeserializer(ILogger logger) : base(logger) { - } - - public override MetricDimensionV1 Deserialize(YamlMappingNode node, IErrorReporter errorReporter) - { - return new MetricDimensionV1 - { - Name = node.GetString(NameTag), - }; + Map(dimension => dimension.Name); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs index 475cbde47..9454ec5c9 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/ScrapingDeserializer.cs @@ -7,7 +7,8 @@ public class ScrapingDeserializer : Deserializer { public ScrapingDeserializer(ILogger logger) : base(logger) { - MapRequired(scraping => scraping.Schedule); + Map(scraping => scraping.Schedule) + .IsRequired(); } } } diff --git a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs index 260d9328d..18b9f3743 100644 --- a/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs +++ b/src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/SecretDeserializer.cs @@ -8,8 +8,8 @@ public class SecretDeserializer : Deserializer { public SecretDeserializer(ILogger logger) : base(logger) { - MapOptional(secret => secret.RawValue); - MapOptional(secret => secret.EnvironmentVariable); + Map(secret => secret.RawValue); + Map(secret => secret.EnvironmentVariable); } public override SecretV1 Deserialize(YamlMappingNode node, IErrorReporter errorReporter)