Skip to content

Commit 6c6e89b

Browse files
Add Readiness and liveness probs to the helm chart
1 parent daf7d53 commit 6c6e89b

File tree

9 files changed

+73
-36
lines changed

9 files changed

+73
-36
lines changed

.idea/workspace.xml

+24-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

k8s/compiler/templates/deployment.yaml

+18-3
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,23 @@ spec:
4141
imagePullPolicy: {{ .Values.image.pullPolicy }}
4242
ports:
4343
- name: http
44-
containerPort: 8082
44+
containerPort: {{ .Values.image.port }}
4545
protocol: TCP
46+
# check for lifetime liveness, restarts if not status 200
47+
{{ if .Values.kafka.enabled }}
48+
livenessProbe:
49+
httpGet:
50+
path: {{ .Values.health.liveness }}
51+
port: {{ .Values.image.port }}
52+
initialDelaySeconds: 20
53+
periodSeconds: 10
54+
{{ end }}
55+
readinessProbe:
56+
httpGet:
57+
path: {{ .Values.health.readiness }}
58+
port: {{ .Values.image.port }}
59+
initialDelaySeconds: 20
60+
periodSeconds: 10
4661
envFrom:
4762
- configMapRef:
4863
name: {{ .Release.Name }}-config
@@ -51,7 +66,7 @@ spec:
5166
volumeMounts:
5267
- mountPath: /var/run # volume used for docker
5368
name: executions-volume
54-
- mountPath: /compiler
69+
- mountPath: {{ .Values.compiler.path }}
5570
name: compilation-volume
5671
resources:
5772
{{- toYaml .Values.resources | nindent 12 }}
@@ -63,7 +78,7 @@ spec:
6378
type: DirectoryOrCreate
6479
- name: compilation-volume
6580
hostPath:
66-
path: /compiler
81+
path: {{ .Values.compiler.path }}
6782
type: DirectoryOrCreate
6883
{{- with .Values.nodeSelector }}
6984
nodeSelector:

k8s/compiler/templates/service.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
type: {{ .Values.service.type }}
99
ports:
1010
- port: {{ .Values.service.port }}
11-
targetPort: 8082
11+
targetPort: {{ .Values.image.port }}
1212
protocol: TCP
1313
name: http
1414
selector:

k8s/compiler/values.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Default values for compiler.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
42

53
replicaCount: 1
64

@@ -9,14 +7,18 @@ image:
97
pullPolicy: Never
108
# Overrides the image tag whose default is the chart appVersion.
119
tag: "latest"
10+
port: 8082
1211

13-
# init container
12+
# Init container
1413
initContainerImage:
1514
repository: environment
1615
pullPolicy: Never
17-
# Overrides the image tag whose default is the chart appVersion.
1816
tag: "latest"
1917

18+
health:
19+
liveness: /health/kafkaStreams # check if Kafka streams is broken
20+
readiness: /health/containerization # check if the containerization system used by the compiler is broken
21+
2022
imagePullSecrets: []
2123
nameOverride: ""
2224
fullnameOverride: ""
@@ -37,6 +39,7 @@ securityContext:
3739
# runAsUser: 1000
3840

3941
compiler:
42+
path: "/compiler" # !! Note: Should be the same as the WORKDIR specified in the dockerfile
4043
deleteDockerImage: true
4144
maxExecutionMemory: 1000
4245
minExecutionMemory: 100

k8s/monitoring/values.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Default values for monitoring.
2-
# This is a YAML-formatted file.
3-
# Declare variables to be passed into your templates.
42

53
prometheus:
64
targetService:

src/main/java/com/cp/compiler/healthchecks/ContainerHealthIndicator.java src/main/java/com/cp/compiler/healthchecks/ContainerizationHealthIndicator.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99
* The type Container health indicator.
1010
*/
1111
@Component
12-
public class ContainerHealthIndicator implements HealthIndicator {
12+
public class ContainerizationHealthIndicator implements HealthIndicator {
1313

14-
private ContainerService containerService;
14+
private final ContainerService containerService;
15+
16+
private static final String BROKEN_STATE = "Container Down";
17+
18+
private static final String UP_STATE = "Containerization UP";
1519

1620
/**
1721
* Instantiates a new Container health indicator.
1822
*
1923
* @param containerService the container service
2024
*/
21-
public ContainerHealthIndicator(ContainerService containerService) {
25+
public ContainerizationHealthIndicator(ContainerService containerService) {
2226
super();
2327
this.containerService = containerService;
2428
}
@@ -28,11 +32,12 @@ public Health health() {
2832
if (containerService.isUp()) {
2933
return Health.up()
3034
.withDetail("Containerization", containerService.getContainerizationName())
35+
.withDetail("State", UP_STATE)
3136
.build();
3237
}
3338
return Health.down()
3439
.withDetail("Containerization", containerService.getContainerizationName())
35-
.withDetail("State", "Container Down")
40+
.withDetail("State", BROKEN_STATE)
3641
.build();
3742
}
3843
}

src/main/java/com/cp/compiler/healthchecks/KafkaStreamsHealthIndicator.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
/**
1111
* The type Kafka streams health indicator.
1212
*/
13-
//Note that class name prefix before `HealthIndicator` will be camel-cased
14-
//and used as a health component name, `kafkaStreams` here
13+
// Note that class name prefix before `HealthIndicator` will be camel-cased
14+
// and used as a health component name, `kafkaStreams` here
1515
@Profile("kafka")
1616
@Component
1717
public class KafkaStreamsHealthIndicator implements HealthIndicator {
@@ -34,8 +34,7 @@ public Health health() {
3434

3535
// CREATED, RUNNING or REBALANCING
3636
if (kafkaStreamsState == KafkaStreams.State.CREATED || kafkaStreamsState.isRunningOrRebalancing()) {
37-
//set details if you need one
38-
return Health.up().build();
37+
return Health.up().withDetail("State", kafkaStreamsState.name()).build();
3938
}
4039

4140
// ERROR, NOT_RUNNING, PENDING_SHUTDOWN,

src/test/java/com/cp/compiler/healths/ContainerHealthIndicatorTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.cp.compiler.healths;
22

3-
import com.cp.compiler.healthchecks.ContainerHealthIndicator;
3+
import com.cp.compiler.healthchecks.ContainerizationHealthIndicator;
44
import com.cp.compiler.services.containers.ContainerService;
55
import org.junit.jupiter.api.Assertions;
66
import org.junit.jupiter.api.Test;
@@ -22,7 +22,7 @@ class ContainerHealthIndicatorTests {
2222
@Test
2323
void shouldReturnHealthUp() {
2424
// Given
25-
var healthIndicator = new ContainerHealthIndicator(containerService);
25+
var healthIndicator = new ContainerizationHealthIndicator(containerService);
2626
Mockito.when(containerService.isUp()).thenReturn(true);
2727
Mockito.when(containerService.getContainerizationName()).thenReturn("Docker");
2828

@@ -31,12 +31,13 @@ void shouldReturnHealthUp() {
3131

3232
// Then
3333
Assertions.assertEquals(Health.up().build().getStatus(), health.getStatus());
34+
Assertions.assertNotNull(health.getDetails());
3435
}
3536

3637
@Test
3738
void shouldReturnHealthDown() {
3839
// Given
39-
var healthIndicator = new ContainerHealthIndicator(containerService);
40+
var healthIndicator = new ContainerizationHealthIndicator(containerService);
4041
Mockito.when(containerService.isUp()).thenReturn(false);
4142
Mockito.when(containerService.getContainerizationName()).thenReturn("Docker");
4243

@@ -45,5 +46,6 @@ void shouldReturnHealthDown() {
4546

4647
// Then
4748
Assertions.assertEquals(Health.down().build().getStatus(), health.getStatus());
49+
Assertions.assertNotNull(health.getDetails());
4850
}
4951
}

src/test/java/com/cp/compiler/healths/KafkaStreamsHealthIndicatorTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void shouldReturnHealthUpWhenKafkaStreamsIsInCreatedState() {
3535

3636
// Then
3737
Assertions.assertEquals(Health.up().build().getStatus(), health.getStatus());
38+
Assertions.assertNotNull(health.getDetails());
3839
}
3940

4041
@Test
@@ -49,6 +50,7 @@ void shouldReturnHealthUpWhenKafkaStreamsIsInRunningState() {
4950

5051
// Then
5152
Assertions.assertEquals(Health.up().build().getStatus(), health.getStatus());
53+
Assertions.assertNotNull(health.getDetails());
5254
}
5355

5456
@Test
@@ -63,6 +65,7 @@ void shouldReturnHealthUpWhenKafkaStreamsIsInRebalancingState() {
6365

6466
// Then
6567
Assertions.assertEquals(Health.up().build().getStatus(), health.getStatus());
68+
Assertions.assertNotNull(health.getDetails());
6669
}
6770

6871
@Test
@@ -77,6 +80,7 @@ void shouldReturnHealthDownWhenKafkaStreamsIsInErrorState() {
7780

7881
// Then
7982
Assertions.assertEquals(Health.down().build().getStatus(), health.getStatus());
83+
Assertions.assertNotNull(health.getDetails());
8084
}
8185

8286
@Test
@@ -91,6 +95,7 @@ void shouldReturnHealthDownWhenKafkaStreamsIsInNotRunningState() {
9195

9296
// Then
9397
Assertions.assertEquals(Health.down().build().getStatus(), health.getStatus());
98+
Assertions.assertNotNull(health.getDetails());
9499
}
95100

96101
@Test
@@ -105,5 +110,6 @@ void shouldReturnHealthDownWhenKafkaStreamsIsInPendingState() {
105110

106111
// Then
107112
Assertions.assertEquals(Health.down().build().getStatus(), health.getStatus());
113+
Assertions.assertNotNull(health.getDetails());
108114
}
109115
}

0 commit comments

Comments
 (0)