Skip to content

Commit 5e5c8fe

Browse files
Added data bridge api healthcheck and tests. (#10)
* Added data bridge api healthcheck and tests. Updated docker compose settings to enable services to run along side each other. * We must disable Data Bridge API health check for integration tests. * Enabled HealthcheckEnabled for component test --------- Co-authored-by: Mark Gent <Mark.Gent@homesengland.gov.uk>
1 parent 8f84d00 commit 5e5c8fe

23 files changed

Lines changed: 396 additions & 35 deletions

.github/workflows/check-pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
- name: Make script executable
8484
run: chmod +x ./working-dir/wait-for-docker-logs.sh
8585
- name: Wait for localstack
86-
run: ./working-dir/wait-for-docker-logs.sh localstack-emulator "Bootstrapping Complete" 60
86+
run: ./working-dir/wait-for-docker-logs.sh kda-localstack-emulator "Bootstrapping Complete" 60
8787
- name: Wait for keeperdata_api to be ready
8888
run: ./working-dir/wait-for-docker-logs.sh keeperdata_api "Now listening on" 60
8989
- name: Run integration tests

docker-compose.override.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ services:
44
com.microsoft.visual-studio.project-name: "KeeperData.Api"
55
environment:
66
- ASPNETCORE_ENVIRONMENT=Development
7-
- ASPNETCORE_HTTP_PORTS=8080
8-
- AWS__ServiceURL=http://localstack-emulator:4566
9-
- Mongo__DatabaseUri=mongodb://mongodb:27017
7+
- ASPNETCORE_HTTP_PORTS=5555
8+
- AWS__ServiceURL=http://kda-localstack-emulator:4566
9+
- Mongo__DatabaseUri=mongodb://kda_mongodb:27017
1010
- StorageConfiguration__ComparisonReportsStorage__BucketName=test-comparison-reports-bucket
1111
- QueueConsumerOptions__IntakeEventQueueOptions__QueueUrl=http://sqs.eu-west-2.127.0.0.1:4566/000000000000/ls_keeper_data_intake_queue
12+
- ApiClients__DataBridgeApi__BaseUrl=http://keeperdata_bridge:5560/
1213
ports:
13-
- "8080"
14+
- "5555"
1415
volumes:
1516
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
1617
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro

docker-compose.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: 'keeperdata_api'
22
services:
33
localstack:
4-
container_name: "localstack-emulator"
4+
container_name: "kda-localstack-emulator"
55
image: localstack/localstack:3.0.2
66
ports:
7-
- '4566:4566' # LocalStack Gateway
8-
- '4510-4559:4510-4559' # external services port range
7+
- '4568:4566'
98
env_file:
109
- 'compose/aws.env'
1110
environment:
@@ -18,28 +17,29 @@ services:
1817
- "/var/run/docker.sock:/var/run/docker.sock"
1918
- ./compose/start-localstack.sh:/etc/localstack/init/ready.d/start-localstack.sh
2019
healthcheck:
21-
test: ['CMD', 'curl', 'http://localstack-emulator:4566/health']
20+
test: ['CMD', 'curl', 'http://kda-localstack-emulator:4566/health']
2221
interval: 5s
2322
start_period: 5s
2423
retries: 3
2524
networks:
2625
- cdp-tenant
2726

2827
redis:
28+
container_name: "kda-redis"
2929
image: redis:7.2.3-alpine3.18
3030
ports:
31-
- '6379:6379'
31+
- '6381:6379'
3232
restart: always
3333
networks:
3434
- cdp-tenant
3535

3636
mongodb:
37-
container_name: mongodb
37+
container_name: kda_mongodb
3838
image: mongo:6.0.13
3939
networks:
4040
- cdp-tenant
4141
ports:
42-
- '27018:27017'
42+
- '27019:27017'
4343
volumes:
4444
- mongodb-data:/data
4545
restart: always
@@ -50,10 +50,7 @@ services:
5050
image: keeperdata_api
5151
build: ./
5252
ports:
53-
- '8080:8080'
54-
links:
55-
- 'localstack:localstack'
56-
- 'mongodb:mongodb'
53+
- '5555:5555'
5754
depends_on:
5855
localstack:
5956
condition: service_healthy
@@ -62,8 +59,8 @@ services:
6259
env_file:
6360
- 'compose/aws.env'
6461
environment:
65-
PORT: 8080
66-
LOCALSTACK_ENDPOINT: http://localstack-emulator:4566
62+
PORT: 5555
63+
LOCALSTACK_ENDPOINT: http://kda-localstack-emulator:4566
6764
networks:
6865
- cdp-tenant
6966

@@ -72,4 +69,4 @@ volumes:
7269

7370
networks:
7471
cdp-tenant:
75-
driver: bridge
72+
name: cdp-tenant

src/KeeperData.Api/KeeperData.Api.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
99
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
1010
</PropertyGroup>
11-
12-
<ItemGroup>
13-
<Content Include="..\..\.dockerignore">
14-
<Link>.dockerignore</Link>
15-
</Content>
16-
</ItemGroup>
1711

1812
<ItemGroup>
1913
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />

src/KeeperData.Api/Setup/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Asp.Versioning;
22
using KeeperData.Application.Setup;
3+
using KeeperData.Infrastructure.ApiClients.Setup;
34
using KeeperData.Infrastructure.Database.Setup;
45
using KeeperData.Infrastructure.Messaging.Setup;
56
using KeeperData.Infrastructure.Storage.Setup;
@@ -41,6 +42,8 @@ public static void ConfigureApi(this IServiceCollection services, IConfiguration
4142
services.AddMessagingDependencies(configuration);
4243

4344
services.AddStorageDependencies(configuration);
45+
46+
services.AddApiClientDependencies(configuration);
4447
}
4548

4649
private static void ConfigureHealthChecks(this IServiceCollection services)

src/KeeperData.Api/appsettings.Development.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
{
2-
"AWS": {
3-
"ServiceURL": "http://sqs.eu-west-2.localhost.localstack.cloud:4566/"
4-
},
5-
"Mongo": {
6-
"DatabaseUri": "mongodb://127.0.0.1:27017",
7-
"DatabaseName": "ls-keeper-data-api"
8-
},
92
"DetailedErrors": true,
103
"AllowedHosts": "*",
114
"Serilog": {

src/KeeperData.Api/appsettings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
"BucketName": "Set in cdp-app-config (or for local development using docker-compose.override.yml)"
2323
}
2424
},
25+
"ApiClients": {
26+
"DataBridgeApi": {
27+
"BaseUrl": "Set in cdp-app-config (or for local development using docker-compose.override.yml",
28+
"HealthcheckEnabled": false,
29+
"ResiliencePolicy": {
30+
"Retries": 3,
31+
"BaseDelaySeconds": 2,
32+
"UseJitter": true,
33+
"TimeoutPeriodSeconds": 30
34+
}
35+
}
36+
},
2537
"AllowedHosts": "*",
2638
"TraceHeader": "x-cdp-request-id",
2739
"Serilog": {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace KeeperData.Infrastructure.ApiClients.Configuration;
2+
3+
public class ApiClientConfiguration
4+
{
5+
public string BaseUrl { get; set; } = string.Empty;
6+
public bool HealthcheckEnabled { get; set; } = false;
7+
public ResiliencePolicy ResiliencePolicy { get; set; } = new();
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace KeeperData.Infrastructure.ApiClients.Configuration;
2+
3+
public class ApiClientsConfiguration
4+
{
5+
public Dictionary<string, ApiClientConfiguration> Clients { get; set; } = [];
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Polly;
2+
3+
namespace KeeperData.Infrastructure.ApiClients.Configuration;
4+
5+
public class ResiliencePolicy
6+
{
7+
public int Retries { get; set; } = 3; // Total retry attempts
8+
public int BaseDelaySeconds { get; set; } = 2; // Base delay before first retry
9+
public bool UseJitter { get; set; } = true; // Adds randomness to avoid thundering herd
10+
public int TimeoutPeriodSeconds { get; set; } = 30; // Canceling execution if it does not complete within a specified time
11+
public DelayBackoffType BackoffType { get; set; } = DelayBackoffType.Exponential; // Retry strategy
12+
}

0 commit comments

Comments
 (0)