{{- if .Values.enabled | default false }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: datasources
data:
  datasources.yaml: |
    apiVersion: 1 
    datasources:
      - name: Prometheus
        type: prometheus
        typeName: Prometheus
        typeLogoUrl: public/app/plugins/datasource/prometheus/img/prometheus_logo.svg
        access: proxy
        url: {{ .Values.env.prometheusUrl }}
        uid: af6b44aa-0703-4979-825c-c1afba946534
        user: ''
        database: ''
        basicAuth: false
        isDefault: false
        jsonData:
          httpMethod: POST
          prometheusType: Prometheus
          prometheusVersion: 2.40.1
        readOnly: false
      - name: Loki
        type: loki
        uid: e4f43364-7019-45a7-aa7a-14ce2d4ddb0b
        typeName: Loki
        typeLogoUrl: public/app/plugins/datasource/loki/img/loki_icon.svg
        access: proxy
        url: {{ .Values.env.lokiUrl }}
        user: ''
        database: ''
        basicAuth: false
        isDefault: false
        jsonData:
          derivedFields:
          - datasourceUid: fee7e008-f836-424a-b701-88cad583c715
            matcherRegex: '"traceID":\s*"([a-fA-F0-9]+)"'
            name: traceID
            url: "$${__value.raw}"
        readOnly: false
      - name: Tempo
        type: tempo
        typeName: Tempo
        typeLogoUrl: public/app/plugins/datasource/tempo/img/tempo_logo.svg
        uid: fee7e008-f836-424a-b701-88cad583c715
        access: proxy
        url: {{ .Values.env.tempoUrl }} 
        user: ''
        database: ''
        basicAuth: false
        isDefault: false
        jsonData:
          lokiSearch:
            datasourceUid: e4f43364-7019-45a7-aa7a-14ce2d4ddb0b
        readOnly: false
---

apiVersion: v1
kind: ConfigMap
metadata:
  name: default
data:
  default.yaml: |
    apiVersion: 1
    providers:
      - name: Default # A uniquely identifiable name for the provider
        orgId: 1
        folder: "" # The folder where to place the dashboards
        folderUid: ""
        type: file
        disableDeletion: false
        allowUiUpdates: true
        options:
          path: /var/lib/grafana/dashboards

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: kubernetes-dashboard
data:
  kubernetes-dashboard.json: |
{{ .Files.Get "kubernetes-dashboard.json" | indent 4 }}

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: loki-logs
data:
  loki-logs.json: |
{{ .Files.Get "loki-logs.json" | indent 4 }}
{{- end }}