-
Notifications
You must be signed in to change notification settings - Fork 253
fix: ready endpoint checks for fully hydrated cache #2553
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1ebd7ac
docs: clarify ready endpoint checks for fully hydrated cache
devin-ai-integration[bot] b82542e
style: fix formatting issue in ready.rs
devin-ai-integration[bot] 0d673e4
feat: add is_ready method to Cache trait and update ready endpoint
devin-ai-integration[bot] 7c7c716
fix: rename is_ready to is_cache_ready to avoid name conflict
devin-ai-integration[bot] 41547f9
style: fix formatting issues to pass CI
devin-ai-integration[bot] fbcef36
docs: add documentation for is_cache_ready method
devin-ai-integration[bot] d646c06
feat: update is_cache_ready to check if cache is at least 90% full
devin-ai-integration[bot] f3e11fd
docs: complete docstring for is_cache_ready method
devin-ai-integration[bot] 65b4445
doc: add docstring
tejasbadadare 692a293
fix: use slots to measure readiness
tejasbadadare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
use { | ||
crate::{api::ApiState, state::aggregate::Aggregates}, | ||
crate::{ | ||
api::ApiState, | ||
state::{aggregate::Aggregates, cache::Cache}, | ||
}, | ||
axum::{ | ||
extract::State, | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
Json, | ||
}, | ||
serde_json::json, | ||
}; | ||
|
||
/// Endpoint that returns OK (200) only when the cache is fully hydrated. | ||
/// | ||
/// The cache is considered fully hydrated when all of the following conditions are met: | ||
/// - `has_completed_recently`: The latest completed update is recent (within the staleness threshold) | ||
/// - `is_not_behind`: The latest completed slot isn't too far behind the latest observed slot | ||
/// - `is_metadata_loaded`: Price feeds metadata is not empty | ||
/// | ||
/// If any of these conditions are not met, the endpoint returns SERVICE_UNAVAILABLE (503) | ||
/// along with detailed metadata about the readiness state. | ||
pub async fn ready<S>(State(state): State<ApiState<S>>) -> Response | ||
where | ||
S: Aggregates, | ||
S: Aggregates + Cache, | ||
{ | ||
let state = &*state.state; | ||
match Aggregates::is_ready(state).await { | ||
(true, _) => (StatusCode::OK, "OK").into_response(), | ||
(false, metadata) => (StatusCode::SERVICE_UNAVAILABLE, Json(metadata)).into_response(), | ||
let (aggregates_ready, metadata) = Aggregates::is_ready(state).await; | ||
let cache_ready = Cache::is_cache_ready(state).await; | ||
|
||
if aggregates_ready && cache_ready { | ||
(StatusCode::OK, "OK").into_response() | ||
} else { | ||
let response_metadata = json!({ | ||
"aggregates_ready": aggregates_ready, | ||
"cache_ready": cache_ready, | ||
"details": metadata | ||
}); | ||
(StatusCode::SERVICE_UNAVAILABLE, Json(response_metadata)).into_response() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to finish this docstring