-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/runtime + agent: introduce /notify/shard-failure API
The runtime invokes a new /notify/shard-failure control-plane API which is told of shard failures that have occurred within a data-plane. At the moment, this API verifies the data-plane token and logs the failure, but takes no further action. Update the taskBase.heartbeatLoop() to perform this notification if the shard's primary loop exits with a non-cancellation error. Issue #1666
- Loading branch information
1 parent
fd93dc4
commit 5a20739
Showing
6 changed files
with
202 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use super::{App, Snapshot}; | ||
use std::sync::Arc; | ||
|
||
/// Request sent by data-plane reactors to notify the data-plane of a shard failure. | ||
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Request { | ||
/// # JWT token which identifies the shard and authorizes the request. | ||
/// The token subject is the shard ID. | ||
pub token: String, | ||
/// # Error encountered by the shard. | ||
pub error: String, | ||
} | ||
|
||
#[derive(Debug, Default, serde::Serialize, schemars::JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Response { | ||
/// # Number of milliseconds to wait before retrying the request. | ||
/// Zero if the request was successful. | ||
pub retry_millis: u64, | ||
} | ||
|
||
#[axum::debug_handler] | ||
pub async fn notify_shard_failure( | ||
axum::extract::State(app): axum::extract::State<Arc<App>>, | ||
axum::Json(request): axum::Json<Request>, | ||
) -> axum::response::Response { | ||
super::wrap(async move { do_notify_shard_failure(&app, &request).await }).await | ||
} | ||
|
||
#[tracing::instrument(skip(app), err(level = tracing::Level::WARN))] | ||
async fn do_notify_shard_failure( | ||
app: &App, | ||
Request { token, error }: &Request, | ||
) -> anyhow::Result<Response> { | ||
let (_header, claims) = super::parse_untrusted_data_plane_claims(token)?; | ||
|
||
match Snapshot::evaluate( | ||
&app.snapshot, | ||
claims.iat, | ||
|Snapshot { | ||
data_planes, tasks, .. | ||
}: &Snapshot| { | ||
_ = super::verify_data_plane_claims( | ||
data_planes, | ||
tasks, | ||
&claims.sub, | ||
&claims.iss, | ||
token, | ||
)?; | ||
Ok(()) | ||
}, | ||
) { | ||
Ok(()) => { | ||
// TODO(johnny): This is a placeholder for enqueuing an automation to perform | ||
// shard restart. | ||
tracing::info!(%error, %claims.sub, %claims.iss, "notified of shard failure"); | ||
|
||
Ok(Response { | ||
..Default::default() | ||
}) | ||
} | ||
Err(Ok(retry_millis)) => Ok(Response { | ||
retry_millis, | ||
..Default::default() | ||
}), | ||
Err(Err(err)) => Err(err), | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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