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

Cu 86by7bekc create new kafka topics for validate and match rules kenya #254

Conversation

MatthewErispe
Copy link
Collaborator

@MatthewErispe MatthewErispe commented May 28, 2024

Summary by CodeRabbit

  • New Features

    • Introduced asynchronous validation messaging using Kafka.
    • Added new topics for interaction validation and matching.
  • Enhancements

    • Added constants for new Kafka topics.
    • Implemented new data models for validation and match notifications.
  • Infrastructure

    • Updated Docker configuration to support new Kafka topics with specific partition, replication, and retention settings.

@rcrichton
Copy link
Member

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The recent changes introduce Kafka-based asynchronous messaging to the JeMPI application. Specifically, new Kafka topics for validation and matching interactions were added, along with corresponding producers in the LibMPI and LinkerDWH classes. New data models for validation and match notifications were created to support these interactions, and relevant configurations were updated in the Docker helper script.

Changes

Files/Paths Change Summary
.../LibMPI.java Added a MyKafkaProducer instance for topicValidation to produce validation messages asynchronously using UUID for message identification.
.../GlobalConstants.java Added new constants TOPIC_INTERACTION_VALIDATE and TOPIC_INTERACTION_MATCH.
.../MatchNotification.java Introduced a new Java record MatchNotification containing Interaction and GoldenRecordWithScore objects.
.../Validation.java Introduced a new Java record Validation with fields for interactionId, goldenRecordId, deterministicScore, and probabilisticScore.
.../LinkerDWH.java Added a static field matchNoficationProducer, initialized it in the doMatch method, and handled related exceptions. Added a method for MatchNotification serialization.
.../topics-config.sh Added new Kafka topics JeMPI-interaction-validate and JeMPI-interaction-match with corresponding configurations in partitions, replication, retention, and segment bytes.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant LibMPI
    participant KafkaProducer
    participant KafkaTopicValidate
    participant LinkerDWH
    participant KafkaTopicMatch

    LibMPI->>KafkaProducer: Create Validation Message
    KafkaProducer->>KafkaTopicValidate: Send Validation Message
    link KafkaTopicValidate: Kafka Topic for Validation

    LinkerDWH->>KafkaProducer: Create MatchNotification Message
    KafkaProducer->>KafkaTopicMatch: Send MatchNotification Message
    link KafkaTopicMatch: Kafka Topic for Matching
Loading

🐰 "In code we trust," the rabbit said,
"With Kafka's streams, our data's led.
From validation to matching's grace,
Asynchronous flows now interlace.
In Docker's realm, new topics rise,
To meet the needs of enterprise."


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 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 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 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 as 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 full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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.

@MatthewErispe MatthewErispe marked this pull request as ready for review May 28, 2024 14:16
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.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
devops/linux/docker/helper/topics/topics-config.sh (1)

Line range hint 52-72: Consider using $(...) notation instead of legacy backticks for command substitution for better readability and nesting capabilities.

- RETENTION_MS[$TOPIC_INTERACTION_ETL]=`echo "1*24*60*60*1000" | bc`
+ RETENTION_MS[$TOPIC_INTERACTION_ETL]=$(echo "1*24*60*60*1000" | bc)
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e251e72 and feb24ad.
Files selected for processing (6)
  • JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/LibMPI.java (3 hunks)
  • JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/GlobalConstants.java (1 hunks)
  • JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/MatchNotification.java (1 hunks)
  • JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/Validation.java (1 hunks)
  • JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java (3 hunks)
  • devops/linux/docker/helper/topics/topics-config.sh (6 hunks)
Files skipped from review due to trivial changes (2)
  • JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/MatchNotification.java
  • JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/Validation.java
Additional Context Used
ShellCheck (35)
devops/linux/docker/helper/topics/topics-config.sh (35)

[warning] 14-14: TOPICS appears unused. Verify use (or export if used externally).


[warning] 15-15: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 16-16: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 17-17: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 18-18: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 19-19: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 20-20: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 21-21: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 22-22: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 23-23: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 24-24: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.


[warning] 37-37: PARTITIONS appears unused. Verify use (or export if used externally).


[warning] 49-49: REPLICATION appears unused. Verify use (or export if used externally).


[style] 52-52: Use $(...) notation instead of legacy backticks ....


[style] 53-53: Use $(...) notation instead of legacy backticks ....


[style] 54-54: Use $(...) notation instead of legacy backticks ....


[style] 55-55: Use $(...) notation instead of legacy backticks ....


[style] 56-56: Use $(...) notation instead of legacy backticks ....


[style] 57-57: Use $(...) notation instead of legacy backticks ....


[style] 58-58: Use $(...) notation instead of legacy backticks ....


[style] 59-59: Use $(...) notation instead of legacy backticks ....


[style] 60-60: Use $(...) notation instead of legacy backticks ....


[warning] 61-61: RETENTION_MS appears unused. Verify use (or export if used externally).


[style] 61-61: Use $(...) notation instead of legacy backticks ....


[style] 64-64: Use $(...) notation instead of legacy backticks ....


[style] 65-65: Use $(...) notation instead of legacy backticks ....


[style] 66-66: Use $(...) notation instead of legacy backticks ....


[style] 67-67: Use $(...) notation instead of legacy backticks ....


[style] 68-68: Use $(...) notation instead of legacy backticks ....


[style] 69-69: Use $(...) notation instead of legacy backticks ....


[style] 70-70: Use $(...) notation instead of legacy backticks ....


[style] 71-71: Use $(...) notation instead of legacy backticks ....


[style] 72-72: Use $(...) notation instead of legacy backticks ....


[warning] 73-73: SEGMENT_BYTES appears unused. Verify use (or export if used externally).


[style] 73-73: Use $(...) notation instead of legacy backticks ....

Additional comments not posted (6)
devops/linux/docker/helper/topics/topics-config.sh (3)

7-8: Added new Kafka topics for validation and matching as per PR objectives.


Line range hint 14-14: Verify the usage or export of arrays TOPICS, PARTITIONS, REPLICATION, RETENTION_MS, and SEGMENT_BYTES to ensure they are not unused.

Also applies to: 37-37, 49-49, 61-61, 73-73

Verification successful

The arrays TOPICS, PARTITIONS, REPLICATION, RETENTION_MS, and SEGMENT_BYTES are indeed used in various scripts within the repository. Here are the relevant locations:

  • devops/linux/docker/helper/topics/topics-config.sh
  • devops/linux/docker/helper/topics/topics-create.sh
  • devops/linux/docker/helper/topics/topics-describe.sh
  • devops/linux/docker/helper/topics/topics-delete.sh
  • devops/windows/base-docker-linux/helper/topics/topics-create.sh
  • devops/windows/base-docker-linux/helper/topics/topics-describe.sh
  • devops/windows/base-docker-linux/helper/topics/topics-delete.sh
  • devops/windows/base-docker-wsl/helper/topics/topics-create.sh
  • devops/windows/base-docker-wsl/helper/topics/topics-describe.sh
  • devops/windows/base-docker-wsl/helper/topics/topics-delete.sh

These arrays are actively used and not unused.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage or export of the arrays.

# Test: Search for the usage or export of the arrays. Expect: Usage in scripts or export statements.
rg --type sh $'TOPICS|PARTITIONS|REPLICATION|RETENTION_MS|SEGMENT_BYTES'

Length of output: 14418


19-20: Ensure that the new topics are correctly integrated into the system and are being used as intended.

Also applies to: 32-33, 44-45, 56-57, 68-69

Verification successful

The new Kafka topics JeMPI-interaction-validate and JeMPI-interaction-match are defined in GlobalConstants.java and topics-config.sh. Additionally, they are referenced in LinkerDWH.java and LibMPI.java, indicating their integration into the system.

  • JeMPI-interaction-validate is used in LibMPI.java.
  • JeMPI-interaction-match is used in LinkerDWH.java.

These references suggest that the new topics are being utilized as intended in the producer and consumer configurations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of new Kafka topics in the system.

# Test: Search for the usage of new topics. Expect: Occurrences in producer and consumer configurations.
rg --type sh --type java $'JeMPI-interaction-validate|JeMPI-interaction-match'

Length of output: 643



Script:

#!/bin/bash
# Description: Verify the usage of new Kafka topics in producer and consumer configurations.

# Test: Search for the usage of new topics in Java files, focusing on producer and consumer configurations.
rg --type java 'TOPIC_INTERACTION_VALIDATE|TOPIC_INTERACTION_MATCH'

Length of output: 779

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/GlobalConstants.java (1)

10-11: Added new constants for Kafka topics as per PR objectives.

JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java (2)

38-38: Added a new Kafka producer for match notifications. Ensure proper error handling and integration with the rest of the system.

Also applies to: 206-222

Verification successful

The initialization and usage of matchNoficationProducer in LinkerDWH.java appear to be properly integrated. The producer is initialized with necessary configurations and used to produce messages. Error handling is also present in the usage.

  • Initialization:

    matchNoficationProducer = new MyKafkaProducer<>(AppConfig.KAFKA_BOOTSTRAP_SERVERS,
                                                    GlobalConstants.TOPIC_INTERACTION_MATCH,
                                                    stringSerializer(),
                                                    matchNotificationSerializer(),
                                                    "LinkerDWH-INTERACTION-MATCH-NOTIFICATIONS");
  • Usage:

    matchNoficationProducer.produceSync(UUID.randomUUID().toString(),
                                        new MatchNotification(interaction,
                                                              new GoldenRecordWithScore(workCandidate.goldenRecord,
                                                                                        workCandidate.score)));
    } catch (JsonProcessingException e) {
        LOGGER.error(e.getLocalizedMessage(), e);
    }

