---
apiVersion: v1
kind: ConfigMap
metadata:
  name: thanos-receiver-dashboard
  namespace: kubenav
  labels:
    kubenav.io/prometheus-dashboard: "true"
data:
  title: "Thanos Receiver"
  description: "Dashboard for Thanos Receiver Metrics"
  variables: |
    [
      {
        "name": "Namespace",
        "label": "namespace",
        "query": "thanos_receive_forward_requests_total",
        "allowAll": false
      },
      {
        "name": "Pod",
        "label": "pod",
        "query": "thanos_receive_forward_requests_total{namespace=~\"{{ .Namespace }}\"}",
        "allowAll": true
      }
    ]
  charts: |
    [
      {
        "title": "Incoming Request: Rate",
        "unit": "",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "{{ .status_code }}",
            "query": "sum(label_replace(rate(http_requests_total{handler=\"receive\", namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\"}[5m]), \"status_code\", \"${1}xx\", \"code\", \"([0-9])..\")) by (status_code)"
          }
        ]
      },
      {
        "title": "Incoming Request: Errors",
        "unit": "%",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "Errors",
            "query": "sum(rate(http_requests_total{handler=\"receive\", namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\",code=~\"5..\"}[5m])) / sum(rate(http_requests_total{handler=\"receive\", namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\"}[5m])) * 100"
          }
        ]
      },
      {
        "title": "Incoming Request: Duration",
        "unit": "s",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "P99",
            "query": "histogram_quantile(0.99, sum(rate(http_request_duration_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", handler=\"receive\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P90",
            "query": "histogram_quantile(0.90, sum(rate(http_request_duration_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", handler=\"receive\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P50",
            "query": "histogram_quantile(0.50, sum(rate(http_request_duration_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", handler=\"receive\"}[5m])) by (le)) * 1"
          },
          {
            "label": "Mean",
            "query": "sum(rate(http_request_duration_seconds_sum{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", handler=\"receive\"}[5m])) * 1 / sum(rate(http_request_duration_seconds_count{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", handler=\"receive\"}[5m]))"
          }
        ]
      },
      {
        "title": "Forward Request: Rate",
        "unit": "",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "6",
          "xl": "6"
        },
        "type": "area",
        "queries": [
          {
            "label": "{{ .pod }}",
            "query": "sum(rate(thanos_receive_forward_requests_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\"}[5m]))"
          }
        ]
      },
      {
        "title": "Forward Request: Errors",
        "unit": "%",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "6",
          "xl": "6"
        },
        "type": "area",
        "queries": [
          {
            "label": "Errors",
            "query": "sum(rate(thanos_receive_forward_requests_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", result=\"error\"}[5m])) / sum(rate(thanos_receive_forward_requests_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\"}[5m])) * 100"
          }
        ]
      },
      {
        "title": "gRPC (Unary): Rate",
        "unit": "",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "{{ .grpc_code }}",
            "query": "sum(rate(grpc_server_handled_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) by (grpc_code)"
          }
        ]
      },
      {
        "title": "gRPC (Unary): Errors",
        "unit": "%",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "Errors",
            "query": "sum(rate(grpc_server_handled_total{grpc_code=~\"Unknown|ResourceExhausted|Internal|Unavailable\", namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) / sum(rate(grpc_server_started_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) * 100"
          }
        ]
      },
      {
        "title": "gRPC (Unary): Duration",
        "unit": "s",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "P99",
            "query": "histogram_quantile(0.99, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P90",
            "query": "histogram_quantile(0.90, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P50",
            "query": "histogram_quantile(0.50, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) by (le)) * 1"
          },
          {
            "label": "Mean",
            "query": "sum(rate(grpc_server_handling_seconds_sum{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m])) * 1 / sum(rate(grpc_server_handling_seconds_count{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"unary\"}[5m]))"
          }
        ]
      },
      {
        "title": "gRPC (Stream): Rate",
        "unit": "",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "{{ .grpc_code }}",
            "query": "sum(rate(grpc_server_handled_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) by (grpc_code)"
          }
        ]
      },
      {
        "title": "gRPC (Stream): Errors",
        "unit": "%",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "Errors",
            "query": "sum(rate(grpc_server_handled_total{grpc_code=~\"Unknown|ResourceExhausted|Internal|Unavailable\", namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) / sum(rate(grpc_server_started_total{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) * 100"
          }
        ]
      },
      {
        "title": "gRPC (Stream): Duration",
        "unit": "s",
        "size": {
          "xs": "12",
          "sm": "12",
          "md": "12",
          "lg": "4",
          "xl": "4"
        },
        "type": "area",
        "queries": [
          {
            "label": "P99",
            "query": "histogram_quantile(0.99, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P90",
            "query": "histogram_quantile(0.90, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) by (le)) * 1"
          },
          {
            "label": "P50",
            "query": "histogram_quantile(0.50, sum(rate(grpc_server_handling_seconds_bucket{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) by (le)) * 1"
          },
          {
            "label": "Mean",
            "query": "sum(rate(grpc_server_handling_seconds_sum{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m])) * 1 / sum(rate(grpc_server_handling_seconds_count{namespace=~\"{{ .Namespace }}\", pod=~\"{{ .Pod }}\", grpc_type=\"server_stream\"}[5m]))"
          }
        ]
      }
    ]
