Add sync health and explicit sync trigger
This commit is contained in:
parent
1336fa38e8
commit
3c5e95fb87
8 changed files with 1085 additions and 98 deletions
|
|
@ -37,6 +37,10 @@ pub enum Command {
|
|||
command: DaemonCommand,
|
||||
},
|
||||
Status,
|
||||
Sync {
|
||||
#[command(subcommand)]
|
||||
command: SyncCommand,
|
||||
},
|
||||
Node {
|
||||
#[command(subcommand)]
|
||||
command: NodeCommand,
|
||||
|
|
@ -134,6 +138,12 @@ pub enum ServiceCommand {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum SyncCommand {
|
||||
Status,
|
||||
Now { node: Option<String> },
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum NodeCommand {
|
||||
Id,
|
||||
|
|
@ -825,6 +835,12 @@ pub async fn run() -> Result<()> {
|
|||
fn request_for_command(command: Command) -> Result<ControlRequest> {
|
||||
Ok(match command {
|
||||
Command::Status => ControlRequest::Status,
|
||||
Command::Sync {
|
||||
command: SyncCommand::Status,
|
||||
} => ControlRequest::SyncStatus,
|
||||
Command::Sync {
|
||||
command: SyncCommand::Now { node },
|
||||
} => ControlRequest::SyncNow { node },
|
||||
Command::Node {
|
||||
command: NodeCommand::Id,
|
||||
} => ControlRequest::NodeId,
|
||||
|
|
@ -1851,6 +1867,7 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
|
|||
ops_imported,
|
||||
signatures_imported,
|
||||
invalid_ops_rejected,
|
||||
high_water_ms,
|
||||
note,
|
||||
} => {
|
||||
println!("synced keychain from: {peer_node_id}");
|
||||
|
|
@ -1859,6 +1876,7 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
|
|||
println!("ops_imported: {ops_imported}");
|
||||
println!("signatures_imported: {signatures_imported}");
|
||||
println!("invalid_ops_rejected: {invalid_ops_rejected}");
|
||||
println!("high_water_ms: {high_water_ms}");
|
||||
println!("note: {note}");
|
||||
}
|
||||
ControlResponse::AuthSynced {
|
||||
|
|
@ -1868,6 +1886,7 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
|
|||
ops_imported,
|
||||
signatures_imported,
|
||||
invalid_ops_rejected,
|
||||
high_water_ms,
|
||||
note,
|
||||
} => {
|
||||
println!("synced auth from: {peer_node_id}");
|
||||
|
|
@ -1876,6 +1895,66 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
|
|||
println!("ops_imported: {ops_imported}");
|
||||
println!("signatures_imported: {signatures_imported}");
|
||||
println!("invalid_ops_rejected: {invalid_ops_rejected}");
|
||||
println!("high_water_ms: {high_water_ms}");
|
||||
println!("note: {note}");
|
||||
}
|
||||
ControlResponse::SyncStatus { peers, note } => {
|
||||
if peers.is_empty() {
|
||||
println!("no sync peers");
|
||||
} else {
|
||||
for peer in peers {
|
||||
println!("peer: {}", peer.peer_node_id);
|
||||
if peer.streams.is_empty() {
|
||||
println!(" no sync attempts recorded");
|
||||
}
|
||||
for stream in peer.streams {
|
||||
println!(
|
||||
" {}\tcursor={}\tlast_attempt={}\tlast_success={}\timported={}\trejected={}\terror={}",
|
||||
stream.stream,
|
||||
stream.cursor_ms,
|
||||
stream
|
||||
.last_attempt_ms
|
||||
.map(|value| value.to_string())
|
||||
.unwrap_or_else(|| "never".to_owned()),
|
||||
stream
|
||||
.last_success_ms
|
||||
.map(|value| value.to_string())
|
||||
.unwrap_or_else(|| "never".to_owned()),
|
||||
stream.last_imported,
|
||||
stream.last_rejected,
|
||||
stream.last_error.unwrap_or_else(|| "-".to_owned())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("note: {note}");
|
||||
}
|
||||
ControlResponse::SyncRan { peers, note } => {
|
||||
if peers.is_empty() {
|
||||
println!("no sync peers");
|
||||
} else {
|
||||
for peer in peers {
|
||||
println!("peer: {}", peer.peer_node_id);
|
||||
for stream in peer.streams {
|
||||
let state = if !stream.attempted {
|
||||
"skipped"
|
||||
} else if stream.success {
|
||||
"ok"
|
||||
} else {
|
||||
"failed"
|
||||
};
|
||||
println!(
|
||||
" {}\t{}\tcursor={}\timported={}\trejected={}\terror={}",
|
||||
stream.stream,
|
||||
state,
|
||||
stream.cursor_ms,
|
||||
stream.imported,
|
||||
stream.rejected,
|
||||
stream.error.unwrap_or_else(|| "-".to_owned())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("note: {note}");
|
||||
}
|
||||
ControlResponse::SecretStatus { secrets } => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue