Hystrix dashboard doesn't load Metrics DOTNET 6.0
Describe the bug
hystrix/hystrix.stream, is not giving any JSON result and it is not displaying in the dashboard. I am using dotnet 6.0 framework with https://docs.steeltoe.io/api/v3/circuitbreaker/hystrix.html in my web API project.
Steps to reproduce
Steps to reproduce the behavior:
- I have added: services.AddHystrixMetricsStream(Configuration);
- Also added code
app.UseHystrixRequestContext();&app.UseMvc();in startup file - And then I am running the app and hitting hystrix/hystrix.stream endpoint
Getting this error intermittently
commandMetircs.ExecutionTimeMean threw an expection of type : 'System.indexOutOfRangeException'
I did some debugging and found that below both properties are causing the problem
TotalTimeMean & ExecutionTimeMean
I see sometimes it's generating string value and sometimes number.
package version used int code -
<PackageReference Include="Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore" Version="3.1.3" />
<PackageReference Include="Steeltoe.CircuitBreaker.HystrixCore" Version="3.1.3" />
Expected behavior
hystrix/hystrix.stream endpoint must provide proper JSON data
Environment (please complete the following information):
- Steeltoe Version 3.1.3
- Platform: Azure Service Febric also local machine
- OS: Window
- .NET 6.0
Satckoverflow link
Additional context or links
Error Log
at System.Reactive.Subjects.BehaviorSubject`1.TryGetValue(T& value) in …\Source\src\System.Reactive\Subjects\BehaviorSubject.cs:line 130
at Steeltoe.CircuitBreaker.Hystrix.Metric.Consumer.RollingDistributionStream`1.get_Latest() in …\source\Steeltoe-3.1.3\src\CircuitBreaker\src\HystrixBase\Metric\Consumer\RollingDistributionStream.cs:line 105
at Steeltoe.CircuitBreaker.Hystrix.Metric.Consumer.RollingDistributionStream`1.get_LatestMean() in …\source\Steeltoe-3.1.3\src\CircuitBreaker\src\HystrixBase\Metric\Consumer\RollingDistributionStream.cs:line 58
at Steeltoe.CircuitBreaker.Hystrix.HystrixCommandMetrics.get_ExecutionTimeMean() in …\source\Steeltoe-3.1.3\src\CircuitBreaker\src\HystrixBase\HystrixCommandMetrics.cs:line 199
@shadikkhan I was able to run the sample in our samples repo... would you please give that a try?
https://github.com/SteeltoeOSS/Samples/tree/main/CircuitBreaker
See the Readme(s) for each component for more details. The sample is the fortune teller application which uses hystrix in the UI component.
Let us know if you have problems or questions. Dave
Hi Dave,
Totally true samples repo is working fine ….. But Problem is different, My application is working fine with netstandard2.0 with Steeltoe's Hystrix … but after upgrade with .NET6.0 … hystrix/hystrix.stream, is not giving any JSON result and it is not displaying in the dashboard.
After debug with Steeltoe's library we find out most of the cases TotalTimeMean , ExecutionTimeMean properties are throwing an error like below.
ommandMetircs.ExecutionTimeMean threw an expection of type : 'System.indexOutOfRangeException' @ writer.WriteIntegerField("latencyExecute_mean", commandMetrics.ExecutionTimeMean);
Could you please help us , how we can fix this issue to generate stream or we are missing something? package version used initial code is mentioned above issue.
Thanks Deepak
Hi @deepakapj, I was able to run the Hystrix sample I mentioned above on .NET 6.0 and successfully tied into hystrix/hystrix.stream.
Do you have a sample repo I can look at to try and debug and figure out what problem you are having? Dave
Hi Dave,
We can't share the code with you due to security issues. In the sample application, we are not seeing this issue but with our application, we are seeing the above issue with some of the APIs.
But when we are trying to put try and catch block with the "ToJsonString(HystrixCommandMetrics commandMetrics)" function which is part of "Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore" project then Dashboard is working as expected below is the code snapshot with Try & catch.
public static string ToJsonString(HystrixCommandMetrics commandMetrics) { using var sw = new StringWriter(); using var writer = new JsonTextWriter(sw); try { WriteCommandMetrics(writer, commandMetrics); } catch (Exception ex) { var error = Newtonsoft.Json.JsonConvert.SerializeObject(ex); Debug.Write("Error in WriteCommandMetrics " + error); } return sw.ToString(); }
Thanks Deepak Saxena
Hi Dave,
Could you please let me know if you want PR for this? Or do you think some other solution?
Thanks Deepak Saxena
@deepakapj : Yes, feel free to create a PR for this change... Thanks!
I will share the PR ASAP
HI @dtillman
I did find any root cause but the whole stream is not coming if any exceptions come in any operation like TotalTimeMean , ExecutionTimeMean properties so I just put a try-catch block, Please suggest if this is good then I will raise PR to avoid confusion and unnecessary code change.

@deepakapj : Would you mind changing to adding try/catch's in all of the Write*Metrics methods, including the WriteCommandMetrics .... just to have exception coverage in all those methods...
Then go ahead and crate a PR .. we'll get this added to the 3.2 release which we are about to do!
Dave
Thanks , We will do and create PR soon
Deepak
Hi Dave ,
I raised the PR https://github.com/SteeltoeOSS/Steeltoe/pull/847, Also When we are planning to deploy 3.2 version with this?
Thanks Deepak Saxena
@deepakapj we need you to sign the CLA before we can merge your PR. We might be able to ship 3.2 this week
Hi,
I signed CLA. Please let know once 3.2 availabale so that i can validate in my project ?
Thanks Deepak Saxena
Hi @TimHess & @dtillman ,
Any item pending from my side. Please let me know. I saw that SonarCloud Quality Gate failed in the pipeline.
Thanks Deepak Saxena
Hi @TimHess & @dtillman ,
Could you please add this for 3.2 pre-release or release so that we can use in our project? This is blocker to release our project.
Hi @deepakapj ,
Sorry about the delays in release, several small issues have surfaced that have delayed the release. This fix is already included in builds from the CI/dev feed, which is available with this addition to a nuget.config:
<add key="SteeltoeDev" value="https://pkgs.dev.azure.com/dotnet/Steeltoe/_packaging/dev/nuget/v3/index.json" />
We are expecting to ship 3.2.0 early this week.
Thanks Tim,
Sure,
Thanks again for the report, 3.2.0 has now shipped, please re-open this issue if the problem is not resolved!