Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass initial kafka timestamp from Ender -> Vulcan for better e2e order latency tracking #1211

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

dydxwill
Copy link
Contributor

@dydxwill dydxwill commented Mar 20, 2024

Changelist

pass initial kafka timestamp from Ender -> Vulcan for better e2e order latency tracking

Test Plan

unit tested.

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2024

Walkthrough

These changes introduce a new headers field to the Kafka messaging system and update the handling of this field in the test data. This enhancement allows for additional metadata in Kafka messages, improving message processing capabilities.

Changes

Files Change Summary
indexer/packages/kafka/__tests__/batch-kafka-producer.test.ts Introduce a new headers field in the TestMessage interface and update the related test data processing function.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 852930e and b7454ca.
Files selected for processing (21)
  • indexer/packages/kafka/tests/batch-kafka-producer.test.ts (2 hunks)
  • indexer/packages/kafka/src/batch-kafka-producer.ts (3 hunks)
  • indexer/services/ender/tests/lib/block-processor.test.ts (2 hunks)
  • indexer/services/ender/src/handlers/handler.ts (2 hunks)
  • indexer/services/ender/src/lib/block-processor.ts (2 hunks)
  • indexer/services/ender/src/lib/on-message.ts (1 hunks)
  • indexer/services/ender/src/lib/types.ts (2 hunks)
  • indexer/services/ender/src/validators/asset-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/deleveraging-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/funding-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/liquidity-tier-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/market-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/order-fill-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/perpetual-market-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/stateful-order-validator.ts (2 hunks)
  • indexer/services/ender/src/validators/subaccount-update-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/trading-rewards-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/transfer-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/update-clob-pair-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/update-perpetual-validator.ts (1 hunks)
  • indexer/services/ender/src/validators/validator.ts (1 hunks)
Additional comments: 17
indexer/services/ender/src/validators/asset-validator.ts (1)
  • 13-13: The addition of the parameter _ in the createHandlers method is noted. It's common to use _ for unused parameters, but for clarity and future maintainability, consider renaming it to something more descriptive, even if it remains unused for now. Could you share the intended use of this parameter?
indexer/services/ender/src/validators/subaccount-update-validator.ts (1)
  • 22-22: Similar to the previous file, consider renaming the unused parameter _ in the createHandlers method to something more descriptive for clarity and future code maintainability. Could you clarify the intended use of this parameter?
indexer/services/ender/src/validators/update-perpetual-validator.ts (1)
  • 21-21: As seen in other validators, the unused parameter _ in the createHandlers method could benefit from a more descriptive name for clarity. What is the intended future use of this parameter?
indexer/services/ender/src/validators/update-clob-pair-validator.ts (1)
  • 23-23: Following the pattern in other validators, renaming the unused parameter _ in the createHandlers method to something more descriptive would enhance clarity. Could you explain the intended use of this parameter?
indexer/services/ender/src/validators/liquidity-tier-validator.ts (1)
  • 37-37: Consistent with previous observations, consider renaming the unused parameter _ in the createHandlers method for enhanced clarity. What is the purpose of this parameter?
indexer/services/ender/src/validators/deleveraging-validator.ts (1)
  • 41-41: In line with previous files, renaming the unused parameter _ in the createHandlers method could improve clarity. Could you share the intended use of this parameter?
indexer/services/ender/src/validators/trading-rewards-validator.ts (1)
  • 39-39: Noticing a slight variation, the unused parameter __ in the createHandlers method could also benefit from a more descriptive name. What is the intended use of this parameter?
indexer/services/ender/src/validators/perpetual-market-validator.ts (1)
  • 41-41: As with the other validators, consider renaming the unused parameter _ in the createHandlers method to enhance clarity. Could you explain the intended use of this parameter?
indexer/services/ender/src/validators/funding-validator.ts (1)
  • 45-45: The addition of a new parameter _ of type string to the createHandlers method is noted. It's important to ensure that this parameter is named descriptively if it's being used, or if it's intended to be a placeholder for future use, consider adding a comment to clarify its purpose. This will improve code readability and maintainability.
indexer/services/ender/src/validators/validator.ts (1)
  • 59-59: The addition of the messageReceivedTimestamp parameter to the createHandlers method is a positive change that aligns with the PR's objectives to incorporate Kafka message timestamps into the stateful order processing workflow. This enhances the application's ability to manage stateful operations with additional context.
indexer/services/ender/src/validators/transfer-validator.ts (1)
  • 49-49: Similar to the change in the FundingValidator, the addition of a new parameter _ of type string to the createHandlers method is noted. If this parameter is being used, consider renaming it to reflect its purpose more clearly. If it's intended to be a placeholder for future use, adding a comment to clarify its purpose would improve code readability and maintainability.
indexer/packages/kafka/src/batch-kafka-producer.ts (1)
  • 2-2: The addition of IHeaders to the import statement, the inclusion of headers?: IHeaders in the ProducerMessage type, and the handling of headers: message.headers in the push method for producerMessages are all positive changes that align with the PR's objectives. These modifications enable the incorporation of Kafka message timestamps and potentially other metadata into the stateful order processing workflow, enhancing the application's capabilities.

