-
Notifications
You must be signed in to change notification settings - Fork 245
Initial pass at Metrics support in ILogger #709
Conversation
@@ -136,6 +139,21 @@ public IDisposable BeginScope<TState>(TState state) | |||
return scope; | |||
} | |||
|
|||
public IMetric DefineMetric(string name) | |||
{ | |||
if (!_metrics.TryGetValue(name, out var metric)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is dictionary safe for multi thread read during the write?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm honestly not sure. I was having the same concern and thinking I should just use ConcurrentDictionary
@@ -13,6 +13,7 @@ | |||
<ItemGroup> | |||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" /> | |||
<PackageReference Include="Microsoft.Extensions.Options" /> | |||
<PackageReference Include="System.Collections.Immutable" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it still used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not anymore, will remove
_name = name; | ||
} | ||
|
||
public void RecordValue(double value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed this implementation has to be optimized to update metrics array only when required.
} | ||
} | ||
|
||
public void RecordValue<T>(double value, T properties) where T : IEnumerable<KeyValuePair<string, object>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for this and TimeSpan
extension method.
Closing this, we're going to look at using EventCounters for our metrics needs. |
This implements #708. It's got some naive elements, like the way we handle filters (which involves some locking). I want to clean that up but wanted to get this into a PR first.