Skip to content

Commit 8b0094f

Browse files
ishimmingsIan Shimmings
andauthored
Bug/cdms 446 health check (#38)
* Removed unused SendLegacyResponseToBtms config value * Removed health check posting of messages * Moved health check to custom health-dotnet and slowed down the check period * Fixed test --------- Co-authored-by: Ian Shimmings <ian.shimmings@hotmail.com>
1 parent 3326bf7 commit 8b0094f

File tree

12 files changed

+24
-62
lines changed

12 files changed

+24
-62
lines changed

BtmsGateway.Test/EndToEnd/Fixtures/TargetRoutingConfig.json

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"Legend": "Legend",
77
"LegacyLinkName": "Cds",
88
"BtmsLinkName": "Btms",
9-
"SendLegacyResponseToBtms": false,
109
"RouteTo": "Legacy"
1110
},
1211
"CDSFinalisationNotificationToAlvs": {
@@ -15,7 +14,6 @@
1514
"Legend": "Legend",
1615
"LegacyLinkName": "Cds",
1716
"BtmsLinkName": "Btms",
18-
"SendLegacyResponseToBtms": false,
1917
"RouteTo": "Legacy"
2018
},
2119
"CDSErrorNotificationToAlvs": {
@@ -24,7 +22,6 @@
2422
"Legend": "Legend",
2523
"LegacyLinkName": "Cds",
2624
"BtmsLinkName": "Btms",
27-
"SendLegacyResponseToBtms": false,
2825
"RouteTo": "Legacy"
2926
},
3027
"ALVSDecisionNotificationToCds": {
@@ -34,7 +31,6 @@
3431
"LegacyLinkName": "AlvsCds",
3532
"BtmsLinkName": "Btms",
3633
"MessageBodyDepth": 2,
37-
"SendLegacyResponseToBtms": false,
3834
"RouteTo": "Legacy"
3935
},
4036
"ALVSErrorNotificationToCds": {
@@ -44,7 +40,6 @@
4440
"LegacyLinkName": "AlvsCds",
4541
"BtmsLinkName": "Btms",
4642
"MessageBodyDepth": 2,
47-
"SendLegacyResponseToBtms": false,
4843
"RouteTo": "Legacy"
4944
},
5045
"ALVSClearanceRequestToIpaffs": {
@@ -54,7 +49,6 @@
5449
"LegacyLinkName": "AlvsIpaffs",
5550
"BtmsLinkName": "Btms",
5651
"MessageBodyDepth": 2,
57-
"SendLegacyResponseToBtms": false,
5852
"RouteTo": "Legacy"
5953
},
6054
"ALVSFinalisationNotificationToIpaffs": {
@@ -64,7 +58,6 @@
6458
"LegacyLinkName": "AlvsIpaffs",
6559
"BtmsLinkName": "Btms",
6660
"MessageBodyDepth": 2,
67-
"SendLegacyResponseToBtms": false,
6861
"RouteTo": "Legacy"
6962
},
7063
"BTMSDecisionNotificationToCds": {
@@ -73,7 +66,6 @@
7366
"Legend": "Legend",
7467
"LegacyLinkName": "Cds",
7568
"BtmsLinkName": "None",
76-
"SendLegacyResponseToBtms": false,
7769
"RouteTo": "Legacy"
7870
},
7971
"CDSClearanceRequestToBtms": {
@@ -82,7 +74,6 @@
8274
"Legend": "Legend",
8375
"LegacyLinkName": "None",
8476
"BtmsLinkName": "Btms",
85-
"SendLegacyResponseToBtms": false,
8677
"RouteTo": "Btms"
8778
},
8879
"ALVSDecisionForkToBtmsQueue": {
@@ -92,7 +83,6 @@
9283
"LegacyLinkName": "Cds",
9384
"BtmsLinkName": "AlvsDecisionForkQueue",
9485
"MessageBodyDepth": 2,
95-
"SendLegacyResponseToBtms": false,
9686
"RouteTo": "Legacy"
9787
},
9888
"ALVSDecisionRouteToBtmsQueue": {
@@ -102,7 +92,6 @@
10292
"LegacyLinkName": "None",
10393
"BtmsLinkName": "AlvsDecisionRouteQueue",
10494
"MessageBodyDepth": 2,
105-
"SendLegacyResponseToBtms": false,
10695
"RouteTo": "Btms"
10796
},
10897

