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

Health propagation between API an UI not possible due to sealed & un(de)serializable #58541

Open
ibruynin opened this issue Oct 21, 2024 · 0 comments
Labels
area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo)

Comments

@ibruynin
Copy link

I'm trying to propagate the degraded health from the API to the UI (using that API) as follows:

API:8080/health returns JsonSerializer.Serialize<HealthReport>(result)

UI:8080/health returns health info based on the result of the API

var s = await response.Content.ReadAsStringAsync();                
var hr = JsonNode.Parse(s).AsObject();
var entries = hr["Entries"];
var entry = entries["API_XYZ"];
var hres = Int32.Parse(entry["Status"].ToString());
HealthStatus status = (HealthStatus)hres;
return status switch
{
    HealthStatus.Healthy => HealthCheckResult.Healthy("Degraded API up"),
    HealthStatus.Degraded => HealthCheckResult.Degraded("Degraded API up, but degraded"),
    HealthStatus.Unhealthy => HealthCheckResult.Unhealthy("Degraded API unavailable")
};

It would be cleaner (and more typesafe) if the following was possible:

var s = await response.Content.ReadAsStringAsync();                
var hr = JsonSerializer.Deserialize<HealthReport>(s);

But that's not possible due to the lack of a default constructor:
System.NotSupportedException: 'Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Microsoft.Extensions.Diagnostics.HealthChecks.HealthReport'.

Extending the type is also not a workaround, since the class is sealed.

Are we trying to do something that's not intended to do?
Thoughts welcome.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo) label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo)
Projects
None yet
Development

No branches or pull requests

1 participant