Skip to content

chore(router): add drainReason label to pipeline_processed_events - #7561

Merged
shekhar-rudder merged 3 commits into
masterfrom
feat/drain-reason-label
Nov 3, 2026
Merged

shekhar-rudder merged 3 commits into
masterfrom
feat/drain-reason-label

Conversation

@shekhar-rudder

@shekhar-rudder shekhar-rudder commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Description

Drained jobs abort with code 410 whatever the reason (DRAIN_ERROR_CODE), and pipeline_processed_events has no reason label. So alerts built on pipeline_processed_events{code="410"} can't tell a 30-day job expiry from a deliberate drain, e.g. a customer cancelling an rETL sync (cancelled jobRunID). Today the golden async-destination expiry alert pages on cancelled syncs. The current workaround subtracts drained_events from the 410 count, which goes wrong across pod restarts.

This PR adds a drainReason label to pipeline_processed_events for drained jobs, so the alert can filter with drainReason!="cancelled jobRunID".

How

  • New non-persisted field jobsdb.JobStatusT.DrainReason (json:"-"), following the existing WorkspaceId / PartitionID / CustomVal fields that are never stored in the DB.
  • Set at the two places that turn a drain decision into a status: router/worker.go (router) and router/batchrouter/worker.go (batch router).
  • UpdateProcessedEventsMetrics emits it as drainReason when set. Non-drained statuses keep exactly their current label set, so existing series and queries are unaffected.
  • UpdateProcessedEventsMetrics now groups on a struct key (sourceId, destinationId, state, code, drainReason) via lo.CountValuesBy, the same pattern as countTransformedJobStatuses. The old three-level nested map keyed on a "source,destination" string had no clean place for a per-status dimension. Grouping and emitted series are unchanged apart from the new label.

Label values are bounded and fixed, at most 7: the five DrainReason* constants, plus retry limit reached (router only) and source_not_found (batch router only). None of them come from customer input. The label appears only on state="aborted", code="410" series, so each connection with drains gains one series per reason that actually occurs. Drained 410s move from the unlabelled series to the labelled ones, and sum by queries over code are unaffected.

Why not drained_events? It has the reason but no sourceId, uses destId rather than destinationId, and in the batch router reports one comma-joined reasons value per destination per batch, so mixed batches can't be split. Some 410s also never pass through the drainer, so an alert based on it would miss them.

Not changed: batch router / async retry-limit aborts (router/batchrouter/handle.go, handle_async.go) don't go through the drainer and stay unlabelled. So drainReason="retry limit reached" appears for the router only.

Tests: new unit test for the label in router/utils, plus DrainReason assertions added to the existing router and batch router drain tests.

Linear Ticket

None yet.

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

🤖 Generated with Claude Code

Drained jobs abort with code 410 whatever the reason, so alerts on
pipeline_processed_events{code="410"} cannot tell a job expiry from a
deliberate drain such as a cancelled rETL sync ("cancelled jobRunID").

Carry the drain reason on the job status in a new non-persisted
JobStatusT.DrainReason field, set where the router and batch router drain a
job, and emit it as a drainReason label when set. Values are the drainer's
fixed reasons plus "retry limit reached" (router) and "source_not_found"
(batch router). Non-drained statuses keep their existing label set.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the changes adding drain-reason labels to processed-event metrics.

No open issues 🎉

What changed in this PR

Adds a drainReason label to pipeline_processed_events for drained jobs, allowing alerts to distinguish job expiry from deliberate cancellations. Non-drained statuses retain their existing labels.

Changes:

  • Carries a non-persisted drain reason through router and batch router job statuses.
  • Groups processed-event metrics by connection, state, code, and drain reason.
  • Adds metric-label coverage and drain-reason assertions to existing tests.
File Description
router/​worker.go Sets the drain reason on router abort statuses.
router/​utils/​utils.go Uses struct-keyed aggregation and emits the optional label.
router/​utils/​utils_test.go Tests distinct drain reasons and unlabelled statuses.
router/​router_test.go Checks the drain reason for expired router jobs.
router/​batchrouter/​worker.go Sets the drain reason on batch router abort statuses.
router/​batchrouter/​worker_test.go Checks drain-reason propagation in batch router statuses.
jobsdb/​jobsdb.go Adds the non-persisted DrainReason status field.

