Skip to content

feat: count live workers and worker slots per tenant - #4813

Open
grutt wants to merge 2 commits into
mainfrom
feat/meter-allocated-workers-slots
Open

grutt wants to merge 2 commits into
mainfrom
feat/meter-allocated-workers-slots

Conversation

@grutt

@grutt grutt commented Aug 27, 2026

Copy link
Copy Markdown
Member

Description

Extend per-tenant allocated-resource counts with currently connected workers and their configured slot capacity, so cloud billing can SetUsage those gauges the same way as crons, scheduled runs, and webhooks.

Type of change

  • New feature (non-breaking change which adds functionality)

What's Changed

  • Count live non-operator workers (5s heartbeat, assigned dispatcher, active, not paused) per tenant
  • Sum configured slot units for those same workers from v1_worker_slot_config
  • Notify allocated-usage refresh on worker create, delete, pause, and active-status changes (not heartbeats)
  • Cover the new counts in the allocated-resources repository test

Checklist

Changes have been:

  • Tested (unit, integration, or manually with steps specified)
  • Linted and formatted
  • Documented (where applicable)
  • Added to CHANGELOG (where applicable) -- see Keep a Changelog

Testing

CountAllocatedResourcesByTenant now asserts a live worker is counted and a stale/paused worker is not. Plan checked on a production shard: tenant-filtered worker+slot path uses Worker_tenantId_lastHeartbeatAt_idx.


🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.

  • Details: Implemented the SQL, repository callbacks, generated sqlc, and tests.

grutt added 2 commits August 27, 2026 10:52
Add connected-worker and configured-slot counts to allocated-resource
metering so Autumn can SetUsage those gauges the same way as crons.
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hatchet-docs Ready Ready Preview Aug 27, 2026 3:00pm

Request Review

@github-actions github-actions Bot added the engine Related to the core Hatchet engine label Aug 27, 2026
@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown

Greptile Summary

Extends tenant allocated-resource aggregation with live non-operator worker counts and configured slot capacity. It also emits allocated-resource change notifications after relevant worker mutations and expands repository coverage.

  • Adds active-worker, worker-count, slot-count, and tenant-union CTEs.
  • Extends generated sqlc rows with worker and slot totals.
  • Adds worker lifecycle callback hooks after successful mutations.
  • Tests that live workers are counted while stale and paused workers are excluded.

Confidence Score: 4/5

The PR appears safe to merge, with only a non-blocking comment clarification needed.

The worker predicates align with existing live-worker metering semantics, slot capacities are aggregated through the tenant-scoped worker relation, and the accepted concern is limited to how the query-plan constraint is documented.

Files Needing Attention: pkg/repository/sqlcv1/allocated_resources.sql, pkg/repository/sqlcv1/allocated_resources.sql.go

Reviews (1): Last reviewed commit: "Merge origin/main into feat/meter-alloca..." | Re-trigger Greptile

Comment on lines +11 to +13
-- Active workers are collected once and reused for both counts so the
-- tenant-filtered path can use Worker_tenantId_lastHeartbeatAt_idx
-- instead of scanning historical v1_worker_slot_config rows.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 State Current Query Constraint

This comment contrasts the query with an alternative implementation rather than documenting the current tenant-first query-plan constraint, making the invariant less clear for future maintainers.

Suggested change
-- Active workers are collected once and reused for both counts so the
-- tenant-filtered path can use Worker_tenantId_lastHeartbeatAt_idx
-- instead of scanning historical v1_worker_slot_config rows.
-- Keep the tenant filter in active_workers so tenant-scoped queries use
-- Worker_tenantId_lastHeartbeatAt_idx before joining worker slot rows.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch was successfully deployed

1 active deployment
Preview b5496702 Deployed Aug 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Related to the core Hatchet engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant