Skip to content

Commit

Permalink
Removed support for generating both Loki ConfigMap and custom resourc…
Browse files Browse the repository at this point in the history
…e at the same time
  • Loading branch information
bastianeicher committed Jul 10, 2024
1 parent 81afec2 commit 4eb6fe6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 48 deletions.
2 changes: 1 addition & 1 deletion charts/generic-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ app:
| `alerting.logs.levels.*.severity` | `warning` | The severity of the alert when the maximum count of a messages of a specific log level is exceeded |
| `alerting.logs.levels.lokiConfigMap.label` | `loki_rule` | The label attached to the ConfigMap holding the Loki Rules |
| `alerting.logs.levels.lokiConfigMap.labelValue` | `""` | The value of the label attached to the Loki Rule ConfigMap |
| `alerting.logs.createLokiRule` | `false` | Whether to create a `LokiRule` custom resource for log alerting |
| `alerting.logs.createLokiRule` | `false` | Whether to create a `LokiRule` custom resource of a ConfigMap for log alerting |
| `alerting.custom.*.metric` | __required if used__ | The name of the Prometheus metric exposed by the service |
| `alerting.custom.*.labelMatchers` | | Prometheus label matchers to use for filtering the metric (e.g., `some_key="some_value"`) |
| `alerting.custom.*.aggregate` | __required if used__ | The aggregate function to use to combine metric values from multiple replicas (e.g., `max` or `sum`) |
Expand Down
18 changes: 0 additions & 18 deletions charts/generic-service/ci/log-alerts-both-values.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions charts/generic-service/ci/log-alerts-operator-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ alerting:
severity: Warning
maxCount: 10
error: {}
# setting this to an empty object (`{}`) will not suppress cm creation, use `null` instead
lokiConfigMap: null
createLokiRule: true
38 changes: 12 additions & 26 deletions charts/generic-service/templates/alerts-logs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{{- if and .Values.alerting.enabled .Values.alerting.logs.levels }}
{{- if .Values.alerting.logs.lokiConfigMap }}
---
{{- if and (and .Values.alerting.enabled .Values.alerting.logs.levels) (or .Values.alerting.logs.createLokiRule .Values.alerting.logs.lokiConfigMap) }}

{{- if .Values.alerting.logs.createLokiRule }}
apiVersion: logging.opsgy.com/v1beta1
kind: LokiRule
metadata:
name: {{ include "generic-service.fullname" . }}
labels: {{- include "generic-service.top-level-labels" . | nindent 4 }}

spec:
{{- else }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -10,6 +18,7 @@ metadata:

data:
'{{ .Release.Namespace }}.{{ .Release.Name }}.yaml': |
{{- end }}
groups:
- name: {{ include "generic-service.fullname" . }}.logs
rules:
Expand All @@ -23,26 +32,3 @@ data:
description: '{{ $.Release.Name }} reported {{"{{ $value }}"}} {{ $level }} log messages in the last {{ $.Values.alerting.logs.countInterval }}.'
{{- end }}
{{- end }}
{{- if .Values.alerting.logs.createLokiRule }}
---
apiVersion: logging.opsgy.com/v1beta1
kind: LokiRule
metadata:
name: {{ include "generic-service.fullname" . }}
labels: {{- include "generic-service.top-level-labels" . | nindent 4 }}

spec:
groups:
- name: {{ include "generic-service.fullname" . }}.logs
rules:
{{- range $level, $options := .Values.alerting.logs.levels }}
- alert: LogMessages{{ $level | title }}
expr: sum(count_over_time(({namespace="{{ $.Release.Namespace }}", container="{{ include "generic-service.fullname" $ }}", {{ $.Values.alerting.logs.levelLabel }}="{{ $level }}"})[{{ $.Values.alerting.logs.countInterval }}])) > {{ $options.maxCount | default 0 }}
for: 1s
labels: {{- include "generic-service.alert-labels" $ | nindent 12 }} {{ $options.severity | default "warning" }}
topic: logs
annotations: {{- include "generic-service.alert-annotations" $ | nindent 12 }} {{ $level }} logs
description: '{{ $.Release.Name }} reported {{"{{ $value }}"}} {{ $level }} log messages in the last {{ $.Values.alerting.logs.countInterval }}.'
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/generic-service/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@
"createLokiRule": {
"type": "boolean",
"default": false,
"description": "Whether to create a LokiRule custom resource for log alerting"
"description": "Whether to create a LokiRule custom resource instead of a ConfigMap for log alerting"
}
},
"additionalProperties": false
Expand Down

0 comments on commit 4eb6fe6

Please sign in to comment.