Skip to content

feat: implement Forward RPC for control-plane requests to workspace pyt transformers - #7143

Merged
mihir20 merged 15 commits into
masterfrom
mihir/pipe-3144
Jul 6, 2026
Merged

mihir20 merged 15 commits into
masterfrom
mihir/pipe-3144

Conversation

@mihir20

@mihir20 mihir20 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Implements the processor's Forward RPC — the control-plane-facing
entrypoint that routes a transformation-test request to a workspace's
per-workspace pyt-{workspaceID} deployment.

Flow: config-backend → cp-router → rudderstack-processor (this) → pyt-{workspaceID}.
On each call the processor maps the op to a pyt endpoint, scales the (Keda-idled,
0-replica) deployment up if needed, forwards the request, and passes the pyt's
HTTP status/body straight back.

Python only. These four endpoints exist for the Python transformation-test
flow. JavaScript tests stay on rudder-transformer and never reach the processor;
routing JS here would need separate handling.

Changes

processor/cpservice/ — the Forward handler

  • Forward(ctx, req) maps req.Op (proto Op enum) to the matching pyt endpoint
    method; an unspecified/unknown op ⇒ gRPC InvalidArgument.
  • ensureScaled uses get-before-set on the scaler (scale up only when at 0
    replicas). Concurrent Forwards for the same workspace are collapsed via
    singleflight, so a burst triggers one scale-up (and one cluster-wide
    List), not one per request.
  • NewService builds a k8s-backed pyt scaler (falling back to a no-op when the
    k8s client can't be built, so the processor still serves) and a
    user_transformer-backed forwarder; WithScaler/WithForwarder inject fakes in
    tests.
  • Error mapping: missing pyt deployment ⇒ FailedPrecondition; scaler failure ⇒
    Internal; forward failure ⇒ Unavailable.

processor/internal/transformer/user_transformer/ — the forward client

  • New per-endpoint methods on the existing Client: Test (/test), TestRun
    (/testRun), TestLibrary (/test-library), ExtractLibs (/extract-libs),
    all delegating to a shared forwardTest helper.
  • forwardTest reuses the client's existing HTTP client and cold-start detection
    (isColdStartError) but is time-boxed by the caller's ~60s deadline: it
    retries only on cold-start signals (connection refused / DNS / 502 / 503) and
    passes any other response through unchanged.
  • Reuses the existing maxRetry / maxRetryBackoffInterval settings; new options
    WithMaxRetryBackoffInterval / WithMaxRetry let cpservice override them (via
    reloadable Processor.UserTransformer.pytTest* config) so the forward path
    retries a cold pyt quickly instead of with the event path's large default.

app/apphandlers/ — wiring

  • Processor and embedded handlers construct the service via the updated
    NewService when cpservice.ShouldConnect is true (node-0 only).

Config

Key Default Purpose
Processor.UserTransformer.pytTestScaleReplicas 2 replicas to scale a cold pyt up to
Processor.UserTransformer.pytTestMaxRetryBackoffInterval 1s max backoff between forward retries
Processor.UserTransformer.pytTestMaxRetry 60 retry budget for the forward path (ctx deadline is the hard bound)

Testing

Linear Ticket

pipe-3144

Security

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

mihir20 added 8 commits June 25, 2026 12:22
… replica management

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
…ction

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
…yt transformers

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 force-pushed the mihir/pipe-3144 branch from fc3e664 to cf6472d Compare July 1, 2026 20:08
🔒 Scanned for secrets using gitleaks 8.28.0
Base automatically changed from mihir/pipe-3143 to master July 3, 2026 07:58
mihir20 added 3 commits July 3, 2026 14:08
# Conflicts:
#	app/apphandlers/embeddedAppHandler.go
#	app/apphandlers/processorAppHandler.go
#	processor/cpservice/cpservice.go
#	processor/cpservice/cpservice_test.go

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested review from fracasula and ktgowtham July 3, 2026 09:21
@mihir20
mihir20 marked this pull request as ready for review July 3, 2026 09:22
@codecov

codecov Bot commented Jul 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.90476% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.63%. Comparing base (84fc747) to head (2e78c5c).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...l/transformer/user_transformer/user_transformer.go 86.88% 4 Missing and 4 partials ⚠️
processor/cpservice/cpservice.go 71.42% 5 Missing and 1 partial ⚠️
app/apphandlers/processorAppHandler.go 0.00% 4 Missing ⚠️
app/apphandlers/embeddedAppHandler.go 0.00% 2 Missing ⚠️
processor/internal/pytscaler/k8s.go 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7143      +/-   ##
==========================================
- Coverage   80.00%   79.63%   -0.38%     
==========================================
  Files         587      595       +8     
  Lines       65615    66095     +480     
==========================================
+ Hits        52498    52634     +136     
- Misses      10026    10340     +314     
- Partials     3091     3121      +30     

☔ 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.

🔒 Scanned for secrets using gitleaks 8.28.0
return nil, status.Error(codes.InvalidArgument, "workspaceId is required")
}

if err := s.ensureScaled(ctx, req.WorkspaceId); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@mihir20 Possible SSRF below, please have a look:

WorkspaceId (proto3 string, no format constraint) is only lowercased and then strings.ReplaceAll'd into perWorkspacePyTURLTemplate (default http://pyt-{workspaceID}:8080) at user_transformer.go:632, used at :528, dialed at :540.

There is no validation of WorkspaceId anywhere on this path — Forward only checks the op is known and the ID is non-empty (forward.go). URL-significant characters (@, #, ?, :, /) survive lowercasing.

  • workspaceID = "[email protected]#" → the string http://[email protected]#:8080/test, which Go's
    net/url parses (RFC 3986) as userinfo=pyt-a, host=evil.com, port=80, with # starting
    the fragment — so :8080/test becomes the fragment, req.URL.Path is empty, and the outbound
    request is POST / HTTP/1.1 to evil.com:80

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a validation layer

Comment thread processor/cpservice/forward_test.go Outdated

// fakeForwarder records which endpoint method was called and returns a canned
// response, so tests can assert Forward dispatches each op to the right method.
type fakeForwarder struct {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we move the helpers below and start with the tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread processor/cpservice/forward_test.go Outdated

func (s *fakeScaler) SetReplicaCount(_ context.Context, _ string, count int) error {
s.setCalled, s.setCount = true, count
return nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we testing the path where we return an error here?

@mihir20 mihir20 Jul 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a test for when scaler fails

ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
defer cancel()
_, _, err := client.Test(ctx, "ws-1", []byte(`{}`))
require.Error(t, err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you're expecting a context deadline exceeded here. Could be more specific.


t.Run("stops retrying when the deadline is exceeded", func(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusServiceUnavailable)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we add the number of calls here and assert at the end of the test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// signals (connection refused, DNS failure, 502/503);
// any other response is returned as-is for the caller to pass through.
func (u *Client) forwardTest(ctx context.Context, workspaceID, path string, payload []byte) (int, []byte, error) {
url := u.userTransformBaseURL("python", "", workspaceID) + path

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should check the configuration before forwarding, right? The configuration is reloadable and we could return a specific error that we can catch on forward.go like:

	if !u.config.perWorkspacePyTEnabled.Load() || u.config.forMirroring {
		return 0, nil, ErrPerWorkspacePyTNotEnabled
	}

And then in forward.go upon receiving that error we could return:

status.Error(codes.FailedPrecondition, "per-workspace PyT is not enabled")

Wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

makes sense

// different workspaces key on distinct IDs and run independently. (The shared
// call runs on the first caller's ctx; a fast scale makes that window
// negligible, and on error the caller retries the whole RPC.)
func (s *Service) ensureScaled(ctx context.Context, workspaceID string) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With this new ensureScaled you're calling GetReplicaCount and then SetReplicaCount in succession. They are both doing a List() (see s.resolveNamespace(ctx, name)). There could be some room for optimization?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated instead of get and then set, replaced with a single EnsureScaled interface

🔒 Scanned for secrets using gitleaks 8.28.0
🔒 Scanned for secrets using gitleaks 8.28.0
@mihir20
mihir20 requested a review from fracasula July 6, 2026 07:47
@mihir20
mihir20 enabled auto-merge (squash) July 6, 2026 07:51
@mihir20
mihir20 merged commit 8a704cf into master Jul 6, 2026
73 checks passed
@mihir20
mihir20 deleted the mihir/pipe-3144 branch July 6, 2026 08:16
itsmihir pushed a commit that referenced this pull request Jul 6, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.80.0-rc.1](v1.79.0...v1.80.0-rc.1)
(2026-07-06)


### Features

* add control-plane connection management for processor
([#7126](#7126))
([ea6ca00](ea6ca00))
* carry integration version on DestinationT to the transformer
([#7125](#7125))
([421c613](421c613))
* implement Forward RPC for control-plane requests to workspace pyt
transformers
([#7143](#7143))
([8a704cf](8a704cf))
* implement Kubernetes deployment scaler for workspace replica
management
([#7123](#7123))
([84fc747](84fc747))
* monthly active records (MAR) metering pipeline
([#7119](#7119))
([d1df486](d1df486))


### Bug Fixes

* **router:** transformer returning response with empty metadata array
causes server to panic
([#7144](#7144))
([d6a4dbc](d6a4dbc))


### Miscellaneous

* enable compression for google pubsub
([#7137](#7137))
([11c9ab8](11c9ab8))

---
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>
itsmihir pushed a commit that referenced this pull request Jul 7, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.80.0](v1.79.0...v1.80.0)
(2026-07-06)


### Features

* add control-plane connection management for processor
([#7126](#7126))
([ea6ca00](ea6ca00))
* carry integration version on DestinationT to the transformer
([#7125](#7125))
([421c613](421c613))
* implement Forward RPC for control-plane requests to workspace pyt
transformers
([#7143](#7143))
([8a704cf](8a704cf))
* implement Kubernetes deployment scaler for workspace replica
management
([#7123](#7123))
([84fc747](84fc747))
* monthly active records (MAR) metering pipeline
([#7119](#7119))
([d1df486](d1df486))


### Bug Fixes

* **router:** transformer returning response with empty metadata array
causes server to panic
([#7144](#7144))
([d6a4dbc](d6a4dbc))


### Miscellaneous

* enable compression for google pubsub
([#7137](#7137))
([11c9ab8](11c9ab8))

---
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.

3 participants