Repository navigation
fix: correctly handle timestamp and date for airship - #4201
Conversation
WalkthroughThis 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
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
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/v0/destinations/airship/utils.ts (3)
56-87: Enhanced timestamp conversion logic handles multiple formatsThe 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 functionThe 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 messagesWhen 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 documentationThe addition of
AIRSHIP_TIMESTAMP_FORMATwith a comment referencing Airship's API documentation provides a clear source of truth for timestamp formatting.
59-59: Properly exported the new constantThe 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 fieldsThe modifications to the test data appropriately include timestamp-related fields (
af_campaignandaccount_creation) to test the new timestamp handling functionality.
85-96: Expected output correctly reflects timestamp conversionThe expected output for
account_creationis properly formatted as'2025-03-25T07:19:40Z'from the numeric value1742887180, demonstrating the timestamp conversion functionality.
241-245: Configuration for timestampAttributes properly addedThe destination configuration now includes the new
timestampAttributesarray which specifiesaccount_creationas a timestamp attribute, allowing the timestamp conversion to be correctly applied.src/v0/destinations/airship/transform.js (4)
41-41: Properly extracting timestampAttributes from ConfigAdded
timestampAttributesto the destructured Config object to access the new configuration parameter.
61-61: Updated prepareAttributePayload call with timestampAttributesModified function call to pass the timestampAttributes parameter, enabling the timestamp conversion functionality.
159-159: Consistent Config extraction in groupResponseBuilderThe same pattern for extracting
timestampAttributesis correctly applied in the groupResponseBuilder function, maintaining consistency.
177-177: Updated prepareAttributePayload call in groupResponseBuilderAppropriately 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 functionsProperly updated imports to include
convertToAirshipTimestampand remove unnecessary imports.
7-7: Enhanced type definition to support numeric timestampsThe input type for timestamp test cases is correctly updated to
string | numberto support both string and numeric epoch timestamps.
113-113: Added timestampAttributes constant for testingCreated a constant with the appropriate structure to test the new timestamp attribute functionality.
163-163: Updated function call to include timestampAttributesModified prepareAttributePayload call to include the new parameter, properly testing the enhanced functionality.
399-465: Comprehensive test suite for convertToAirshipTimestampThe 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 importIncluding the AIRSHIP_TIMESTAMP_FORMAT constant from config ensures consistent timestamp formatting throughout the Airship integration.
52-54: Well-defined type for timestamp attributesThe TimestampAttributes type provides a clear structure for identifying which attributes should be processed as timestamps.
162-171: Updated getAttributeValue handles timestamp attributes correctlyThe 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 attributesAdding the optional timestampAttributes parameter allows for flexible handling of timestamps in the attribute payload.
187-189: Effective extraction of timestamp attribute namesThe 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 parametersThe function call now correctly passes the attribute key, value, and timestamp attributes list, ensuring that timestamp values are properly processed.
|
Allure Test reports for this run are available at:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
2ca8c83 to
a82b6e7
Compare
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
|
Allure Test reports for this run are available at:
|
|
There was a problem hiding this comment.
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
timestampAttributefield 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
📒 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
convertToAirshipTimestampfunction which is being tested in this file.
7-7: Type update to support both string and number inputs.Good update to the
timestampTctype 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
timestampAttributesconstant properly supports testing the new timestamp handling functionality.
163-163: Function calls updated to include timestamp attributes parameter.All calls to
prepareAttributePayloadare 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
convertToAirshipTimestampincludes 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
commonDestinationConfigconstant 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
commonDestinationConfigreduces 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
getIdentifyTestCasefunction signature has been updated to receive adestinationparameter, allowing for more flexible test configurations.



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:
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
af_campaignandaccount_creationto improve data structure and processing.Tests