---
# yaml-language-server: $schema=https://kubernetes-schemas.pages.dev/helm.toolkit.fluxcd.io/helmrelease_v2beta2.json
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: grafana
spec:
  interval: 30m
  chartRef:
    kind: OCIRepository
    name: grafana
    namespace: flux-system
  driftDetection:
    mode: enabled
  install:
    remediation:
      retries: 3
  upgrade:
    cleanupOnFail: true
    remediation:
      retries: 3
  values:
    deploymentStrategy:
      type: RollingUpdate
    testFramework:
      enabled: false
    serviceMonitor:
      enabled: true
      metricRelabelings:
        - action: labeldrop
          regex: (pod)
    ingress:
      enabled: true
      ingressClassName: internal-nginx
      hosts:
        - &host "grafana.jahanson.tech"
      tls:
        - hosts:
            - *host
    topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app.kubernetes.io/name: grafana
    persistence:
      enabled: false
    plugins:
      - grafana-clock-panel
      - https://github.com/VictoriaMetrics/victorialogs-datasource/releases/download/v0.4.0/victorialogs-datasource-v0.4.0.zip;victorialogs-datasource
      - https://github.com/VictoriaMetrics/victoriametrics-datasource/releases/download/v0.9.0/victoriametrics-datasource-v0.9.0.zip;victoriametrics-datasource

    datasources:
      datasources.yaml:
        apiVersion: 1
        deleteDatasources:
          - { name: Alertmanager, orgId: 1 }
          - { name: Loki, orgId: 1 }
          - { name: Prometheus, orgId: 1 }
        datasources:
          - name: Prometheus
            type: prometheus
            uid: prometheus
            access: proxy
            url: http://vmsingle-victoria.observability.svc:8429
            isDefault: true
            jsonData:
              prometheusType: Prometheus
              timeInterval: 60s
          - name: VictoriaMetrics
            type: victoriametrics-datasource
            access: proxy
            url: http://vmsingle-stack.observability.svc:8429
          - name: VictoriaLogs
            type: victorialogs-datasource
            access: proxy
            url: http://victoria-logs.observability:9428
          - name: Alertmanager
            type: alertmanager
            uid: alertmanager
            access: proxy
            url: http://alertmanager.observability.svc.cluster.local:9093
            jsonData:
              implementation: prometheus

    dashboardProviders:
      dashboardproviders.yaml:
        apiVersion: 1
        providers:
          - name: default
            orgId: 1
            folder: ""
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/default
          - name: flux
            orgId: 1
            folder: Flux
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/flux
          - name: kubernetes
            orgId: 1
            folder: Kubernetes
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/kubernetes
          - name: nginx
            orgId: 1
            folder: Nginx
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/nginx
          - name: observability
            orgId: 1
            folder: Observability
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/observability
          - name: postgres
            orgId: 1
            folder: Postgres
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/postgres
          - name: rook-ceph
            orgId: 1
            folder: Rook-Ceph
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/rook-ceph
          - name: unifi
            orgId: 1
            folder: Unifi
            type: file
            disableDeletion: false
            editable: true
            options:
              path: /var/lib/grafana/dashboards/unifi
    dashboards:
      default:
        cloudflared:
          # renovate: depName="Cloudflare Tunnels (cloudflared)"
          gnetId: 17457
          revision: 6
          datasource:
            - { name: DS_PROMETHEUS, value: Prometheus }
        external-dns:
          # renovate: depName="External-dns"
          gnetId: 15038
          revision: 3
          datasource: Prometheus
        node-exporter-full:
          # renovate: depName="Node Exporter Full"
          gnetId: 1860
          revision: 37
          datasource: Prometheus
        nut-exporter:
          # renovate: depName="Prometheus NUT Exporter for DRuggeri"
          gnetId: 19308
          revision: 3
          datasource:
            - { name: DS_PROMETHEUS, value: Prometheus }
        smart:
          # renovate: depName="Dashboard for smartctl_exporter"
          gnetId: 20204
          revision: 1
          datasource:
            - { name: DS_PROMETHEUS, value: Prometheus }
        volsync:
          # removate: depName="VolSync Dashboard"
          gnetId: 21356
          revision: 3
          datasource:
            - { name: DS_PROMETHEUS, value: Prometheus }
            - { name: VAR_REPLICATIONDESTNAME, value: .*-dst }
        zfs-stats:
          # removate: depName="ZFS Stats"
          gnetId: 7968
          revision: 1
        cert-manager:
          url: https://gitlab.com/uneeq-oss/cert-manager-mixin/-/raw/master/dashboards/cert-manager.json?ref_type=heads
          datasource: Prometheus
        external-secrets:
          url: https://raw.githubusercontent.com/external-secrets/external-secrets/main/docs/snippets/dashboard.json
          datasource: Prometheus
        node-feature-discovery:
          url: https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/master/examples/grafana-dashboard.json
          datasource: Prometheus
      flux:
        flux-cluster:
          url: https://raw.githubusercontent.com/fluxcd/flux2-monitoring-example/main/monitoring/configs/dashboards/cluster.json
          datasource: Prometheus
        flux-control-plane:
          url: https://raw.githubusercontent.com/fluxcd/flux2-monitoring-example/main/monitoring/configs/dashboards/control-plane.json
          datasource: Prometheus
      kubernetes:
        k8s-system-api-server:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-system-api-server.json
          token: ''
        k8s-system-coredns:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-system-coredns.json
          token: ''
        k8s-views-global:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-global.json
          token: ''
        k8s-views-namespaces:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-namespaces.json
          token: ''
        k8s-views-nodes:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-nodes.json
          token: ''
        k8s-views-pods:
          url: https://raw.githubusercontent.com/dotdc/grafana-dashboards-kubernetes/master/dashboards/k8s-views-pods.json
          token: ''
      nginx:
        nginx:
          url: https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/grafana/dashboards/nginx.json
          datasource: Prometheus
        nginx-request-handling-performance:
          url: https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/grafana/dashboards/request-handling-performance.json
          datasource: Prometheus
      observability:
        prometheus:
          # renovate: depName="Prometheus"
          gnetId: 19105
          revision: 6
          datasource: Prometheus
        victoria-agent:
          # renovate: depName="VictoriaMetrics - vmagent"
          gnetId: 12683
          revision: 21
          datasource: Prometheus
        victoria-alert:
          # renovate: depName="VictoriaMetrics - vmalert"
          gnetId: 14950
          revision: 13
          datasource: Prometheus
        victoria-operator:
          # renovate: depName="VictoriaMetrics - operator"
          gnetId: 17869
          revision: 3
          datasource: Prometheus
        victoria-single:
          # renovate: depName="VictoriaMetrics - single-node"
          gnetId: 10229
          revision: 37
          datasource: Prometheus
      postgres:
        crunchy-pgbackrest:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/pgbackrest.json
          datasource: Prometheus
        crunchy-pod-details:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/pod_details.json
          datasource: Prometheus
        crunchy-postgresql-details:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/postgresql_details.json
          datasource: Prometheus
        crunchy-postgresql-overview:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/postgresql_overview.json
          datasource: Prometheus
        crunchy-postgresql-service_health:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/postgresql_service_health.json
          datasource: Prometheus
        crunchy-prometheus-alerts:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/prometheus_alerts.json
          datasource: Prometheus
        crunchy-query-statistics:
          url: https://raw.githubusercontent.com/CrunchyData/postgres-operator-examples/main/kustomize/monitoring/grafana/dashboards/query_statistics.json
          datasource: Prometheus
      rook-ceph:
        rook-ceph-cluster:
          # renovate: depName="Ceph Cluster"
          gnetId: 2842
          revision: 18
          datasource: Prometheus
        rook-ceph-osd-single:
          # renovate: depName="Ceph - OSD (Single)"
          gnetId: 5336
          revision: 9
          datasource: Prometheus
        rook-ceph-pools:
          # renovate: depName="Ceph - Pools"
          gnetId: 5342
          revision: 9
          datasource: Prometheus
      unifi:
        unifi-insights:
          # renovate: depName="UniFi-Poller: Client Insights - Prometheus"
          gnetId: 11315
          revision: 9
          datasource: Prometheus
        unifi-network-sites:
          # renovate: depName="UniFi-Poller: Network Sites - Prometheus"
          gnetId: 11311
          revision: 5
          datasource: Prometheus
        unifi-uap:
          # renovate: depName="UniFi-Poller: UAP Insights - Prometheus"
          gnetId: 11314
          revision: 10
          datasource: Prometheus
        unifi-usw:
          # renovate: depName="UniFi-Poller: USW Insights - Prometheus"
          gnetId: 11312
          revision: 9
          datasource: Prometheus

    ## Grafana's primary configuration
    ## NOTE: values in map will be converted to ini format
    ## ref: http://docs.grafana.org/installation/configuration/
    ##
    grafana.ini:
      analytics:
        check_for_updates: false
        check_for_plugin_updates: false
        reporting_enabled: false
      auth:
        disable_login_form: true
      auth.anonymous:
        enabled: true
      news:
        news_feed_enabled: false
      plugins:
        allow_loading_unsigned_plugins: "victorialogs-datasource,victoriametrics-datasource"
      users:
        allow_sign_up: false
        auto_assign_org: true
        auto_assign_org_role: Admin

    sidecar:
      dashboards:
        enabled: true
        searchNamespace: ALL
        folderAnnotation: grafana_folder
        provider:
          disableDelete: true
          foldersFromFilesStructure: true
      datasources:
        enabled: true
        searchNamespace: ALL
      enableUniqueFilenames: true