Skip to content

feat(mp): add endpointPath to transformer responses - #4649

Merged
koladilip merged 2 commits into
developfrom
chore/add-endpoint-to-transformer-responses
Sep 22, 2025
Merged

koladilip merged 2 commits into
developfrom
chore/add-endpoint-to-transformer-responses

Conversation

@koladilip

Copy link
Copy Markdown
Contributor

Summary

This PR adds the endpointPath field to Mixpanel destination transformer responses to provide additional endpoint information.

Changes

  • transform.js: Refactored setImportCredentials to return endpoint details with path information
  • util.js: Updated batched request configuration to include endpointPath
  • Test files: Updated test data to reflect the new response structure with endpointPath

Technical Details

  • Added endpointPath field to transformer responses for better endpoint identification
  • Maintained backward compatibility while enhancing response structure
  • Updated all relevant test cases to match the new response format

Testing

  • All existing tests have been updated to include the new endpointPath field
  • No breaking changes to existing functionality

@koladilip
koladilip requested review from a team and sivashanmukh as code owners September 18, 2025 07:18
@koladilip
koladilip requested review from a team, maheshkutty and vinayteki95 September 18, 2025 07:18
@coderabbitai

coderabbitai Bot commented Sep 18, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor

    • Standardized endpoint construction across engage and group routes for more consistent request handling.
    • Response objects now include endpointPath to align single and batched request processing.
    • Batched requests propagate endpointPath for improved consistency.
  • Chores

    • Internal restructuring of credential handling and response building to streamline integrations.
  • Notes

    • No user-facing functionality changes; stability and maintainability improvements only.

Walkthrough

Refactors Mixpanel transform flows to split endpoint into base and path: setImportCredentials now returns endpointDetails {endpoint, path}; transform responses and batched requests include endpointPath; engage and groups routes build endpoints as base + '/' + path + '/'.

Changes

Cohort / File(s) Summary
MP transform: endpoint/path split and propagation
src/v0/destinations/mp/transform.js
setImportCredentials now returns { endpointDetails: { endpoint, path }, headers, params }. Response builders consume endpointDetails and set response.endpoint and response.endpointPath. Engage and groups flows assign endpointPath ('engage' / 'groups') and compute endpoint = base + '/' + endpointPath + '/'.
MP util: batch propagation of endpointPath
src/v0/destinations/mp/util.js
generateBatchedPayloadForArray now copies firstEvent.endpointPath into batchedRequest.endpointPath (in addition to endpoint, headers, params) so batched requests carry endpointPath.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Source
  participant Transform as MP Transform
  participant Creds as setImportCredentials
  participant Builder as responseBuilderSimple
  participant Batch as generateBatchedPayloadForArray
  participant Dest as Mixpanel Endpoint

  Source->>Transform: send event(s)
  Transform->>Creds: request credentials
  Creds-->>Transform: { endpointDetails:{endpoint, path}, headers, params }

  Transform->>Builder: build response
  Builder-->>Transform: response { endpoint, endpointPath, headers, params }

  rect #EEF8FF
    note right of Transform: Engage/Groups set endpointPath ('engage'/'groups') and compute endpoint = base + '/' + path + '/'
  end

  alt Single event
    Transform->>Dest: POST response.endpoint (with endpointPath)
  else Batched
    Transform->>Batch: batch events
    Batch-->>Transform: batchedRequest { endpoint, endpointPath, headers, params, payload }
    Transform->>Dest: POST batchedRequest.endpoint (with endpointPath)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • vinayteki95
  • maheshkutty
  • ItsSudip

Suggestions

  • Add unit tests covering single and batched flows to assert endpointPath is set and used.
  • Normalize path concatenation (trim slashes) or centralize join logic to avoid double/missing slashes.
  • Document endpointDetails/endpointPath shape in JSDoc or types for maintainers.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description summarizes the change, lists affected files, provides technical details, and notes testing updates, so it covers much of the template's intent, but it omits the required "What is the related Linear task? Resolved INT-XXX" field and does not include the repository's Developer checklist items that the template explicitly requests. Please add the required Linear ticket reference (for example "Resolves INT-XXX"), complete the "Please explain the objectives" section with any dependent changes or behavioral impacts, and fill in the Developer checklist (style, tests, breaking changes, docs) so reviewers have the standard metadata needed to approve and merge the PR.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "feat(mp): add endpointPath to transformer responses" is concise and accurately reflects the primary change of adding an endpointPath field to transformer responses; it follows conventional commit style and clearly communicates the intent for reviewers scanning the history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/add-endpoint-to-transformer-responses

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 Sep 18, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (bde0785) to head (4e420c0).
⚠️ Report is 7 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4649   +/-   ##
========================================
  Coverage    91.78%   91.78%           
========================================
  Files          642      642           
  Lines        33974    33979    +5     
  Branches      8037     8037           
========================================
+ Hits         31184    31189    +5     
  Misses        2560     2560           
  Partials       230      230           

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

@koladilip
koladilip enabled auto-merge (squash) September 18, 2025 07:28

@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: 1

🧹 Nitpick comments (4)
src/v0/destinations/mp/transform.js (3)

51-55: Structured return from setImportCredentials — add explicit error when credentials are missing

Nice refactor to endpointDetails. Add a clear failure if neither token nor service account creds are provided to avoid base64 of undefined.

Apply this diff:

 const setImportCredentials = (destConfig) => {
   const endpointPath = 'import';
   const endpointDetails = {
     endpoint: `${getBaseEndpoint(destConfig)}/${endpointPath}/`,
     path: endpointPath,
   };
   const params = {
     strict: destConfig.strictMode ? 1 : 0,
   };
   const { serviceAccountUserName, serviceAccountSecret, projectId, token } = destConfig;
   let credentials;
   if (token) {
     credentials = `${token}:`;
   } else if (serviceAccountUserName && serviceAccountSecret && projectId) {
     credentials = `${serviceAccountUserName}:${serviceAccountSecret}`;
     params.projectId = projectId;
   }
+  if (!credentials) {
+    throw new ConfigurationError(
+      'Mixpanel /import requires either a project token or service account credentials (username, secret, projectId).'
+    );
+  }
   const headers = {
     'Content-Type': 'application/json',
     Authorization: `Basic ${base64Convertor(credentials)}`,
   };
   return { endpointDetails, headers, params };
 };

Also applies to: 71-71


82-89: Avoid undefined query param project_id in response.params

If token auth is used, params.projectId is undefined and may leak as project_id=undefined. Set only when defined.

Apply this diff:

-    response.params = {
-      project_id: params?.projectId,
-      strict: params.strict,
-    };
+    const reqParams = { strict: params.strict };
+    if (params.projectId !== undefined) {
+      reqParams.project_id = params.projectId;
+    }
+    response.params = reqParams;

476-478: Group endpoint override — LGTM; consider DRYing URL construction

Overriding endpointPath and endpoint for groups is correct. To reduce duplication, consider a tiny helper to join base + path and ensure consistent trailing slashes.

src/v0/destinations/mp/util.js (1)

303-314: Propagate endpointPath safely when batching

batchedRequest.endpointPath is taken from firstEvent (src/v0/destinations/mp/util.js:303). transform.js and deleteUsers.js normally set endpointPath (e.g., src/v0/destinations/mp/transform.js:84,108,476; src/v0/destinations/mp/deleteUsers.js:15), but combineBatchRequestsWithSameJobIds (src/v0/util/index.js:2287) has no endpointPath handling — merged batches may lose it. Add a small fallback when building the batched request (e.g., default 'engage' or derive from firstEvent.endpoint) or update combineBatchRequestsWithSameJobIds to preserve/carry endpointPath.

📜 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 8808f72 and 3018150.

⛔ Files ignored due to path filters (2)
  • test/integrations/destinations/mp/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/mp/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (2)
  • src/v0/destinations/mp/transform.js (5 hunks)
  • src/v0/destinations/mp/util.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/mp/util.js
  • src/v0/destinations/mp/transform.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.

Applied to files:

  • src/v0/destinations/mp/util.js
🧬 Code graph analysis (1)
src/v0/destinations/mp/transform.js (2)
src/v0/destinations/mp/deleteUsers.js (2)
  • endpointPath (15-15)
  • endpointPath (79-79)
