Skip to content

Commit 37be908

Browse files
committed
Merged PR 873: add dronescheduler readiness/liveness probe
- add /health endpoint for readiness and liveness - add liveness/readiness probe cfg solve: #133008
1 parent 33c2431 commit 37be908

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

charts/dronescheduler/templates/dronescheduler-deploy.yaml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,38 @@ spec:
4646
- name: fabrikam-dronescheduler
4747
image: {{ .Values.dockerregistry }}{{ .Values.dockerregistrynamespace }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
4848
imagePullPolicy: {{ .Values.image.pullPolicy }}
49+
readinessProbe:
50+
httpGet:
51+
path: {{ required "readinessProbe.httpGet.path is required" .Values.readinessProbe.httpGet.path }}
52+
port: {{ required "readinessProbe.httpGet.port is required" .Values.readinessProbe.httpGet.port }}
53+
{{- if .Values.readinessProbe.initialDelaySeconds }}
54+
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds }}
55+
{{- end }}
56+
{{- if .Values.readinessProbe.periodSeconds }}
57+
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
58+
{{- end }}
59+
{{- if .Values.readinessProbe.timeoutSeconds }}
60+
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
61+
{{- end }}
62+
{{- if .Values.readinessProbe.failureThreshold }}
63+
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
64+
{{- end }}
65+
livenessProbe:
66+
httpGet:
67+
path: {{ required "livenessProbe.httpGet.path is required" .Values.livenessProbe.httpGet.path }}
68+
port: {{ required "livenessProbe.httpGet.port is required" .Values.livenessProbe.httpGet.port }}
69+
{{- if .Values.livenessProbe.initialDelaySeconds }}
70+
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }}
71+
{{- end }}
72+
{{- if .Values.livenessProbe.periodSeconds }}
73+
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
74+
{{- end }}
75+
{{- if .Values.livenessProbe.timeoutSeconds }}
76+
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
77+
{{- end }}
78+
{{- if .Values.livenessProbe.failureThreshold }}
79+
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
80+
{{- end }}
4981
resources:
5082
requests:
5183
cpu: {{ required "A valid .Values.resources.requests.cpu entry required!" .Values.resources.requests.cpu }}
@@ -66,4 +98,4 @@ spec:
6698
value: 169.254.169.254
6799
ports:
68100
- name: service
69-
containerPort: 8080
101+
containerPort: 8080

charts/dronescheduler/values.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ keyvault:
1414
cosmosdb:
1515
id:
1616
collectionid:
17+
readinessProbe:
18+
httpGet:
19+
path: /healthz
20+
port: 8080
21+
initialDelaySeconds: 40
22+
periodSeconds: 15
23+
timeoutSeconds: 2
24+
failureThreshold: 5
25+
livenessProbe:
26+
httpGet:
27+
path: /healthz
28+
port: 8080
29+
initialDelaySeconds: 50
30+
periodSeconds: 15
1731
reason: unknown
1832
telemetry:
1933
level: "Error"
@@ -22,4 +36,4 @@ tags:
2236
prod: false
2337
qa: false
2438
staging: false
25-
current: false
39+
current: false

src/shipping/dronescheduler/Fabrikam.DroneDelivery.DroneSchedulerService/Startup.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
// ------------------------------------------------------------
55

66
using Microsoft.AspNetCore.Builder;
7+
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.Http;
910
using Microsoft.AspNetCore.Mvc;
1011
using Microsoft.Extensions.Configuration;
1112
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Diagnostics.HealthChecks;
1214
using Microsoft.Extensions.Logging;
1315
using Microsoft.FeatureManagement;
1416
using Fabrikam.DroneDelivery.DroneSchedulerService.Models;
@@ -21,6 +23,8 @@ namespace Fabrikam.DroneDelivery.DroneSchedulerService
2123
{
2224
public class Startup
2325
{
26+
private const string HealCheckName = "ReadinessLiveness";
27+
2428
public Startup(IConfiguration configuration)
2529
{
2630
Configuration = configuration;
@@ -42,6 +46,11 @@ public void ConfigureServices(IServiceCollection services)
4246
// Add framework services.
4347
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
4448

49+
// Add health check
50+
services.AddHealthChecks().AddCheck(
51+
HealCheckName,
52+
() => HealthCheckResult.Healthy("OK"));
53+
4554
// Register the Swagger generator, defining one or more Swagger documents
4655
services.AddSwaggerGen(c =>
4756
{
@@ -62,6 +71,9 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
6271
.ReadFrom.Configuration(Configuration)
6372
.CreateLogger();
6473

74+
// Map health checks
75+
app.UseHealthChecks("/healthz");
76+
6577
app.UseMvc();
6678

6779
// Enable middleware to serve generated Swagger as a JSON endpoint.

0 commit comments

Comments
 (0)