Review effort: Balanced

…dd the drainReason key

Revert the struct-key rewrite; the drain reason now rides along in the
existing composite key, so the diff is limited to the label.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the drain-reason metric-label changes.

No open issues 🎉

Review effort: Balanced

…, only add the drainReason key"

This reverts commit 9f3f575.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The drain-reason metric-label changes have no active review issues.

No open issues 🎉

Review effort: Balanced

@shekhar-rudder shekhar-rudder changed the title feat(router): add drainReason label to pipeline_processed_events chore(router): add drainReason label to pipeline_processed_events Nov 2, 2026
@achettyiitr
achettyiitr requested a review from atzoum November 2, 2026 11:02
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.22%. Comparing base (b0a097a) to head (4d818e6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7561      +/-   ##
==========================================
+ Coverage   84.77%   85.22%   +0.45%     
==========================================
  Files         631      631              
  Lines       62987    62979       -8     
==========================================
+ Hits        53396    53676     +280     
+ Misses       9588     9300     -288     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lvrach lvrach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved. drainReason takes only 7 fixed values. Each drain path passes the same *JobStatusT to UpdateProcessedEventsMetrics, and series for jobs that are not drained keep their tag set and counts.

Optional follow-up: the worker tests check the struct field only. No router or batch router test checks drainReason on the emitted pipeline_processed_events series. A later refactor that copies the status into a new JobStatusT would drop the label and no test would fail.

@shekhar-rudder
shekhar-rudder merged commit af0aef8 into master Nov 3, 2026
116 of 118 checks passed
@shekhar-rudder
shekhar-rudder deleted the feat/drain-reason-label branch November 3, 2026 04:50
atzoum pushed a commit that referenced this pull request Nov 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.93.0-rc.1](v1.92.0...v1.93.0-rc.1)
(2026-11-09)


### Features

