Skip to content

Commit

Permalink
[CLI] Adjust Diesel deps, improve messages, improve Docker daemon det…
Browse files Browse the repository at this point in the history
…ection, improve ready server re indexer API
  • Loading branch information
banool committed Oct 11, 2023
1 parent 4c10535 commit bf7f740
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 124 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ sha2 = "0.9.3"
sha2_0_10_6 = { package = "sha2", version = "0.10.6" }
sha3 = "0.9.1"
siphasher = "0.3.10"
# For more information about why we are pinned to 1.0.149, see this issue:
# https://github.com/aptos-labs/aptos-core/issues/10424
serde = { version = "=1.0.149", features = ["derive", "rc"] }
serde_bytes = "0.11.6"
serde_json = { version = "1.0.81", features = ["preserve_order", "arbitrary_precision"] } # Note: arbitrary_precision is required to parse u256 in JSON
Expand Down Expand Up @@ -730,3 +732,5 @@ debug = true
serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "839aed62a20ddccf043c08961cfe74875741ccba" }
merlin = { git = "https://github.com/aptos-labs/merlin" }
x25519-dalek = { git = "https://github.com/aptos-labs/x25519-dalek", branch = "zeroize_v1" }
# More context here: https://github.com/weiznich/diesel_async/pull/121.
diesel-async = { git = "https://github.com/banool/diesel_async", rev = "7115c8668b88d56029cb1471e84d2ea0234ff035" }
2 changes: 1 addition & 1 deletion crates/aptos/src/common/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn prompt_yes(prompt: &str) -> bool {
result.unwrap()
}

/// Convert any successful response to Success. If there is an error, show as JSON
/// Convert any successful response to Success. If there is an error, show it as JSON
/// unless `jsonify_error` is false.
pub async fn to_common_success_result<T>(
command: &str,
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
// Shutdown the runtime with a timeout. We do this to make sure that we don't sit
// here waiting forever waiting for tasks that sometimes don't want to exit on
// their own (e.g. telemetry, containers spawned by the local testnet, etc).
runtime.shutdown_timeout(Duration::from_millis(100));
runtime.shutdown_timeout(Duration::from_millis(50));

match result {
Ok(inner) => println!("{}", inner),
Expand Down
2 changes: 1 addition & 1 deletion crates/aptos/src/node/local_testnet/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ServiceManager for FaucetManager {
"Faucet".to_string()
}

fn get_healthchecks(&self) -> HashSet<HealthChecker> {
fn get_health_checkers(&self) -> HashSet<HealthChecker> {
hashset! {HealthChecker::http_checker_from_port(
self.config.server_config.listen_port,
self.get_name(),
Expand Down
18 changes: 15 additions & 3 deletions crates/aptos/src/node/local_testnet/health_checker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

use super::indexer_api::confirm_metadata_applied;
use anyhow::{anyhow, Context, Result};
use aptos_protos::indexer::v1::GetTransactionsRequest;
use diesel_async::{pg::AsyncPgConnection, AsyncConnection};
Expand All @@ -13,10 +14,12 @@ use tokio::time::Instant;
const MAX_WAIT_S: u64 = 60;
const WAIT_INTERVAL_MS: u64 = 200;

/// This provides a single place to define a variety of different healthchecks.
/// This provides a single place to define a variety of different healthchecks. In
/// cases where the name of the service being checked isn't obvious, the enum will take
/// a string arg that names it.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
pub enum HealthChecker {
/// Check that an HTTP API is up. The second param is the name of the HTTP service.
/// Check that a HTTP API is up. The second param is the name of the HTTP service.
Http(Url, String),
/// Check that the node API is up. This is just a specific case of Http for extra
/// guarantees around liveliness.
Expand All @@ -25,6 +28,9 @@ pub enum HealthChecker {
DataServiceGrpc(Url),
/// Check that a postgres instance is up.
Postgres(String),
/// Check that the indexer API is up and the metadata has been applied. We only use
/// this one in the ready server.
IndexerApiMetadata(Url),
}

impl HealthChecker {
Expand All @@ -47,7 +53,7 @@ impl HealthChecker {
url.clone(),
Some(Duration::from_secs(5)),
)
.await;
.await?;
let request = tonic::Request::new(GetTransactionsRequest {
starting_version: Some(0),
..Default::default()
Expand All @@ -70,6 +76,10 @@ impl HealthChecker {
.context("Failed to connect to postgres")?;
Ok(())
},
HealthChecker::IndexerApiMetadata(url) => {
confirm_metadata_applied(url.clone()).await?;
Ok(())
},
}
}

Expand Down Expand Up @@ -100,6 +110,7 @@ impl HealthChecker {
HealthChecker::NodeApi(url) => url.as_str(),
HealthChecker::DataServiceGrpc(url) => url.as_str(),
HealthChecker::Postgres(url) => url.as_str(),
HealthChecker::IndexerApiMetadata(url) => url.as_str(),
}
}

Expand All @@ -119,6 +130,7 @@ impl std::fmt::Display for HealthChecker {
HealthChecker::NodeApi(_) => write!(f, "Node API"),
HealthChecker::DataServiceGrpc(_) => write!(f, "Transaction stream"),
HealthChecker::Postgres(_) => write!(f, "Postgres"),
HealthChecker::IndexerApiMetadata(_) => write!(f, "Indexer API with metadata applied"),
}
}
}
Expand Down

0 comments on commit bf7f740

Please sign in to comment.