{
  "title": "Talooner — PR review activity",
  "uid": "talooner-pr-review",
  "tags": [
    "talooner",
    "code-review"
  ],
  "timezone": "browser",
  "schemaVersion": 39,
  "editable": true,
  "time": {
    "from": "now-7d",
    "to": "now"
  },
  "refresh": "1m",
  "templating": {
    "list": [
      {
        "name": "datasource",
        "label": "Prometheus",
        "type": "datasource",
        "query": "prometheus",
        "current": {},
        "hide": 0
      },
      {
        "name": "repo",
        "label": "Repository",
        "type": "query",
        "datasource": {
          "type": "prometheus",
          "uid": "${datasource}"
        },
        "query": "label_values(talooner_pr_evaluations_total, repo)",
        "includeAll": true,
        "multi": true,
        "current": {
          "text": "All",
          "value": "$__all"
        },
        "refresh": 2
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "title": "Auto-approval rate",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 8,
        "x": 0,
        "y": 0
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "min": 0,
          "max": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "yellow",
                "value": 0.3
              },
              {
                "color": "green",
                "value": 0.6
              }
            ]
          }
        }
      },
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum(rate(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\", verdict=\"approve\"}[$__rate_interval])) / clamp_min(sum(rate(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval])), 1e-9)"
        }
      ]
    },
    {
      "id": 2,
      "title": "Needs a human (block) rate",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 8,
        "x": 8,
        "y": 0
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "min": 0,
          "max": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "yellow",
                "value": 0.3
              },
              {
                "color": "red",
                "value": 0.6
              }
            ]
          }
        }
      },
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum(rate(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\", verdict=\"block\"}[$__rate_interval])) / clamp_min(sum(rate(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval])), 1e-9)"
        }
      ]
    },
    {
      "id": 3,
      "title": "Evaluation error rate",
      "type": "stat",
      "gridPos": {
        "h": 5,
        "w": 8,
        "x": 16,
        "y": 0
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "percentunit",
          "min": 0,
          "max": 1,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "yellow",
                "value": 0.01
              },
              {
                "color": "red",
                "value": 0.05
              }
            ]
          }
        }
      },
      "options": {
        "colorMode": "value",
        "graphMode": "area",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum(rate(talooner_action_requests_total{repo=~\"$repo\", result=\"error\"}[$__rate_interval])) / clamp_min(sum(rate(talooner_action_requests_total{repo=~\"$repo\"}[$__rate_interval])), 1e-9)"
        }
      ]
    },
    {
      "id": 4,
      "title": "Verdict mix over time (execute)",
      "type": "timeseries",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 5
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "fillOpacity": 40,
            "stacking": {
              "mode": "normal"
            }
          }
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (verdict) (rate(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval]))",
          "legendFormat": "{{verdict}}"
        }
      ]
    },
    {
      "id": 5,
      "title": "Evaluation latency (p50 / p95 / p99)",
      "type": "timeseries",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 5
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "s",
          "custom": {
            "drawStyle": "line",
            "fillOpacity": 10
          }
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "histogram_quantile(0.50, sum by (le) (rate(talooner_pr_evaluation_duration_seconds_bucket{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval])))",
          "legendFormat": "p50"
        },
        {
          "refId": "B",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "histogram_quantile(0.95, sum by (le) (rate(talooner_pr_evaluation_duration_seconds_bucket{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval])))",
          "legendFormat": "p95"
        },
        {
          "refId": "C",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "histogram_quantile(0.99, sum by (le) (rate(talooner_pr_evaluation_duration_seconds_bucket{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval])))",
          "legendFormat": "p99"
        }
      ]
    },
    {
      "id": 6,
      "title": "Top repositories",
      "type": "table",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 13
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "options": {
        "showHeader": true
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "topk(10, sum by (repo) (increase(talooner_pr_evaluations_total{repo=~\"$repo\", mode=\"execute\"}[$__range])))",
          "instant": true,
          "format": "table"
        }
      ]
    },
    {
      "id": 7,
      "title": "Action mix (execute)",
      "type": "piechart",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 13
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "right"
        },
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ]
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (verb) (increase(talooner_pr_actions_total{repo=~\"$repo\", mode=\"execute\"}[$__range]))",
          "legendFormat": "{{verb}}",
          "instant": true
        }
      ]
    },
    {
      "id": 8,
      "title": "LLM reviews by result",
      "type": "timeseries",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 21
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "fillOpacity": 40,
            "stacking": {
              "mode": "normal"
            }
          }
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (result) (rate(talooner_llm_reviews_total{repo=~\"$repo\"}[$__rate_interval]))",
          "legendFormat": "{{result}}"
        }
      ]
    },
    {
      "id": 9,
      "title": "Warnings by code (ruleset health)",
      "type": "timeseries",
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 21
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "unit": "ops",
          "custom": {
            "drawStyle": "line",
            "fillOpacity": 20
          }
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (code) (rate(talooner_pr_warnings_total{repo=~\"$repo\"}[$__rate_interval]))",
          "legendFormat": "{{code}}"
        }
      ]
    },
    {
      "id": 10,
      "title": "Rules fired per evaluation (execute)",
      "type": "heatmap",
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 29
      },
      "datasource": {
        "type": "prometheus",
        "uid": "${datasource}"
      },
      "options": {
        "calculate": false,
        "cellGap": 1,
        "yAxis": {
          "unit": "short"
        }
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "prometheus",
            "uid": "${datasource}"
          },
          "expr": "sum by (le) (rate(talooner_pr_rules_fired_bucket{repo=~\"$repo\", mode=\"execute\"}[$__rate_interval]))",
          "legendFormat": "{{le}}",
          "format": "heatmap"
        }
      ]
    }
  ],
  "description": "Talooner pipeline-step metrics pushed to a Prometheus aggregation gateway. https://talooner.dev/install/#pipeline"
}