* **destination:** recognize machine_oauth accounts as oauth
([#7549](#7549))
([f51e4ca](f51e4ca))
* incremental definitions on the v2 namespace config
([#7487](#7487))
([ce51e38](ce51e38))
* **processor:** add flag to abort python transformations on deployments
that do not offer them
([#7571](#7571))
([ca85eb2](ca85eb2))
* **processor:** filter http v2 events by destination message types
([#7538](#7538))
([58fd176](58fd176))
* **processor:** send the workspace id to per-workspace pyt pods
([#7551](#7551))
([ea33835](ea33835))
* **warehouse:** add maxcompute destination
([#7568](#7568))
([a64bfd9](a64bfd9))


### Bug Fixes

* **batchrouter:** abort bq stream all events jobs on terminal auth
failures
([#7548](#7548))
([6b7e023](6b7e023))
* bump andybalholm/brotli to v1.2.7 [SEC-759]
([#7525](#7525))
([6dfe468](6dfe468))
* bump rudder-go-kit to v0.84.3
([#7547](#7547))
([355054a](355054a))
* **core:** schema forwarder panics on shutdown
([#7519](#7519))
([dd61cfc](dd61cfc))
* database connections hang when context is cancelled during a copy
([#7578](#7578))
([8dae6e3](8dae6e3))
* **jobsdb:** compaction missing pairs after one that doesn't fit
([#7574](#7574))
([573271b](573271b))
* **jobsdb:** multiconsumer recovery misses a consumer's executing
status after another consumer's later status
([#7554](#7554))
([69b43e0](69b43e0))
* **jobsdb:** old jobs not expiring for every consumer
([#7573](#7573))
([366f114](366f114))
* **jobsdb:** pickups stalling on status tables with skewed stats
([#7572](#7572))
([318446f](318446f))
* **jobsdb:** unionjobsdb functions pick the first datasets by table
name ([#7558](#7558))
([e94d6c5](e94d6c5))
* **router:** event order test only counts drained jobs of the last
dataset
([#7552](#7552))
([b0a097a](b0a097a))
* **router:** mask secrets in array-shaped reporting samples
([#7536](#7536))
([902160f](902160f))
* **warehouse:** hot-reload degraded workspaces without aborting
restored uploads
([#7564](#7564))
([cb98598](cb98598))
* **warehouse:** match deltalake columns case-insensitively
([#7563](#7563))
([a7d30d7](a7d30d7))
* **warehouse:** migrate snowflake to gosnowflake v2.3.0
([#7542](#7542))
([cc09426](cc09426))
* **warehouse:** skip job-creation error log on router shutdown
([#7567](#7567))
([895367e](895367e))


### Miscellaneous

* **deps:** bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6
([#7545](#7545))
([35ee952](35ee952))
* export only the +Inf bucket for limiter timers
([#7570](#7570))
([4429472](4429472))
* **router:** add drainReason label to pipeline_processed_events
([#7561](#7561))
([af0aef8](af0aef8))
* sync release v1.92.0 to main branch
([#7534](#7534))
([9ab165d](9ab165d))
* **warehouse:** bump sqlconnect-go to v1.37.1
([#7575](#7575))
([acdad67](acdad67))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
atzoum pushed a commit that referenced this pull request Nov 10, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.93.0](v1.92.0...v1.93.0)
(2026-11-09)


### Features

* **destination:** recognize machine_oauth accounts as oauth
([#7549](#7549))
([f51e4ca](f51e4ca))
* incremental definitions on the v2 namespace config
([#7487](#7487))
([ce51e38](ce51e38))
* **processor:** add flag to abort python transformations on deployments
that do not offer them
([#7571](#7571))
([ca85eb2](ca85eb2))
* **processor:** filter http v2 events by destination message types
([#7538](#7538))
([58fd176](58fd176))
* **processor:** send the workspace id to per-workspace pyt pods
([#7551](#7551))
([ea33835](ea33835))
* **warehouse:** add maxcompute destination
([#7568](#7568))
([a64bfd9](a64bfd9))


### Bug Fixes

* **batchrouter:** abort bq stream all events jobs on terminal auth
failures
([#7548](#7548))
([6b7e023](6b7e023))
* bump andybalholm/brotli to v1.2.7 [SEC-759]
([#7525](#7525))
([6dfe468](6dfe468))
* bump rudder-go-kit to v0.84.3
([#7547](#7547))
([355054a](355054a))
* **core:** schema forwarder panics on shutdown
([#7519](#7519))
([dd61cfc](dd61cfc))
* database connections hang when context is cancelled during a copy
([#7578](#7578))
([8dae6e3](8dae6e3))
* **jobsdb:** compaction missing pairs after one that doesn't fit
([#7574](#7574))
([573271b](573271b))
* **jobsdb:** multiconsumer recovery misses a consumer's executing
status after another consumer's later status
([#7554](#7554))
([69b43e0](69b43e0))
* **jobsdb:** old jobs not expiring for every consumer
([#7573](#7573))
([366f114](366f114))
* **jobsdb:** pickups stalling on status tables with skewed stats
([#7572](#7572))
([318446f](318446f))
* **jobsdb:** unionjobsdb functions pick the first datasets by table
name ([#7558](#7558))
([e94d6c5](e94d6c5))
* **router:** event order test only counts drained jobs of the last
dataset
([#7552](#7552))
([b0a097a](b0a097a))
* **router:** mask secrets in array-shaped reporting samples
([#7536](#7536))
([902160f](902160f))
* **warehouse:** hot-reload degraded workspaces without aborting
restored uploads
([#7564](#7564))
([cb98598](cb98598))
* **warehouse:** match deltalake columns case-insensitively
([#7563](#7563))
([a7d30d7](a7d30d7))
* **warehouse:** migrate snowflake to gosnowflake v2.3.0
([#7542](#7542))
([cc09426](cc09426))
* **warehouse:** skip job-creation error log on router shutdown
([#7567](#7567))
([895367e](895367e))


### Miscellaneous

* **deps:** bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6
([#7545](#7545))
([35ee952](35ee952))
* export only the +Inf bucket for limiter timers
([#7570](#7570))
([4429472](4429472))
* **router:** add drainReason label to pipeline_processed_events
([#7561](#7561))
([af0aef8](af0aef8))
* sync release v1.92.0 to main branch
([#7534](#7534))
([9ab165d](9ab165d))
* **warehouse:** bump sqlconnect-go to v1.37.1
([#7575](#7575))
([acdad67](acdad67))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants