Skip to content
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

[Dotnet Monitor] Add Metadata Support For CounterPayload #3498

Merged
merged 5 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public CounterPayload(DateTime timestamp,
string unit,
double value,
CounterType counterType,
float interval)
float interval,
Dictionary<string, string> metadata)
kkeirstead marked this conversation as resolved.
Show resolved Hide resolved
{
Timestamp = timestamp;
Name = name;
Expand All @@ -28,6 +29,7 @@ public CounterPayload(DateTime timestamp,
CounterType = counterType;
Provider = provider;
Interval = interval;
Metadata = metadata;
}

public string Namespace { get; }
Expand All @@ -47,5 +49,7 @@ public CounterPayload(DateTime timestamp,
public CounterType CounterType { get; }

public string Provider { get; }

public Dictionary<string, string> Metadata { get; } = new Dictionary<string, string>(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ internal interface ICounterPayload
DateTime Timestamp { get; }

float Interval { get; }

public Dictionary<string, string> Metadata { get; }
kkeirstead marked this conversation as resolved.
Show resolved Hide resolved
kkeirstead marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ public static bool TryGetCounterPayload(this TraceEvent traceEvent, CounterFilte
string series = payloadFields["Series"].ToString();
string counterName = payloadFields["Name"].ToString();

var metadataDict = new Dictionary<string, string>();

string[] kvPairs = payloadFields["Metadata"].ToString().Split(",");
kkeirstead marked this conversation as resolved.
Show resolved Hide resolved

foreach (string kvPair in kvPairs)
{
int colonIndex = kvPair.IndexOf(':');
if (colonIndex == -1)
{
// Remove all entries from metadataDict if has bad formatting
metadataDict.Clear();
break;
}
else
{
string metadataKey = kvPair.Substring(0, colonIndex);
string metadataValue = kvPair.Substring(colonIndex + 1);
metadataDict[metadataKey] = metadataValue;
}
}

//CONSIDER
//Concurrent counter sessions do not each get a separate interval. Instead the payload
//for _all_ the counters changes the Series to be the lowest specified interval, on a per provider basis.
Expand Down Expand Up @@ -62,7 +83,8 @@ public static bool TryGetCounterPayload(this TraceEvent traceEvent, CounterFilte
displayUnits,
value,
counterType,
intervalSec);
intervalSec,
metadataDict);
return true;
}

Expand Down