{
  "__inputs": [
    {
      "name": "DS_PROMETHEUS",
      "label": "Prometheus",
      "description": "",
      "type": "datasource",
      "pluginId": "prometheus",
      "pluginName": "Prometheus"
    }
  ],
  "__requires": [
    { "type": "grafana", "id": "grafana", "name": "Grafana", "version": "10.0.0" },
    { "type": "datasource", "id": "prometheus", "name": "Prometheus", "version": "1.0.0" },
    { "type": "panel", "id": "timeseries", "name": "Time series", "version": "" },
    { "type": "panel", "id": "stat", "name": "Stat", "version": "" }
  ],
  "id": null,
  "uid": "trustpin-attest-verifier",
  "title": "TrustPin Attestation Verifier",
  "description": "Every metric of the TrustPin attestation verifier: attestations, tokens, challenges, policy, upstreams and store.",
  "tags": ["trustpin", "attestation"],
  "timezone": "browser",
  "editable": true,
  "graphTooltip": 1,
  "schemaVersion": 39,
  "version": 1,
  "refresh": "30s",
  "time": { "from": "now-6h", "to": "now" },
  "templating": {
    "list": [
      {
        "name": "datasource",
        "label": "Data source",
        "type": "datasource",
        "query": "prometheus",
        "current": { "selected": false, "text": "Prometheus", "value": "Prometheus" },
        "hide": 0,
        "refresh": 1
      },
      {
        "name": "instance",
        "label": "Instance",
        "type": "query",
        "datasource": { "type": "prometheus", "uid": "${datasource}" },
        "query": "label_values(trustpin_attest_build_info, instance)",
        "definition": "label_values(trustpin_attest_build_info, instance)",
        "includeAll": true,
        "multi": true,
        "allValue": ".*",
        "current": { "selected": true, "text": ["All"], "value": ["$__all"] },
        "refresh": 2,
        "sort": 1
      }
    ]
  },
  "panels": [
    { "type": "row", "id": 100, "title": "Overview", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 } },
    {
      "type": "stat", "id": 1, "title": "Policy version",
      "gridPos": { "h": 4, "w": 4, "x": 0, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "max(trustpin_attest_policy_version{instance=~\"$instance\"})", "instant": true }],
      "fieldConfig": { "defaults": { "unit": "none", "color": { "mode": "fixed", "fixedColor": "blue" } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat", "id": 2, "title": "Since last policy success",
      "gridPos": { "h": 4, "w": 4, "x": 4, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "time() - min(trustpin_attest_policy_last_success_timestamp_seconds{instance=~\"$instance\"})", "instant": true }],
      "fieldConfig": { "defaults": { "unit": "s", "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "orange", "value": 900 }, { "color": "red", "value": 3600 } ] } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat", "id": 3, "title": "Attestations / s",
      "gridPos": { "h": 4, "w": 4, "x": 8, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum(rate(trustpin_attest_attestations_total{instance=~\"$instance\"}[5m]))", "instant": true }],
      "fieldConfig": { "defaults": { "unit": "reqps", "decimals": 2 }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "area" }
    },
    {
      "type": "stat", "id": 4, "title": "Tokens issued / s",
      "gridPos": { "h": 4, "w": 4, "x": 12, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum(rate(trustpin_attest_tokens_issued_total{instance=~\"$instance\"}[5m]))", "instant": true }],
      "fieldConfig": { "defaults": { "unit": "reqps", "decimals": 2 }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "none", "graphMode": "area" }
    },
    {
      "type": "stat", "id": 5, "title": "Revocation list age",
      "gridPos": { "h": 4, "w": 4, "x": 16, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "max(trustpin_attest_revocation_list_age_seconds{instance=~\"$instance\"})", "instant": true }],
      "fieldConfig": { "defaults": { "unit": "s", "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 604800 } ] } }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none" }
    },
    {
      "type": "stat", "id": 6, "title": "Build",
      "gridPos": { "h": 4, "w": 4, "x": 20, "y": 1 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "trustpin_attest_build_info{instance=~\"$instance\"}", "instant": true, "legendFormat": "{{version}} ({{go_version}})", "format": "table" }],
      "fieldConfig": { "defaults": { "unit": "none" }, "overrides": [] },
      "options": { "reduceOptions": { "calcs": ["lastNotNull"], "fields": "/^version$/" }, "colorMode": "none", "graphMode": "none", "textMode": "value" }
    },

    { "type": "row", "id": 101, "title": "Attestations and tokens", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 5 } },
    {
      "type": "timeseries", "id": 10, "title": "Attestations by platform and result",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (platform, result) (rate(trustpin_attest_attestations_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{platform}} {{result}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps", "custom": { "stacking": { "mode": "normal" }, "fillOpacity": 20 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean", "max"] } }
    },
    {
      "type": "timeseries", "id": 11, "title": "Failed attestations by reason",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 6 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (reason) (rate(trustpin_attest_attestations_total{instance=~\"$instance\",result!=\"pass\"}[5m]))", "legendFormat": "{{reason}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean", "max"] } }
    },
    {
      "type": "timeseries", "id": 12, "title": "Tokens issued by mode, result and binding",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 14 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (platform, mode, result, bound) (rate(trustpin_attest_tokens_issued_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{platform}} {{mode}} {{result}} bound={{bound}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps", "custom": { "stacking": { "mode": "normal" }, "fillOpacity": 20 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean"] } }
    },
    {
      "type": "timeseries", "id": 13, "title": "Attestations by evidence",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 14 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (evidence) (rate(trustpin_attest_attestations_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{evidence}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" } }
    },

    { "type": "row", "id": 102, "title": "Challenges and HTTP", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 22 } },
    {
      "type": "timeseries", "id": 20, "title": "Challenges issued and rejected",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 23 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [
        { "refId": "A", "expr": "sum(rate(trustpin_attest_challenges_issued_total{instance=~\"$instance\"}[5m]))", "legendFormat": "issued" },
        { "refId": "B", "expr": "sum by (reason) (rate(trustpin_attest_challenge_rejections_total{instance=~\"$instance\"}[5m]))", "legendFormat": "rejected {{reason}}" }
      ],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "timeseries", "id": 21, "title": "HTTP requests by endpoint and code",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 23 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (endpoint, code) (rate(trustpin_attest_http_requests_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{endpoint}} {{code}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean"] } }
    },
    {
      "type": "timeseries", "id": 22, "title": "HTTP latency p50 / p95 / p99",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 31 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [
        { "refId": "A", "expr": "histogram_quantile(0.5, sum by (le, endpoint) (rate(trustpin_attest_http_request_duration_seconds_bucket{instance=~\"$instance\"}[5m])))", "legendFormat": "p50 {{endpoint}}" },
        { "refId": "B", "expr": "histogram_quantile(0.95, sum by (le, endpoint) (rate(trustpin_attest_http_request_duration_seconds_bucket{instance=~\"$instance\"}[5m])))", "legendFormat": "p95 {{endpoint}}" },
        { "refId": "C", "expr": "histogram_quantile(0.99, sum by (le, endpoint) (rate(trustpin_attest_http_request_duration_seconds_bucket{instance=~\"$instance\"}[5m])))", "legendFormat": "p99 {{endpoint}}" }
      ],
      "fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["max"] } }
    },
    {
      "type": "timeseries", "id": 23, "title": "Store operations",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 31 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (operation, outcome) (rate(trustpin_attest_store_operations_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{operation}} {{outcome}}" }],
      "fieldConfig": { "defaults": { "unit": "ops" }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean"] } }
    },

    { "type": "row", "id": 103, "title": "Policy and upstreams", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 39 } },
    {
      "type": "timeseries", "id": 30, "title": "Policy refresh outcomes",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 40 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (outcome) (increase(trustpin_attest_policy_refresh_total{instance=~\"$instance\"}[15m]))", "legendFormat": "{{outcome}}" }],
      "fieldConfig": { "defaults": { "unit": "short", "custom": { "drawStyle": "bars", "fillOpacity": 60 } }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" } }
    },
    {
      "type": "timeseries", "id": 31, "title": "Upstream requests by outcome",
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 40 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "sum by (upstream, outcome) (rate(trustpin_attest_upstream_requests_total{instance=~\"$instance\"}[5m]))", "legendFormat": "{{upstream}} {{outcome}}" }],
      "fieldConfig": { "defaults": { "unit": "reqps" }, "overrides": [] },
      "options": { "legend": { "displayMode": "table", "placement": "right", "calcs": ["mean"] } }
    },
    {
      "type": "timeseries", "id": 32, "title": "Upstream latency p95",
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 48 },
      "datasource": { "type": "prometheus", "uid": "${datasource}" },
      "targets": [{ "refId": "A", "expr": "histogram_quantile(0.95, sum by (le, upstream) (rate(trustpin_attest_upstream_request_duration_seconds_bucket{instance=~\"$instance\"}[5m])))", "legendFormat": "{{upstream}}" }],
      "fieldConfig": { "defaults": { "unit": "s" }, "overrides": [] },
      "options": { "legend": { "displayMode": "list", "placement": "bottom" } }
    }
  ]
}
