apiVersion: perses.dev/v1alpha2
kind: PersesDashboard
metadata:
  name: component-health-dashboard
  namespace: openshift-cluster-observability-operator
spec:
  config:
    display:
      name: Component Health Dashboard
    duration: 1h
    layouts:
      - kind: Grid
        spec:
          display:
            title: Component Health Overview
          items:
            - content:
                $ref: '#/spec/panels/0_0'
              height: 8
              width: 24
              x: 0
              'y': 0
      - kind: Grid
        spec:
          display:
            title: Component Details
          items:
            - content:
                $ref: '#/spec/panels/1_0'
              height: 8
              width: 24
              x: 0
              'y': 0
    panels:
      '0_0':
        kind: Panel
        spec:
          display:
            name: Top level components
          plugin:
            kind: Table
            spec:
              cellSettings:
                - condition:
                    kind: Value
                    spec:
                      value: warning
                  text: WARNING
                  textColor: '#ffb700'
                - condition:
                    kind: Value
                    spec:
                      value: error
                  text: ERROR
                  textColor: '#ff0000'
                - condition:
                    kind: Value
                    spec:
                      value: OK
                  text: OK
                  textColor: '#23c200'
              columnSettings:
                - hide: true
                  name: timestamp
                - hide: true
                  name: value
              density: comfortable
          queries:
            - kind: TimeSeriesQuery
              spec:
                plugin:
                  kind: PrometheusTimeSeriesQuery
                  spec:
                    query: >-
                      sum
                      without(job,instance,container,endpoint,namespace,pod,prometheus,service)
                      (component_health)
                    seriesNameFormat: '{{component}}'
      '1_0':
        kind: Panel
        spec:
          display:
            name: 'Component Details: ${component}'
          plugin:
            kind: Table
            spec:
              cellSettings:
                - condition:
                    kind: Value
                    spec:
                      value: warning
                  text: WARNING
                  textColor: '#ffb700'
                - condition:
                    kind: Value
                    spec:
                      value: error
                  text: ERROR
                  textColor: '#ff0000'
                - condition:
                    kind: Value
                    spec:
                      value: OK
                  text: OK
                  textColor: '#23c200'
              columnSettings:
                - hide: true
                  name: timestamp
                - hide: true
                  name: value
                - name: component
                - name: name
                - name: resource
                - name: progressing
                - name: status
              enableFiltering: true
              transforms:
                - kind: MergeColumns
                  spec:
                    columns:
                      - name
                      - src_alertname
                    name: name
          queries:
            - kind: TimeSeriesQuery
              spec:
                plugin:
                  kind: PrometheusTimeSeriesQuery
                  spec:
                    query: >-
                      sum
                      by(component,name,progressing,resource,status,src_alertname)
                      (component_health_object{component=~"${component}.*"} or
                      component_health_alert{component=~"${component}.*"})
    refreshInterval: 30s
    variables:
      - kind: ListVariable
        spec:
          allowAllValue: true
          allowMultiple: false
          defaultValue: $__all
          display:
            description: >-
              Select a component to view detailed health information. Use 'All
              Components' to see everything.
            hidden: false
            name: Component Filter
          name: component
          plugin:
            kind: PrometheusLabelValuesVariable
            spec:
              labelName: component
              matchers:
                - 'component_health{}'

