Skip to content

Commit b16feb9

Browse files
Per Kopsperkops
authored andcommitted
feat: restructuring healthcheck response
1 parent 9101f5f commit b16feb9

File tree

9 files changed

+167
-163
lines changed

9 files changed

+167
-163
lines changed

docs/CodeDoc/Atc.Rest.HealthChecks/Atc.Rest.HealthChecks.Extensions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
1818
#### ToHealthCheck
1919
>```csharp
20-
>HealthCheck ToHealthCheck(this KeyValuePair<string, HealthReportEntry> healthReportEntry)
20+
>HealthCheck ToHealthCheck(this KeyValuePair<string, HealthReportEntry> kvp)
2121
>```
2222
#### ToHealthChecks
2323
>```csharp
24-
>IList<HealthCheck> ToHealthChecks(this IReadOnlyDictionary<string, HealthReportEntry> healthReportEntries)
24+
>IList<HealthCheck> ToHealthChecks(this IReadOnlyDictionary<string, HealthReportEntry> entries)
2525
>```
2626
2727
<br />

docs/CodeDoc/Atc.Rest.HealthChecks/Atc.Rest.HealthChecks.Models.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
1616
### Properties
1717
18+
#### Data
19+
>```csharp
20+
>Data
21+
>```
22+
#### Description
23+
>```csharp
24+
>Description
25+
>```
1826
#### Duration
1927
>```csharp
2028
>Duration
@@ -23,10 +31,6 @@
2331
>```csharp
2432
>Name
2533
>```
26-
#### Resources
27-
>```csharp
28-
>Resources
29-
>```
3034
#### Status
3135
>```csharp
3236
>Status
@@ -39,7 +43,7 @@
3943
>```
4044
#### Deconstruct
4145
>```csharp
42-
>void Deconstruct(out string Name, out IList`1 Resources, out HealthStatus Status, out TimeSpan Duration)
46+
>void Deconstruct(out string Name, out HealthStatus Status, out TimeSpan Duration, out string Description, out IReadOnlyDictionary`2 Data)
4347
>```
4448
#### Equals
4549
>```csharp
@@ -121,13 +125,13 @@
121125
122126
### Properties
123127
124-
#### Duration
128+
#### Description
125129
>```csharp
126-
>Duration
130+
>Description
127131
>```
128-
#### Message
132+
#### Duration
129133
>```csharp
130-
>Message
134+
>Duration
131135
>```
132136
#### Name
133137
>```csharp
@@ -145,7 +149,7 @@
145149
>```
146150
#### Deconstruct
147151
>```csharp
148-
>void Deconstruct(out string Name, out HealthStatus Status, out string Message, out TimeSpan Duration)
152+
>void Deconstruct(out string Name, out HealthStatus Status, out string Description, out TimeSpan Duration)
149153
>```
150154
#### Equals
151155
>```csharp

docs/CodeDoc/Atc.Rest.HealthChecks/IndexExtended.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
- [HealthReportEntryExtensions](Atc.Rest.HealthChecks.Extensions.md#healthreportentryextensions)
1414
- Static Methods
15-
- ToHealthCheck(this KeyValuePair&lt;string, HealthReportEntry&gt; healthReportEntry)
16-
- ToHealthChecks(this IReadOnlyDictionary&lt;string, HealthReportEntry&gt; healthReportEntries)
15+
- ToHealthCheck(this KeyValuePair&lt;string, HealthReportEntry&gt; kvp)
16+
- ToHealthChecks(this IReadOnlyDictionary&lt;string, HealthReportEntry&gt; entries)
1717
- [ResourceHealthCheckExtensions](Atc.Rest.HealthChecks.Extensions.md#resourcehealthcheckextensions)
1818
- Static Methods
1919
- ToIReadOnlyDictionary(this IEnumerable&lt;ResourceHealthCheck&gt; resourceHealthCheck)
@@ -28,13 +28,14 @@
2828

2929
- [HealthCheck](Atc.Rest.HealthChecks.Models.md#healthcheck)
3030
- Properties
31+
- Data
32+
- Description
3133
- Duration
3234
- Name
33-
- Resources
3435
- Status
3536
- Methods
3637
- <Clone>$()
37-
- Deconstruct(out string Name, out IList`1 Resources, out HealthStatus Status, out TimeSpan Duration)
38+
- Deconstruct(out string Name, out HealthStatus Status, out TimeSpan Duration, out string Description, out IReadOnlyDictionary`2 Data)
3839
- Equals(HealthCheck other)
3940
- Equals(object obj)
4041
- GetHashCode()
@@ -54,13 +55,13 @@
5455
- ToString()
5556
- [ResourceHealthCheck](Atc.Rest.HealthChecks.Models.md#resourcehealthcheck)
5657
- Properties
58+
- Description
5759
- Duration
58-
- Message
5960
- Name
6061
- Status
6162
- Methods
6263
- <Clone>$()
63-
- Deconstruct(out string Name, out HealthStatus Status, out string Message, out TimeSpan Duration)
64+
- Deconstruct(out string Name, out HealthStatus Status, out string Description, out TimeSpan Duration)
6465
- Equals(ResourceHealthCheck other)
6566
- Equals(object obj)
6667
- GetHashCode()

src/Atc.Rest.HealthChecks/Extensions/HealthReportEntryExtensions.cs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,25 @@ namespace Atc.Rest.HealthChecks.Extensions;
33
public static class HealthReportEntryExtensions
44
{
55
public static HealthCheck ToHealthCheck(
6-
this KeyValuePair<string, HealthReportEntry> healthReportEntry)
6+
this KeyValuePair<string, HealthReportEntry> kvp)
77
{
8-
var resourceHealthChecks = new List<ResourceHealthCheck>();
9-
foreach (var item in healthReportEntry.Value.Data)
10-
{
11-
switch (item.Value)
12-
{
13-
case ResourceHealthCheck resourceHealthCheck:
14-
resourceHealthChecks.Add(resourceHealthCheck);
15-
break;
16-
case string stringContent:
17-
resourceHealthChecks.Add(
18-
new ResourceHealthCheck(
19-
item.Key,
20-
healthReportEntry.Value.Status,
21-
stringContent,
22-
TimeSpan.Zero));
23-
break;
24-
}
25-
}
8+
var entry = kvp.Value;
9+
10+
var data = entry.Data.Count > 0
11+
? entry.Data
12+
: null;
2613

2714
return new HealthCheck(
28-
healthReportEntry.Key,
29-
resourceHealthChecks,
30-
healthReportEntry.Value.Status,
31-
healthReportEntry.Value.Duration);
15+
Name: kvp.Key,
16+
Status: entry.Status,
17+
Duration: entry.Duration,
18+
Description: entry.Description,
19+
Data: data);
3220
}
3321

3422
public static IList<HealthCheck> ToHealthChecks(
35-
this IReadOnlyDictionary<string, HealthReportEntry> healthReportEntries)
36-
=> healthReportEntries
37-
.Select(x => x.ToHealthCheck())
23+
this IReadOnlyDictionary<string, HealthReportEntry> entries)
24+
=> entries
25+
.Select(ToHealthCheck)
3826
.ToList();
3927
}

src/Atc.Rest.HealthChecks/Extensions/ResourceHealthCheckExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ public static class ResourceHealthCheckExtensions
55
public static IReadOnlyDictionary<string, object> ToIReadOnlyDictionary(
66
this IEnumerable<ResourceHealthCheck> resourceHealthCheck)
77
=> resourceHealthCheck.ToDictionary(
8-
keySelector: _ => Guid.NewGuid().ToString(),
9-
elementSelector: e => (object)e,
8+
keySelector: key => key.Name,
9+
elementSelector: e => (object)new
10+
{
11+
e.Status,
12+
e.Duration,
13+
e.Description,
14+
},
1015
StringComparer.Ordinal);
1116
}

src/Atc.Rest.HealthChecks/Models/HealthCheck.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Atc.Rest.HealthChecks.Models;
22

33
public sealed record HealthCheck(
44
string Name,
5-
IList<ResourceHealthCheck> Resources,
65
HealthStatus Status,
7-
TimeSpan Duration);
6+
TimeSpan Duration,
7+
string? Description,
8+
IReadOnlyDictionary<string, object>? Data);

src/Atc.Rest.HealthChecks/Models/ResourceHealthCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ namespace Atc.Rest.HealthChecks.Models;
33
public sealed record ResourceHealthCheck(
44
string Name,
55
HealthStatus Status,
6-
string Message,
6+
string Description,
77
TimeSpan Duration);

0 commit comments

Comments
 (0)