Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ability to disable prometheus scraping #3597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions helm/aws-load-balancer-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ The default values set by the application itself can be confirmed [here](https:/
| `disableRestrictedSecurityGroupRules` | If disabled, controller will not specify port range restriction in the backend security group rules | `false` |
| `objectSelector.matchExpressions` | Webhook configuration to select specific pods by specifying the expression to be matched | None |
| `objectSelector.matchLabels` | Webhook configuration to select specific pods by specifying the key value label pair to be matched | None |
| `prometheusScrape.enabled` | If enabled, and `serviceMonitor.enabled` add the `prometheus.io` annotations to enable metrics scraping | `true` |
| `serviceMonitor.enabled` | Specifies whether a service monitor should be created, requires the ServiceMonitor CRD to be installed | `false` |
| `serviceMonitor.namespace` | Namespace in which to create the service monitor | None |
| `serviceMonitor.additionalLabels` | Labels to add to the service monitor | `{}` |
Expand Down
11 changes: 5 additions & 6 deletions helm/aws-load-balancer-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ spec:
{{- toYaml .Values.podLabels | nindent 8 }}
{{- end }}
annotations:
{{- if not .Values.serviceMonitor.enabled }}
prometheus.io/scrape: "true"
prometheus.io/port: "{{ (split ":" .Values.metricsBindAddr)._1 | default 8080 }}"
{{- end}}
{{- if .Values.podAnnotations }}
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{- $promethusAnnotations := dict }}
{{- if and .Values.prometheusScrape.enabled (not .Values.serviceMonitor.enabled) }}
{{- $promethusAnnotations = dict "prometheus.io/scrape" "true" "prometheus.io/port" "8080"}}
{{- end }}
{{- $podAnnotations := merge $promethusAnnotations .Values.podAnnotations }}
{{- toYaml $podAnnotations | default (dict) | nindent 8 }}
Comment on lines +30 to +35
Copy link

@mkilchhofer mkilchhofer Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so complicated?
IMO using something like I already suggested in comment #3597 (comment) would be perfectly fine:

Wrong usage of helm and keyword.
Correct is
{{- if and (not .Values.serviceMonitor.enabled) .Values.prometheusScrape.enabled }}

Resulting change would be very simple:

diff --git a/helm/aws-load-balancer-controller/templates/deployment.yaml b/helm/aws-load-balancer-controller/templates/deployment.yaml
index 70fe8d5ca..4c993782a 100644
--- a/helm/aws-load-balancer-controller/templates/deployment.yaml
+++ b/helm/aws-load-balancer-controller/templates/deployment.yaml
@@ -27,7 +27,7 @@ spec:
         {{- toYaml .Values.podLabels | nindent 8 }}
         {{- end }}
       annotations:
-        {{- if not .Values.serviceMonitor.enabled }}
+        {{- if and (not .Values.serviceMonitor.enabled) .Values.prometheusScrape.enabled }}
         prometheus.io/scrape: "true"
         prometheus.io/port: "{{ (split ":" .Values.metricsBindAddr)._1 | default 8080 }}"
         {{- end}}

spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
6 changes: 6 additions & 0 deletions helm/aws-load-balancer-controller/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ objectSelector:
matchLabels:
# key: value

prometheusScrape:
# Specifies whether the controller should be annotated for Prometheus scraping.
# Scraping annotations will not be added if serviceMonitor.enabled is set to true
# to prevent duplicate metrics.
enabled: true

serviceMonitor:
# Specifies whether a service monitor should be created
enabled: false
Expand Down
6 changes: 6 additions & 0 deletions helm/aws-load-balancer-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ objectSelector:
matchLabels:
# key: value

prometheusScrape:
# Specifies whether the controller should be annotated for Prometheus scraping.
# Scraping annotations will not be added if serviceMonitor.enabled is set to true
# to prevent duplicate metrics.
enabled: true

serviceMonitor:
# Specifies whether a service monitor should be created
enabled: false
Expand Down