-
Notifications
You must be signed in to change notification settings - Fork 765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Metrics: Use ReadOnlyTagCollection to encapsulate key/values on MetricPoint #2642
Metrics: Use ReadOnlyTagCollection to encapsulate key/values on MetricPoint #2642
Conversation
public string[] Keys { get; internal set; } | ||
|
||
public object[] Values { get; internal set; } | ||
public MetricPointAttributes Attributes { get; } |
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.
The API use the word 'Tags' instead of Attributes, so we can stick with same name here too.
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 renamed the property "Tags" and then I renamed the structure ReadOnlyTagCollection
. There isn't anything really MetricPoint-specific about it, so I thought it would be good to keep it general in case we wanted to use it in other spots in the future?
@CodeBlanch This looks good. It do increase our public API than using a simple IEnumerable, but its worth it in my opinion. |
Codecov Report
@@ Coverage Diff @@
## main #2642 +/- ##
==========================================
+ Coverage 81.31% 81.34% +0.02%
==========================================
Files 245 246 +1
Lines 8645 8658 +13
==========================================
+ Hits 7030 7043 +13
Misses 1615 1615
|
|
||
using System.Collections.Generic; | ||
|
||
namespace OpenTelemetry |
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.
We might be able to leverage this for Activity.TagLists, by doing the alloc-free thingie internally and exposing this ReadOnlyTagCollection for exporters, so each exporters doesn't have to repeat the alloc-free foreach.
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.
LGTM.
(I know the PR is in draft, but this looks good)
I ran a benchmark to make sure Struct
Class
Benchmarks [MemoryDiagnoser]
public class MetricPointBenchmarks
{
private readonly string[] keys = new string[] { "key1", "key2" };
private readonly object[] values = new object[] { 1, 2 };
private MetricPoint metricPoint;
public MetricPointBenchmarks()
{
this.metricPoint = new MetricPoint(
AggregationType.LongSumIncomingDelta,
DateTimeOffset.UtcNow,
this.keys,
this.values,
null);
}
[Benchmark]
public int MetricPointBenchmark()
{
ref var metricPoint = ref this.metricPoint;
var tags = metricPoint.Tags;
int tagCount = 0;
foreach (var tag in tags)
{
if (!string.IsNullOrEmpty(tag.Key))
{
tagCount++;
}
}
return tagCount;
}
} |
Closes #2062
Relates to #2062 (comment)
Changes
Add
ReadOnlyTagCollection
and exposeTags
onMetricPoint
instead ofstring[] Keys
&object[] Values
Public API Changes
New struct:
TODOs
CHANGELOG.md
updated for non-trivial changes