Skip to content

Commit 7af5171

Browse files
Enable monitor testing in CI (#12643)
This PR enhances the CI/CD to also run tests related to monitor module when helm test is invoked. --------- Signed-off-by: Ivan Kavaldzhiev <ivankavaldzhiev@gmail.com>
1 parent 852676c commit 7af5171

File tree

9 files changed

+195
-15
lines changed

9 files changed

+195
-15
lines changed

.github/workflows/acceptance.yaml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,21 @@ jobs:
172172
env:
173173
HIERO_MIRROR_IMPORTER_BLOCK_NODES_0_HOST: 'block-node-1.${SOLO_NAMESPACE}.svc.cluster.local'
174174
SPRING_PROFILES_ACTIVE: 'blocknode'
175+
monitor:
176+
env:
177+
HIERO_MIRROR_MONITOR_HEALTH_RELEASE_FAILWHENINACTIVE: "true"
178+
test:
179+
annotations:
180+
helm.sh/hook-delete-policy: before-hook-creation
181+
enabled: true
182+
rest:
183+
test:
184+
annotations:
185+
helm.sh/hook-delete-policy: before-hook-creation
186+
restjava:
187+
test:
188+
annotations:
189+
helm.sh/hook-delete-policy: before-hook-creation
175190
test:
176191
cucumberTags: "@acceptance and not @ethereum and not @ethcall and not @crud"
177192
annotations:
@@ -184,10 +199,28 @@ jobs:
184199
web3:
185200
env:
186201
HIERO_MIRROR_WEB3_OPCODE_TRACER_ENABLED: "true"
202+
test:
203+
annotations:
204+
helm.sh/hook-delete-policy: before-hook-creation
187205
EOF
188206
189207
else
190208
cat <<EOF > mirror.yaml
209+
monitor:
210+
env:
211+
HIERO_MIRROR_MONITOR_HEALTH_RELEASE_FAILWHENINACTIVE: "true"
212+
test:
213+
annotations:
214+
helm.sh/hook-delete-policy: before-hook-creation
215+
enabled: true
216+
rest:
217+
test:
218+
annotations:
219+
helm.sh/hook-delete-policy: before-hook-creation
220+
restjava:
221+
test:
222+
annotations:
223+
helm.sh/hook-delete-policy: before-hook-creation
191224
test:
192225
annotations:
193226
helm.sh/hook-delete-policy: before-hook-creation
@@ -200,6 +233,9 @@ jobs:
200233
web3:
201234
env:
202235
HIERO_MIRROR_WEB3_OPCODE_TRACER_ENABLED: "true"
236+
test:
237+
annotations:
238+
helm.sh/hook-delete-policy: before-hook-creation
203239
EOF
204240
fi
205241
@@ -215,7 +251,7 @@ jobs:
215251
- name: Run acceptance tests
216252
run: |
217253
helm test "${HELM_RELEASE_NAME}" -n "${SOLO_NAMESPACE}" --logs \
218-
--filter name="${HELM_RELEASE_NAME}-mirror-acceptance" --timeout 20m | tee output_log.txt
254+
--timeout 20m | tee output_log.txt
219255
220256
- name: Run k6 tests
221257
if: ${{ matrix.stream-type != 'BLOCK' }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"info": {
3+
"_postman_id": "e015390f-8007-4371-8703-0b9ad853f718",
4+
"name": "Monitor API",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
6+
"_exporter_id": "25186531"
7+
},
8+
"item": [
9+
{
10+
"name": "Check Cluster Health",
11+
"event": [
12+
{
13+
"listen": "test",
14+
"script": {
15+
"exec": [
16+
"pm.test('Status code is 200', function () {",
17+
" pm.expect(pm.response.code).to.equal(200);",
18+
"});"
19+
],
20+
"type": "text/javascript",
21+
"packages": {},
22+
"requests": {}
23+
}
24+
}
25+
],
26+
"request": {
27+
"method": "GET",
28+
"header": [],
29+
"url": {
30+
"raw": "{{baseUrl}}/actuator/health/cluster",
31+
"host": ["{{baseUrl}}"],
32+
"path": ["actuator", "health", "cluster"]
33+
}
34+
},
35+
"response": []
36+
}
37+
],
38+
"variable": [
39+
{
40+
"key": "baseUrl",
41+
"value": "http://localhost:8082"
42+
}
43+
]
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
{{ if .Values.test.enabled -}}
4+
apiVersion: v1
5+
kind: ConfigMap
6+
metadata:
7+
annotations: {{- toYaml .Values.test.annotations | nindent 4 }}
8+
labels: {{- include "hedera-mirror-monitor.labels" . | nindent 4 }}
9+
app.kubernetes.io/name: {{ include "hedera-mirror-monitor.name" . }}-test
10+
name: {{ include "hedera-mirror-monitor.fullname" . }}-test
11+
namespace: {{ include "hedera-mirror-monitor.namespace" . }}
12+
data:
13+
postman.json: |-
14+
{{- .Values.test.postman | b64dec | default (.Files.Get "postman.json") | nindent 4 }}
15+
{{- end -}}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
{{ if .Values.test.enabled -}}
4+
apiVersion: v1
5+
kind: Pod
6+
metadata:
7+
annotations: {{- toYaml .Values.test.annotations | nindent 4 }}
8+
labels: {{- include "hedera-mirror-monitor.labels" . | nindent 4 }}
9+
app.kubernetes.io/name: {{ include "hedera-mirror-monitor.name" . }}-test
10+
name: {{ include "hedera-mirror-monitor.fullname" . }}-test
11+
namespace: {{ include "hedera-mirror-monitor.namespace" . }}
12+
spec:
13+
containers:
14+
- name: test
15+
image: "{{ .Values.test.image.repository }}:{{ .Values.test.image.tag }}"
16+
imagePullPolicy: {{ .Values.test.image.pullPolicy }}
17+
args:
18+
- run
19+
- /test/postman.json
20+
- --env-var
21+
- baseUrl=http://{{ include "hedera-mirror-monitor.fullname" . }}:{{ .Values.service.port }}
22+
securityContext:
23+
allowPrivilegeEscalation: false
24+
capabilities:
25+
drop: [ALL]
26+
readOnlyRootFilesystem: true
27+
volumeMounts:
28+
- name: monitor-test
29+
mountPath: /test
30+
readOnly: true
31+
imagePullSecrets: {{ toYaml .Values.test.image.pullSecrets | nindent 4 }}
32+
priorityClassName: {{ .Values.test.priorityClassName }}
33+
restartPolicy: Never
34+
securityContext:
35+
fsGroup: 1000
36+
runAsGroup: 1000
37+
runAsNonRoot: true
38+
runAsUser: 1000
39+
seccompProfile:
40+
type: RuntimeDefault
41+
terminationGracePeriodSeconds: 1
42+
volumes:
43+
- name: monitor-test
44+
configMap:
45+
defaultMode: 420
46+
name: {{ include "hedera-mirror-monitor.fullname" . }}-test
47+
{{- end -}}

charts/hedera-mirror-monitor/values.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,20 @@ serviceMonitor:
301301

302302
terminationGracePeriodSeconds: 60
303303

304+
test:
305+
annotations:
306+
helm.sh/hook: test-success
307+
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
308+
helm.sh/hook-weight: "30"
309+
enabled: false
310+
image:
311+
pullPolicy: IfNotPresent
312+
pullSecrets: []
313+
repository: postman/newman
314+
tag: 6.1.3-alpine
315+
postman: "" # Custom postman.json in base64 encoding
316+
priorityClassName: ""
317+
304318
tolerations: []
305319

306320
updateStrategy:

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ monitor.
432432
| ----------------------------------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
433433
| `hiero.mirror.monitor.health.release.cacheExpiry` | 30s | The amount of time to cache cluster release health status |
434434
| `hiero.mirror.monitor.health.release.enabled` | false | Whether to enable cluster release health check |
435+
| `hiero.mirror.monitor.health.release.failWhenInactive` | false | Whether to enable Status.DOWN when publisher or subscriber metric rates go to zero. |
435436
| `hiero.mirror.monitor.mirrorNode.grpc.host` | "" | The hostname of the mirror node's gRPC API |
436437
| `hiero.mirror.monitor.mirrorNode.grpc.port` | 5600 | The port of the mirror node's gRPC API |
437438
| `hiero.mirror.monitor.mirrorNode.rest.host` | "" | The hostname of the mirror node's REST API |

monitor/src/main/java/org/hiero/mirror/monitor/health/ClusterHealthIndicator.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public class ClusterHealthIndicator implements ReactiveHealthIndicator {
2626

2727
private static final Mono<Health> UNKNOWN = health(Status.UNKNOWN, "Publishing is inactive");
2828
private static final Mono<Health> UP = health(Status.UP, "");
29+
private static final Mono<Health> DOWN = health(Status.DOWN, "");
2930

31+
private final ReleaseHealthProperties releaseHealthProperties;
3032
private final MirrorSubscriber mirrorSubscriber;
3133
private final RestApiClient restApiClient;
3234
private final TransactionGenerator transactionGenerator;
@@ -47,25 +49,26 @@ public Mono<Health> health() {
4749
: Mono.just(health));
4850
}
4951

50-
// Returns unknown if all publish scenarios aggregated rate has dropped to zero, otherwise returns an empty flux
52+
// Returns down or unknown if all publish scenarios aggregated rate has dropped to zero, otherwise returns an empty
53+
// flux
5154
private Mono<Health> publishing() {
5255
return transactionGenerator
5356
.scenarios()
5457
.map(Scenario::getRate)
5558
.reduce(0.0, (c, n) -> c + n)
5659
.filter(sum -> sum <= 0)
57-
.flatMap(n -> UNKNOWN);
60+
.flatMap(n -> getHealthForZeroRate());
5861
}
5962

60-
// Returns up if any subscription is running and its rate is above zero, otherwise returns unknown
63+
// Returns up if any subscription is running and its rate is above zero, otherwise returns down or unknown
6164
private Mono<Health> subscribing() {
6265
return mirrorSubscriber
6366
.getSubscriptions()
6467
.map(Scenario::getRate)
6568
.reduce(0.0, (cur, next) -> cur + next)
6669
.filter(sum -> sum > 0)
6770
.flatMap(n -> UP)
68-
.switchIfEmpty(UNKNOWN);
71+
.switchIfEmpty(getHealthForZeroRate());
6972
}
7073

7174
private Mono<Health> restNetworkStakeHealth() {
@@ -98,4 +101,8 @@ private Mono<Health> restNetworkStakeHealth() {
98101
return health(status, statusMessage);
99102
});
100103
}
104+
105+
private Mono<Health> getHealthForZeroRate() {
106+
return releaseHealthProperties.isFailWhenInactive() ? DOWN : UNKNOWN;
107+
}
101108
}

monitor/src/main/java/org/hiero/mirror/monitor/health/ReleaseHealthProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public class ReleaseHealthProperties {
1919
private Duration cacheExpiry = Duration.ofSeconds(30);
2020

2121
private boolean enabled = false;
22+
23+
private boolean failWhenInactive = false;
2224
}

monitor/src/test/java/org/hiero/mirror/monitor/health/ClusterHealthIndicatorTest.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,36 @@ class ClusterHealthIndicatorTest {
4949
@Mock
5050
private TransactionGenerator transactionGenerator;
5151

52+
@Mock
53+
private ReleaseHealthProperties releaseHealthProperties;
54+
5255
@InjectMocks
5356
private ClusterHealthIndicator clusterHealthIndicator;
5457

5558
@ParameterizedTest
5659
@CsvSource({
57-
"1.0, 1.0, 200, UP", // healthy
58-
"0.0, 1.0, 200, UNKNOWN", // publishing inactive
59-
"1.0, 0.0, 200, UNKNOWN", // subscribing inactive
60-
"0.0, 0.0, 200, UNKNOWN", // publishing and subscribing inactive
61-
"1.0, 1.0, 400, UNKNOWN", // unknown network stake
62-
"1.0, 1.0, 500, DOWN", // network stake down
63-
"0.0, 0.0, 500, DOWN", // publishing and subscribing inactive and network stake down
64-
"0.0, 1.0, 500, DOWN", // network stake down and publishing inactive
65-
"1.0, 0.0, 500, DOWN", // network stake down and subscribing inactive
60+
"1.0, 1.0, 200, UP, false", // healthy
61+
"0.0, 1.0, 200, UNKNOWN, false", // publishing inactive
62+
"1.0, 0.0, 200, UNKNOWN, false", // subscribing inactive
63+
"0.0, 0.0, 200, UNKNOWN, false", // publishing and subscribing inactive
64+
"1.0, 1.0, 400, UNKNOWN, false", // unknown network stake
65+
"1.0, 1.0, 500, DOWN, false", // network stake down
66+
"0.0, 0.0, 500, DOWN, false", // publishing and subscribing inactive and network stake down
67+
"0.0, 1.0, 500, DOWN, false", // network stake down and publishing inactive
68+
"1.0, 0.0, 500, DOWN, false", // network stake down and subscribing inactive
69+
"1.0, 1.0, 200, UP, true", // healthy
70+
"0.0, 1.0, 500, DOWN, true", // publishing inactive
71+
"1.0, 0.0, 500, DOWN, true", // subscribing inactive
72+
"0.0, 0.0, 500, DOWN, true", // publishing and subscribing inactive
73+
"1.0, 1.0, 400, UNKNOWN, true", // unknown network stake
74+
"1.0, 1.0, 500, DOWN, true", // network stake down
75+
"0.0, 0.0, 500, DOWN, true", // publishing and subscribing inactive and network stake down
76+
"0.0, 1.0, 500, DOWN, true", // network stake down and publishing inactive
77+
"1.0, 0.0, 500, DOWN, true", // network stake down and subscribing inactive
6678
})
67-
void health(double publishRate, double subscribeRate, int networkStatusCode, Status status) {
79+
void health(
80+
double publishRate, double subscribeRate, int networkStatusCode, Status status, boolean failWhenInactive) {
81+
when(releaseHealthProperties.isFailWhenInactive()).thenReturn(failWhenInactive);
6882
when(transactionGenerator.scenarios()).thenReturn(Flux.just(publishScenario(publishRate)));
6983
when(mirrorSubscriber.getSubscriptions()).thenReturn(Flux.just(subscribeScenario(subscribeRate)));
7084
when(restApiClient.getNetworkStakeStatusCode())

0 commit comments

Comments
 (0)