dotnet / dotnet/aspnetcore

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

Open
#58,541 1 comment 0 reactions 0 assignees View on GitHub
area-healthchecks
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

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(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(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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.