Skip to content

fix: correctly handle timestamp and date for airship - #4201

Merged
maheshkutty merged 5 commits into
developfrom
fix.airship_known_issue
Mar 26, 2025
Merged

maheshkutty merged 5 commits into
developfrom
fix.airship_known_issue

Conversation

@maheshkutty

@maheshkutty maheshkutty commented Mar 25, 2025 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

In this pr, we change our approach for checking the timestamp value we get from the source.
We now depend on destinationConfig to get a list of timestamp fields and try to convert the timestamp field to a format that airship expects.
We created a function to handle the below set of timestamp values, which we possibly get from the source:

  • Epoch timestamp as number
  • Epoch timestamp as a string
  • Date time, which is ISO-8601 compliant

If the above condition is not true, we will throw an error with relevant message.

What is the related Linear task?

Resolves INT-3356
Resolves INT-3423

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.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced timestamp processing for Airship, ensuring consistent formatting and more accurate event attribute tracking.
    • Extended payload construction to include additional time-specific details for improved data precision.
    • Added new attributes such as af_campaign and account_creation to improve data structure and processing.
  • Tests

    • Introduced comprehensive test cases to validate the new timestamp conversion and attribute handling, ensuring robust integration.
    • Updated existing tests to reflect changes in input structures and expected outputs, enhancing overall test coverage.

@maheshkutty
maheshkutty requested review from a team and sivashanmukh as code owners March 25, 2025 08:10
@maheshkutty
maheshkutty requested review from a team, chandumlg and krishna2020 March 25, 2025 08:10
@coderabbitai

coderabbitai Bot commented Mar 25, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request introduces changes to enhance timestamp handling for the Airship integration. A new constant for the Airship timestamp format is added to the configuration. Functions in the transformation and utility modules have been updated to accept and process a new parameter—timestamp attributes. Corresponding tests have been revised to validate the new conversion logic and ensure that timestamp attributes are handled correctly in both unit and integration test scenarios.

Changes

File(s) Change Summary
src/v0/destinations/airship/config.js Added constant AIRSHIP_TIMESTAMP_FORMAT ('YYYY-MM-DD[T]HH:mm:ss[Z]') and exported it.
src/v0/destinations/airship/transform.js Updated identifyResponseBuilder and groupResponseBuilder to extract timestampAttributes from config and pass it to prepareAttributePayload.
src/v0/destinations/airship/utils.ts,
src/v0/destinations/airship/utils.test.ts
Introduced type TimestampAttributes and enhanced convertToAirshipTimestamp, getAttributeValue, and prepareAttributePayload to process timestamp attributes; updated tests to include new cases and removed obsolete timestamp validations.
test/integrations/destinations/airship/processor/business.ts Modified integration tests: updated trait values, added new properties (af_campaign, account_creation), and revised expected outputs to account for new timestamp conversions.

Sequence Diagram(s)

sequenceDiagram
    participant R as Request (RudderMessage)
    participant TB as Response Builder (Identify/Group)
    participant PA as prepareAttributePayload
    participant GA as getAttributeValue
    participant CAT as convertToAirshipTimestamp

    R->>TB: Read Config (apiKey, dataCenter, timestampAttributes)
    TB->>PA: Call prepareAttributePayload(traits, Request, timestampAttributes)
    PA->>GA: Check if attribute needs timestamp conversion
    GA->>CAT: Convert value to Airship timestamp
    CAT-->>GA: Return formatted timestamp
    GA-->>PA: Return processed attribute
    PA-->>TB: Return complete attribute payload
Loading

Suggested reviewers

  • sivashanmukh
  • ItsSudip
  • koladilip
  • krishna2020
  • manish339k

Poem

I’m a rabbit hopping through lines of code,
With timestamps now in a brand new mode.
Constants and tests in a joyful array,
Each change a carrot to brighten the day.
My whiskers twitch at the bug-free delight,
Celebrating each hop with code shining bright!
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@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 (3)
src/v0/destinations/airship/utils.ts (3)

56-87: Enhanced timestamp conversion logic handles multiple formats

The rewritten function now properly handles various timestamp formats including:

  • Numeric strings
  • ISO 8601 date strings
  • Unix timestamps in seconds (10 digits)
  • Unix timestamps in milliseconds (13 digits)
  • Unix timestamps in microseconds (16 digits)

This implementation aligns with the PR objective of correctly handling timestamps for Airship.

Consider adding defensive coding for null/undefined values:

