Skip to content

fix: transformBatch reporting metrics issue - #4559

Merged
itsmihir merged 12 commits into
developfrom
fix.reporting-metric-amplification
Sep 4, 2025
Merged

itsmihir merged 12 commits into
developfrom
fix.reporting-metric-amplification

Conversation

@itsmihir

@itsmihir itsmihir commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

This PR fixes the issue with reporting metrics generated when transformBatch is used.

What is the related Linear task?

Resolves OBS-828

Please explain the objectives of your changes below

Currently, there are two issues with the UT response when transformBatch is used:

  • Newly added events in UT do not contain a messageId. As a result, these events are not tracked in reporting metrics.
  • When UT fails, all input events are incorrectly marked as filtered. This causes rudder-transformer to return N + 1 events (where N is the number of input events marked as filtered, plus one additional event indicating the UT failure). However, the expected behavior is to return only a single event—the failed UT event—without any filtered events.

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.

@coderabbitai

coderabbitai Bot commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Ensures all transformed events include a valid message ID when missing from input.
    • Preserves and sets event name/type in output metadata for consistent downstream behavior.
    • Improves error-path handling by retaining links to original input message IDs.
  • Refactor

    • Streamlined metadata generation to consistently produce complete, reliable metadata across outputs.

Walkthrough

Adds generation and propagation of messageId/eventName/eventType for transformed events by importing generateUUID, introducing generateNewMetadata, and enhancing tracking of output/input message IDs (including on error) when assembling output metadata.

Changes

Cohort / File(s) Summary
User transform metadata handling
src/services/userTransform.ts
- Import generateUUID from @rudderstack/integrations-lib.
- Add generateNewMetadata to copy first input metadata and set new messageId plus eventName/eventType from the transform result.
- Track output IDs from ev.metadata.messageId or ev.metadata.messageIds; on ev.error also include input messageIds from commonMetadata.
- When emitting events, use ev.metadata if it contains a messageId, otherwise use generateNewMetadata(ev) to ensure metadata completeness.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant UserTransform as userTransform
  participant GenMeta as generateNewMetadata
  participant GenUUID as generateUUID

  Caller->>UserTransform: submit input events
  Note right of UserTransform: iterate transformed events

  alt metadata missing or no messageId
    UserTransform->>GenMeta: request metadata (ev, firstInput)
    GenMeta->>GenUUID: generate messageId
    GenUUID-->>GenMeta: messageId
    GenMeta-->>UserTransform: metadata with messageId & eventName/type
  else metadata present with messageId
    UserTransform-->>UserTransform: retain ev.metadata
  end

  UserTransform-->>UserTransform: collect output messageIds (ev.metadata.messageId / messageIds)
  alt ev.error present
    UserTransform-->>UserTransform: include input messageIds from commonMetadata
  end

  UserTransform-->>Caller: return events with ensured metadata
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • ItsSudip
  • vinayteki95
  • sandeepdsvs
  • koladilip

Suggestions:

  • Add unit tests for missing metadata, existing messageId, multiple messageIds, and error-path inclusion of input IDs.
  • Add inline comments documenting precedence for metadata fields and when generateNewMetadata is used.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 61496cb and 8089082.

📒 Files selected for processing (1)
  • src/services/userTransform.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/userTransform.ts
⏰ 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 AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • 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: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix.reporting-metric-amplification

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Aug 13, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.78%. Comparing base (d74003b) to head (8089082).
⚠️ Report is 4 commits behind head on develop.

Files with missing lines Patch % Lines
src/services/userTransform.ts 57.14% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4559      +/-   ##
===========================================
- Coverage    91.78%   91.78%   -0.01%     
===========================================
  Files          642      642              
  Lines        33931    33941      +10     
  Branches      8032     8035       +3     
===========================================
+ Hits         31145    31152       +7     
- Misses        2556     2559       +3     
  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.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

1 similar comment
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@itsmihir itsmihir changed the title fix: add messageIds to output set if metadata is empty chore: refactor transformBatch to return similar output as transformEvent Aug 14, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

2 similar comments
@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:

@itsmihir itsmihir changed the title chore: refactor transformBatch to return similar output as transformEvent fix: transformBatch reporting metrics issue Aug 20, 2025
@itsmihir
itsmihir marked this pull request as ready for review August 20, 2025 09:18
@itsmihir
itsmihir requested a review from a team as a code owner August 20, 2025 09:18
@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/services/userTransform.ts (1)

115-122: Don’t treat any error event as “global failure”; gate adding all input IDs to output set

Currently, when ev.error is present without messageId(s), you add every input messageId to messageIdsInOutputSet. If UT returns a mixed result (some successes and a separate error event without metadata), this will mask legitimately filtered inputs. Gate this behavior to the “single error event with no metadata” case.

Apply this diff:

-            } else if (ev.error) {
-              commonMetadata.messageIds.forEach((id) => messageIdsInOutputSet.add(id));
+            } else if (ev.error && destTransformedEvents.length === 1 && isEmpty(ev.metadata)) {
+              // When UT returns exactly one error event (no metadata), treat it as a batch-level failure
+              commonMetadata.messageIds.forEach((id) => messageIdsInOutputSet.add(id));

I also recommend adding tests to cover:

  • Single batch-level error event with no metadata → no filtered events emitted.
  • Mixed outputs: some success events with proper metadata + one error event with no metadata → only inputs without outputs are filtered; successes are preserved.

I can draft these tests if helpful.

🧹 Nitpick comments (1)
src/services/userTransform.ts (1)

143-147: LGTM on ensuring metadata.messageId for new/malformed metadata

This correctly ensures output events carry a messageId when ev.metadata is empty or missing one. With the revised generateNewMetadata, this will also preserve ev.metadata fields when present and avoid copying unrelated first-event messageIds into new events.

Optional: For readability, consider using optional chaining in the condition:

  • Replace !ev.metadata.messageId with !ev.metadata?.messageId
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bfa80ef and 01a8006.

📒 Files selected for processing (1)
  • src/services/userTransform.ts (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/services/userTransform.ts (1)
src/types/userTransformation.ts (1)
  • UserTransformationResponse (14-18)
⏰ 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). (6)
  • 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 AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
🔇 Additional comments (1)
src/services/userTransform.ts (1)

4-4: Confirm uuid dependency or switch to native crypto.randomUUID

It looks like no package.json was detected in the workspace, so we can’t automatically verify that the uuid package is declared. Please check your project’s manifest and either add uuid to dependencies or drop the external dependency in favor of Node’s built-in API.

• Ensure you have a package.json (at the repo root or in the relevant workspace) with:
"uuid": "<version>" under dependencies
• If you’d rather avoid a new dependency, replace:

- import { v4 as uuidv4 } from 'uuid';
+ import { randomUUID } from 'crypto';

and update all uuidv4() calls to randomUUID().
• Verify your target Node.js version supports crypto.randomUUID (Node v14.17+).

Comment thread src/services/userTransform.ts Resolved
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

Comment thread src/services/userTransform.ts Resolved
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

Comment thread src/services/userTransform.ts Resolved
@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:

@krishna2020
krishna2020 force-pushed the fix.reporting-metric-amplification branch from 35047e9 to 8089082 Compare September 4, 2025 06:38
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2025

Copy link
Copy Markdown

@itsmihir
itsmihir merged commit 3192141 into develop Sep 4, 2025
@itsmihir
itsmihir deleted the fix.reporting-metric-amplification branch September 4, 2025 14:39
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