src/v0/destinations/mp/util.js (2)
  • getBaseEndpoint (458-468)
  • destination (197-197)
⏰ 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 Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • 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: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

Comment thread src/v0/destinations/mp/transform.js Resolved
@koladilip
koladilip force-pushed the chore/add-endpoint-to-transformer-responses branch from 3018150 to 5a3c750 Compare September 18, 2025 14:27
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

- Add endpointPath field to Mixpanel destination responses
- Refactor setImportCredentials to return endpoint details with path
- Update batched request configuration to include endpointPath
- Update test data to reflect new response structure with endpointPath
@koladilip
koladilip force-pushed the chore/add-endpoint-to-transformer-responses branch from 5a3c750 to c4fa00e Compare September 22, 2025 05:08
@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: 1

🧹 Nitpick comments (3)
src/v0/destinations/mp/transform.js (2)

82-89: Avoid undefined query params in router responses

Ensure project_id is omitted when absent to reduce noise and potential lint warnings.

-    response.params = {
-      project_id: params?.projectId,
-      strict: params.strict,
-    };
+    response.params = removeUndefinedValues({
+      project_id: params?.projectId,
+      strict: params.strict,
+    });

476-478: Groups endpoint set correctly; consider centralizing URL join

Setting endpointPath = 'groups' and composing with base is consistent. To DRY this and prevent future slash issues, consider a small helper (e.g., joinBaseAndPath(base, path)) used here and in the default branch.

src/v0/destinations/mp/util.js (1)

303-304: Add fallback for missing endpointPath in batched requests

Prefer an explicit endpointPath but fall back to the last path segment of endpoint when endpointPath is absent to support legacy transforms.

Location: src/v0/destinations/mp/util.js (around lines 303-304)

-  batchedRequest.endpointPath = firstEvent.endpointPath;
+  // Prefer explicit endpointPath; fallback to last path segment of endpoint (without trailing slash)
+  batchedRequest.endpointPath =
+    firstEvent.endpointPath ??
+    (typeof firstEvent.endpoint === 'string'
+      ? firstEvent.endpoint.replace(/\/+$/, '').split('/').pop()
+      : undefined);
📜 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 5a3c750 and c4fa00e.

⛔ Files ignored due to path filters (2)
  • test/integrations/destinations/mp/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/mp/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (2)
  • src/v0/destinations/mp/transform.js (5 hunks)
  • src/v0/destinations/mp/util.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/mp/util.js
  • src/v0/destinations/mp/transform.js
🧠 Learnings (1)
📚 Learning: 2025-05-29T13:29:39.436Z
Learnt from: maheshkutty
PR: rudderlabs/rudder-transformer#4359
File: src/v0/util/index.js:2272-2272
Timestamp: 2025-05-29T13:29:39.436Z
Learning: The `combineBatchRequestsWithSameJobIds` function in `src/v0/util/index.js` is used by both Mixpanel and Google AdWords Offline Conversions destinations in production. The function assumes metadata is always an array in multiple operations (forEach, filter, sort, map) and needs defensive programming to handle non-array metadata cases to prevent runtime errors.

Applied to files:

  • src/v0/destinations/mp/util.js
🧬 Code graph analysis (1)
src/v0/destinations/mp/transform.js (1)
src/v0/destinations/mp/util.js (2)
  • getBaseEndpoint (458-468)
  • destination (197-197)
🔇 Additional comments (1)
src/v0/destinations/mp/transform.js (1)

108-110: Endpoint composition for engage: normalized path segment — nice

Using endpointPath = 'engage' (no leading slash) and composing ${base}/${path}/ keeps URLs clean and avoids double slashes. This aligns with prior guidance.

Comment thread src/v0/destinations/mp/transform.js Resolved
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@koladilip
koladilip merged commit ff66dbf into develop Sep 22, 2025
@koladilip
koladilip deleted the chore/add-endpoint-to-transformer-responses branch September 22, 2025 07:07
maheshkutty pushed a commit that referenced this pull request Sep 24, 2025
- Add endpointPath field to Mixpanel destination responses
- Refactor setImportCredentials to return endpoint details with path
- Update batched request configuration to include endpointPath
- Update test data to reflect new response structure with endpointPath
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