Repository navigation
Description
Description
Gauges can be distincted by tags, but process holds old gauge with old tags, after this removed from data source.
This behaviour is fine for counters, but make unuseful metrics values for gauges.
Reproduction Steps
Example source code:
using System.Diagnostics.Metrics;
namespace Test
{
public class Program
{
static Meter s_meter = new Meter("HatCo.HatStore", "1.0.0");
static IEnumerable<Measurement<int>> m;
static void Main(string[] args)
{
s_meter.CreateObservableGauge<int>("orders-pending", () => m);
m = new Measurement<int>[]
{
new Measurement<int>(1, new KeyValuePair<string,object>("Country", "Italy")),
};
Console.WriteLine("Change to Spain");
Console.ReadLine();
m = new Measurement<int>[]
{
new Measurement<int>(1, new KeyValuePair<string,object>("Country", "Spain")),
};
Console.WriteLine("Remove Spain, Update Italy");
Console.ReadLine();
m = new Measurement<int>[]
{
new Measurement<int>(2, new KeyValuePair<string,object>("Country", "Italy")),
};
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
}
}Expected behavior
Run example and watch its metrics:
dotnet-counters monitor --name ConsoleApp HatCo.HatStore
After process started metrics is:
[HatCo.HatStore]
orders-pending
Country=Italy 1
Press enter in example console, this will change metrics from Italy to Spain:
[HatCo.HatStore]
orders-pending
Country=Spain 1
Here is added Spain and removed Italy.
Press enter in example console, this will change metrics to Italy:
[HatCo.HatStore]
orders-pending
Country=Italy 2
Now we have updated Italy and removed Spain.
Actual behavior
Run example and watch its metrics:
dotnet-counters monitor --name ConsoleApp HatCo.HatStore
After process started metrics is:
[HatCo.HatStore]
orders-pending
Country=Italy 1
Press enter in example console, this will change metrics from Italy to Spain:
[HatCo.HatStore]
orders-pending
Country=Italy 1
Country=Spain 1
Here is added Spain, but removed Italy is remainded.
Press enter in example console, this will change metrics to Italy:
[HatCo.HatStore]
orders-pending
Country=Italy 2
Country=Spain 1
Now we have update Italy, but remainded Spain.
Regression?
No response
Known Workarounds
Track metrics+tags in own Measurement collection. Return this collection to CreateObservableGauge.
In own collection track missing metrics during update (with respect to metric name, tags, and tags combinations) - set its value to zero.
Configuration
No response
Other information
No response
Activity
Yustos commentedon Jul 14, 2022
I see that area is area-System.Diagnostics.Metric, but i have no idea how to add label for issue.
tommcdon commentedon Jul 18, 2022
@noahfalk @tarekgh
carlossanlop commentedon Jul 18, 2022
@noahfalk @tarekgh should there be a
@dotnet/area-system-diagnostics-metricgroup created? There isn't one yet.tarekgh commentedon Jul 18, 2022
It is ok to create such a group and add me and Noah to it. This will apply to
System.Diagnostics.Activitytoo.noahfalk commentedon Jul 22, 2022
I reproduced the problem and it looks like an issue with the dotnet-counters console UI logic. I have PR open that hopefully resolves it.
Yustos commentedon Aug 1, 2022
Hi, @noahfalk. Thank you!
But i'm not sure that problem in client tools (like dotnet-conters or somewhat other).
Looks like there some cache in the monitored process. Some array with tags permutations (somewhere in https://github.com/open-telemetry/opentelemetry-dotnet/blob/8511e92f062f1a8dbef6e248addf3eeb3417c34b/src/OpenTelemetry/Metrics/AggregatorStore.cs - not sure).
Proof. Add prometheus exporter to first example after Main:
And use http://localhost:9184/metrics endpoint to observe metrics (instead of dotnet-counters). Behavior will be identical to dotnet-counters - stale metrics retains.
noahfalk commentedon Aug 1, 2022
This sounds like a separate issue we should file with the OpenTelemetry team. Roughly the flow of metrics data looks like this:
The runtime team maintains the Meter APIs the stuff in the left column, the OpenTelemetry team owns the OTel SDK. Do you want me to open an issue on your behalf or you can open it?
Yustos commentedon Aug 18, 2022
Hi @noahfalk, you are right. I did some debugging and saw that OpenTelemetry AggregatorStore class retains metrics.
Their repository have multiple issues about this (like open-telemetry/opentelemetry-dotnet#3508).
Thank you!
noahfalk commentedon Aug 19, 2022
Thanks for letting us know and I'm glad you were able to track it down!