Skip to content

Commit

Permalink
Added helper templates for app label and deployment name (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: Shehbaz Pathan (Consultant) <[email protected]>
  • Loading branch information
shehbaz-pathan and Shehbaz Pathan (Consultant) authored May 28, 2024
1 parent 5bde5c1 commit 69c75e0
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 127 deletions.
2 changes: 1 addition & 1 deletion charts/nopo11y/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.1
version: 1.0.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
19 changes: 18 additions & 1 deletion charts/nopo11y/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{{- define "dashboard-uid" -}}
{{- printf "%s-%s" .Release.Name .Release.Namespace | trunc 40 -}}
{{- end -}}
{{- end -}}


{{- define "app.label" -}}
{{- if .Values.includeReleaseNameInMetricsLabels }}
{{- printf "%s-%s" .Release.Name .Values.appLabel -}}
{{- else -}}
{{ printf "%s" .Values.appLabel }}
{{- end }}
{{- end }}

{{- define "deployment.name" -}}
{{- if .Values.includeReleaseNameInMetricsLabels }}
{{- printf "%s-%s" .Release.Name .Values.deploymentName -}}
{{- else -}}
{{ printf "%s" .Values.deploymentName }}
{{- end }}
{{- end }}
48 changes: 20 additions & 28 deletions charts/nopo11y/templates/defaultAlerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,55 @@ apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
namespace: {{ .Values.namespace }}
name: {{ .Values.appLabel }}-default-alert-rules
name: {{ include "app.label" . }}-default-alert-rules
labels:
release: {{ .Values.prometheusReleaseLabel }}
spec:
groups:
- name: {{ .Values.appLabel }}-default-alert-rules
- name: {{ include "app.label" . }}-default-alert-rules
rules:
{{- if .Values.istioMetrics.enabled }}
- alert: {{ .Values.appLabel }}High5xxErrorRate
{{- if .Values.includeReleaseNameInMetricsLabels }}
expr: sum(rate(istio_requests_total{app="{{ .Release.Name }}-{{ .Values.appLabel }}", destination_app=~"{{ .Release.Name }}-{{ .Values.appLabel }}", response_code=~"5.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ .Release.Name }}-{{ .Values.appLabel }}", destination_app=~"{{ .Release.Name }}-{{ .Values.appLabel }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate5xx }}
{{- else }}
expr: sum(rate(istio_requests_total{app="{{ .Values.appLabel }}", destination_app=~"{{ .Values.appLabel }}", response_code=~"5.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ .Values.appLabel }}", destination_app=~"{{ .Values.appLabel }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate5xx }}
{{- end }}
- alert: {{ include "app.label" . }}High5xxErrorRate
expr: sum(rate(istio_requests_total{app="{{ include "app.label" . }}", destination_app=~"{{ include "app.label" . }}", response_code=~"5.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ include "app.label" . }}", destination_app=~"{{ include "app.label" . }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate5xx }}
annotations:
description: {{- if .Values.includeReleaseNameInMetricsLabels }} {{ .Release.Name }}-{{ .Values.appLabel }}{{- else }} {{ .Values.appLabel }}{{- end }} service is experiencing high 5xx errors rate from last 5 minutes.
summary: {{- if .Values.includeReleaseNameInMetricsLabels }} {{ .Release.Name }}-{{ .Values.appLabel }}{{- else }} {{ .Values.appLabel }}{{- end }} service is experiencing high 5xx error rate.
description: {{ include "app.label" . }} service is experiencing high 5xx errors rate from last 5 minutes.
summary: {{ include "app.label" . }} service is experiencing high 5xx error rate.
{{- if .Values.grafanaURL }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" . }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" .}}
{{- end }}
labels:
severity: critical
- alert: {{ .Values.appLabel }}High4xxErrorRate
{{- if .Values.includeReleaseNameInMetricsLabels }}
expr: sum(rate(istio_requests_total{app="{{ .Release.Name }}-{{ .Values.appLabel }}", destination_app=~"{{ .Release.Name }}-{{ .Values.appLabel }}", response_code=~"4.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ .Release.Name }}-{{ .Values.appLabel }}", destination_app=~"{{ .Release.Name }}-{{ .Values.appLabel }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate4xx }}
{{- else }}
expr: sum(rate(istio_requests_total{app="{{ .Values.appLabel }}", destination_app=~"{{ .Values.appLabel }}", response_code=~"4.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ .Values.appLabel }}", destination_app=~"{{ .Values.appLabel }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate4xx }}
{{- end }}
- alert: {{ include "app.label" . }}High4xxErrorRate
expr: sum(rate(istio_requests_total{app="{{ include "app.label" . }}", destination_app=~"{{ include "app.label" . }}", response_code=~"4.."}[5m])) by (instance) / sum(rate(istio_requests_total{app="{{ include "app.label" . }}", destination_app=~"{{ include "app.label" . }}"}[5m])) by (instance) * 100 > {{ .Values.errorRate4xx }}
for: 5m
annotations:
{{- if .Values.grafanaURL }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" . }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" .}}
{{- end }}
description: {{- if .Values.includeReleaseNameInMetricsLabels }} {{ .Release.Name }}-{{ .Values.appLabel }}{{- else }} {{ .Values.appLabel }}{{- end }} service is experiencing high 4xx errors rate from last 5 minutes.
summary: {{- if .Values.includeReleaseNameInMetricsLabels }} {{ .Release.Name }}-{{ .Values.appLabel }}{{- else }} {{ .Values.appLabel }}{{- end }} service is experiencing high 4xx error rate.
description: {{ include "app.label" . }} service is experiencing high 4xx errors rate from last 5 minutes.
summary: {{ include "app.label" . }} service is experiencing high 4xx error rate.
labels:
severity: warning
{{- end }}
{{- if .Values.nginxIngressMetrics.enabled }}
- alert: {{ .Values.appLabel }}IngressHigh5xxErrorRate
- alert: {{ include "app.label" . }}IngressHigh5xxErrorRate
expr: sum(rate(nginx_ingress_controller_requests{ingress=~"{{ .Values.nginxIngressMetrics.ingressName }}",status=~"5.."}[5m])) / sum(rate(nginx_ingress_controller_requests{ingress=~"{{ .Values.nginxIngressMetrics.ingressName }}"}[5m])) * 100 > {{ .Values.errorRate5xx }}
annotations:
description: {{ .Values.appLabel }} service is experiencing high 5xx errors rate from last 5 minutes.
summary: {{ .Values.appLabel }} is experiencing high 5xx error rate.
description: {{ include "app.label" . }} service is experiencing high 5xx errors rate from last 5 minutes.
summary: {{ include "app.label" . }} is experiencing high 5xx error rate.
{{- if .Values.grafanaURL }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" . }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" .}}
{{- end }}
labels:
severity: critical
- alert: {{ .Values.appLabel }}IngressHigh4xxErrorRate
- alert: {{ include "app.label" . }}IngressHigh4xxErrorRate
expr: sum(rate(nginx_ingress_controller_requests{ingress=~"{{ .Values.nginxIngressMetrics.ingressName }}",status=~"4.."}[5m])) / sum(rate(nginx_ingress_controller_requests{ingress=~"{{ .Values.nginxIngressMetrics.ingressName }}"}[5m])) * 100 > {{ .Values.rrorRate4xx }}
for: 10m
annotations:
description: {{ .Values.appLabel }} service is experiencing high 4xx errors rate from last 5 minutes.
summary: {{ .Values.appLabel }} service is experiencing high 4xx error rate.
description: {{ include "app.label" . }} service is experiencing high 4xx errors rate from last 5 minutes.
summary: {{ include "app.label" . }} service is experiencing high 4xx error rate.
{{- if .Values.grafanaURL }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" . }}
dashboard: {{ .Values.grafanaURL }}/d/{{ include "dashboard-uid" .}}
{{- end }}
labels:
severity: warning
Expand Down
Loading

0 comments on commit 69c75e0

Please sign in to comment.