The integration seems correct, and error handling is in place.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration and usage of the new Kafka producer for match notifications.

# Test: Search for the usage of `matchNoficationProducer`. Expect: Occurrences in method calls and configurations.
rg --type java $'matchNoficationProducer'

Length of output: 705



Script:

#!/bin/bash
# Extract the relevant code segments for detailed review of initialization and usage of matchNoficationProducer.

# Extract the initialization code
rg --type java -A 5 'matchNoficationProducer = new MyKafkaProducer' 

# Extract the usage code
rg --type java -A 5 'matchNoficationProducer.produceSync'

Length of output: 2179


431-433: Added a serializer for MatchNotification. Ensure that it is correctly implemented and used.

Verification successful

The matchNotificationSerializer method is correctly implemented and used. The JsonPojoSerializer class properly serializes objects to JSON, and the MyKafkaProducer class correctly utilizes the serializer for producing Kafka messages.

  • JsonPojoSerializer implementation is found in JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/serdes/JsonPojoSerializer.java.
  • MyKafkaProducer correctly initializes a Kafka producer with the provided serializers.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation and usage of the `matchNotificationSerializer`.

# Test: Search for the usage of `matchNotificationSerializer`. Expect: Occurrences in method calls and configurations.
rg --type java $'matchNotificationSerializer'

Length of output: 389



Script:

#!/bin/bash
# Extract lines around the usage of matchNotificationSerializer in LinkerDWH.java
rg --type java -A 5 -B 5 $'matchNotificationSerializer' JeMPI_Apps/JeMPI_Linker/src/main/java/org/jembi/jempi/linker/backend/LinkerDWH.java

# Locate the implementation of JsonPojoSerializer
rg --type java 'class JsonPojoSerializer'

Length of output: 1376



Script:

#!/bin/bash
# Extract the implementation of JsonPojoSerializer
rg --type java -A 20 -B 0 'class JsonPojoSerializer' JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/serdes/JsonPojoSerializer.java

# Locate the implementation of MyKafkaProducer
rg --type java 'class MyKafkaProducer'

Length of output: 451



Script:

#!/bin/bash
# Locate the correct path for JsonPojoSerializer
fd --type f --name 'JsonPojoSerializer.java'

# Extract the implementation of MyKafkaProducer
rg --type java -A 20 -B 0 'class MyKafkaProducer' JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/kafka/MyKafkaProducer.java

Length of output: 1347



Script:

#!/bin/bash
# Correct the fd command to locate the correct path for JsonPojoSerializer
fd 'JsonPojoSerializer.java'

# Extract the full implementation of MyKafkaProducer
rg --type java -A 50 -B 0 'class MyKafkaProducer' JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/kafka/MyKafkaProducer.java

Length of output: 1960



Script:

#!/bin/bash
# Extract the implementation of JsonPojoSerializer
rg --type java -A 50 -B 0 'class JsonPojoSerializer' JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/serdes/JsonPojoSerializer.java

Length of output: 776

@@ -15,12 +15,14 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification script did not find any try-catch blocks in the LibMPI.java file, indicating a potential lack of explicit error handling around the Kafka producer usage.

  • Ensure that error handling is robust around the Kafka producer usage to handle any potential exceptions.
Analysis chain

Added a new Kafka producer for validation messages. Ensure that error handling is robust and that the producer is properly integrated and used throughout the system.

Also applies to: 25-46, 399-408

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration and usage of the new Kafka producer for validation messages.

# Test: Search for the usage of `topicValidation`. Expect: Occurrences in method calls and configurations.
rg --type java $'topicValidation'

Length of output: 458



Script:

#!/bin/bash
# Description: Verify error handling around the Kafka producer usage.

# Test: Search for try-catch blocks around the usage of `topicValidation`.
rg --type java -A 5 -B 5 'topicValidation.produceAsync'

Length of output: 1574



Script:

#!/bin/bash
# Description: Verify the presence of try-catch blocks in the `LibMPI.java` file.

# Test: Search for try-catch blocks in the `LibMPI.java` file.
rg --type java 'try\s*\{|\}\s*catch\s*\(' JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/LibMPI.java

Length of output: 116

@NyashaMuusha NyashaMuusha self-assigned this Jun 7, 2024
@MatthewErispe MatthewErispe merged commit 5c35648 into dev Jun 9, 2024
5 checks passed
@MatthewErispe MatthewErispe deleted the CU-86by7bekc_Create-New-Kafka-Topics-for-Validate-and-Match-RulesKenya branch June 9, 2024 09:19
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.

3 participants