Skip to content

Commit 3e391b6

Browse files
committed
feat: Provide way to configure alerting rules
1 parent d842fe7 commit 3e391b6

File tree

8 files changed

+94
-20
lines changed

8 files changed

+94
-20
lines changed

charts/dependencies/README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ elasticsearch:
277277
use_default_credentials: false
278278
```
279279

280-
For backward compatibility `HTTP_POST2_ALERT_URL` environment variable needs to be added to elastalert configuration. All alerts will be send to country config service and forwarded to email address
280+
### Elastalert
281+
282+
283+
For backward compatibility `HTTP_POST2_ALERT_URL` environment variable needs to be added to elastalert configuration. All alerts will be send to country config service and forwarded to email address defined while SMTP server configuration.
281284

282285
See example:
283286
```yaml
@@ -288,7 +291,45 @@ elastalert:
288291

289292
> NOTE: This behavior will be changed in future releases, see [#10608](https://github.com/opencrvs/opencrvs-core/issues/10608)
290293

291-
294+
**Custom rules**
295+
296+
Elastalert rules can be extended by modifying or defining new rules. Rules can be stored as Kubernetes configmap within the same namespace as elastalert deployment.
297+
298+
1. Create new folder and place rules there, e/g:
299+
```
300+
~$ ls -1 rules/
301+
alert.yaml
302+
log-alert-foo.yaml
303+
log-error-bar.yaml
304+
custom-service-error-foo.yaml
305+
custom-service-error-bar.yaml
306+
ssh-alert.yaml
307+
```
308+
2. Run following command to create configmap from rules:
309+
```
310+
kubectl create configmap elastalert-custom-rules \
311+
--from-file=charts/dependencies/files/elastalert/rules/
312+
```
313+
3. Add `elastalert.custom_rules_configmap` to values.yaml to point elastalert to new configmap:
314+
```yaml
315+
elastalert:
316+
custom_rules_configmap: elastalert-custom-rules
317+
```
318+
319+
### Kibana
320+
321+
Kibana has support for custom configuration shipped by default as config.ndjson file in helm chart: [charts/dependencies/files/kibana/config.ndjson](https://github.com/opencrvs/infrastructure/blob/develop/charts/dependencies/files/kibana/config.ndjson)
322+
323+
If you need to customize that file please do following steps:
324+
1. Create configmap from `config.ndjson`
325+
```bash
326+
kubectl create cm kibana-custom-config --from-file config.ndjson
327+
```
328+
2. Add `kibana.custom_config_configmap` to values.yaml to point kibana to new configmap:
329+
```yaml
330+
kibana:
331+
custom_config_configmap: kibana-custom-config
332+
```
292333
## Backup Configuration
293334

294335
The dependencies chart includes a built-in backup feature that supports automated backups for internal components. Backups are stored on an external server via an SSH connection.

charts/dependencies/TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
Open Questions:
22
- Should we build dedicated helm chart for Monitoring?
3-
- Move MinIO restore to cronjob

charts/dependencies/files/kibana/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _curl --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD "$kibana
8080
done
8181

8282
# Import configuration
83-
_curl --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -X POST "${KIBANA_URL}/api/saved_objects/_import?overwrite=true" -H 'kbn-xsrf: true' --form file=@/scripts/config.ndjson > /dev/null
83+
_curl --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD -X POST "${KIBANA_URL}/api/saved_objects/_import?overwrite=true" -H 'kbn-xsrf: true' --form file=@/config/config.ndjson > /dev/null
8484

8585
# Re-enable all alerts
8686
_curl --connect-timeout 60 -u elastic:$ELASTICSEARCH_SUPERUSER_PASSWORD "$kibana_alerting_api_url" | jq -r '.data[].id' | while read -r id; do

charts/dependencies/templates/elastalert.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ spec:
6262
echo "processing file $f"
6363
envsubst < "$f" > "/rules/$(basename $f)"
6464
done
65+
[ ! -d /rules-custom ] && exit 0
66+
for f in /rules-custom/*.yaml; do
67+
echo "processing file $f"
68+
envsubst < "$f" > "/rules/$(basename $f)"
69+
done
6570
volumeMounts:
6671
- name: rules
6772
mountPath: /rules
6873
- name: rules-templates
6974
mountPath: /rules-templates
75+
{{- if .Values.elastalert.custom_rules_configmap }}
76+
- name: custom-rules
77+
mountPath: /rules-custom
78+
{{- end }}
7079
containers:
7180
- name: elastalert
7281
image: jertel/elastalert2:2.25.0
@@ -97,4 +106,9 @@ spec:
97106
- name: rules-templates
98107
configMap:
99108
name: elastalert-rules
109+
{{- if .Values.elastalert.custom_rules_configmap }}
110+
- name: rules-custom
111+
configMap:
112+
name: {{ .Values.elastalert.custom_rules_configmap }}
113+
{{- end }}
100114
{{- end }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{- if .Values.monitoring.enabled }}
2+
apiVersion: v1
3+
data:
4+
setup.sh: |
5+
{{ .Files.Get "files/kibana/setup.sh" | indent 4 }}
6+
kind: ConfigMap
7+
metadata:
8+
labels:
9+
app: kibana
10+
name: kibana-on-deploy-script
11+
{{- if not .Values.kibana.custom_config_configmap }}
12+
---
13+
apiVersion: v1
14+
data:
15+
config.ndjson: |
16+
{{ .Files.Get "files/kibana/config.ndjson" | indent 4 }}
17+
kind: ConfigMap
18+
metadata:
19+
labels:
20+
app: kibana
21+
name: kibana-on-deploy-config
22+
{{- end }}
23+
{{- end }}

charts/dependencies/templates/kibana-on-update.yaml renamed to charts/dependencies/templates/kibana-on-deploy.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ spec:
3030
key: ELASTIC_PASSWORD
3131
volumeMounts:
3232
- mountPath: /scripts
33-
name: kibana-on-update-script
33+
name: kibana-on-deploy-script
34+
- mountPath: /config
35+
name: kibana-configmap
3436
volumes:
35-
- name: kibana-on-update-script
37+
- name: kibana-on-deploy-script
3638
configMap:
37-
name: kibana-on-update-script
39+
name: kibana-on-deploy-script
40+
defaultMode: 0755
41+
- name: kibana-configmap
42+
configMap:
43+
name: {{ .Values.kibana.custom_config_configmap | default "kibana-on-deploy-script" }}
3844
defaultMode: 0755
3945
restartPolicy: "OnFailure"
4046
{{- end }}

charts/dependencies/templates/kibana-on-update-configmap.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

charts/dependencies/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ monitoring:
7676

7777
kibana:
7878
users_secret: kibana-users-secret
79+
# Configure Kibana and persist updated configuration as configmap
80+
# custom_config_configmap:
7981
metricbeat:
8082
dashboards:
8183
- kubernetes-e0195ce0-bcaf-11ec-b64f-7dd6e8e82013
8284
filebeat: {}
8385
logstash: {}
8486

8587
elastalert:
88+
# Create configmap with custom rules for elastalert
89+
# custom_rules_configmap:
8690
env: {}
8791

8892
minio:

0 commit comments

Comments
 (0)