@@ -113,7 +102,6 @@
113102
"LegacyLinkName": "Cds",
114103
"BtmsLinkName": "AlvsErrorForkQueue",
115104
"MessageBodyDepth": 2,
116-
"SendLegacyResponseToBtms": false,
117105
"RouteTo": "Legacy"
118106
},
119107
"ALVSErrorNotificationRouteToBtmsQueue": {
@@ -123,7 +111,6 @@
123111
"LegacyLinkName": "None",
124112
"BtmsLinkName": "AlvsErrorRouteQueue",
125113
"MessageBodyDepth": 2,
126-
"SendLegacyResponseToBtms": false,
127114
"RouteTo": "Btms"
128115
},
129116

@@ -133,7 +120,6 @@
133120
"Legend": "Legend",
134121
"LegacyLinkName": "AlvsCds",
135122
"BtmsLinkName": "CustomsClearanceForkQueue",
136-
"SendLegacyResponseToBtms": false,
137123
"RouteTo": "Legacy"
138124
},
139125
"CDSClearanceRequestRouteToBtmsQueue": {
@@ -142,7 +128,6 @@
142128
"Legend": "Legend",
143129
"LegacyLinkName": "None",
144130
"BtmsLinkName": "CustomsClearanceRouteQueue",
145-
"SendLegacyResponseToBtms": false,
146131
"RouteTo": "Btms"
147132
},
148133

@@ -152,7 +137,6 @@
152137
"Legend": "Legend",
153138
"LegacyLinkName": "AlvsCds",
154139
"BtmsLinkName": "CustomsErrorForkQueue",
155-
"SendLegacyResponseToBtms": false,
156140
"RouteTo": "Legacy"
157141
},
158142
"CDSErrorNotificationRouteToBtmsQueue": {
@@ -161,7 +145,6 @@
161145
"Legend": "Legend",
162146
"LegacyLinkName": "None",
163147
"BtmsLinkName": "CustomsErrorRouteQueue",
164-
"SendLegacyResponseToBtms": false,
165148
"RouteTo": "Btms"
166149
},
167150

@@ -171,7 +154,6 @@
171154
"Legend": "Legend",
172155
"LegacyLinkName": "AlvsCds",
173156
"BtmsLinkName": "CustomsFinalisationForkQueue",
174-
"SendLegacyResponseToBtms": false,
175157
"RouteTo": "Legacy"
176158
},
177159
"CDSFinalisationNotificationRouteToBtmsQueue": {
@@ -180,7 +162,6 @@
180162
"Legend": "Legend",
181163
"LegacyLinkName": "None",
182164
"BtmsLinkName": "CustomsFinalisationRouteQueue",
183-
"SendLegacyResponseToBtms": false,
184165
"RouteTo": "Btms"
185166
}
186167
},

BtmsGateway.Test/EndToEnd/GeneralEndToEndTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public GeneralEndToEndTests()
3737
BtmsLinkName = "BtmsPath",
3838
Legend = "legend",
3939
MessageSubXPath = "Message",
40-
RouteTo = RouteTo.Legacy,
41-
SendLegacyResponseToBtms = false
40+
RouteTo = RouteTo.Legacy
4241
}
4342
}
4443
},

BtmsGateway.Test/Services/Health/NetworkHealthCheckTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public async Task When_health_checking_a_route_that_throws_Then_should_set_corre
6363

6464
var result = await routeHealthCheck.CheckHealthAsync(new HealthCheckContext());
6565

66-
result.Status.Should().Be(HealthStatus.Unhealthy);
66+
result.Status.Should().Be(HealthStatus.Degraded);
6767
result.Description.Should().Be("Network route: Health Check Name");
6868
result.Exception.Should().Be(exceptionToThrow);
6969
result.Data["route"].Should().Be(healthCheckUrl.Url);

BtmsGateway.Test/Services/Routing/RoutingConfigTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public void When_getting_route_1_Then_should_retrieve_routed_links()
1919
route.BtmsLink.Should().Be("btms-link-queue");
2020
route.BtmsLinkType.Should().Be(LinkType.Queue);
2121
route.BtmsHostHeader.Should().BeNull();
22-
route.SendLegacyResponseToBtms.Should().BeTrue();
2322
route.RouteTo.Should().Be(RouteTo.Legacy);
2423
}
2524

