- name: observability
  namespace: observability
  create_namespace: true
  chart_ref: {{ .Modules.Observability.ChartRef }}
  chart_version: {{ .Modules.Observability.ChartVersion }}
  {{- if .Modules.Observability.Enabled }}
  release_state: "present"
  {{- else }}
  release_state: "absent"
  {{- end }}
  values:
    prometheus:
      enabled: {{ .Modules.Observability.Monitoring.Enabled }}
      serviceMonitor: true
      image:
        repository: {{ .Modules.Observability.Monitoring.Prometheus.Image }}
        tag: {{ .Modules.Observability.Monitoring.Prometheus.Tag }}
        pullPolicy: IfNotPresent

      clustering:
        enabled: false
        replicas: 3
        shards: 1

      persistence:
        enabled: true

        storageClassName: "{{ .Modules.Observability.Monitoring.Prometheus.Persistence.StorageClass }}"
        storageResources:
          requests:
            storage: {{ .Modules.Observability.Monitoring.Prometheus.Persistence.StorageSize }}

      scrapeInterval: {{ .Modules.Observability.Monitoring.Prometheus.ScrapeInterval }}
      retention: {{ .Modules.Observability.Monitoring.Prometheus.Persistence.Retention }}
      # serviceNodePort: 30008

      additionalConfigs: |
        - job_name: "kubelet"
          scheme: https
          metrics_path: /metrics/cadvisor
          tls_config:
            insecure_skip_verify: true
          authorization:
            credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
          kubernetes_sd_configs:
            - role: node
          relabel_configs:
            - action: labelmap
              regex: __meta_kubernetes_node_label_(.+)

        - job_name: "kubernetes-apiservers"
          kubernetes_sd_configs:
            - role: endpoints
          scheme: https
          tls_config:
            ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
          authorization:
            credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
          relabel_configs:
            - source_labels:
                [
                  __meta_kubernetes_namespace,
                  __meta_kubernetes_service_name,
                  __meta_kubernetes_endpoint_port_name,
                ]
              action: keep
              regex: default;kubernetes;https

        - job_name: "coredns"
          kubernetes_sd_configs:
            - role: endpoints
          scheme: http
          relabel_configs:
            - source_labels:
                [
                  __meta_kubernetes_namespace,
                  __meta_kubernetes_service_name,
                  __meta_kubernetes_endpoint_port_name,
                ]
              action: keep
              regex: kube-system;.*dns.*;metrics

        - job_name: 'ingress-endpoints'
          metrics_path: /probe
          params:
            module: [https_ok]
          kubernetes_sd_configs:
            - role: ingress
          relabel_configs:
            - source_labels: [__address__]
              target_label: __param_target
            - source_labels: [__param_target]
              target_label: instance
            - source_labels:
                [
                  __meta_kubernetes_ingress_scheme,
                  __address__,
                  __meta_kubernetes_ingress_path,
                ]
              regex: (.+);(.+);(.+)
              replacement: https://${2}${3}
              target_label: __param_target
            - target_label: __address__
              replacement: observability-blackbox-exporter:9115

    alertManager:
      enabled: {{ .Modules.Observability.Monitoring.AlertManager.Enabled }}
      serviceMonitor: {{ .Modules.Observability.Monitoring.Enabled }}
      enableDefaultRules: true
      image:
        repository: {{ .Modules.Observability.Monitoring.AlertManager.Image }}
        tag: "{{ .Modules.Observability.Monitoring.AlertManager.Tag }}"
        pullPolicy: IfNotPresent

      # serviceNodePort: 30009

      configPath: /etc/alertmanager
      {{- if .Modules.Observability.Monitoring.AlertManager.AdditionalMessageTemplates }}
      additionalMessageTemplates:
        {{- .Modules.Observability.Monitoring.AlertManager.AdditionalMessageTemplates | toYaml | nindent 8 }}
      {{- end }}
      {{- if .Modules.Observability.Monitoring.AlertManager.Route }}
      route:
        {{- .Modules.Observability.Monitoring.AlertManager.Route | toYaml | nindent 8 }}
      {{- end }}
      {{- if .Modules.Observability.Monitoring.AlertManager.Receivers }}
      receivers:
        {{- .Modules.Observability.Monitoring.AlertManager.Receivers | toYaml | nindent 8 }}
      {{- end }}

    blackboxExporter:
      enabled: {{ .Modules.Observability.Monitoring.Blackbox.Enabled }}
      serviceMonitor: {{ .Modules.Observability.Monitoring.Enabled }}
      image:
        repository: {{ .Modules.Observability.Monitoring.Blackbox.Image }}
        tag: "{{ .Modules.Observability.Monitoring.Blackbox.Tag }}"
        pullPolicy: IfNotPresent

      # serviceNodePort: 30012

      configPath: /etc/blackbox_exporter
      additionalModules:


    kubeStateMetrics:
      enabled: {{ .Modules.Observability.Monitoring.KubeState.Enabled }}
      image:
        repository: {{ .Modules.Observability.Monitoring.KubeState.Image }}
        tag: "{{ .Modules.Observability.Monitoring.KubeState.Tag }}"
        pullPolicy: IfNotPresent
      resources:
        requests:
          cpu: 30m
          memory: 120Mi
        limits:
          memory: 240Mi
          cpu: 60m

    prometheusOperator:
      enabled: {{ .Modules.Observability.Monitoring.Enabled }}
      image:
        repository: {{ .Modules.Observability.Monitoring.Prometheus.Operator.Image }}
        tag: {{ .Modules.Observability.Monitoring.Prometheus.Operator.Tag }}
        pullPolicy: IfNotPresent

      prometheusConfigReloader:
        image:
          repository: {{ .Modules.Observability.Monitoring.Prometheus.Operator.ConfigReloader.Image }}
          tag: {{ .Modules.Observability.Monitoring.Prometheus.Operator.ConfigReloader.Tag }}
          pullPolicy: IfNotPresent

      kubeRbacProxy:
        image:
          repository: {{ .Modules.Observability.Monitoring.Prometheus.Operator.KubeRbacProxy.Image }}
          tag: {{ .Modules.Observability.Monitoring.Prometheus.Operator.KubeRbacProxy.Tag }}
          pullPolicy: IfNotPresent

    nodeExporter:
      enabled: {{ .Modules.Observability.Monitoring.Node.Enabled }}
      image:
        repository: {{ .Modules.Observability.Monitoring.Node.Image }}
        tag: {{ .Modules.Observability.Monitoring.Node.Tag }}
        pullPolicy: IfNotPresent

    kubeEventsExporter:
      enabled: {{ and .Modules.Observability.Logging.Enabled .Modules.Observability.Logging.Events.Enabled }}
      image:
        repository: {{ .Modules.Observability.Logging.Events.Exporter.Image }}
        tag: {{ .Modules.Observability.Logging.Events.Exporter.Tag }}
        pullPolicy: IfNotPresent
      lokiAddress: http://loki.observability.svc.cluster.local:3100
      logLevel: warn
      logFormat: json
      kubeQPS: 100
      kubeBurst: 500
      maxEventAgeSeconds: 120
      metricsNamePrefix: event_exporter_

      cron:
        restartSchedule: "{{ .Modules.Observability.Logging.Events.Cron.Schedule }}"
        image:
          repository: {{ .Modules.Observability.Logging.Events.Cron.Image }}
          tag: {{ .Modules.Observability.Logging.Events.Cron.Tag }}
          pullPolicy: IfNotPresent
      additionalRoutes:
      additionalReceivers:

    grafana:
      enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Visualization.Grafana.Enabled }}
      serviceMonitor: {{ .Modules.Observability.Monitoring.Enabled }}
      domain: &grafanaDomain {{ .Modules.Observability.Visualization.Grafana.Expose.Domain }}
      path: {{ .Modules.Observability.Visualization.Grafana.Expose.Path }}
      {{- if eq .Modules.Observability.Visualization.Grafana.Expose.Type "NodePort" }}
      serviceNodePort: {{ .Modules.Observability.Visualization.Grafana.Expose.NodePortHttp }}
      {{- end }}
      image:
        repository: {{ .Modules.Observability.Visualization.Grafana.Image }}
        tag: {{ .Modules.Observability.Visualization.Grafana.Tag }}
        pullPolicy: IfNotPresent

      storageClassName: "{{ .Modules.Observability.Visualization.Grafana.Persistence.StorageClass }}"
      storageResources:
        requests:
          storage: {{ .Modules.Observability.Visualization.Grafana.Persistence.StorageSize }}

      config:
        server: |
          enable_gzip = true
          root_url = {{ if .Modules.Observability.Visualization.Grafana.Expose.Tls.Enabled }}https{{ else }}http{{ end }}://{{ .Modules.Observability.Visualization.Grafana.Expose.Domain }}{{ .Modules.Observability.Visualization.Grafana.Expose.Path }}
          {{- if not (eq .Modules.Observability.Visualization.Grafana.Expose.Path  "/") }}
          serve_from_sub_path = true
          {{- end }}

        security: |
          admin_user = admin
          admin_password = {{ .Modules.AdminPassword }}

        auth: |
          {{- .Modules.Observability.Visualization.Grafana.Config.Auth | toString | nindent 10 }}

        authGenericAuth: |
          {{- .Modules.Observability.Visualization.Grafana.Config.AuthGenericAuth | toString | nindent 10 }}

        additionalDatasources:
          {{- if and .Modules.Observability.Enabled .Modules.Observability.Logging.Enabled }}
          - name: Kube-loki
            type: loki
            uid: P2895588539814C92
            access: proxy
            url: http://loki:3100
            editable: false
            basicAuth: false
            isDefault: false
            jsonData:
              maxLines: 1000
          {{- end }}
          {{- if and .Modules.Observability.Enabled .Modules.Observability.Tracing.Enabled }}
          - name: Kube-jaeger-query
            type: jaeger
            access: proxy
            url: http://tempo:16686
            editable: false
            basicAuth: false
            isDefault: false
          {{- end }}
          {{- if .Modules.Observability.Visualization.Grafana.Config.AdditionalDatasources }}
          {{- .Modules.Observability.Visualization.Grafana.Config.AdditionalDatasources | toYaml | nindent 10 }}
          {{- end }}

    opentelemetryCollector:
      enabled: {{ and .Modules.Observability.Enabled .Modules.Observability.Tracing.Enabled }}
      serviceMonitor: true
      config: |
        receivers:
          otlp:
            protocols:
              grpc:
              http:
        exporters:
          otlphttp:
            endpoint: http://tempo:4318
        service:
          telemetry:
            logs:
              level: "debug"
          pipelines:
            traces:
              receivers: [otlp]
              exporters: [otlphttp]

    ingress:
      {{- if and .Modules.Observability.Visualization.Grafana.Enabled (eq .Modules.Observability.Visualization.Grafana.Expose.Type "ingress") }}
      enabled: true
      {{- else }}
      enabled: false
      {{- end }}
      accountEmail: {{ .Modules.Additional.CertManager.AccountEmail }}
      class: {{ .Modules.Additional.Ingress.Type }}
      annotations:
        {{- if eq .Modules.Additional.Ingress.Type "nginx" }}
        nginx.ingress.kubernetes.io/proxy-buffer-size: "128k"
        nginx.ingress.kubernetes.io/proxy-buffers: "4 256k"
        nginx.ingress.kubernetes.io/proxy-busy-buffers-size: "256k"
        {{- end }}
      tls:
        {{- if .Modules.Observability.Visualization.Grafana.Expose.Tls.Enabled }}
        enabled: true
        {{- end }}
        hosts:
          - host: {{ .Modules.Observability.Visualization.Grafana.Expose.Domain }}
            secretName: grafana-tls

    containerRuntime: {{ .Orchestrator.ContainerEngine.Type }}

    fluentbit:
      enable: {{ and .Modules.Observability.Enabled .Modules.Observability.Logging.Enabled }}
      serviceMonitor: true
      image:
        repository: "{{ .Modules.Observability.Logging.FluentBit.Image }}"
        tag: "{{ .Modules.Observability.Logging.FluentBit.Tag }}"

      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: node-role.kubernetes.io/edge
                    operator: DoesNotExist
      tolerations:
        - operator: Exists

      input:
        tail:
          enable: true
          refreshIntervalSeconds: 10
          memBufLimit: 100MB
          bufferMaxSize: ""
          path: "/var/log/containers/*.log"
          skipLongLines: true
          readFromHead: false
          storageType: memory
          pauseOnChunksOverlimit: "off"
        systemd:
          enable: true
          systemdFilter:
            enable: true
            filters: []
          path: "/var/log/journal"
          includeKubelet: true
          stripUnderscores: "off"
          storageType: memory
          pauseOnChunksOverlimit: "off"

        nodeExporterMetrics: {}
        fluentBitMetrics: {}

      output:
        es:
          enable: false
          host: "<Elasticsearch url like elasticsearch-logging-data.kubesphere-logging-system.svc>"
          port: 9200
          logstashPrefix: ks-logstash-log
          bufferSize: 20MB
          traceError: true
        kafka:
          enable: false
          brokers: "<kafka broker list like xxx.xxx.xxx.xxx:9092,yyy.yyy.yyy.yyy:9092>"
          topics: ks-log
        opentelemetry: {}
        opensearch:
          enable: false
        stdout:
          enable: false
        loki:
          enable: true
          host: loki
          port: 3100

        stackdriver: {}

      service:
        storage: {}

      filter:
        kubernetes:
          enable: true
          labels: true
          annotations: true
        containerd:
          enable: true
        systemd:
          enable: true

      kubeedge:
        enable: false
        prometheusRemoteWrite:
          # Change the host to the address of a cloud-side Prometheus-compatible server that can receive Prometheus remote write data
          host: "<cloud-prometheus-service-host>"
          # Change the port to the port of a cloud-side Prometheus-compatible server that can receive Prometheus remote write data
          port: "<cloud-prometheus-service-port>"
