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

feat: add the # of messages prioritized in the queue to the http resp… #5043

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kamiyaa
Copy link
Collaborator

@kamiyaa kamiyaa commented Dec 18, 2024

Description

Add a mpsc channel between relayer and message retry handler, so message retry handler knows the retry results from the relayer.

POST /message_retry endpoint now returns a JSON with details on the retry request:

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MessageRetryResponse {
    /// ID of the retry request
    pub uuid: String,
    /// how many pending operations were processed
    pub processed: usize,
    /// how many of the pending operations matched the retry request pattern
    pub matched: u64,
}

Drive-by changes

Related issues

Fixes #4059

Backward compatibility

Testing

Updated unit tests to return a response so the handler is not blocked

Copy link

changeset-bot bot commented Dec 18, 2024

⚠️ No Changeset found

Latest commit: 14d6eae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

rust/main/Cargo.toml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.53%. Comparing base (08cf6ac) to head (14d6eae).
Report is 70 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5043   +/-   ##
=======================================
  Coverage   77.53%   77.53%           
=======================================
  Files         103      103           
  Lines        2110     2110           
  Branches      190      190           
=======================================
  Hits         1636     1636           
  Misses        453      453           
  Partials       21       21           
Components Coverage Δ
core 87.80% <ø> (ø)
hooks 79.39% <ø> (ø)
isms 83.68% <ø> (ø)
token 91.27% <ø> (ø)
middlewares 79.80% <ø> (ø)

Copy link
Collaborator

@tkporter tkporter left a comment

Choose a reason for hiding this comment

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

good stuff!

excited that this task is fairly meaty, lots of interesting concurrency and touching a lot of systemic things in the relayer :)

rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
 - also updating tracing calls to use structured logs
 - update variable names to receiver/transmitter instead of rx/tx
 - this creates a nice separation between each retry request
 and won't cause multiple requests to conflict with each others
 responses
Copy link
Contributor

@daniel-savu daniel-savu left a comment

Choose a reason for hiding this comment

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

😎 awesome work, hitting the ground running from the first PR!!

rust/main/agents/relayer/Cargo.toml Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
match_res
})
.any(|x| x);
if matches {
info!(
Copy link
Contributor

Choose a reason for hiding this comment

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

realizing it'd be useful to include the retry request in this log

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we can't really log the specific retry request because we only check if some retry request matches the operation.
Unless we want to log each retry request that matches in the .map()

Copy link
Contributor

Choose a reason for hiding this comment

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

you're right, though we could take advanced of the filter result and accumulate it into a vec of maps, so we include all request IDs that matched in the log. It'd also be cleaner to refactor everything inside the .map(|Reverse(mut op)| { into its own function, since it's getting quite crowded

rust/main/agents/relayer/src/msg/op_queue.rs Outdated Show resolved Hide resolved
Comment on lines +71 to +75
resp.evaluated += relayer_resp.evaluated;
resp.matched += relayer_resp.matched;
}

Ok(Json(resp))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd make things easier to debug if we returned a map of responses by uuid in the json response

Copy link
Collaborator Author

@kamiyaa kamiyaa Dec 24, 2024

Choose a reason for hiding this comment

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

What do you mean by this? Currently the prepare, submit and confirm queue all return the same UUID response 🤔

Or are you thinking of something like:

{
    "prepare_queue": {
        "evaluated": ...,
        "matched": ...,
   },
    "submit_queue": {
        "evaluated": ...,
        "matched": ...,
   },
    "confirm_queue": {
        "evaluated": ...,
        "matched": ...,
   }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

oh right, every message has its own channel actually and you're just adding up responses from each sender, I missed that

Things are a bit more complicated:

  • we should use try_recv instead of recv everywhere, to avoid blocking on an empty channel. However because different senders may take varying amounts of time to respond to the request and the channel may be spuriously empty before we received all responses:
  • we need to wait on a response from every sender (num_chains * num_queues). So we should keep a counter and only return once we got responses from all receiver.sender_strong_count()

Copy link
Contributor

Choose a reason for hiding this comment

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

your logic to add up the response fields makes sense now

rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
rust/main/agents/relayer/src/server/message_retry.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

Relayer retry API: add the # of messages prioritized in the queue to the http response
3 participants