@@ -37,7 +36,6 @@ public void When_getting_route_2_Then_should_retrieve_routed_links()
3736
route.BtmsLink.Should().Be("http://btms-link-url");
3837
route.BtmsLinkType.Should().Be(LinkType.Url);
3938
route.BtmsHostHeader.Should().Be("btms-host-header");
40-
route.SendLegacyResponseToBtms.Should().BeTrue();
4139
route.RouteTo.Should().Be(RouteTo.Btms);
4240
}
4341

@@ -55,7 +53,6 @@ public void When_getting_route_3_Then_should_retrieve_routed_links()
5553
route.BtmsLink.Should().Be("none");
5654
route.BtmsLinkType.Should().Be(LinkType.None);
5755
route.BtmsHostHeader.Should().BeNull();
58-
route.SendLegacyResponseToBtms.Should().BeFalse();
5956
route.RouteTo.Should().Be(RouteTo.Legacy);
6057
}
6158

@@ -73,7 +70,6 @@ public void When_getting_route_4_Then_should_retrieve_routed_links()
7370
route.BtmsLink.Should().Be("http://btms-link-url");
7471
route.BtmsLinkType.Should().Be(LinkType.Url);
7572
route.BtmsHostHeader.Should().Be("btms-host-header");
76-
route.SendLegacyResponseToBtms.Should().BeFalse();
7773
route.RouteTo.Should().Be(RouteTo.Btms);
7874
}
7975
}

