Skip to content

Commit

Permalink
Update all the core deserializers
Browse files Browse the repository at this point in the history
I've updated all the deserializers in the core namespace to use the new mapping syntax.

Part of tomkerkhove#1092
  • Loading branch information
adamconnelly committed Jun 16, 2020
1 parent eae2747 commit 53394c9
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class AggregationDeserializer : Deserializer<AggregationV1>

public AggregationDeserializer(ILogger<AggregationDeserializer> logger) : base(logger)
{
MapOptional(aggregation => aggregation.Interval, defaultAggregationInterval);
Map(aggregation => aggregation.Interval)
.WithDefault(defaultAggregationInterval);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ public class AzureMetricConfigurationDeserializer : Deserializer<AzureMetricConf
public AzureMetricConfigurationDeserializer(IDeserializer<MetricDimensionV1> dimensionDeserializer, IDeserializer<MetricAggregationV1> aggregationDeserializer, ILogger<AzureMetricConfigurationDeserializer> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class AzureResourceCollectionDeserializer : Deserializer<AzureResourceCol
{
public AzureResourceCollectionDeserializer(ILogger<AzureResourceCollectionDeserializer> logger) : base(logger)
{
MapRequired(metadata => metadata.Name);
Map(metadata => metadata.Name)
.IsRequired();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class MetricAggregationDeserializer : Deserializer<MetricAggregationV1>
{
public MetricAggregationDeserializer(ILogger<MetricAggregationDeserializer> logger) : base(logger)
{
MapRequired(aggregation => aggregation.Type);
MapOptional(aggregation => aggregation.Interval);
Map(aggregation => aggregation.Type)
.IsRequired();
Map(aggregation => aggregation.Interval);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ public MetricDefaultsDeserializer(
IDeserializer<ScrapingV1> scrapingDeserializer,
ILogger<MetricDefaultsDeserializer> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public MetricDefinitionDeserializer(IDeserializer<AzureMetricConfigurationV1> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MetricDimensionV1>
{
private const string NameTag = "name";

public MetricDimensionDeserializer(ILogger<MetricDimensionDeserializer> logger)
: base(logger)
{
}

public override MetricDimensionV1 Deserialize(YamlMappingNode node, IErrorReporter errorReporter)
{
return new MetricDimensionV1
{
Name = node.GetString(NameTag),
};
Map(dimension => dimension.Name);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public class ScrapingDeserializer : Deserializer<ScrapingV1>
{
public ScrapingDeserializer(ILogger<ScrapingDeserializer> logger) : base(logger)
{
MapRequired(scraping => scraping.Schedule);
Map(scraping => scraping.Schedule)
.IsRequired();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class SecretDeserializer : Deserializer<SecretV1>
{
public SecretDeserializer(ILogger<SecretDeserializer> 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)
Expand Down

0 comments on commit 53394c9

Please sign in to comment.