This repository was archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Initial Custom Metrics - Node & Task Heartbeat #3082
Merged
nharper285
merged 55 commits into
microsoft:main
from
nharper285:user/noharper/custom-metrics-refactor-fork
May 16, 2023
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
60ecef4
Refactor logging to use and new function queue
nharper285 e9a1ce2
Testing setup of custom metric.
nharper285 1830f47
Changing host.json
nharper285 519f9b4
Merge branch 'main' into user/noharper/custom-metrics-refactor
nharper285 90a9270
Updating log interface.
nharper285 388bcc9
Merge branch 'user/noharper/custom-metrics-refactor' of https://githu…
nharper285 2dd4341
changes.
nharper285 41cc646
Fix encoding.
nharper285 17f777f
Merge branch 'main' into user/noharper/custom-metrics-refactor
nharper285 ab5358d
Updating.
nharper285 bc53750
Updating tests.
nharper285 86b7803
Adding metrics to program
nharper285 55d2529
Merge branch 'main' into user/noharper/custom-metrics-refactor
nharper285 f35923c
Pushing latest changes.
nharper285 5c82dc4
Merge branch 'user/noharper/custom-metrics-refactor' of https://githu…
nharper285 e6dfbcc
Update interface references.
nharper285 fb0da50
Removing string type.
nharper285 18bffa4
Add string back.
nharper285 605c6f6
Getting additional data for task heartbeat.
nharper285 9e95769
Removing additional fields.
nharper285 98dc451
Removing containers.
nharper285 5d21f34
Cleaning up.
nharper285 ac7aff4
Adding feature flag.
nharper285 11023f5
Merge branch 'main' into user/noharper/custom-metrics-refactor
nharper285 73041a2
Adding bicep changes.
nharper285 4b4465e
Fixing tests.
nharper285 dd4899a
Fixing test metrics.
nharper285 747b32b
Removing most of tests.
nharper285 959d391
Telemetry Refact Round 2.
nharper285 3472eb1
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 fdbfb53
Updated metrics.
nharper285 0c5bf9e
Merge branch 'user/noharper/custom-metrics-refactor-fork' of https://…
nharper285 9b876db
Remove custom metric function.
nharper285 556099b
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 3671f98
Syncing events.cs
nharper285 2a536d6
Making optional.
nharper285 f62367f
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 cd5a430
Using events as metric dimensions.
nharper285 090b396
Merge branch 'user/noharper/custom-metrics-refactor-fork' of https://…
nharper285 650bd25
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 bec622f
Fixing ORM tests.
nharper285 a21e158
Merge branch 'user/noharper/custom-metrics-refactor-fork' of https://…
nharper285 4d70cae
Remove metric records.
nharper285 e8f4ff2
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 2570643
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 0ff2cf1
Removing bad test.
nharper285 77c3fd8
Merge branch 'user/noharper/custom-metrics-refactor-fork' of https://…
nharper285 ccb3493
Remove testmetrics.'
nharper285 d491349
Adding test back.
nharper285 86bc52f
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 d32a3e0
Improving custom dimensions serialization.
nharper285 5800d4e
Update src/ApiService/ApiService/onefuzzlib/Metrics.cs
nharper285 acc202d
Reverting change.
nharper285 475f1c1
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 641cda1
Merge branch 'main' into user/noharper/custom-metrics-refactor-fork
nharper285 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,54 @@ | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.OneFuzz.Service.OneFuzzLib.Orm; | ||
|
|
||
| namespace Microsoft.OneFuzz.Service { | ||
|
|
||
| public record CustomMetric( | ||
| string name, | ||
| int value, | ||
| Dictionary<string, string> customDimensions | ||
| ); | ||
|
|
||
|
|
||
| public interface IMetrics { | ||
| void SendMetric(int metricValue, BaseEvent customDimensions); | ||
|
|
||
| void LogMetric(BaseEvent metric); | ||
| } | ||
|
|
||
| public class Metrics : IMetrics { | ||
| private readonly ILogTracer _log; | ||
| private readonly IOnefuzzContext _context; | ||
| private readonly JsonSerializerOptions _options; | ||
|
|
||
| public Metrics(ILogTracer log, IOnefuzzContext context) { | ||
| _context = context; | ||
| _log = log; | ||
| _options = new JsonSerializerOptions(EntityConverter.GetJsonSerializerOptions()) { | ||
| DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull | ||
| }; | ||
| _options.Converters.Add(new RemoveUserInfo()); | ||
| } | ||
|
|
||
| public void SendMetric(int metricValue, BaseEvent customDimensions) { | ||
| var metricType = customDimensions.GetEventType(); | ||
|
|
||
| _ = _options.PropertyNamingPolicy ?? throw new ArgumentException("Serializer _options not available."); | ||
|
|
||
| var metricTypeSnakeCase = _options.PropertyNamingPolicy.ConvertName($"{metricType}"); | ||
|
|
||
| var dimensionNode = JsonSerializer.SerializeToNode(customDimensions, customDimensions.GetType(), _options); | ||
| _ = dimensionNode ?? throw new JsonException("Was not able to properly serialize the custom dimensions."); | ||
| var dimensionDict = dimensionNode.AsObject().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value is not null ? kvp.Value.ToString() : ""); | ||
|
|
||
| _log.Metric($"{metricTypeSnakeCase}", metricValue, dimensionDict); | ||
| LogMetric(customDimensions); | ||
| } | ||
|
|
||
| public void LogMetric(BaseEvent metric) { | ||
| var serializedMetric = JsonSerializer.Serialize(metric, metric.GetType(), _options); | ||
| _log.Info($"sending metric: {metric.GetEventType():Tag:MetricType} - {serializedMetric}"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| using System.Collections.Generic; | ||
| using Microsoft.OneFuzz.Service; | ||
|
|
||
| namespace IntegrationTests.Fakes; | ||
|
|
||
| public sealed class TestMetrics : Metrics { | ||
|
|
||
| public List<BaseEvent> Metrics { get; } = new(); | ||
| public List<EventMessage> CustomMetrics { get; } = new(); | ||
| public TestMetrics(ILogTracer log, IOnefuzzContext context) | ||
| : base(log, context) { } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.