Bakery Scheduler Dashboards — Logic and Decisions
Bakery Scheduler Dashboards — Logic and Decisions
Documentation of the logic behind the bakery-scheduler dashboards.
Dashboards
Dashboard | UID | Purpose |
|---|---|---|
Bakery Scheduler |
| Quick overview — spot problems in seconds |
Bakery Scheduler — Performance |
| Deep-dive — investigate slow commands, counts, failures |
Bakery Scheduler — Errors |
| Dedicated errors view — exceptions, OOMKills, CrashLoops |
The dashboards are linked: from the Overview you can navigate to Performance by clicking the Failed, Avg CPU, Avg RAM panels, or the Command Execution Count table.
Scheduler log format
Laravel schedule:work produces lines with this format:
2026-03-10 15:00:03 Running ['artisan' twilio:fetch-callbacks-from-pubsub] 4,461ms DONE
2026-03-10 15:00:15 Running ['artisan' orders:complete] ....... 4,028ms DONE
2026-03-10 15:01:03 Running ['artisan' tenants:run shopify:fetch-abandoned-checkouts] 2026-03-10 15:01:06 Running ['artisan' tenants:run wfs:remove-cooldown-timestamps-from-contacts] 12,737ms DONE
24,794ms DONE
Orphan lines
When a command takes a long time and another command starts before it finishes, the output gets interleaved. The result is that the closing line (24,794ms DONE) ends up separated from the Running [...] line. These "orphan lines" contain neither Running nor 'artisan', so:
The command name cannot be extracted
They cannot be joined with the original line (Loki has no JOIN between lines)
Solution: All counting queries and tables filter with |= "Running" to exclude orphan lines. This means the count is accurate — each execution is counted exactly once, from the complete line.
Pod selector
All queries use:
namespace="default", pod=~"bakery-scheduler.*", container="bakery-container"
Datasources
Datasource | Use |
|---|---|
Loki | Execution counts (DONE/FAIL), durations, logs, command extraction |
Prometheus | CPU, RAM, request/limit, restarts, OOMKilled, CrashLoopBackOff |
Variable: command_filter
Textbox that allows filtering by command name. Applied to ALL Loki panels via |= \${command_filter}`. Passed automatically between dashboards via URL (?var-command_filter=...`).
Loki queries — patterns used
Execution count
sum(count_over_time(
{namespace="default", pod=~"bakery-scheduler.*", container="bakery-container"}
|= `${command_filter}` |= "Running" |~ "DONE|FAIL"
[$__range]
))
|= "Running" filters out orphan lines. |~ "DONE|FAIL" counts both successes and failures.
Command name extraction
| regexp `'artisan'\s+(?P<command>[^\]']+?)\s*[\]']`
Captures the text after 'artisan' up to the closing ] or '. Examples:
['artisan' orders:complete]→orders:complete['artisan' tenants:run generate:opportunities]→tenants:run generate:opportunities
Duration extraction (with commas)
Laravel formats durations with a thousands separator: 14,081ms, 4,461ms.
| regexp `'artisan'\s+(?P<command>[^\]']+?)\s*[\]'].*?(?P<duration>[\d,]+)ms`
| label_format duration=`{{ Replace .duration "," "" -1 }}`
| unwrap duration
(?P<duration>[\d,]+)ms— captures digits and commas before "ms"label_formatwith the Go templateReplace— strips the commas (14,081→14081)unwrap duration— converts to a number for use withavg_over_time,topk, etc.
Excluding false positives in FAIL
|= "FAIL" !~ "FAILED_CHARGES|failed-charges|fetch-failed"
The samcart:get-failed-charges command contains "failed" in its name and produces logs with "FAILED_CHARGES". These are excluded so they don't pollute the count of real failures.
Prometheus queries
CPU in millicores
rate(container_cpu_usage_seconds_total{...}[5m]) * 1000
RAM in MB
container_memory_working_set_bytes{...} / 1024 / 1024
Request and Limit (reference lines)
avg(kube_pod_container_resource_requests{..., resource="cpu"}) * 1000 # request
avg(kube_pod_container_resource_limits{..., resource="cpu"}) * 1000 # limit
Shown as dashed lines in yellow (request) and red (limit).
Restarts (cumulative)
kube_pod_container_status_restarts_total{...}
Shown with stepAfter — each vertical jump = one restart. When a new pod appears (new color), the previous one died.
Panels per dashboard
Overview (bakery-scheduler)
Panel | Type | Datasource | Purpose |
|---|---|---|---|
Total Executions | stat | Loki | Total DONE+FAIL count in the range |
Successful | stat | Loki | DONE only |
Failed | stat | Loki | FAIL only (link → Performance) |
Pod Restarts | stat | Prometheus | Restarts in the range |
Avg CPU | stat | Prometheus | Current average CPU (link → Performance) |
Avg RAM | stat | Prometheus | Current average RAM (link → Performance) |
Command Executions Over Time | timeseries | Loki | DONE vs FAIL in 5m windows |
Pod Restarts (cumulative) | timeseries | Prometheus | stepAfter line per pod |
Pod CPU Over Time | timeseries | Prometheus | CPU per pod + request + limit |
Pod RAM Over Time | timeseries | Prometheus | RAM per pod + request + limit |
Command Execution Count | table | Loki | Top 30 commands by executions (link → Performance) |
Scheduler Logs | logs | Loki | Last 5 min, ascending order (terminal-style) |
Performance (bakery-scheduler-perf)
Panel | Type | Datasource | Purpose |
|---|---|---|---|
Command Executions Over Time | timeseries | Loki | DONE vs FAIL |
Pod CPU Over Time | timeseries | Prometheus | CPU + request + limit |
Pod RAM Over Time | timeseries | Prometheus | RAM + request + limit |
Slowest Commands | table | Loki | Top 20 by avg duration (topk + avg_over_time + unwrap) |
Execution Count | table | Loki | Top 30 by number of executions |
Failed Commands Detail | table | Loki | Top 20 commands with the most failures |
Scheduler Logs | logs | Loki | Last 5 min, terminal-style |
Errors (bakery-scheduler-errors)
Panel | Type | Datasource | Purpose |
|---|---|---|---|
Total Errors | stat | Loki | error/exception/fatal (excluding false positives) |
Failed Commands | stat | Loki | Lines with FAIL |
Exceptions | stat | Loki | exception/throwable/stack trace |
Pod Restarts | stat | Prometheus | increase of restarts |
OOMKilled | stat | Prometheus | last_terminated_reason OOMKilled |
CrashLoopBackOff | stat | Prometheus | waiting_reason CrashLoopBackOff |
Errors Over Time | timeseries | Loki | Errors + Failed Commands in 5m windows |
Pod Restarts Over Time | timeseries | Prometheus | increase of restarts over 5m |
RAM vs Limit | timeseries | Prometheus | Current RAM vs limit (detect OOM) |
Failed Commands Breakdown | table | Loki | Commands with the most failures |
Pod Termination Reasons | table | Prometheus | Termination reasons (OOMKilled, Error, etc.) |
Scheduler Lifecycle Events | table | Loki | Events status=X reason=Y |
Error Logs | logs | Loki | Only lines with error/exception/fatal |
Logs panel — terminal behavior
The logs panel uses:
"sortOrder": "Ascending"— newest goes at the bottom (like a terminal)"timeFrom": "5m"— always shows the last 5 minutes regardless of the dashboard's time range"wrapLogMessage": true— long lines wrap
Implementation notes
The Slowest Commands tables use
avg_over_time+unwrapto calculate average durationsThe
label_formatwith Go template backticks is necessary to avoid escaping conflicts with JSONThe dashboards are applied as ConfigMaps with the
grafana_dashboard=1label (see dashboards-management-guide.md)The scheduler's current resource limits: CPU request 100m / limit 500m, RAM request 100Mi / limit 1100Mi