apiVersion: v1
kind: Namespace
metadata:
  name: observability
spec: { }

---
apiVersion: core.oam.dev/v1beta1
kind: Application
metadata:
  annotations:
    addons.oam.dev/description: "An out of the box solution for KubeVela observability"
  name: grafana
  namespace: observability
spec:
  components:
    # install grafana datasource registration chart
    - name: grafana-registration-release
      type: helm
      properties:
        repoType: git
        url: https://github.com/oam-dev/grafana-registration
        git:
          branch: master
        chart: ./chart
        targetNamespace: observability
        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: observability
        releaseName: grafana
      type: helm
      traits:
        - type: pure-ingress
          properties:
            domain: grafana.c58136db32cbc44cca364bf1cf7f90519.cn-hongkong.alicontainer.com
            http:
              "/": 80
        - type: import-grafana-dashboard
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: observability
            credentialSecret: grafana
            credentialSecretNamespace: observability
            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/flux2/cluster.json"
              - "https://charts.kubevela.net/addons/dashboards/kubevela_application_logging.json"

    # 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: observability
        releaseName: loki
      traits:
        - type: register-grafana-datasource # register loki datasource to Grafana
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: observability
            credentialSecret: grafana
            credentialSecretNamespace: observability
            name: loki
            service: loki
            namespace: observability
            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: observability
        releaseName: prometheus
        values:
          alertmanager:
            persistentVolume:
              storageClass: "alicloud-disk-available"
              size: "20Gi"
          server:
            persistentVolume:
              storageClass: "alicloud-disk-available"
              size: "20Gi"

      traits:
        - type: register-grafana-datasource # register Prometheus datasource to Grafana
          properties:
            grafanaServiceName: grafana
            grafanaServiceNamespace: observability
            credentialSecret: grafana
            credentialSecretNamespace: observability
            name: prometheus
            service: prometheus-server
            namespace: observability
            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: observability
        values:
          image:
            repository: oamdev/kube-state-metrics
            tag: v2.1.0
