Skip to content

Commit cf3c2fa

Browse files
authored
feat: add metrics monitoring for rspamd and dovecot (#461)
* feat: add metrics monitoring for rspamd Signed-off-by: fastlorenzo <git@bernardi.be> * Added missing networkpolicies config Signed-off-by: fastlorenzo <git@bernardi.be> * fix indentation Signed-off-by: fastlorenzo <git@bernardi.be> * Install Prometheus CRDs in CI to test serviceMonitors Signed-off-by: fastlorenzo <git@bernardi.be> * fix ci Signed-off-by: fastlorenzo <git@bernardi.be> * Add dovecot metrics Signed-off-by: fastlorenzo <git@bernardi.be> --------- Signed-off-by: fastlorenzo <git@bernardi.be>
1 parent 2a1d418 commit cf3c2fa

19 files changed

Lines changed: 576 additions & 168 deletions

.github/workflows/lint-and-test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ jobs:
7272
kubectl -n kube-system rollout restart deployment coredns
7373
kubectl -n kube-system rollout status deployment coredns --timeout=120s
7474
75+
- name: Install Prometheus CRDs (required for serviceMonitors)
76+
if: steps.list-changed.outputs.changed == 'true'
77+
run: |
78+
kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/bundle.yaml
79+
7580
- name: Run chart-testing (install)
7681
id: install
7782
if: steps.list-changed.outputs.changed == 'true'

charts/mailu/README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ Check that the deployed pods are all running.
166166
app.kubernetes.io/instance: ingress-nginx
167167
app.kubernetes.io/component: controller
168168
` |
169+
| `networkPolicy.monitoring.namespace` | Namespace where the monitoring pods are deployed | `monitoring` |
170+
| `networkPolicy.monitoring.podSelector` | Selector for the monitoring pods | `matchLabels:
171+
app.kubernetes.io/name: prometheus-agent
172+
app.kubernetes.io/instance: kps
173+
` |
169174
| `mailuVersion` | Override Mailu version to be deployed (tag of mailu images). Defaults to `Chart.AppVersion` - must be master or a version >= 2.0 | `""` |
170175
| `logLevel` | default log level. can be overridden globally or per service | `WARNING` |
171176
| `postmaster` | local part of the postmaster email address (Mailu will use @$DOMAIN as domain part) | `postmaster` |
@@ -583,6 +588,11 @@ Check that the deployed pods are all running.
583588
| `dovecot.hostAliases` | Pod pod host aliases | `[]` |
584589
| `dovecot.schedulerName` | Name of the k8s scheduler (other than default) | `""` |
585590
| `dovecot.service.annotations` | Admin service annotations | `{}` |
591+
| `dovecot.serviceMonitor.enabled` | If true, a serviceMonitor will be created for Dovecot | `false` |
592+
| `dovecot.serviceMonitor.annotations` | Dovecot serviceMonitor annotations | `{}` |
593+
| `dovecot.serviceMonitor.interval` | Dovecot serviceMonitor scrape interval | `""` |
594+
| `dovecot.serviceMonitor.metricRelabelings` | MetricRelabelConfigs to apply to samples after scraping, but before ingestion. | `[]` |
595+
| `dovecot.serviceMonitor.relabelings` | RelabelConfigs to apply to samples before scraping | `[]` |
586596
| `dovecot.topologySpreadConstraints` | Topology Spread Constraints for pod assignment | `[]` |
587597
| `dovecot.updateStrategy.type` | Can be set to RollingUpdate or OnDelete | `RollingUpdate` |
588598
| `dovecot.extraEnvVars` | Extra environment variable to pass to the running container | `[]` |
@@ -647,7 +657,12 @@ Check that the deployed pods are all running.
647657
| `rspamd.revisionHistoryLimit` | Configure the revisionHistoryLimit of the deployment | `3` |
648658
| `rspamd.hostAliases` | Pod pod host aliases | `[]` |
649659
| `rspamd.schedulerName` | Name of the k8s scheduler (other than default) | `""` |
650-
| `rspamd.service.annotations` | Admin service annotations | `{}` |
660+
| `rspamd.service.annotations` | Rspamd service annotations | `{}` |
661+
| `rspamd.serviceMonitor.enabled` | If true, a serviceMonitor will be created for Rspamd | `false` |
662+
| `rspamd.serviceMonitor.annotations` | Rspamd serviceMonitor annotations | `{}` |
663+
| `rspamd.serviceMonitor.interval` | Rspamd serviceMonitor scrape interval | `""` |
664+
| `rspamd.serviceMonitor.metricRelabelings` | MetricRelabelConfigs to apply to samples after scraping, but before ingestion. | `[]` |
665+
| `rspamd.serviceMonitor.relabelings` | RelabelConfigs to apply to samples before scraping | `[]` |
651666
| `rspamd.topologySpreadConstraints` | Topology Spread Constraints for pod assignment | `[]` |
652667
| `rspamd.updateStrategy.type` | Can be set to RollingUpdate or OnDelete | `RollingUpdate` |
653668
| `rspamd.extraEnvVars` | Extra environment variable to pass to the running container | `[]` |

charts/mailu/ci/helm-lint-values.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,77 @@ dovecot:
106106
limits:
107107
memory: 1Gi
108108
cpu: 2
109+
serviceMonitor:
110+
enabled: true
111+
interval: 30s
112+
# Random relabellings to test behavior
113+
metricRelabelings:
114+
- action: keep
115+
regex: "kube_(daemonset|deployment|pod|namespace|node|statefulset).+"
116+
sourceLabels: [__name__]
117+
relabelings:
118+
- sourceLabels: [__meta_kubernetes_pod_node_name]
119+
separator: ;
120+
regex: ^(.*)$
121+
targetLabel: nodename
122+
replacement: $1
123+
action: replace
124+
overrides:
125+
dovecot.conf: |
126+
##
127+
## Statistics and metrics
128+
##
129+
130+
# Dovecot supports gathering statistics from events.
131+
# Currently there are no statistics logged by default, and therefore they must
132+
# be explicitly added using the metric configuration blocks.
133+
#
134+
# Unlike old stats, the new statistics do not require any plugins loaded.
135+
#
136+
# See https://doc.dovecot.org/2.3/configuration_manual/stats/ for more details.
137+
138+
##
139+
## Example metrics
140+
##
141+
142+
metric auth_success {
143+
filter = event=auth_request_finished AND success=yes
144+
}
145+
146+
metric auth_failures {
147+
filter = event=auth_request_finished AND NOT success=yes
148+
}
149+
150+
metric imap_command {
151+
filter = event=imap_command_finished
152+
group_by = cmd_name tagged_reply_state
153+
}
154+
155+
metric smtp_command {
156+
filter = event=smtp_server_command_finished
157+
group_by = cmd_name status_code duration:exponential:1:5:10
158+
}
159+
160+
metric mail_delivery {
161+
filter = event=mail_delivery_finished
162+
group_by = duration:exponential:1:5:10
163+
}
164+
165+
##
166+
## Prometheus
167+
##
168+
169+
# To allow access to statistics with Prometheus, enable http listener
170+
# on stats process. Stats will be available on /metrics path.
171+
#
172+
# See https://doc.dovecot.org/2.3/configuration_manual/stats/openmetrics/ for more
173+
# details.
174+
175+
service stats {
176+
inet_listener http {
177+
port = 9900
178+
}
179+
}
109180
110181
rspamd:
111182
logLevel: INFO
@@ -118,6 +189,21 @@ rspamd:
118189
limits:
119190
memory: 1Gi
120191
cpu: 2
192+
serviceMonitor:
193+
enabled: true
194+
interval: 30s
195+
# Random relabellings to test behavior
196+
metricRelabelings:
197+
- action: keep
198+
regex: "kube_(daemonset|deployment|pod|namespace|node|statefulset).+"
199+
sourceLabels: [__name__]
200+
relabelings:
201+
- sourceLabels: [__meta_kubernetes_pod_node_name]
202+
separator: ;
203+
regex: ^(.*)$
204+
targetLabel: nodename
205+
replacement: $1
206+
action: replace
121207

122208
clamav:
123209
logLevel: INFO

charts/mailu/templates/NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ After you created an initial admin login (see docs), you can login to the admin
3636
If you're upgrading from Mailu < 2024.06, please read this: https://mailu.io/2024.06/releases.html#after-upgrading
3737

3838
{{ include "mailu.validateValues" . }}
39+
40+
{{ include "mailu.dovecot.validateServiceMonitor" . }}

charts/mailu/templates/_helpers.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,12 @@ mailu: tika
208208
{{- print "off" -}}
209209
{{- end -}}
210210
{{- end -}}
211+
212+
213+
{{/* If .Values.dovecot.serviceMonitor.enabled is true and .Values.dovecot.overrides is an empty object, throw an alert message as it would not work */}}
214+
{{- define "mailu.dovecot.validateServiceMonitor" -}}
215+
{{- if and .Values.dovecot.serviceMonitor.enabled (eq (len .Values.dovecot.overrides) 0) -}}
216+
mailu: dovecot
217+
You need to set at least one override for Dovecot's service monitor
218+
{{- end -}}
219+
{{- end -}}

charts/mailu/templates/dovecot/deployment.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ spec:
119119
- name: sieve
120120
containerPort: 4190
121121
protocol: TCP
122+
{{- if .Values.dovecot.serviceMonitor.enabled }}
123+
- name: dovecot-metrics
124+
containerPort: 9900
125+
protocol: TCP
126+
{{- end }}
122127
{{- if .Values.dovecot.resources }}
123128
resources: {{- toYaml .Values.dovecot.resources | nindent 12 }}
124129
{{- end }}

charts/mailu/templates/dovecot/service.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ spec:
3232
- name: sieve
3333
port: 4190
3434
protocol: TCP
35+
{{- if .Values.dovecot.serviceMonitor.enabled }}
36+
- name: dovecot-metrics
37+
port: 9900
38+
protocol: TCP
39+
{{- end }}
3540
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if and .Values.dovecot.enabled .Values.dovecot.serviceMonitor.enabled }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ include "mailu.dovecot.serviceName" . }}
6+
namespace: {{ include "common.names.namespace" . | quote }}
7+
labels: {{- include "common.labels.standard" . | nindent 4 }}
8+
app.kubernetes.io/component: dovecot
9+
{{- if .Values.commonLabels }}
10+
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
11+
{{- end }}
12+
{{- if .Values.dovecot.serviceMonitor.annotations }}
13+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.dovecot.serviceMonitor.annotations "context" $) | nindent 4 }}
14+
{{- end }}
15+
spec:
16+
selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
17+
app.kubernetes.io/component: dovecot
18+
namespaceSelector:
19+
matchNames:
20+
- {{ include "common.names.namespace" . | quote }}
21+
endpoints:
22+
- port: dovecot-metrics
23+
path: /metrics
24+
scheme: http
25+
{{- if .Values.dovecot.serviceMonitor.interval }}
26+
interval: {{ .Values.dovecot.serviceMonitor.interval }}
27+
{{- end }}
28+
{{- if .Values.dovecot.serviceMonitor.relabelings }}
29+
relabelings: {{- tpl (toYaml .Values.dovecot.serviceMonitor.relabelings | nindent 6) . }}
30+
{{- end }}
31+
{{- if .Values.dovecot.serviceMonitor.metricRelabelings }}
32+
metricRelabelings: {{- tpl (toYaml .Values.dovecot.serviceMonitor.metricRelabelings | nindent 6) . }}
33+
{{- end }}
34+
{{- end }}

charts/mailu/templates/network-policies.yaml

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

0 commit comments

Comments
 (0)