Steeltoe icon indicating copy to clipboard operation
Steeltoe copied to clipboard

Hystrix dashboard doesn't load Metrics DOTNET 6.0

Open shadikkhan opened this issue 4 years ago • 18 comments

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:

  1. I have added: services.AddHystrixMetricsStream(Configuration);
  2. Also added code app.UseHystrixRequestContext(); & app.UseMvc(); in startup file
  3. 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

https://stackoverflow.com/questions/71651056/hystrix-dashboard-doesnt-load-metrics-dotnet-6-0/71651599?noredirect=1#comment126678747_71651599

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 avatar Apr 11 '22 13:04 shadikkhan

@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

dtillman avatar Apr 11 '22 21:04 dtillman

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

deepakapj avatar Apr 12 '22 13:04 deepakapj

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

dtillman avatar Apr 12 '22 15:04 dtillman

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

deepakapj avatar Apr 19 '22 19:04 deepakapj

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 avatar Apr 22 '22 13:04 deepakapj

@deepakapj : Yes, feel free to create a PR for this change... Thanks!

dtillman avatar May 02 '22 14:05 dtillman

I will share the PR ASAP

deepakapj avatar May 09 '22 12:05 deepakapj

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. Add-try-catch

deepakapj avatar May 09 '22 13:05 deepakapj

@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

dtillman avatar May 09 '22 14:05 dtillman

Thanks , We will do and create PR soon

Deepak

deepakapj avatar May 12 '22 13:05 deepakapj

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 avatar May 12 '22 15:05 deepakapj

@deepakapj we need you to sign the CLA before we can merge your PR. We might be able to ship 3.2 this week

TimHess avatar May 17 '22 19:05 TimHess

Hi,

I signed CLA. Please let know once 3.2 availabale so that i can validate in my project ?

Thanks Deepak Saxena

deepakapj avatar May 18 '22 20:05 deepakapj

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

deepakapj avatar May 20 '22 16:05 deepakapj

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.

deepakapj avatar May 23 '22 17:05 deepakapj

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.

TimHess avatar May 23 '22 17:05 TimHess

Thanks Tim,

Sure,

deepakapj avatar May 23 '22 17:05 deepakapj

Thanks again for the report, 3.2.0 has now shipped, please re-open this issue if the problem is not resolved!

TimHess avatar May 26 '22 20:05 TimHess