Repository navigation
feat: implement Forward RPC for control-plane requests to workspace pyt transformers - #7143
Conversation
… 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
# 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
Codecov Report❌ Patch coverage is 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. 🚀 New features to boost your workflow:
|
🔒 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 { |
There was a problem hiding this comment.
@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 stringhttp://[email protected]#:8080/test, which Go's
net/urlparses (RFC 3986) as userinfo=pyt-a, host=evil.com, port=80, with#starting
the fragment — so:8080/testbecomes the fragment,req.URL.Pathis empty, and the outbound
request isPOST / HTTP/1.1toevil.com:80
There was a problem hiding this comment.
added a validation layer
|
|
||
| // 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 { |
There was a problem hiding this comment.
Can we move the helpers below and start with the tests?
|
|
||
| func (s *fakeScaler) SetReplicaCount(_ context.Context, _ string, count int) error { | ||
| s.setCalled, s.setCount = true, count | ||
| return nil |
There was a problem hiding this comment.
Are we testing the path where we return an error here?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Should we add the number of calls here and assert at the end of the test?
| // 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 |
There was a problem hiding this comment.
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?
| // 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
🤖 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>
🤖 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>
Description
Implements the processor's
ForwardRPC — the control-plane-facingentrypoint 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.
Changes
processor/cpservice/— theForwardhandlerForward(ctx, req)mapsreq.Op(protoOpenum) to the matching pyt endpointmethod; an unspecified/unknown op ⇒ gRPC
InvalidArgument.ensureScaleduses get-before-set on the scaler (scale up only when at 0replicas). Concurrent Forwards for the same workspace are collapsed via
singleflight, so a burst triggers one scale-up (and one cluster-wideList), not one per request.
NewServicebuilds a k8s-backed pyt scaler (falling back to a no-op when thek8s client can't be built, so the processor still serves) and a
user_transformer-backed forwarder;
WithScaler/WithForwarderinject fakes intests.
FailedPrecondition; scaler failure ⇒Internal; forward failure ⇒Unavailable.processor/internal/transformer/user_transformer/— the forward clientClient:Test(/test),TestRun(
/testRun),TestLibrary(/test-library),ExtractLibs(/extract-libs),all delegating to a shared
forwardTesthelper.forwardTestreuses the client's existing HTTP client and cold-start detection(
isColdStartError) but is time-boxed by the caller's ~60s deadline: itretries only on cold-start signals (connection refused / DNS / 502 / 503) and
passes any other response through unchanged.
maxRetry/maxRetryBackoffIntervalsettings; new optionsWithMaxRetryBackoffInterval/WithMaxRetrylet cpservice override them (viareloadable
Processor.UserTransformer.pytTest*config) so the forward pathretries a cold pyt quickly instead of with the event path's large default.
app/apphandlers/— wiringNewServicewhencpservice.ShouldConnectis true (node-0 only).Config
Processor.UserTransformer.pytTestScaleReplicasProcessor.UserTransformer.pytTestMaxRetryBackoffIntervalProcessor.UserTransformer.pytTestMaxRetryTesting
Linear Ticket
pipe-3144
Security