forked from tomkerkhove/promitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of new validation approach
I've altered the way that the deserializers work and are defined so that they are simpler to create, but also so that we can record validation failures during the deserialization process. This allows us to provide much better validation messages than we can if we take the approach of validating based on the deserialized objects. In this initial change I haven't gone ahead and updated all of the deserializers because I wanted the change to be kept small. I've also not actually hooked up the validation messages in any way - instead I've just provided a stub ErrorReporter object that doesn't actually do anything yet. Part of tomkerkhove#592
- Loading branch information
1 parent
dcda55e
commit 683408e
Showing
49 changed files
with
813 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Promitor.Core.Scraping/Configuration/Serialization/ErrorReporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization | ||
{ | ||
public class ErrorReporter : IErrorReporter | ||
{ | ||
public void ReportError(YamlNode node, string message) | ||
{ | ||
} | ||
|
||
public void ReportWarning(YamlNode node, string message) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Promitor.Core.Scraping/Configuration/Serialization/IErrorReporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using YamlDotNet.RepresentationModel; | ||
|
||
namespace Promitor.Core.Scraping.Configuration.Serialization | ||
{ | ||
/// <summary> | ||
/// Used to report errors discovered during the deserialization process. | ||
/// </summary> | ||
public interface IErrorReporter | ||
{ | ||
/// <summary> | ||
/// Reports an error. | ||
/// </summary> | ||
/// <param name="node">The node containing the error / that should be highlighted to the user.</param> | ||
/// <param name="message">The error message.</param> | ||
void ReportError(YamlNode node, string message); | ||
|
||
/// <summary> | ||
/// Reports a warning (i.e. something that doesn't prevent Promitor from functioning). | ||
/// </summary> | ||
/// <param name="node">The node containing the error / that should be highlighted to the user.</param> | ||
/// <param name="message">The error message.</param> | ||
void ReportWarning(YamlNode node, string message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 3 additions & 18 deletions
21
src/Promitor.Core.Scraping/Configuration/Serialization/v1/Core/AggregationDeserializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
using System; | ||
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 AggregationDeserializer : Deserializer<AggregationV1> | ||
{ | ||
private const string IntervalTag = "interval"; | ||
|
||
private readonly TimeSpan _defaultAggregationInterval = TimeSpan.FromMinutes(5); | ||
private static readonly TimeSpan DefaultAggregationInterval = TimeSpan.FromMinutes(5); | ||
|
||
public AggregationDeserializer(ILogger<AggregationDeserializer> logger) : base(logger) | ||
{ | ||
MapOptional(aggregation => aggregation.Interval, DefaultAggregationInterval); | ||
} | ||
|
||
public override AggregationV1 Deserialize(YamlMappingNode node) | ||
{ | ||
var interval = node.GetTimeSpan(IntervalTag); | ||
|
||
var aggregation = new AggregationV1 {Interval = interval}; | ||
|
||
if (aggregation.Interval == null) | ||
{ | ||
aggregation.Interval = _defaultAggregationInterval; | ||
Logger.LogWarning( | ||
"No default aggregation was configured, falling back to {AggregationInterval}", | ||
aggregation.Interval?.ToString("g")); | ||
} | ||
|
||
return aggregation; | ||
} | ||
// TODO: Figure out if we want to make Interval required depending on the context | ||
} | ||
} |
Oops, something went wrong.