Skip to content

Commit

Permalink
Add AgentManager::ping
Browse files Browse the repository at this point in the history
The GraphQL query `nodeStatusList` will use this method rather than
creating a raw `Ping` message.
  • Loading branch information
msk committed Mar 1, 2024
1 parent 10f4224 commit 17a489e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- `AgentManager::ping` method to measure the latency between the agent manager
and a host.
- `AgentManager::reboot` method to reboot a host.

## [0.18.0] - 2024-02-26
Expand Down
4 changes: 4 additions & 0 deletions examples/minireview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ impl AgentManager for Manager {
bail!("Not supported")
}

async fn ping(&self, hostname: &str) -> Result<i64, Error> {
bail!("Host {hostname} is unreachable")
}

async fn reboot(&self, hostname: &str) -> Result<(), Error> {
bail!("Host {hostname} is unreachable")
}
Expand Down
12 changes: 12 additions & 0 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ pub trait AgentManager: Send + Sync {
) -> Result<HashMap<String, Vec<(String, String)>>, anyhow::Error>;
async fn send_and_recv(&self, key: &str, msg: &[u8]) -> Result<Vec<u8>, anyhow::Error>;

/// Sends a ping message to the given host and waits for a response. Returns
/// the round-trip time in microseconds.
async fn ping(&self, _hostname: &str) -> Result<i64, anyhow::Error> {
// TODO: This body is only to avoid breaking changes. It should be
// removed when all the implementations are updated. See #144.
anyhow::bail!("not implemented")
}

/// Reboots the node with the given hostname.
async fn reboot(&self, _hostname: &str) -> Result<(), anyhow::Error> {
// TODO: This body is only to avoid breaking changes. It should be
Expand Down Expand Up @@ -568,6 +576,10 @@ impl AgentManager for MockAgentManager {
unimplemented!()
}

async fn ping(&self, _hostname: &str) -> Result<i64, anyhow::Error> {
unimplemented!()
}

async fn reboot(&self, _hostname: &str) -> Result<(), anyhow::Error> {
unimplemented!()
}
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/node/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ async fn load(
},
);

// TODO: Refactor this code to use `AgentManager::ping` after
// `review` implements it. See #144.
let start = Utc::now().timestamp_micros();
if let Ok(response) = agents.send_and_recv(&key, &ping_msg).await {
let end = Utc::now().timestamp_micros();
Expand Down

0 comments on commit 17a489e

Please sign in to comment.