apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  annotations:
    addons.oam.dev/description: "An out of the box solution for KubeVela observability"
  name: observability
  namespace: vela-system
spec:
  workflow:
    steps:
      - name: checking-depends-on
        type: depends-on-app
        properties:
          name: fluxcd
          namespace: vela-system
      - name: apply-resources
        type: apply-remaining
  components:
    - name: grafana-registration
      type: helm
      properties:
        repoType: git
        url: https://github.com/oam-dev/grafana-registration
        git:
          branch: master
        chart: ./chart
        targetNamespace: vela-system
        values:
          replicaCount: 1

    # install Grafana
    - name: grafana
      properties:
        chart: grafana
        version: 6.14.1
        repoType: helm
        # original url: https://grafana.github.io/helm-charts
        url: https://charts.kubevela.net/addons
        targetNamespace: vela-system
        releaseName: grafana
      type: helm
      traits:
        - type: pure-ingress
          properties:
            domain: '[[ index .Args "grafana-domain" ]]'
            http:
              "/": 80
        - type: import-grafana-dashboard
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: vela-system
            credentialSecret: grafana
            credentialSecretNamespace: vela-system
            urls:
              - https://charts.kubevela.net/addons/dashboards/kubevela_core_logging.json
              - https://charts.kubevela.net/addons/dashboards/kubevela_core_monitoring.json
              - https://charts.kubevela.net/addons/dashboards/kubevela_application_logging.json
              - https://charts.kubevela.net/addons/dashboards/flux2/cluster.json # fluxcd

    # install loki
    - name: loki
      type: helm
      properties:
        chart: loki-stack
        version: 2.4.1
        repoType: helm
        # original url: https://grafana.github.io/helm-charts
        url: https://charts.kubevela.net/addons
        targetNamespace: vela-system
        releaseName: loki
      traits:
        - type: register-grafana-datasource # register loki datasource to Grafana
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: vela-system
            credentialSecret: grafana
            credentialSecretNamespace: vela-system
            name: loki
            service: loki
            namespace: vela-system
            type: loki
            access: proxy

      # install Prometheus
    - name: prometheus-server
      type: helm
      properties:
        chart: prometheus
        version: 14.4.1
        repoType: helm
        # original url: https://prometheus-community.github.io/helm-charts
        url: https://charts.kubevela.net/addons
        targetNamespace: vela-system
        releaseName: prometheus
        values:
          alertmanager:
            persistentVolume:
              enabled: '[[ index .Args "alertmanager-pvc-enabled" | default "true" ]]'
              storageClass: '[[ index .Args "alertmanager-pvc-class" ]]'
              size: '[[ index .Args "alertmanager-pvc-size" | default "20Gi" ]]'
          server:
            persistentVolume:
              enabled: '[[ index .Args "server-pvc-enabled" | default "true" ]]'
              storageClass: '[[ index .Args "server-pvc-class" ]]'
              size: '[[ index .Args "server-pvc-size" | default "20Gi" ]]'
      traits:
        - type: register-grafana-datasource # register Prometheus datasource to Grafana
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: vela-system
            credentialSecret: grafana
            credentialSecretNamespace: vela-system
            name: prometheus
            service: prometheus-server
            namespace: vela-system
            type: prometheus
            access: proxy

    # install kube-state-metrics
    - name: kube-state-metrics
      type: helm
      properties:
        chart: kube-state-metrics
        version: 3.4.1
        repoType: helm
        # original url: https://prometheus-community.github.io/helm-charts
        url: https://charts.kubevela.net/addons
        targetNamespace: vela-system
        values:
          image:
            repository: oamdev/kube-state-metrics
            tag: v2.1.0
{{ range .ResourceFiles }}
    - name: {{ .Name }}
      type: raw
      properties:
{{ .Content | indent 8 }} {{ end }}
{{ range .DefinitionFiles }}
    - name: {{ .Name }}
      type: raw
      properties:
{{ .Content | indent 8 }} {{ end }}