BtmsGateway.Test/Services/Routing/TestRoutes.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public static class TestRoutes
88
{
99
NamedRoutes = new Dictionary<string, NamedRoute>
1010
{
11-
{ "route-1", new NamedRoute { RoutePath = "/route/path-1/sub/path", Legend = "Route 1", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "btms_link_name_1", SendLegacyResponseToBtms = true, MessageSubXPath = "Message1", RouteTo = RouteTo.Legacy } },
12-
{ "route-2", new NamedRoute { RoutePath = "/route/path-2/sub/path", Legend = "Route 2", LegacyLinkName = "legacy_link_name_2", BtmsLinkName = "btms_link_name_2", SendLegacyResponseToBtms = true, MessageSubXPath = "Message2", RouteTo = RouteTo.Btms } },
13-
{ "route-3", new NamedRoute { RoutePath = "/route/path-3/sub/path", Legend = "Route 3", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "none", SendLegacyResponseToBtms = false, MessageSubXPath = "Message3", RouteTo = RouteTo.Legacy } },
14-
{ "route-4", new NamedRoute { RoutePath = "/route/path-4/sub/path", Legend = "Route 4", LegacyLinkName = "none", BtmsLinkName = "btms_link_name_2", SendLegacyResponseToBtms = false, MessageSubXPath = "Message4", RouteTo = RouteTo.Btms } }
11+
{ "route-1", new NamedRoute { RoutePath = "/route/path-1/sub/path", Legend = "Route 1", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "btms_link_name_1", MessageSubXPath = "Message1", RouteTo = RouteTo.Legacy } },
12+
{ "route-2", new NamedRoute { RoutePath = "/route/path-2/sub/path", Legend = "Route 2", LegacyLinkName = "legacy_link_name_2", BtmsLinkName = "btms_link_name_2", MessageSubXPath = "Message2", RouteTo = RouteTo.Btms } },
13+
{ "route-3", new NamedRoute { RoutePath = "/route/path-3/sub/path", Legend = "Route 3", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "none", MessageSubXPath = "Message3", RouteTo = RouteTo.Legacy } },
14+
{ "route-4", new NamedRoute { RoutePath = "/route/path-4/sub/path", Legend = "Route 4", LegacyLinkName = "none", BtmsLinkName = "btms_link_name_2", MessageSubXPath = "Message4", RouteTo = RouteTo.Btms } }
1515
},
1616
NamedLinks = new Dictionary<string, NamedLink>
1717
{
@@ -27,8 +27,8 @@ public static class TestRoutes
2727
{
2828
NamedRoutes = new Dictionary<string, NamedRoute>
2929
{
30-
{ "route-1", new NamedRoute { RoutePath = "/route/path-A/sub/path", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "btms_link_name_1", MessageSubXPath = "Message1/Message", Legend = "Route 1", SendLegacyResponseToBtms = true, RouteTo = RouteTo.Legacy } },
31-
{ "route-2", new NamedRoute { RoutePath = "/route/path-A/sub/path", LegacyLinkName = "legacy_link_name_2", BtmsLinkName = "btms_link_name_2", MessageSubXPath = "Message2/Message", Legend = "Route 2", SendLegacyResponseToBtms = true, RouteTo = RouteTo.Legacy } }
30+
{ "route-1", new NamedRoute { RoutePath = "/route/path-A/sub/path", LegacyLinkName = "legacy_link_name_1", BtmsLinkName = "btms_link_name_1", MessageSubXPath = "Message1/Message", Legend = "Route 1", RouteTo = RouteTo.Legacy } },
31+
{ "route-2", new NamedRoute { RoutePath = "/route/path-A/sub/path", LegacyLinkName = "legacy_link_name_2", BtmsLinkName = "btms_link_name_2", MessageSubXPath = "Message2/Message", Legend = "Route 2", RouteTo = RouteTo.Legacy } }
3232
},
3333
NamedLinks = new Dictionary<string, NamedLink>
3434
{
@@ -43,7 +43,7 @@ public static class TestRoutes
4343
{
4444
NamedRoutes = new Dictionary<string, NamedRoute>
4545
{
46-
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", SendLegacyResponseToBtms = true, RouteTo = RouteTo.Legacy } }
46+
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", RouteTo = RouteTo.Legacy } }
4747
},
4848
NamedLinks = new Dictionary<string, NamedLink>
4949
{
@@ -55,7 +55,7 @@ public static class TestRoutes
5555
{
5656
NamedRoutes = new Dictionary<string, NamedRoute>
5757
{
58-
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", SendLegacyResponseToBtms = true, RouteTo = (RouteTo)99 } }
58+
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", RouteTo = (RouteTo)99 } }
5959
},
6060
NamedLinks = new Dictionary<string, NamedLink>
6161
{
@@ -67,7 +67,7 @@ public static class TestRoutes
6767
{
6868
NamedRoutes = new Dictionary<string, NamedRoute>
6969
{
70-
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", SendLegacyResponseToBtms = true, RouteTo = RouteTo.Legacy } }
70+
{ "route-1", new NamedRoute { RoutePath = "/route/path-1", LegacyLinkName = "link_name_1", BtmsLinkName = "link_name_1", MessageSubXPath = "Message1", Legend = "legend", RouteTo = RouteTo.Legacy } }
7171
},
7272
NamedLinks = new Dictionary<string, NamedLink>
7373
{

BtmsGateway/Services/Checking/CheckRouteConfig.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public record HealthCheckUrl
1313
public required string Method { get; init; }
1414
public required string Url { get; init; }
1515
public string? HostHeader { get; init; }
16-
public string? PostData { get; init; }
1716
public required bool IncludeInAutomatedHealthCheck { get; init; }
1817
}
1918

@@ -24,7 +23,6 @@ public record CheckRouteUrl
2423
public required string CheckType { get; init; }
2524
public required string Method { get; init; }
2625
public string? HostHeader { get; init; }
27-
public string? PostData { get; init; }
2826
public required string Url { get; init; }
2927
public Uri Uri => new(Url);
3028
}

BtmsGateway/Services/Checking/CheckRoutes.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task<IEnumerable<CheckRouteResult>> CheckIpaffs()
2727

2828
private static CheckRouteUrl GetCheckRouteUrl(KeyValuePair<string, HealthCheckUrl> x)
2929
{
30-
return new CheckRouteUrl { Name = x.Key, Method = x.Value.Method, Disabled = x.Value.Disabled, HostHeader = x.Value.HostHeader, PostData = x.Value.PostData, Url = x.Value.Url, CheckType = "HTTP" };
30+
return new CheckRouteUrl { Name = x.Key, Method = x.Value.Method, Disabled = x.Value.Disabled, HostHeader = x.Value.HostHeader, Url = x.Value.Url, CheckType = "HTTP" };
3131
}
3232

3333
private async Task<IEnumerable<CheckRouteResult>> CheckAll(CheckRouteUrl checkRouteUrl, CancellationTokenSource cts)
@@ -55,7 +55,6 @@ private async Task<CheckRouteResult> CheckHttp(CheckRouteUrl checkRouteUrl, bool
5555
var client = clientFactory.CreateClient(Proxy.ProxyClientWithoutRetry);
5656
var request = new HttpRequestMessage(new HttpMethod(checkRouteUrl.Method), checkRouteUrl.Url);
5757
if (checkRouteUrl.HostHeader != null) request.Headers.TryAddWithoutValidation("host", checkRouteUrl.HostHeader);
58-
if (checkRouteUrl.PostData != null) request.Content = new StreamContent(new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services", "Fixtures", checkRouteUrl.PostData), FileMode.Open, FileAccess.Read, FileShare.Read));
5958
stopwatch.Start();
6059
var response = await client.SendAsync(request, token);
6160
checkRouteResult = checkRouteResult with { ResponseResult = $"{response.StatusCode.ToString()} ({(int)response.StatusCode}){(includeResponseBody ? $"\n{await response.Content.ReadAsStringAsync(token)}" : string.Empty)}", Elapsed = stopwatch.Elapsed };

BtmsGateway/Services/Health/ConfigureHealthChecks.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ namespace BtmsGateway.Services.Health;
99
[ExcludeFromCodeCoverage]
1010
public static class ConfigureHealthChecks
1111
{
12-
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(10);
12+
public static readonly TimeSpan Timeout = TimeSpan.FromSeconds(15);
1313

1414
public static void AddCustomHealthChecks(this WebApplicationBuilder builder, HealthCheckConfig? healthCheckConfig, RoutingConfig? routingConfig)
1515
{
1616
builder.Services.AddHealthChecks()
1717
.AddResourceUtilizationHealthCheck()
1818
.AddNetworkChecks(healthCheckConfig)
1919
.AddQueueChecks(routingConfig);
20-
builder.Services.Configure<HealthCheckPublisherOptions>(options => options.Delay = TimeSpan.FromSeconds(15));
20+
builder.Services.Configure<HealthCheckPublisherOptions>(options =>
21+
{
22+
options.Delay = TimeSpan.FromSeconds(30);
23+
options.Period = TimeSpan.FromMinutes(5);
24+
});
2125
builder.Services.AddSingleton<IHealthCheckPublisher, HealthCheckPublisher>();
2226
}
2327

@@ -45,7 +49,8 @@ private static void AddQueueChecks(this IHealthChecksBuilder builder, RoutingCon
4549

4650
public static void UseCustomHealthChecks(this WebApplication app)
4751
{
48-
app.MapHealthChecks("/health", new HealthCheckOptions
52+
app.MapGet("/health", () => Results.Ok()).AllowAnonymous();
53+
app.MapHealthChecks("/health-dotnet", new HealthCheckOptions
4954
{
5055
ResponseWriter = (context, healthReport) =>
5156
{

BtmsGateway/Services/Health/NetworkHealthCheck.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class NetworkHealthCheck(string name, HealthCheckUrl healthCheckUrl, IHtt
1515
var client = httpClientFactory.CreateClient(Proxy.RoutedClientWithRetry);
1616
var request = new HttpRequestMessage(HttpMethod.Parse(healthCheckUrl.Method), healthCheckUrl.Url);
1717
if (healthCheckUrl.HostHeader != null) request.Headers.TryAddWithoutValidation("host", healthCheckUrl.HostHeader);
18-
if (healthCheckUrl.PostData != null) request.Content = new StreamContent(new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services", "Fixtures", healthCheckUrl.PostData), FileMode.Open, FileAccess.Read, FileShare.Read));
1918

2019
HttpResponseMessage? response = null;
2120
string? content = null;
@@ -48,7 +47,7 @@ public class NetworkHealthCheck(string name, HealthCheckUrl healthCheckUrl, IHtt
4847
var healthStatus = response?.IsSuccessStatusCode == true ? HealthStatus.Healthy : HealthStatus.Degraded;
4948
if (exception != null)
5049
{
51-
healthStatus = HealthStatus.Unhealthy;
50+
healthStatus = HealthStatus.Degraded;
5251
data.Add("error", $"{exception.Message} - {exception.InnerException?.Message}");
5352
}
5453

BtmsGateway/Services/Health/QueueHealthCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class QueueHealthCheck(string name, string topicArn, IAmazonSimpleNotific
4343

4444
if (exception != null)
4545
{
46-
healthStatus = HealthStatus.Unhealthy;
46+
healthStatus = HealthStatus.Degraded;
4747
data.Add("error", $"{exception.Message} - {exception.InnerException?.Message}");
4848
}
4949

0 commit comments

Comments
 (0)