Skip to content

chore: add test cases to am for onboarding amplitude to transformerproxy - #4701

Merged
ItsSudip merged 6 commits into
hotfix/amplitudefrom
chore/amProxyTestCases
Oct 14, 2025
Merged

ItsSudip merged 6 commits into
hotfix/amplitudefrom
chore/amProxyTestCases

Conversation

@ItsSudip

@ItsSudip ItsSudip commented Oct 7, 2025

Copy link
Copy Markdown
Member

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.

@ItsSudip
ItsSudip requested a review from a team as a code owner October 7, 2025 16:05
@ItsSudip
ItsSudip requested review from koladilip and utsabc October 7, 2025 16:05
@coderabbitai

coderabbitai Bot commented Oct 7, 2025 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features
    • Introduces a robust network handler for the AM destination, improving delivery reliability.
    • Supports per-event success metadata and detailed error feedback for batch and non-batch requests.
    • Automatically retries transient and throttled scenarios, with smarter throttling detection.
    • Decomposes batch failures to flag non-batchable items and continue processing others.
    • Provides clearer, destination-specific messaging for successes and failures.

Walkthrough

Adds 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

Cohort / File(s) Summary
AM destination network handler
src/v1/destinations/am/networkHandler.ts
New module implementing proxy preparation/invocation, Axios response parsing, and a destination-specific responseHandler covering success, retryable, throttled, batch-failure, and aborted cases; includes helper for non-batchable per-event error responses; exports networkHandler via module.exports.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Suggestions: Verify edge-case mappings for mixed throttling/partial failures, ensure error classes are correctly imported and surfaced, add unit tests for each status branch and per-item dontBatch handling.

Suggested reviewers

  • utsabc
  • vinayteki95

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title misrepresents the main change by mentioning “add test cases to am for onboarding amplitude to transformerproxy,” whereas the actual diff introduces a new networkHandler module for the AM destination rather than test files. Therefore it fails to summarize the primary change. Please update the title to clearly reflect the actual work—such as the addition of the AM destination networkHandler module—instead of referencing test cases.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed The pull request description adheres to the repository template by providing sections for change summary, related Linear task, objectives, behavioral changes, dependencies, utilities, performance notes, and both developer and reviewer checklists, with no missing sections.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Oct 7, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (hotfix/amplitude@b8d180a). Learn more about missing BASE report.

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.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

},
{
name: 'am',
description: 'Test 11: for http endpoint single event throttled scenario',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is no longer needed right we are going to remove it right

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, but as we will onboard the routerTransformer batching later, after onboarding the transformerProxy, we need this.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

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
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 clarity

The 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 formatting

Avoid 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 errorMessage

Avoid 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
In src/v1/destinations/am/networkHandler.ts, both item-level and general 429 cases should throw ThrottledError—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

📥 Commits

Reviewing files that changed from the base of the PR and between b8d180a and dcdc81c.

⛔ Files ignored due to path filters (1)
  • test/integrations/destinations/am/dataDelivery/data.ts is 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 LGTM

Using RetryableError with a hardcoded 500 here aligns with the established error flow.

Based on learnings


100-107: Handler wiring LGTM

Consistent with other destinations (prepareProxy, proxy, processAxiosResponse, responseHandler).

@ItsSudip
ItsSudip changed the base branch from develop to hotfix/amplitude October 14, 2025 10:06
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@ItsSudip
ItsSudip merged commit d511e7f into hotfix/amplitude Oct 14, 2025
@ItsSudip
ItsSudip deleted the chore/amProxyTestCases branch October 14, 2025 11:17
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.

5 participants