Repository navigation
chore: add test cases to am for onboarding amplitude to transformerproxy - #4701
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Summary by CodeRabbit
WalkthroughAdds a new AM destination network handler that prepares and invokes a proxy, processes Axios responses, and maps HTTP outcomes to per-event results. It handles success, retryable errors (including throttling), batch failures with per-item flags, and aborts, exporting a single networkHandler function. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant S as Source Events
participant NH as networkHandler (AM)
participant PP as prepareProxy
participant PX as proxy.invoke
participant AX as Axios
participant API as AM Destination API
participant RH as responseHandler
S->>NH: events, request config
NH->>PP: build proxy request
PP-->>NH: proxyRequest
NH->>PX: send proxyRequest
PX->>AX: HTTP request
AX->>API: POST batch
API-->>AX: HTTP response (status, data, headers)
AX-->>PX: response
PX-->>NH: response
NH->>RH: process response (status, payload)
alt 2xx Success
RH-->>NH: per-event success metadata
else 429/5xx Retryable
RH-->>NH: throws RetryableError
else Throttled subset
RH-->>NH: throws RetryableError or ThrottledError (tagged items)
else Batch failure (partial)
RH-->>NH: per-item results with dontBatch flags
else Other errors
RH-->>NH: throws AbortedError
end
NH-->>S: mapped results or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## hotfix/amplitude #4701 +/- ##
===================================================
Coverage ? 91.81%
===================================================
Files ? 651
Lines ? 34529
Branches ? 8107
===================================================
Hits ? 31703
Misses ? 2574
Partials ? 252 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
| }, | ||
| { | ||
| name: 'am', | ||
| description: 'Test 11: for http endpoint single event throttled scenario', |
There was a problem hiding this comment.
this is no longer needed right we are going to remove it right
There was a problem hiding this comment.
Yes, but as we will onboard the routerTransformer batching later, after onboarding the transformerProxy, we need this.
|
Allure Test reports for this run are available at:
|
* feat: implement transformerProxy for am * fix: test cases * chore: add type to function * chore: add some more type and test cases * chore: add small comment
|
Allure Test reports for this run are available at:
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/v1/destinations/am/networkHandler.ts (5)
13-28: Two‑phase dontBatch status logic looks right; simplify to a map for clarityThe 400/500 split is correct for two‑phase retries. You can return directly via map to reduce mutation.
Apply this diff:
-const populateResponseWithDontBatch = (rudderJobMetadata: ProxyMetdata[], errorMessage: string) => { - const responseWithIndividualEvents: DeliveryJobState[] = []; - - rudderJobMetadata.forEach((metadata) => { - responseWithIndividualEvents.push({ - // dontBatch will only exist if it is in batch + proxy flow. - statusCode: metadata.dontBatch ? 400 : 500, - metadata: { - ...metadata, - dontBatch: true, - }, - error: errorMessage, - }); - }); - return responseWithIndividualEvents; -}; +const populateResponseWithDontBatch = (rudderJobMetadata: ProxyMetdata[], errorMessage: string) => { + return rudderJobMetadata.map((metadata) => ({ + // dontBatch will only exist if it is in batch + proxy flow. + statusCode: metadata.dontBatch ? 400 : 500, + metadata: { + ...metadata, + dontBatch: true, + }, + error: errorMessage, + })); +};Based on learnings
36-39: Safer error extraction and cleaner formattingAvoid destructuring when response may be undefined, and don’t JSON.stringify strings (adds quotes).
Apply this diff:
- const { status, response } = destinationResponse; - const { error } = response; - const errorMessage = JSON.stringify(error) || 'unknown error'; + const { status, response } = destinationResponse; + const rawErr = response?.error; + const errorMessage = + typeof rawErr === 'string' + ? rawErr + : rawErr?.message ?? JSON.stringify(rawErr) ?? 'unknown error';
80-90: Add statTags for observability on batch failures (optional)Helps categorize failures without parsing messages.
Apply this diff:
return { status, // this status is not used by server, server uses the status of response message: `Request Failed for a batch of events during ${DESTINATION} response transformation: with status "${status}" due to ${errorMessage} (Retryable)`, + statTags: { errorCategory: 'batch_failure', destination: DESTINATION }, destinationResponse, response: populateResponseWithDontBatch(rudderJobMetadata, errorMessage), };
91-97: Reuse computed errorMessageAvoid recomputing/quoting the error; use the already-normalized message.
Apply this diff:
- throw new AbortedError( - `Request Failed during ${DESTINATION} response transformation: with status "${status}" due to "${ - JSON.stringify(response.error) || 'unknown error' - }", (Aborted)`, - 400, - destinationResponse, - ); + throw new AbortedError( + `Request Failed during ${DESTINATION} response transformation: with status "${status}" due to "${errorMessage}", (Aborted)`, + 400, + destinationResponse, + );
60-78: Align 429 throttling to use ThrottledError consistently
Insrc/v1/destinations/am/networkHandler.ts, both item-level and general 429 cases should throwThrottledError—all other v1 handlers rely on it to trigger throttling metrics/backoff. If you need a distinct retry path for specific items, document why it diverges.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
test/integrations/destinations/am/dataDelivery/data.tsis excluded by!**/test/**
📒 Files selected for processing (1)
src/v1/destinations/am/networkHandler.ts(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4707
File: src/v1/destinations/am/networkHandler.ts:0-0
Timestamp: 2025-10-13T03:41:56.467Z
Learning: In the AM destination network handler (src/v1/destinations/am/networkHandler.ts), the populateResponseWithDontBatch function uses conditional status codes: 400 for events that already have metadata.dontBatch=true (meaning they've been retried individually and failed), and 500 for first-time failures (to trigger an unbatched retry). This two-phase retry pattern prevents infinite retries of persistently failing events.
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4589
File: scripts/common.ts:74-78
Timestamp: 2025-08-28T15:39:08.293Z
Learning: User ItsSudip prefers simpler solutions over complex edge case handling, especially when the simpler approach is sufficient for the actual use case.
📚 Learning: 2025-09-24T10:41:29.258Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4654
File: src/v1/destinations/am/networkHandler.ts:50-86
Timestamp: 2025-09-24T10:41:29.258Z
Learning: In the AM destination network handler (src/v1/destinations/am/networkHandler.ts), ItsSudip confirmed that hardcoded status codes (500/400) in RetryableError and AbortedError constructors are acceptable because the actual HTTP status verification happens before setting these codes in the error flow.
Applied to files:
src/v1/destinations/am/networkHandler.ts
📚 Learning: 2025-10-13T03:41:56.467Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4707
File: src/v1/destinations/am/networkHandler.ts:0-0
Timestamp: 2025-10-13T03:41:56.467Z
Learning: In the AM destination network handler (src/v1/destinations/am/networkHandler.ts), the populateResponseWithDontBatch function uses conditional status codes: 400 for events that already have metadata.dontBatch=true (meaning they've been retried individually and failed), and 500 for first-time failures (to trigger an unbatched retry). This two-phase retry pattern prevents infinite retries of persistently failing events.
Applied to files:
src/v1/destinations/am/networkHandler.ts
🧬 Code graph analysis (1)
src/v1/destinations/am/networkHandler.ts (2)
src/v1/destinations/reddit/networkHandler.js (1)
populateResponseWithDontBatch(13-24)src/types/destinationTransformation.ts (3)
ProxyMetdata(136-147)DeliveryJobState(231-235)DeliveryV1Response(237-244)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
- GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
- GitHub Check: Code Coverage
- GitHub Check: UT Tests
- GitHub Check: test_and_publish
- GitHub Check: Analyze (go)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
src/v1/destinations/am/networkHandler.ts (2)
53-59: Retryable path LGTMUsing RetryableError with a hardcoded 500 here aligns with the established error flow.
Based on learnings
100-107: Handler wiring LGTMConsistent with other destinations (prepareProxy, proxy, processAxiosResponse, responseHandler).
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
Adding test cases for transformerproxy.
What is the related Linear task?
Resolves INT-4077
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.