{
 "uid": "openlm-services",
 "title": "OpenLM services",
 "tags": [
  "openlm"
 ],
 "timezone": "browser",
 "schemaVersion": 39,
 "version": 2,
 "refresh": "30s",
 "time": {
  "from": "now-1h",
  "to": "now"
 },
 "editable": true,
 "panels": [
  {
   "id": 1,
   "title": "Services sending traces",
   "type": "stat",
   "gridPos": {
    "x": 0,
    "y": 0,
    "w": 6,
    "h": 4
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "OpenLM services that sent at least one span to the collector.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "count(count by (service) (traces_spanmetrics_calls_total{service=~\"$service\"}))",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "time_series"
    }
   ],
   "fieldConfig": {
    "defaults": {},
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 2,
   "title": "Requests per second",
   "type": "stat",
   "gridPos": {
    "x": 6,
    "y": 0,
    "w": 6,
    "h": 4
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "Incoming requests across the selected services, health checks left out.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "sum(rate(traces_spanmetrics_calls_total{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\"}[5m]))",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "time_series"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "reqps"
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 3,
   "title": "Failed requests per second",
   "type": "stat",
   "gridPos": {
    "x": 12,
    "y": 0,
    "w": 6,
    "h": 4
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "Incoming requests whose span ended with an error status.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "sum(rate(traces_spanmetrics_calls_total{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\",status_code=\"STATUS_CODE_ERROR\"}[5m])) or vector(0)",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "time_series"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "reqps",
     "thresholds": {
      "mode": "absolute",
      "steps": [
       {
        "color": "green",
        "value": null
       },
       {
        "color": "red",
        "value": 0.01
       }
      ]
     }
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 4,
   "title": "95th percentile response time",
   "type": "stat",
   "gridPos": {
    "x": 18,
    "y": 0,
    "w": 6,
    "h": 4
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "95% of incoming requests finish faster than this.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "histogram_quantile(0.95, sum by (le) (rate(traces_spanmetrics_latency_bucket{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\"}[5m])))",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "time_series"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "s"
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 5,
   "title": "Requests per second by service",
   "type": "timeseries",
   "gridPos": {
    "x": 0,
    "y": 4,
    "w": 12,
    "h": 8
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "sum by (service) (rate(traces_spanmetrics_calls_total{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\"}[5m]))",
     "refId": "A",
     "legendFormat": "{{service}}"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "reqps"
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 6,
   "title": "95th percentile response time by service",
   "type": "timeseries",
   "gridPos": {
    "x": 12,
    "y": 4,
    "w": 12,
    "h": 8
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "histogram_quantile(0.95, sum by (le, service) (rate(traces_spanmetrics_latency_bucket{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\"}[5m])))",
     "refId": "A",
     "legendFormat": "{{service}}"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "s"
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 7,
   "title": "Who calls whom",
   "type": "nodeGraph",
   "gridPos": {
    "x": 0,
    "y": 12,
    "w": 24,
    "h": 12
   },
   "datasource": {
    "type": "tempo",
    "uid": "tempo"
   },
   "description": "Built from traces by Tempo: each arrow is a call from one OpenLM service to another, or to MongoDB, Redis or another data service. Requests that start a trace (from the gateway or a background job) are left out.",
   "targets": [
    {
     "datasource": {
      "type": "tempo",
      "uid": "tempo"
     },
     "queryType": "serviceMap",
     "refId": "A",
     "serviceMapQuery": "{client!=\"user\"}"
    }
   ],
   "fieldConfig": {
    "defaults": {},
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 8,
   "title": "Slowest operations (95th percentile, last 15 min)",
   "type": "table",
   "gridPos": {
    "x": 0,
    "y": 24,
    "w": 12,
    "h": 9
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "topk(15, histogram_quantile(0.95, sum by (le, service, span_name) (rate(traces_spanmetrics_latency_bucket{span_kind=\"SPAN_KIND_SERVER\",span_name!~\"GET /health.*\",service=~\"$service\"}[15m]))))",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "table"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "s"
    },
    "overrides": []
   },
   "options": {},
   "transformations": [
    {
     "id": "organize",
     "options": {
      "excludeByName": {
       "Time": true
      },
      "renameByName": {
       "service": "Service",
       "span_name": "Operation",
       "Value": "95th percentile"
      }
     }
    },
    {
     "id": "sortBy",
     "options": {
      "sort": [
       {
        "field": "95th percentile",
        "desc": true
       }
      ]
     }
    }
   ]
  },
  {
   "id": 9,
   "title": "Errors by operation (last hour)",
   "type": "table",
   "gridPos": {
    "x": 12,
    "y": 24,
    "w": 12,
    "h": 9
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "Spans of any kind (incoming, outgoing, background jobs) that ended with an error.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "sum by (service, span_name) (increase(traces_spanmetrics_calls_total{status_code=\"STATUS_CODE_ERROR\",service=~\"$service\"}[1h])) > 0",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "table"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "short"
    },
    "overrides": []
   },
   "options": {},
   "transformations": [
    {
     "id": "organize",
     "options": {
      "excludeByName": {
       "Time": true
      },
      "renameByName": {
       "service": "Service",
       "span_name": "Operation",
       "Value": "Errors"
      }
     }
    },
    {
     "id": "sortBy",
     "options": {
      "sort": [
       {
        "field": "Errors",
        "desc": true
       }
      ]
     }
    }
   ]
  },
  {
   "id": 10,
   "title": "Slow requests (traces over 300 ms)",
   "type": "table",
   "gridPos": {
    "x": 0,
    "y": 33,
    "w": 24,
    "h": 9
   },
   "datasource": {
    "type": "tempo",
    "uid": "tempo"
   },
   "description": "Select a trace to open it and see where the time went, span by span.",
   "targets": [
    {
     "datasource": {
      "type": "tempo",
      "uid": "tempo"
     },
     "queryType": "traceql",
     "query": "{ kind = server && duration > 300ms && name !~ \"GET /health.*\" }",
     "limit": 20,
     "tableType": "traces",
     "refId": "A"
    }
   ],
   "fieldConfig": {
    "defaults": {},
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 11,
   "title": "Memory per OpenLM pod (top 10)",
   "type": "timeseries",
   "gridPos": {
    "x": 0,
    "y": 42,
    "w": 12,
    "h": 8
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "Working set, the memory Kubernetes compares with the pod's limit.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "topk(10, sum by (pod) (container_memory_working_set_bytes{namespace=\"openlm\",container!=\"\"}))",
     "refId": "A",
     "legendFormat": "{{pod}}"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "bytes"
    },
    "overrides": []
   },
   "options": {}
  },
  {
   "id": 12,
   "title": "Pod restarts (last hour)",
   "type": "table",
   "gridPos": {
    "x": 12,
    "y": 42,
    "w": 12,
    "h": 8
   },
   "datasource": {
    "type": "prometheus",
    "uid": "prometheus"
   },
   "description": "A pod that keeps restarting usually shows why in its log or its events in Headlamp.",
   "targets": [
    {
     "datasource": {
      "type": "prometheus",
      "uid": "prometheus"
     },
     "expr": "sum by (pod) (increase(kube_pod_container_status_restarts_total{namespace=\"openlm\"}[1h])) > 0",
     "refId": "A",
     "legendFormat": "",
     "instant": true,
     "range": false,
     "format": "table"
    }
   ],
   "fieldConfig": {
    "defaults": {
     "unit": "short"
    },
    "overrides": []
   },
   "options": {},
   "transformations": [
    {
     "id": "organize",
     "options": {
      "excludeByName": {
       "Time": true
      },
      "renameByName": {
       "pod": "Pod",
       "Value": "Restarts"
      }
     }
    }
   ]
  }
 ],
 "templating": {
  "list": [
   {
    "name": "service",
    "label": "Service",
    "type": "query",
    "datasource": {
     "type": "prometheus",
     "uid": "prometheus"
    },
    "query": {
     "query": "label_values(traces_spanmetrics_calls_total, service)",
     "refId": "S"
    },
    "definition": "label_values(traces_spanmetrics_calls_total, service)",
    "multi": true,
    "includeAll": true,
    "allValue": ".*",
    "current": {
     "text": "All",
     "value": "$__all"
    },
    "refresh": 2,
    "sort": 1
   }
  ]
 }
}