bjw-s / helm-charts

A collection of Helm charts
https://bjw-s.github.io/helm-charts/
Apache License 2.0
524 stars 98 forks source link

serviceMonitor missing job labels and namespace selectors #309

Closed nklmilojevic closed 3 months ago

nklmilojevic commented 3 months ago

Details

What steps did you take and what happened: I upgraded to app-template 3.0.4 recently and started having problem with any servicemonitor that is via app-template. I tracked down the problem and it seems that it is because it doesn't have Job label and Namespace Selector fields. As soon as I added them manually to service monitors, it scraping in VictoriaMetrics. Before that, there were 0/0 servicescrapes.

What did you expect to happen:

I expect serviceMonitor to have job label and namespace selector

Anything else you would like to add: A quick comparison between, for example, the one created by Grafana (external-secrets as well, etc):

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  annotations:
    meta.helm.sh/release-name: grafana
    meta.helm.sh/release-namespace: monitoring
  creationTimestamp: "2024-03-25T20:50:08Z"
  generation: 1
  labels:
    app.kubernetes.io/instance: grafana
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: grafana
    app.kubernetes.io/version: 10.4.0
    helm.sh/chart: grafana-7.3.7
    helm.toolkit.fluxcd.io/name: grafana
    helm.toolkit.fluxcd.io/namespace: monitoring
  name: grafana
  namespace: monitoring
  resourceVersion: "217766523"
  uid: 11d28831-6914-4c42-8c93-028a4d5143f3
spec:
  endpoints:
  - honorLabels: true
    interval: 30s
    path: /metrics
    port: service
    scheme: http
    scrapeTimeout: 30s
  jobLabel: grafana
  namespaceSelector:
    matchNames:
    - monitoring
  selector:
    matchLabels:
      app.kubernetes.io/instance: grafana
      app.kubernetes.io/name: grafana

The one created by app-template for nut-exporter:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  annotations:
    meta.helm.sh/release-name: nut-exporter
    meta.helm.sh/release-namespace: monitoring
  creationTimestamp: "2024-03-27T20:54:25Z"
  generation: 1
  labels:
    app.kubernetes.io/instance: nut-exporter
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: nut-exporter
    helm.sh/chart: app-template-3.0.4
    helm.toolkit.fluxcd.io/name: nut-exporter
    helm.toolkit.fluxcd.io/namespace: monitoring
  name: nut-exporter
  namespace: monitoring
  resourceVersion: "219358039"
  uid: 32fb2710-2baf-4a5d-8784-800c2d367825
spec:
  endpoints:
  - interval: 1m
    path: /ups_metrics
    port: http
    scheme: http
    scrapeTimeout: 30s
  - interval: 1m
    path: /metrics
    port: http
    scheme: http
    scrapeTimeout: 30s
  selector:
    matchLabels:
      app.kubernetes.io/instance: nut-exporter
      app.kubernetes.io/name: nut-exporter
      app.kubernetes.io/service: main

Additional Information:

Full config is here.

https://github.com/nklmilojevic/home/blob/main/kubernetes/apps/monitoring/nut-exporter/app/helm-release.yaml

bjw-s commented 3 months ago

hi, thank you for raising this issue! This feature was never implemented, so that explains why the fields aren't available. I'll add them to the upcoming release 👍

nklmilojevic commented 3 months ago

Thank you so much for the fast answer!