Zum Inhalt springen
Plugins

observability Plugin

Worker Timeline

The `worker_timeline` plugin (`plugins/worker_timeline/`) visualizes overlapping Syrus activity as a multi-lane timeline: one lane per durable worker process role (`worker_storage_key` + `queue_role`), with Job/Workflow spans over time. It is a self-contained Rails engine plugin, installed but disabled by default (`default_enabled: false`, `disableable: true`, category `observability`). As with `mysql_db_browser`, the plugin's own `PluginRecord.enabled` toggle *is* the feature gate — there is no separate `Feature` flag — and `WorkerTimeline::SidebarPages#sidebar_pages` self-gates on both `WorkerTimeline.enabled?` and `Current.user&.admin?`, returning `[]` otherwise (the `sidebar_page` extension point itself has no per-page visibility concept). It covers the **macro** (cross-job, multi-lane) timeline, a scoped **Live Workers** view, and a **micro** per-workflow Step/Run waterfall drill-down (`/worker_timeline/workflow?id=<id>`, reachable by clicking a macro-view Workflow span).

worker_timelineQuellcode

Worker Timeline

The worker_timeline plugin (plugins/worker_timeline/) visualizes overlapping Syrus activity as a multi-lane timeline: one lane per durable worker process role (worker_storage_key + queue_role), with Job/Workflow spans over time. It is a self-contained Rails engine plugin, installed but disabled by default (default_enabled: false, disableable: true, category observability). As with mysql_db_browser, the plugin's own PluginRecord.enabled toggle *is* the feature gate — there is no separate Feature flag — and WorkerTimeline::SidebarPages#sidebar_pages self-gates on both WorkerTimeline.enabled? and Current.user&.admin?, returning [] otherwise (the sidebar_page extension point itself has no per-page visibility concept).

It covers the macro (cross-job, multi-lane) timeline, a scoped Live Workers view, and a micro per-workflow Step/Run waterfall drill-down (/worker_timeline/workflow?id=<id>, reachable by clicking a macro-view Workflow span).

Data sources

The plugin reads:

  • WorkflowActivityEvent / SpawnedProcess / InstanceVersion (worker

attribution — see Timeline::WorkerAttribution).

  • Workflow/Step/Run started_at/finished_at timestamps.
  • SolidQueue::Process worker metadata, SpawnedProcess.running, active

Run/Workflow/Step rows, WorkerHostHealthSample, and InstanceVersion for the Live Workers card payload.

  • WorkUnits::StartBlock.explain for the same blocked-reason explanation

Admin::StuckJobExplainer uses — historical (already-resolved) spans may have no stored blocked-reason, and the API says so explicitly (available: false) rather than fabricating one. Shaping this into JSON (iso8601-encoding the Time fields) lives in Timeline::BlockedExplanation, shared by both query services below.

A queued Workflow that has been waiting to start for longer than Timeline::MacroQuery::STALE_PENDING_THRESHOLD (1 week) is dropped from the pending list entirely — it's unlikely to start any time soon and just clutters the "Waiting to start" panel. It's still visible through the normal Job/Workflow admin views; this only affects the timeline's pending list.

WorkflowActivityEvent now captures queue_role for RunJob executions, which lets the macro query distinguish separate worker processes that share one storage volume, such as runs and merges. Workflow#worker_storage_key provides the durable storage/pod identity. hostname and pid stay on each span as point-in-time attributes for tooltips and restart markers, but they are no longer the primary lane key when both durable fields are available. Rows that predate queue_role, lack worker_storage_key, or come from non-RunJob activity still fall back to legacy hostname + pid lane grouping. The timeline backend does not allocate per-thread slots; the frontend packs overlapping spans inside a lane from timestamps. The Live Workers endpoint is likewise explicit that Syrus has no exact per-thread ownership instrumentation: it infers slot occupancy from running spawned processes, active Run/Workflow/Step rows, and live Solid Queue worker capacity.

app/services/timeline/macro_query.rb (Timeline::MacroQuery) is the underlying macro query service, and app/services/timeline/workflow_waterfall_query.rb (Timeline::WorkflowWaterfallQuery) the per-workflow one — both shared with the bearer-token-gated GET /api/v1/admin/worker_timeline/macro and GET /api/v1/admin/worker_timeline/workflow endpoints meant for external admin API clients. Steps have no blocked-reason machinery of their own (only Workflows do), so WorkflowWaterfallQuery attaches the Workflow's own blocked explanation to every not-yet-started Step payload — the same value it puts on the top-level workflow payload — rather than fabricating a per-Step reason.

API

The plugin exposes both an admin surface and a session-authenticated surface, sharing the same query services and payload shape:

  • Api::V1::Admin::WorkerTimelineController (bearer-token auth via

Api::V1::Admin::BaseController#require_admin_api, plus its own require_worker_timeline_enabled gate mirroring admin_mysql) — for external admin API clients, the same address space as every other operator diagnostic (/api/v1/admin/overview, /stuck, /queue, /processes, ...). This used to be a core-owned controller at /api/v1/timeline/* with no plugin gate; it moved into the plugin (and under /api/v1/admin/worker_timeline/*) so the resource is addressable from the operations interface and answers plugin_disabled like every other plugin-owned admin endpoint .

  • GET /api/v1/admin/worker_timeline/macro — flat query params:

repository_id, epic_id, job_id, hostname, status, job_type, from/to (ISO8601; default window is the last hour). See docs/engineering/architecture/worker_activity_timeline.md for the full param and response shape.

  • GET /api/v1/admin/worker_timeline/live — flat query params:

hostname, status (idle, busy, degraded, overloaded), and from/to for the health-sample window. Returns one card payload per worker host/storage identity, with queue pools and inferred active slots nested inside each card.

  • GET /api/v1/admin/worker_timeline/workflow — ?id=<workflow_id>.
  • Api::V1::App::Admin::WorkerTimelineController (session auth via

Api::V1::App::Admin::BaseController#require_admin, plus its own require_worker_timeline_enabled gate) — for the browser SPA, which authenticates via session cookie, not an API token, and so cannot call the bearer-token endpoints above directly:

  • GET /api/v1/app/admin/worker_timeline/macro — `?q=<base64-encoded

filter tree>, the same wire format the app-wide shared FilterBar (app/frontend/components/FilterBar.tsx) uses everywhere else (Filters::QueryParam/Filters::Ast). Timeline::MacroQueryFilter decodes q into the repository_id/epic_id/hostname/status/ source-aware predicate evaluated by Timeline::MacroQuery, and exposes a registry-backed filter_schema for the worker_timeline subject: repository_id/epic_id/hostname as fk (typeahead) fields backed by the existing /api/v1/app/filters/fk_options resolver (Filters::FkOptionsResolver serves repository_id/epic_id unscoped — every repository/epic in the instance, not just ones the signed-in admin owns — when the current user is an admin, since this is a cross-tenant admin view and every visitor is admin-gated already; non-admin callers elsewhere in the app keep the ownership-scoped relation), status and job_type as multi-select enum fields (job_type values are user and system, with the system option labeled "Infrastructure" in the timeline UI), and a window date field supporting within_last (relative) and between (absolute) — no q (no chips at all) defaults to within_last the last 3 hours with no other filters applied, i.e. every worker lane and every workflow in that window. The response echoes back filter (the applied tree) and filter_schema alongside range/ lanes/pending. Each lane includes key, worker_storage_key, queue_role, representative hostname/pid, instance, and spans; each span includes its own worker_storage_key, queue_role, hostname, and pid` along with Workflow timing/status fields.

  • GET /api/v1/app/admin/worker_timeline/live — `?q=<base64-encoded filter

tree> using a Live Workers-specific filter_schema (hostname, status, and window). The response echoes filter/filter_schema alongside summary, workers, and an attribution block whose exact_thread_ownership: false flag documents that active slots are inferred. Each worker payload includes status, status reasons, slot occupancy, current health, CPU/memory/I/O sparklines, and queue pools. Each pool has capacity, used, queue names, and zero or more inferred active slots containing the best available Job/Workflow/Step/Run/process attribution and a redacted command excerpt when a running spawned process provides one. Inferred Run and Step slots only count as live occupancy when their parent Workflow is still running; if stale running descendant rows remain under a terminal Workflow, the response classifies them under diagnostics.stale_terminal_descendants` instead of rendering them as ordinary active slots.

  • GET /api/v1/app/admin/worker_timeline/workflow — ?id=<workflow_id>,

the Step/Run waterfall for one Workflow (wraps Timeline::WorkflowWaterfallQuery). The workflow and each Step payload include the resolved worker_storage_key, queue_role, hostname, and pid. The workflow payload also includes the canonical WF-<id> slug plus job_slug, job_path, and workflow_path; WorkflowWaterfall.tsx renders those as links and applies the active SPA route prefix (for example /app-shell) at the edge.

worker_timeline is a Filters::Registry and SmartFolder subject, so the shared FilterBar, suggestion search, usage recording, and saved-folder create/update/delete/navigation controls use the same infrastructure as the other filtered admin surfaces. A saved folder stores the complete AST and an explicit q= edit replaces the folder expression, including an explicitly empty expression. Folder badges use Timeline::MacroQuery#capped_count, which stops after SmartFolder::COUNT_CAP + 1 matching timeline entries and does not construct lane/span payloads or blocked explanations for count-only queries.

The macro query deliberately does not pretend its data is one ActiveRecord relation. WorkerTimeline::MacroQueryFilter evaluates and, or, and not recursively against each source. Workflow fields (repository_id, epic_id, status, and job_type) can match running/completed spans and pending workflows; they do not match idle worker lanes. hostname can match attributed spans and idle lanes, but not an unattributed pending workflow. window uses interval overlap for spans and idle instances and the workflow creation time for pending entries. Boolean negation follows those source semantics (for example, an idle lane satisfies NOT status:failed). Unsupported fields, operators, and malformed window values return invalid_filter rather than being ignored. Positive window chips establish the displayed range envelope; a negated window is an exclusion inside the default three-hour range and does not shrink that range to the interval being excluded. With no positive window chip, the view remains bounded to the last three hours.

Before evaluating the expression, the session-authenticated endpoint scopes both started and pending workflows through Job.accessible_to(Current.user). This ordering prevents predicates from probing workflows in repositories the operator cannot access. Idle InstanceVersion lanes have no repository ownership and are evaluated only against the source-appropriate predicates. The separate bearer-token GET /api/v1/admin/worker_timeline/macro endpoint (see docs/engineering/architecture/worker_activity_timeline.md) keeps its own flat repository_id=/epic_id=/job_id=/hostname=/status=/job_type=/ from=/to= params and 1-hour default. job_type=system filters to system/infrastructure Job kinds, job_type=user filters to user-facing Job kinds, and job_type=infra/job_type=infrastructure are accepted aliases for system.

Frontend

/worker_timeline (sidebar page worker_timeline.macro, icon timeline) renders WorkerTimeline.tsx with exactly two tabs:

  • Timeline — hand-rolled React+SVG bars per span (no charting library,

consistent with spending_insights), d3-scale for the time axis and d3-zoom/d3-selection for pan/zoom gesture handling, and the app-wide shared FilterBar (same component and query-tree wiring as AdminQueue/AdminUsers/Dashboard) for repository/epic/hostname/status/ job-type/time-window filtering. All lanes render up front (no row virtualization, no internal vertical scroll container) so the page itself scrolls to show every lane. Hovering a span shows a tooltip with the Job/Workflow id and title, duration, and the blocked-reason explanation (or a plain "no historical data" message when none survives). Clicking a Workflow span navigates to /worker_timeline/workflow?id=<id>.

  • Live Workers — compact cards keyed by worker host/storage identity.

Each card shows inferred occupancy, restrained status pills for idle, busy, degraded, and overloaded, CPU/memory/I/O sparklines from recent WorkerHostHealthSample rows, and queue-pool sections with active slots nested under the pool they were assigned to. When a slot cannot be matched to a specific pool, it is kept in one inferred pool rather than duplicated across matching pools. Stale running Step/Run rows whose parent Workflow is already terminal are excluded from occupancy and surfaced only as diagnostic response records. This first version intentionally reuses FilterBar without SmartFolder save/update controls and does not add top-right page header actions.

That route renders WorkflowWaterfall.tsx: one lane per Step (in position order), with that Step's Run attempt(s) drawn as spans within the lane so retries are visible as sequential bars. It reuses the macro view's useZoomableTimeScale hook, the formatDuration/blockedMessage tooltip helpers (extracted under components/timeline/), and the shared TimeAxis, TimelineBar, and TooltipCard rendering primitives rather than reimplementing pan/zoom or tooltip logic, but — unlike the macro view — still virtualizes its Step rows via useVirtualizedRows inside a fixed-height, vertically scrollable container, since a single workflow's Step list is not expected to grow the way the macro view's worker lanes can. A Step with no started Run yet renders as a hoverable "not started" marker instead of a bar (there's no timestamp to place a bar at); its tooltip reuses the same blocked-reason explanation the macro view shows for a pending Workflow. If the Workflow itself hasn't started, the waterfall skips the time axis entirely (there's no meaningful scale yet) and shows every Step as a "not started" marker.

TimeAxis, TimelineBar, and TooltipCard themselves live in core at app/frontend/components/timeline/ (not under this plugin), since they have no worker_timeline-specific behavior — this plugin's TimelineLanes.tsx and WorkflowWaterfall.tsx import them from @app/components/timeline/* the same way test_insights imports shared core components. components/timeline/constants.ts (CHART_WIDTH, ROW_HEIGHT, STATUS_COLORS) stays plugin-local; TimeAxis takes chart width as a prop rather than importing a plugin constant. See docs/engineering/architecture/worker_activity_timeline.md for the separate, non-admin-safe GET /api/v1/app/jobs/:id/waterfall endpoint that also wraps Timeline::WorkflowWaterfallQuery for a Job detail page Timeline tab.

The macro view wires FilterBar's suggestionSearch to surface: "worker_timeline", subject: "worker_timeline" and records applied filters through /api/v1/app/filters/usage on the same surface/subject. Typing free text in the add-filter search before choosing a field therefore offers one-click top-level suggested chips for matching repositories, epics, and worker hostnames (for example, "Repository is tkadauke/syrus") in addition to the per-field typeahead that appears inside an already-added FK chip.