-
Notifications
You must be signed in to change notification settings - Fork 3
feat: rest of impact metrics definitions for dotnet #76
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
Changes from 4 commits
a6bac62
6d27798
aca6916
c31bfab
0f4b925
7fa3437
baa5c5b
8cc8b58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,118 @@ public static byte[] CreateDefineCounterBuffer(FlatBufferBuilder builder, string | |||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static byte[] CreateIncCounterBuffer(FlatBufferBuilder builder, string name, long value, IDictionary<string, string>? labels = null) | ||||||||||
| { | ||||||||||
| var nameOffset = builder.CreateString(name); | ||||||||||
| var labelsOffset = CreateSampleLabelsVector(builder, labels); | ||||||||||
|
|
||||||||||
| IncCounter.StartIncCounter(builder); | ||||||||||
| IncCounter.AddName(builder, nameOffset); | ||||||||||
| IncCounter.AddValue(builder, value); | ||||||||||
| if (labelsOffset.HasValue) | ||||||||||
| { | ||||||||||
| IncCounter.AddLabels(builder, labelsOffset.Value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var incCounterMessage = IncCounter.EndIncCounter(builder); | ||||||||||
| builder.Finish(incCounterMessage.Value); | ||||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static byte[] CreateDefineGaugeBuffer(FlatBufferBuilder builder, string name, string help) | ||||||||||
| { | ||||||||||
| var nameOffset = builder.CreateString(name); | ||||||||||
| var helpOffset = builder.CreateString(help); | ||||||||||
|
|
||||||||||
| DefineGauge.StartDefineGauge(builder); | ||||||||||
| DefineGauge.AddName(builder, nameOffset); | ||||||||||
| DefineGauge.AddHelp(builder, helpOffset); | ||||||||||
|
|
||||||||||
| var defineGaugeMessage = DefineGauge.EndDefineGauge(builder); | ||||||||||
| builder.Finish(defineGaugeMessage.Value); | ||||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static byte[] CreateSetGaugeBuffer(FlatBufferBuilder builder, string name, double value, IDictionary<string, string>? labels = null) | ||||||||||
| { | ||||||||||
| var nameOffset = builder.CreateString(name); | ||||||||||
| var labelsOffset = CreateSampleLabelsVector(builder, labels); | ||||||||||
|
|
||||||||||
| SetGauge.StartSetGauge(builder); | ||||||||||
| SetGauge.AddName(builder, nameOffset); | ||||||||||
| SetGauge.AddValue(builder, value); | ||||||||||
| if (labelsOffset.HasValue) | ||||||||||
| { | ||||||||||
| SetGauge.AddLabels(builder, labelsOffset.Value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var setGaugeMessage = SetGauge.EndSetGauge(builder); | ||||||||||
| builder.Finish(setGaugeMessage.Value); | ||||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static byte[] CreateDefineHistogramBuffer(FlatBufferBuilder builder, string name, string help, IEnumerable<double>? buckets = null) | ||||||||||
| { | ||||||||||
| var nameOffset = builder.CreateString(name); | ||||||||||
| var helpOffset = builder.CreateString(help); | ||||||||||
| var bucketArray = (buckets ?? Enumerable.Empty<double>()).ToArray(); | ||||||||||
| var bucketsOffset = bucketArray.Length > 0 | ||||||||||
| ? DefineHistogram.CreateBucketsVector(builder, bucketArray) | ||||||||||
| : default(VectorOffset); | ||||||||||
|
|
||||||||||
| DefineHistogram.StartDefineHistogram(builder); | ||||||||||
| DefineHistogram.AddName(builder, nameOffset); | ||||||||||
| DefineHistogram.AddHelp(builder, helpOffset); | ||||||||||
| if (bucketArray.Length > 0) | ||||||||||
| { | ||||||||||
| DefineHistogram.AddBuckets(builder, bucketsOffset); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var defineHistogramMessage = DefineHistogram.EndDefineHistogram(builder); | ||||||||||
| builder.Finish(defineHistogramMessage.Value); | ||||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static byte[] CreateObserveHistogramBuffer(FlatBufferBuilder builder, string name, double value, IDictionary<string, string>? labels = null) | ||||||||||
| { | ||||||||||
| var nameOffset = builder.CreateString(name); | ||||||||||
| var labelsOffset = CreateSampleLabelsVector(builder, labels); | ||||||||||
|
|
||||||||||
| ObserveHistogram.StartObserveHistogram(builder); | ||||||||||
| ObserveHistogram.AddName(builder, nameOffset); | ||||||||||
| ObserveHistogram.AddValue(builder, value); | ||||||||||
| if (labelsOffset.HasValue) | ||||||||||
| { | ||||||||||
| ObserveHistogram.AddLabels(builder, labelsOffset.Value); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var observeHistogramMessage = ObserveHistogram.EndObserveHistogram(builder); | ||||||||||
| builder.Finish(observeHistogramMessage.Value); | ||||||||||
| return builder.SizedByteArray(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private static VectorOffset? CreateSampleLabelsVector(FlatBufferBuilder builder, IDictionary<string, string>? labels) | ||||||||||
| { | ||||||||||
| if (labels == null || labels.Count == 0) | ||||||||||
| { | ||||||||||
| return null; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var labelEntries = new Offset<SampleLabelEntry>[labels.Count]; | ||||||||||
| var index = 0; | ||||||||||
| foreach (var kvp in labels) | ||||||||||
| { | ||||||||||
| labelEntries[index] = SampleLabelEntry.CreateSampleLabelEntry( | ||||||||||
| builder, | ||||||||||
| builder.CreateString(kvp.Key), | ||||||||||
| builder.CreateString(kvp.Value) | ||||||||||
| ); | ||||||||||
| index++; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return IncCounter.CreateLabelsVector(builder, labelEntries); | ||||||||||
|
Comment on lines
157
to
176
|
||||||||||
| return IncCounter.CreateLabelsVector(builder, labelEntries); | |
| return builder.CreateVectorOfTables(labelEntries); |
Copilot
AI
Feb 13, 2026
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 method uses IncCounter.CreateLabelsVector to create label vectors for all message types (IncCounter, SetGauge, ObserveHistogram). While this works because all generated FlatBuffer types have identical CreateLabelsVector methods, it's semantically confusing and reduces code clarity. Consider using a more neutral type like SetGauge.CreateLabelsVector or documenting why IncCounter is used here.
| return IncCounter.CreateLabelsVector(builder, labelEntries); | |
| return SetGauge.CreateLabelsVector(builder, labelEntries); |
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.
CreateSampleLabelsVector builds the
[SampleLabelEntry]vector by callingIncCounter.CreateLabelsVector(...), which unnecessarily couples label serialization to the presence/name of theIncCountertable. Consider building the vector directly withFlatBufferBuilder.StartVector/AddOffset(or introducing a dedicated helper) so label encoding remains independent of any specific message type.