Skip to content

Commit

Permalink
Merge pull request #9 from vany0114/health-checks
Browse files Browse the repository at this point in the history
Health checks implementation & ConfigMap set up
  • Loading branch information
vany0114 authored Mar 17, 2020
2 parents ae91141 + 8b09d99 commit cb5e8c1
Show file tree
Hide file tree
Showing 44 changed files with 615 additions and 219 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ msbuild.wrn
src/Web/Duber.WebSite/wwwroot/lib
node_modules
packages/
src/Web/Duber.WebSite/healthchecksdb-shm
src/Web/Duber.WebSite/healthchecksdb
src/Web/Duber.WebSite/healthchecksdb-wal
9 changes: 9 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 2.0.4
**Health checks implementation & ConfigMap set up:**
* Add health checks to all microservices
* Add health checks UI add-on to frontend
* Upgrade EF Core to `3.0.0`
* Organize better the `Startup` files
* Set up k8s probes
* Move env variables to a common `ConfigMap`

## 2.0.3
**Event bus handlers idempotency:**
* Add *Duber.Infrastructure.EventBus.Idempotency* project to handle idempotency at integration events level.
Expand Down
10 changes: 10 additions & 0 deletions build-images.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
param([String]$service="all")

if ($service -eq "all")
{
docker-compose -f docker-compose.yml build
}
else
{
docker-compose -f docker-compose.yml build $service
}
3 changes: 3 additions & 0 deletions deploy/k8s/local/delete-resources.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# configmap
kubectl delete cm env-config

# external system
kubectl delete deploy payment
kubectl delete svc payment
Expand Down
3 changes: 3 additions & 0 deletions deploy/k8s/local/deploy-local.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ kubectl apply -f dashboard-adminuser.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f nginx-ingress\custom-service.yaml

# configmap
kubectl apply -f env-config.yaml