Also applies to: 13-13, 56-56

indexer/services/ender/src/lib/on-message.ts (1)
  • 86-86: The addition of message.timestamp as a parameter to the BlockProcessor constructor aligns with the PR's objectives to incorporate Kafka message timestamps into the processing workflow. Ensure that the BlockProcessor class is updated accordingly to handle this new parameter effectively. Additionally, verify the handling of the timestamp's format and time zone to ensure consistency and accuracy in temporal information processing.
indexer/services/ender/src/lib/types.ts (1)
  • 36-36: The addition of the IHeaders import and the headers field to the VulcanMessage interface is a suitable enhancement for incorporating Kafka message headers. Ensure that the usage of the headers field is correctly handled throughout the codebase, and take precautions to secure any sensitive information that might be included in these headers.
indexer/services/ender/src/handlers/handler.ts (1)
  • 36-36: The addition of the messageReceivedTimestamp parameter to the HandlerInitializer type and the Handler class constructor is well-aligned with the PR's objectives. Ensure that all handlers inheriting from the Handler class are updated to handle this new parameter effectively. Additionally, verify the handling of the timestamp's format and time zone within handlers to ensure consistency and accuracy in temporal information processing.
indexer/services/ender/src/validators/stateful-order-validator.ts (1)
  • 214-214: The addition of the messageReceivedTimestamp parameter to the createHandlers method in the StatefulOrderValidator class aligns with the PR's objectives. Ensure that handlers created by this class are updated to handle this new parameter effectively. Additionally, verify the handling of the timestamp's format and time zone within these handlers to ensure consistency and accuracy in temporal information processing.
indexer/services/ender/src/lib/block-processor.ts (1)
  • 80-80: The addition of the messageReceivedTimestamp property to the BlockProcessor class constructor is well-aligned with the PR's objectives. Ensure that the handling of this property within the class is consistent and accurate, especially regarding the timestamp's format and time zone. Additionally, consider the potential impacts on downstream processing logic that relies on the BlockProcessor.

@dydxwill dydxwill changed the title Add initial Kafka message timestamp for stateful order processing pass initial kafka timestamp from Ender -> Vulcan for better e2e order latency tracking Mar 20, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b7454ca and 13a8901.
Files selected for processing (11)
  • indexer/packages/kafka/tests/batch-kafka-producer.test.ts (3 hunks)
  • indexer/services/bazooka/src/vulcan-helpers.ts (3 hunks)
  • indexer/services/ender/tests/handlers/stateful-order/conditional-order-triggered-handler.test.ts (1 hunks)
  • indexer/services/ender/tests/handlers/stateful-order/stateful-order-placement-handler.test.ts (1 hunks)
  • indexer/services/ender/tests/handlers/stateful-order/stateful-order-removal-handler.test.ts (2 hunks)
  • indexer/services/ender/tests/helpers/indexer-proto-helpers.ts (4 hunks)
  • indexer/services/ender/src/handlers/handler.ts (5 hunks)
  • indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts (1 hunks)
  • indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (1 hunks)
  • indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts (1 hunks)
  • indexer/services/ender/src/lib/kafka-publisher.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • indexer/packages/kafka/tests/batch-kafka-producer.test.ts
  • indexer/services/ender/src/handlers/handler.ts
Additional comments: 13
indexer/services/ender/src/handlers/stateful-order/stateful-order-removal-handler.ts (1)
  • 45-48: The addition of message_received_timestamp and event_type to the generateConsolidatedVulcanKafkaEvent method call aligns with the PR's objective to incorporate Kafka message timestamps for stateful order processing. This change enhances the temporal context of the events being processed, which can be beneficial for order management and debugging.

Ensure that the messageReceivedTimestamp property is being correctly set and passed to this handler, as its correct functioning is crucial for the intended temporal tracking.

indexer/services/ender/src/handlers/stateful-order/stateful-order-placement-handler.ts (1)
  • 57-60: The inclusion of message_received_timestamp and event_type in the generateConsolidatedVulcanKafkaEvent method call within the createKafkaEvents method is consistent with the PR's goal to leverage Kafka message timestamps for improved order processing. This enhancement provides valuable temporal information for the events being handled.

It's important to verify that the messageReceivedTimestamp is accurately captured and utilized, as it plays a critical role in the temporal aspects of order processing.

indexer/services/ender/src/handlers/stateful-order/conditional-order-triggered-handler.ts (1)
  • 57-60: Adding message_received_timestamp and event_type to the generateConsolidatedVulcanKafkaEvent method call in the ConditionalOrderTriggeredHandler class aligns with the PR's objectives. This modification enriches the event data with temporal context, which is crucial for managing stateful order processing more effectively.

Confirm that the messageReceivedTimestamp is being correctly set and utilized within this handler to ensure the temporal data's accuracy and relevance.

indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-removal-handler.test.ts (1)
  • 136-136: The addition of headers in the test case for the StatefulOrderRemovalHandler class, specifically setting message_received_timestamp and event_type, is a good practice to ensure that the new functionality is covered by tests. This change helps validate that the headers are correctly included and processed in the Kafka events generated by the handler.

Ensure that the message_received_timestamp value used in tests accurately reflects the format and type expected in production to maintain test reliability and relevance.

indexer/services/bazooka/src/vulcan-helpers.ts (2)
  • 34-34: The addition of the headers field to the VulcanMessage interface is a crucial update that aligns with the PR's objectives to incorporate Kafka message timestamps into the stateful order processing workflow. This change enables the inclusion of metadata such as message_received_timestamp and event_type in the messages sent to Vulcan, enhancing the temporal context and categorization of the events.

Ensure that all instances where VulcanMessage is used are updated to consider the new headers field, maintaining consistency and leveraging the added metadata effectively.

  • 134-134: Including the headers property in the messages sent by the sendStatefulOrderMessages function is a positive step towards enriching the messages with additional context. This modification facilitates better tracking and processing of stateful order events by providing temporal and type information directly within the message headers.

Verify that the headers are correctly populated with the intended values, especially the message_received_timestamp, to ensure the accuracy and usefulness of the temporal data included in the messages.

indexer/services/ender/__tests__/handlers/stateful-order/conditional-order-triggered-handler.test.ts (1)
  • 146-146: The inclusion of headers in the test case for the ConditionalOrderTriggeredHandler class, specifically setting message_received_timestamp and event_type, ensures that the new functionality is adequately tested. This addition helps verify that the headers are correctly included and processed in the Kafka events generated by the handler.

It's important to ensure that the message_received_timestamp used in tests accurately reflects the expected format and type in production environments to maintain the reliability and relevance of the tests.

indexer/services/ender/__tests__/handlers/stateful-order/stateful-order-placement-handler.test.ts (1)
  • 183-183: The addition of headers in the test case for the StatefulOrderPlacementHandler class, with specific values for message_received_timestamp and event_type, is commendable as it ensures comprehensive test coverage for the new functionality. This change validates that the headers are correctly included and processed in the Kafka events generated by the handler.

Confirm that the message_received_timestamp used in the tests accurately mirrors the format and type expected in production to ensure the tests remain reliable and relevant.

indexer/services/ender/src/lib/kafka-publisher.ts (1)
  • 250-250: Including the headers field in the messages generated by the KafkaPublisher class is a significant enhancement that aligns with the PR's objectives. This change allows for the inclusion of additional metadata, such as message_received_timestamp and event_type, directly within the Kafka messages, providing valuable context for the message consumers.

Ensure that the headers are populated with accurate and relevant information, particularly the message_received_timestamp, to maximize the utility of the added metadata.

indexer/services/ender/__tests__/helpers/indexer-proto-helpers.ts (4)
  • 54-54: The import of IHeaders from 'kafkajs' aligns with the PR's objective to incorporate Kafka message timestamps for stateful order processing. This addition is crucial for handling message metadata, including timestamps.
  • 321-326: The addition of an optional headers parameter to the expectVulcanKafkaMessage function is a direct implementation of the PR's objective to leverage Kafka message timestamps. This change allows the function to accept message headers, including timestamps, for more precise testing and validation of Kafka messages.
  • 352-352: Assigning the headers property from the message object to the returned VulcanMessage is a necessary step to ensure that message metadata, including timestamps, is correctly propagated and available for further processing or testing. This change effectively integrates the new headers functionality into the existing message handling logic.
  • 360-360: Ensuring that the headers are included in the expect assertion for VulcanMessage is crucial for validating that the message headers, including any timestamp information, are correctly attached and handled. This addition enhances the test's ability to verify the correct handling of message metadata.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 13a8901 and c1876d2.
Files selected for processing (1)
  • indexer/packages/kafka/tests/batch-kafka-producer.test.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • indexer/packages/kafka/tests/batch-kafka-producer.test.ts

) {
this.block = block;
this.blockEventIndex = blockEventIndex;
this.indexerTendermintEvent = indexerTendermintEvent;
this.timestamp = DateTime.fromJSDate(block.time!);
this.txId = txId;
this.event = event;
this.messageReceivedTimestamp = messageReceivedTimestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just use the timestamp from this.block? I'm pretty sure we already have a helper to pull timestamp out of it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I wanted to only track Indexer system latency without block gossiping latency.

) {
this.block = block;
this.txId = txId;
this.messageReceivedTimestamp = messageReceivedTimestamp;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

@Christopher-Li Christopher-Li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to add metrics to Vulcan in another PR?

@dydxwill
Copy link
Contributor Author

Are you going to add metrics to Vulcan in another PR?

yeah

@dydxwill dydxwill merged commit 293bb47 into main Mar 20, 2024
11 checks passed
@dydxwill dydxwill deleted the wl/add_timestamps branch March 20, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants