-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #613 from hjgraca/fix-metrics-resolution-context
chore: Fix metrics lambda context and storage resolution
- Loading branch information
Showing
10 changed files
with
205 additions
and
119 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
2 changes: 1 addition & 1 deletion
2
libraries/src/AWS.Lambda.Powertools.Metrics/Model/MetricResolution.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
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
49 changes: 49 additions & 0 deletions
49
libraries/src/AWS.Lambda.Powertools.Metrics/Serializer/MetricResolutionJsonConverter.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,49 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace AWS.Lambda.Powertools.Metrics; | ||
|
||
/// <summary> | ||
/// Class MetricResolutionJsonConverter. | ||
/// Implements the <see cref="System.Text.Json.Serialization.JsonConverter{T}" /> | ||
/// </summary> | ||
/// <seealso cref="System.Text.Json.Serialization.JsonConverter{T}" /> | ||
public class MetricResolutionJsonConverter : JsonConverter<MetricResolution> | ||
{ | ||
/// <summary> | ||
/// Reads the JSON representation of the object. | ||
/// </summary> | ||
/// <param name="reader">The <see cref="T:Utf8JsonReader" /> to read from.</param> | ||
/// <param name="typeToConvert">The <see cref="T:System.Type" /> being converted.</param> | ||
/// <param name="options">The <see cref="T:Utf8JsonSerializerOptions" /> being used.</param> | ||
/// <returns>The object value.</returns> | ||
public override MetricResolution Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType == JsonTokenType.String) | ||
{ | ||
var stringValue = reader.GetString(); | ||
if (int.TryParse(stringValue, out int value)) | ||
{ | ||
return (MetricResolution)value; | ||
} | ||
} | ||
else if (reader.TokenType == JsonTokenType.Number) | ||
{ | ||
return (MetricResolution)reader.GetInt32(); | ||
} | ||
|
||
throw new JsonException(); | ||
} | ||
|
||
/// <summary> | ||
/// Writes the JSON representation of the object. | ||
/// </summary> | ||
/// <param name="writer">The <see cref="T:Utf8JsonWriter" /> to write to.</param> | ||
/// <param name="value">The value to convert.</param> | ||
/// <param name="options">The <see cref="T:Utf8JsonSerializerOptions" /> being used.</param> | ||
public override void Write(Utf8JsonWriter writer, MetricResolution value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteNumberValue((int)value); | ||
} | ||
} |
102 changes: 0 additions & 102 deletions
102
libraries/src/AWS.Lambda.Powertools.Metrics/Serializer/StringEnumConverter.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.