# mongo
kubectl apply -f mongo\mongo-admin.yaml
kubectl apply -f mongo\mongo-deployment.yaml
Expand Down
18 changes: 18 additions & 0 deletions deploy/k8s/local/env-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-config
data:
ASPNETCORE_ENVIRONMENT: Development
ConnectionStrings__InvoiceDB: Server=sql-data;Database=Duber.InvoiceDb;User Id=sa;Password=Pass@word
ConnectionStrings__WebsiteDB: Server=sql-data;Database=Duber.WebSiteDb;User Id=sa;Password=Pass@word
ConnectionStrings__SignalrBackPlane: redis
EventStoreConfiguration__ConnectionString: mongodb://nosql-data
EventBusConnection: rabbitmq
PaymentServiceBaseUrl: http://payment
InvoiceApiSettings__BaseUrl: http://invoice
TripApiSettings__BaseUrl: http://trip
TripApiSettings__NotificationsClientUrl: http://trip.notifications.local.com:81
TripApiSettings__NotificationsServerUrl: http://notifications
AzureServiceBusEnabled: "false"
IsDeployedOnCluster: "true"
6 changes: 3 additions & 3 deletions deploy/k8s/local/external-system/payment-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ spec:
- name: payment
image: vany0114/externalsystem.paymentservice
imagePullPolicy: Always
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
envFrom:
- configMapRef:
name: env-config
ports:
- containerPort: 80
27 changes: 16 additions & 11 deletions deploy/k8s/local/invoice/invoice-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ spec:
limits:
memory: "256Mi"
cpu: "500m"
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
- name: ConnectionStrings__InvoiceDB
value: "Server=sql-data;Database=Duber.InvoiceDb;User Id=sa;Password=Pass@word"
- name: EventBusConnection
value: "rabbitmq"
- name: PaymentServiceBaseUrl
value: "http://payment"
- name: AzureServiceBusEnabled
value: "False"
envFrom:
- configMapRef:
name: env-config
livenessProbe:
httpGet:
port: 80
path: /liveness
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: 80
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 5
ports:
- containerPort: 80
27 changes: 16 additions & 11 deletions deploy/k8s/local/notifications/notifications-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ spec:
limits:
memory: "256Mi"
cpu: "600m"
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
- name: ConnectionStrings__SignalrBackPlane
value: "redis"
- name: EventBusConnection
value: "rabbitmq"
- name: AzureServiceBusEnabled
value: "False"
- name: IsDeployedOnCluster
value: "True"
envFrom:
- configMapRef:
name: env-config
livenessProbe:
httpGet:
port: 80
path: /liveness
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: 80
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 5
ports:
- containerPort: 80
25 changes: 16 additions & 9 deletions deploy/k8s/local/trip/trip-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ spec:
limits:
memory: "256Mi"
cpu: "600m"
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
- name: EventStoreConfiguration__ConnectionString
value: "mongodb://nosql-data"
- name: EventBusConnection
value: "rabbitmq"
- name: AzureServiceBusEnabled
value: "False"
envFrom:
- configMapRef:
name: env-config
livenessProbe:
httpGet:
port: 80
path: /liveness
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: 80
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 5
ports:
- containerPort: 80
46 changes: 33 additions & 13 deletions deploy/k8s/local/website/website-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,38 @@ spec:
limits:
memory: "256Mi"
cpu: "600m"
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
- name: ConnectionStrings__WebsiteDB
value: "Server=sql-data;Database=Duber.WebSiteDb;User Id=sa;Password=Pass@word"
- name: EventBusConnection
value: "rabbitmq"
- name: TripApiSettings__BaseUrl
value: "http://trip"
- name: TripApiSettings__NotificationsUrl
value: "http://trip.notifications.local.com:81"
- name: AzureServiceBusEnabled
value: "False"
envFrom:
- configMapRef:
name: env-config
env:
- name: HealthChecksUI__HealthChecks__0__Name
value: "Invoice HTTP Check"
- name: HealthChecksUI__HealthChecks__0__Uri
value: $(InvoiceApiSettings__BaseUrl)/readiness
- name: HealthChecksUI__HealthChecks__1__Name
value: "Trip HTTP Check"
- name: HealthChecksUI__HealthChecks__1__Uri
value: $(TripApiSettings__BaseUrl)/readiness
- name: HealthChecksUI__HealthChecks__2__Name
value: "Notifications HTTP Check"
- name: HealthChecksUI__HealthChecks__2__Uri
value: $(TripApiSettings__NotificationsServerUrl)/readiness
- name: HealthChecksUI__HealthChecks__3__Name
value: "Frontend HTTP Check"
- name: HealthChecksUI__HealthChecks__3__Uri
value: "http://frontend/readiness"
livenessProbe:
httpGet:
port: 80
path: /liveness
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /readiness
port: 80
initialDelaySeconds: 60
periodSeconds: 60
timeoutSeconds: 5
ports:
- containerPort: 80
12 changes: 11 additions & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ services:
- ASPNETCORE_ENVIRONMENT=${APP_ENVIRONMENT:-Development}
- ConnectionStrings__WebsiteDB=${AZURE_WEBSITE_DB:-Server=sql.data;Database=Duber.WebSiteDb;User Id=sa;Password=Pass@word}
- EventBusConnection=${AZURE_SERVICE_BUS:-rabbitmq}
- InvoiceApiSettings__BaseUrl=${INVOICE_SERVICE_BASE_URL:-http://duber.invoice.api}
- TripApiSettings__BaseUrl=${TRIP_SERVICE_BASE_URL:-http://duber.trip.api}
- TripApiSettings__NotificationsUrl=${NOTIFICATIONS_SERVICE_URL:-http://docker.for.win.localhost:32778} #docker.for.mac.localhost / docker.for.linux.localhost (you could use the .env file to set this in a common variable, then use it here, i.g: LOCAL_DOMAIN=http://docker.for.win.localhost)
- TripApiSettings__NotificationsServerUrl=${NOTIFICATIONS_SERVER_URL:-http://duber.trip.notifications}
- TripApiSettings__NotificationsClientUrl=${NOTIFICATIONS_CLIENT_URL:-http://docker.for.win.localhost:32778} #docker.for.mac.localhost / docker.for.linux.localhost (you could use the .env file to set this in a common variable, then use it here, i.e: LOCAL_DOMAIN=http://docker.for.win.localhost)
- AzureServiceBusEnabled=${SERVICE_BUS_ENABLED:-False}
- HealthChecksUI__HealthChecks__0__Name=Invoice HTTP Check
- HealthChecksUI__HealthChecks__0__Uri=http://duber.invoice.api/readiness
- HealthChecksUI__HealthChecks__1__Name=Trip HTTP Check
- HealthChecksUI__HealthChecks__1__Uri=http://duber.trip.api/readiness
- HealthChecksUI__HealthChecks__2__Name=Notifications HTTP Check
- HealthChecksUI__HealthChecks__2__Uri=http://duber.trip.notifications/readiness
- HealthChecksUI__HealthChecks__3__Name=Frontend HTTP Check
- HealthChecksUI__HealthChecks__3__Uri=http://duber.website/readiness
ports:
- "32774:80"

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions src/Application/Duber.Invoice.API/Duber.Invoice.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Duber.Infrastructure.EventBus.Abstractions;
using Duber.Invoice.API.Application.IntegrationEvents.Events;
using Duber.Invoice.API.Application.IntegrationEvents.Hnadlers;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Duber.Invoice.API.Extensions
{
public static class ApplicationBuilderExtensions
{
public static IApplicationBuilder UseServiceBroker(this IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
eventBus.Subscribe<TripCancelledIntegrationEvent, TripCancelledIntegrationEventHandler>();
eventBus.Subscribe<TripFinishedIntegrationEvent, TripFinishedIntegrationEventHandler>();
return app;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using Duber.Infrastructure.EventBus.RabbitMQ.IoC;
using Duber.Infrastructure.EventBus.ServiceBus.IoC;
using Duber.Invoice.API.Application.IntegrationEvents.Hnadlers;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.OpenApi.Models;

#pragma warning disable 618
Expand Down Expand Up @@ -136,5 +140,46 @@ private static IAsyncPolicy<HttpResponseMessage> GetResiliencePolicy(IConfigurat

return policies;
}

public static IServiceCollection AddServiceBroker(this IServiceCollection services, IConfiguration configuration)
{
if (configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
services.AddServiceBus(configuration);
}
else
{
services.AddRabbitMQ(configuration);
}

services.AddTransient<TripCancelledIntegrationEventHandler>();
services.AddTransient<TripFinishedIntegrationEventHandler>();

return services;
}

public static IServiceCollection AddHealthChecks(this IServiceCollection services, IConfiguration configuration)
{
var hcBuilder = services.AddHealthChecks();

hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy());

hcBuilder
.AddSqlServer(
configuration["ConnectionStrings:InvoiceDB"],
name: "InvoiceDB-check",
tags: new string[] { "invoicedb" });

if (configuration.GetValue<bool>("AzureServiceBusEnabled"))
{
hcBuilder.AddAzureServiceBusTopic(configuration, "invoice-az-servicebus-check");
}
else
{
hcBuilder.AddRabbitMQ(configuration, "invoice-rabbitmqbus-check");
}

return services;
}
}
}
Loading

0 comments on commit cb5e8c1

Please sign in to comment.