export const convertToAirshipTimestamp = (timeValue: string | number): string => {
+  if (timeValue === null || timeValue === undefined) {
+    throw new InstrumentationError('timestamp is null or undefined');
+  }
  let millis;
  let timestamp = timeValue;
  // Rest of the function...

56-87: Consider adding JSDoc documentation for the enhanced function

The convertToAirshipTimestamp function has become more complex with multiple format handling. Adding JSDoc documentation would help other developers understand its purpose and behavior.

/**
+ * Converts various timestamp formats to Airship's required timestamp format
+ * @param timeValue - A timestamp value as string or number
+ * @returns A formatted timestamp string in Airship's required format
+ * @throws {InstrumentationError} If the timestamp format is not supported
+ */
export const convertToAirshipTimestamp = (timeValue: string | number): string => {
  // Function implementation...

73-81: Consider adding more descriptive error messages

When throwing errors for unsupported timestamp formats, providing more specific information about what formats are supported would be helpful for debugging.

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}`);
+  throw new InstrumentationError(`Timestamp format not supported: ${timestamp}. Expected Unix timestamp in seconds (10 digits), milliseconds (13 digits), or microseconds (16 digits).`);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e6038d and 2ca8c8358a696b42a2fb1d12de64942b2409fc9d.

📒 Files selected for processing (5)
  • src/v0/destinations/airship/config.js (2 hunks)
  • src/v0/destinations/airship/transform.js (4 hunks)
  • src/v0/destinations/airship/utils.test.ts (7 hunks)
  • src/v0/destinations/airship/utils.ts (6 hunks)
  • test/integrations/destinations/airship/processor/business.ts (6 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/v0/destinations/airship/utils.ts (2)
src/v0/destinations/airship/transform.js (1)
  • timestamp (139-139)
src/v0/destinations/airship/config.js (1)
  • AIRSHIP_TIMESTAMP_FORMAT (47-47)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • 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: test_and_publish
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (20)
src/v0/destinations/airship/config.js (2)

46-47: Good addition of Airship timestamp format constant with clear documentation

The addition of AIRSHIP_TIMESTAMP_FORMAT with a comment referencing Airship's API documentation provides a clear source of truth for timestamp formatting.


59-59: Properly exported the new constant

The new constant is correctly exported so that it can be used by other modules.

test/integrations/destinations/airship/processor/business.ts (3)

17-21: Test data updated to include timestamp fields

The modifications to the test data appropriately include timestamp-related fields (af_campaign and account_creation) to test the new timestamp handling functionality.


85-96: Expected output correctly reflects timestamp conversion

The expected output for account_creation is properly formatted as '2025-03-25T07:19:40Z' from the numeric value 1742887180, demonstrating the timestamp conversion functionality.


241-245: Configuration for timestampAttributes properly added

The destination configuration now includes the new timestampAttributes array which specifies account_creation as a timestamp attribute, allowing the timestamp conversion to be correctly applied.

src/v0/destinations/airship/transform.js (4)

41-41: Properly extracting timestampAttributes from Config

Added timestampAttributes to the destructured Config object to access the new configuration parameter.


61-61: Updated prepareAttributePayload call with timestampAttributes

Modified function call to pass the timestampAttributes parameter, enabling the timestamp conversion functionality.


159-159: Consistent Config extraction in groupResponseBuilder

The same pattern for extracting timestampAttributes is correctly applied in the groupResponseBuilder function, maintaining consistency.


177-177: Updated prepareAttributePayload call in groupResponseBuilder

Appropriately modified to pass timestampAttributes to the prepareAttributePayload function, ensuring consistent behavior between identify and group events.

src/v0/destinations/airship/utils.test.ts (5)

2-3: Updated imports to include new timestamp functions

Properly updated imports to include convertToAirshipTimestamp and remove unnecessary imports.


7-7: Enhanced type definition to support numeric timestamps

The input type for timestamp test cases is correctly updated to string | number to support both string and numeric epoch timestamps.


113-113: Added timestampAttributes constant for testing

Created a constant with the appropriate structure to test the new timestamp attribute functionality.


163-163: Updated function call to include timestampAttributes

Modified prepareAttributePayload call to include the new parameter, properly testing the enhanced functionality.


399-465: Comprehensive test suite for convertToAirshipTimestamp

The new test suite thoroughly covers various timestamp formats and edge cases:

  • Standard ISO 8601 timestamps
  • Timestamps with milliseconds
  • Timestamps without 'T' or 'Z' characters
  • Epoch timestamps (seconds and millisecond formats)
  • Error handling for invalid timestamps

This ensures robust handling of different timestamp formats in the Airship integration.

src/v0/destinations/airship/utils.ts (6)

5-5: Good addition of AIRSHIP_TIMESTAMP_FORMAT import

Including the AIRSHIP_TIMESTAMP_FORMAT constant from config ensures consistent timestamp formatting throughout the Airship integration.


52-54: Well-defined type for timestamp attributes

The TimestampAttributes type provides a clear structure for identifying which attributes should be processed as timestamps.


162-171: Updated getAttributeValue handles timestamp attributes correctly

The function now accepts a key parameter and a list of timestamp attributes, allowing it to determine which values should be converted to Airship timestamps.


173-177: Good enhancement to prepareAttributePayload with optional timestamp attributes

Adding the optional timestampAttributes parameter allows for flexible handling of timestamps in the attribute payload.


187-189: Effective extraction of timestamp attribute names

The code efficiently extracts timestamp attribute names from the optional parameter, defaulting to an empty array if none are provided.


218-223: Updated getAttributeValue call with proper parameters

The function call now correctly passes the attribute key, value, and timestamp attributes list, ensuring that timestamp values are properly processed.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Mar 25, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.06%. Comparing base (c8b9912) to head (e393c3b).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4201   +/-   ##
========================================
  Coverage    91.05%   91.06%           
========================================
  Files          635      635           
  Lines        33152    33172   +20     
  Branches      7829     7836    +7     
========================================
+ Hits         30188    30208   +20     
+ Misses        2747     2716   -31     
- Partials       217      248   +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.

@maheshkutty

Copy link
Copy Markdown
Contributor Author

Comment thread src/v0/destinations/airship/utils.ts Resolved
krishna2020
krishna2020 previously approved these changes Mar 25, 2025
@krishna2020
krishna2020 force-pushed the fix.airship_known_issue branch from 2ca8c83 to a82b6e7 Compare March 26, 2025 05:35
@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:

koladilip
koladilip previously approved these changes Mar 26, 2025
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:

@sonarqubecloud

Copy link
Copy Markdown

@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 (1)
test/integrations/destinations/airship/processor/business.ts (1)

15-29: Fix the whitespace in timestamp attribute names.

There are extraneous spaces in the timestampAttribute field values which might cause matching issues.

-            timestampAttribute: 'account_creation ',
+            timestampAttribute: 'account_creation',
-            timestampAttribute: ' date.purchased',
+            timestampAttribute: 'date.purchased',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cbeee8 and e393c3b.

📒 Files selected for processing (3)
  • src/v0/destinations/airship/utils.test.ts (7 hunks)
  • src/v0/destinations/airship/utils.ts (6 hunks)
  • test/integrations/destinations/airship/processor/business.ts (9 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 (5)
  • GitHub Check: Code Coverage
  • 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
🔇 Additional comments (11)
src/v0/destinations/airship/utils.test.ts (5)

3-3: Changes to import statement look good.

The import now correctly includes the new convertToAirshipTimestamp function which is being tested in this file.


7-7: Type update to support both string and number inputs.

Good update to the timestampTc type to support both string and number inputs for timestamp values, reflecting the capability to handle epoch timestamps.


113-113: New constant for timestamp attributes testing.

The introduction of the timestampAttributes constant properly supports testing the new timestamp handling functionality.


163-163: Function calls updated to include timestamp attributes parameter.

All calls to prepareAttributePayload are appropriately updated to include the new parameter, ensuring consistent function signatures throughout the tests.

Also applies to: 195-195, 251-251, 322-322, 394-394


399-470: Comprehensive test cases for timestamp conversion.

The new test suite for convertToAirshipTimestamp includes a thorough set of test cases covering various timestamp formats including:

  • ISO 8601 datetimes with different variations
  • Epoch timestamps in seconds, milliseconds, and microseconds
  • Error cases for unsupported formats

This ensures robust handling of different timestamp formats that might be encountered.

test/integrations/destinations/airship/processor/business.ts (6)

3-9: Good addition of reusable destination configuration.

Creating the commonDestinationConfig constant improves code maintainability by centralizing the configuration.


41-47: Test data update for timestamp handling.

The test input data has been appropriately updated to include timestamp fields in various formats (string and number) to verify the conversion functionality.


110-127: Expected output reflects proper timestamp conversion.

The expected output now includes the timestamp fields with properly formatted ISO 8601 values, correctly testing the timestamp conversion functionality.


153-153: Using common configuration improves maintainability.

Replacing inline configuration with the reusable commonDestinationConfig reduces duplication.


159-163: Additional test coverage for timestamp handling.

Adding different timestamp format test cases ensures thorough verification of the timestamp conversion functionality.


263-263: Function signature update for flexibility.

The getIdentifyTestCase function signature has been updated to receive a destination parameter, allowing for more flexible test configurations.

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