Skip to content

fix: remove hard check for timestamp for airship - #4214

Merged
maheshkutty merged 3 commits into
developfrom
fix.airship_timestamp
Apr 1, 2025
Merged

maheshkutty merged 3 commits into
developfrom
fix.airship_timestamp

Conversation

@maheshkutty

@maheshkutty maheshkutty commented Mar 27, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Remove ISO_8601 timestamp format check when converting to airship defined timestamp

What is the related Linear task?

Resolves INT-3461

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.

@maheshkutty
maheshkutty requested a review from a team as a code owner March 27, 2025 16:01
@coderabbitai

coderabbitai Bot commented Mar 27, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling during date-time string conversion, ensuring that invalid inputs are promptly identified and reported.
  • Tests
    • Added a new test case to verify that date-time strings with timezone offsets are correctly processed, bolstering overall test coverage.

Walkthrough

This pull request updates the functionality of the convertToAirshipTimestamp function by adding a new test case to validate its behavior when processing a date-time string that includes a timezone offset. Additionally, the logic for validating the timestamp variable is simplified, focusing solely on checking if the input is a string before parsing it. The changes enhance error handling by explicitly throwing an error for unsupported timestamps. No modifications were made to the declarations of exported or public entities.

Changes

File(s) Change Summary
src/v0/destinations/airship/utils.test.ts Added a test case for convertToAirshipTimestamp that checks the output for the input date-time string ('2025-03-27 16:00:48 +0100'), expecting the ISO formatted output ('2025-03-27T16:00:48Z').
src/v0/destinations/airship/utils.ts Simplified the validation logic for timestamp by checking if it is a string and parsing it with moment.utc(timestamp), throwing an InstrumentationError for invalid dates.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Suite
    participant U as convertToAirshipTimestamp
    participant M as moment.utc

    T->>U: Call with "2025-03-27 16:00:48 +0100"
    U->>M: Attempt conversion of input string
    M-->>U: Return formatted timestamp ("2025-03-27T16:00:48Z")
    U-->>T: Return formatted timestamp
Loading

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • krishna2020

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a1aac2 and 022c20e.

📒 Files selected for processing (1)
  • src/v0/destinations/airship/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/v0/destinations/airship/utils.ts
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • 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: 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: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: ingestion-service-test
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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.

Documentation and Community

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

@codecov

codecov Bot commented Mar 27, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.06%. Comparing base (078dca8) to head (62ae60d).
Report is 7 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4214      +/-   ##
===========================================
- Coverage    91.06%   91.06%   -0.01%     
===========================================
  Files          635      635              
  Lines        33172    33175       +3     
  Branches      7836     7837       +1     
===========================================
+ Hits         30208    30210       +2     
- Misses        2716     2748      +32     
+ Partials       248      217      -31     

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

@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

🔭 Outside diff range comments (1)
src/v0/destinations/airship/utils.test.ts (1)

399-475: 💡 Verification agent

🧩 Analysis chain

Verify that tests still properly handle error cases.

There are pipeline failures indicating that expected exceptions are not being thrown for invalid timestamps. This suggests the simplified validation check might be affecting error handling.


🏁 Script executed:

#!/bin/bash
# Check if the test failures are directly related to the code changes

# First, let's check the specific test case for invalid timestamps
rg -A 5 -B 5 "should throw error when timestamp is not supported" src/v0/destinations/airship/utils.test.ts

# Then check the corresponding implementation in utils.ts
rg -A 5 -B 5 "timestamp is not supported" src/v0/destinations/airship/utils.ts

# Finally, check the previous implementation of the validation condition 
git show HEAD~1:src/v0/destinations/airship/utils.ts | rg -A 3 -B 3 "Check if the input is a valid date string"

Length of output: 1913


Action Required: Resolve Error Handling Mismatch in Timestamp Conversion

The pipeline failures indicate that when an invalid timestamp like "abcd" is provided, the error message ends up as "timestamp is not supported: NaN" instead of the expected "timestamp is not supported: abcd". This appears to stem from converting the input string to a number before throwing the error.

Suggestions:

  • Preserve the Original Input: Store the original timestamp (e.g., in a variable like originalTimestamp) before converting it. Then use this original value in the error message.
  • Review the Conversion Order: Consider adjusting the order of operations so that the string validation using moment.utc(timestamp, moment.ISO_8601, true) does not inadvertently mask the intended error handling.
  • Double-check Similar Cases: Verify that other error scenarios (such as the incorrect epoch second case) produce error messages that include the initial input rather than its converted form.

For example, updating the error branch as follows could address the issue:

- timestamp = Number(timestamp); // Convert string to number
+ const originalTimestamp = timestamp;
+ timestamp = Number(timestamp); // Convert string to number
...
- throw new InstrumentationError(`timestamp is not supported: ${timestamp}`);
+ throw new InstrumentationError(`timestamp is not supported: ${originalTimestamp}`);

Please adjust the error handling accordingly so that the tests correctly catch and match the expected exception messages.

🧰 Tools
🪛 GitHub Actions: Allure Test Reporter

[error] 468-468: Test failed: Expected substring 'timestamp is not supported: abcd' but received function did not throw.

🧹 Nitpick comments (1)
src/v0/destinations/airship/utils.ts (1)

57-88: Consider refactoring to improve readability and consistency.

The function has multiple code paths and validation conditions. The change to simplify the string validation makes sense, but consider refactoring to make the validation logic more consistent between string and number inputs.

export const convertToAirshipTimestamp = (timeValue: string | number): string => {
  let millis;
  let timestamp = timeValue;
  // Check if the input is a string containing a numeric timestamp
  if (typeof timestamp === 'string' && isNumeric(timestamp)) {
    timestamp = Number(timestamp); // Convert string to number
  }

  // Check if the input is a valid date string
  if (typeof timestamp === 'string') {
+    const parsedDate = moment.utc(timestamp);
+    if (!parsedDate.isValid()) {
+      throw new InstrumentationError(`timestamp is not supported: ${timestamp}`);
+    }
-    return moment.utc(timestamp).format(AIRSHIP_TIMESTAMP_FORMAT);
+    return parsedDate.format(AIRSHIP_TIMESTAMP_FORMAT);
  }

  // If it's a number, handle different timestamp formats
  if (typeof timestamp === 'number') {
    const { length } = timestamp.toString();

    if (length === 10) {
      millis = timestamp * 1000; // Convert seconds to milliseconds
    } else if (length === 13) {
      millis = timestamp; // Already in milliseconds
    } else if (length === 16) {
      millis = Math.floor(timestamp / 1000); // Convert microseconds to milliseconds
    } else {
      throw new InstrumentationError(`timestamp is not supported: ${timestamp}`);
    }

+    const parsedDate = moment.utc(millis);
+    if (!parsedDate.isValid()) {
+      throw new InstrumentationError(`timestamp is not supported: ${timestamp}`);
+    }
-    return moment.utc(millis).format(AIRSHIP_TIMESTAMP_FORMAT);
+    return parsedDate.format(AIRSHIP_TIMESTAMP_FORMAT);
  }

  throw new InstrumentationError(`timestamp is not supported: ${timestamp}`);
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 59c5d1e and 9a1aac2.

📒 Files selected for processing (2)
  • src/v0/destinations/airship/utils.test.ts (1 hunks)
  • src/v0/destinations/airship/utils.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/v0/destinations/airship/utils.ts (1)
src/v0/destinations/airship/transform.js (1)
  • timestamp (139-139)
🪛 GitHub Actions: Allure Test Reporter
src/v0/destinations/airship/utils.test.ts

[error] 57-57: Test failed: Expected substring 'timestamp is not supported: abcd' but received function did not throw.


[error] 468-468: Test failed: Expected substring 'timestamp is not supported: abcd' but received function did not throw.

⏰ Context from checks skipped due to timeout of 90000ms (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 ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: ingestion-service-test
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/airship/utils.test.ts (1)

452-456: Test case addition looks appropriate.

The new test case checks for handling date-time strings with timezone offsets, which aligns with the changes made to the validation logic in the utils.ts file. This test helps verify that removing the strict ISO 8601 validation doesn't break functionality for valid date-time strings in different formats.

Comment thread src/v0/destinations/airship/utils.ts Resolved
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@krishna2020 krishna2020 added the DO NOT MERGE Don't merge this PR without having discussion label Mar 28, 2025
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2025

Copy link
Copy Markdown

@maheshkutty maheshkutty removed the DO NOT MERGE Don't merge this PR without having discussion label Apr 1, 2025
@maheshkutty
maheshkutty requested a review from krishna2020 April 1, 2025 09:04
@maheshkutty
maheshkutty merged commit c03829d into develop Apr 1, 2025
@maheshkutty
maheshkutty deleted the fix.airship_timestamp branch April 1, 2025 09:57
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.

4 participants