Skip to content
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

Upgrade to rocket 0.5.0-rc #1913

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,060 changes: 615 additions & 445 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions admin-http-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mc-util-uri = { path = "../util/uri" }

clap = { version = "3.1", features = ["derive", "env"] }
grpcio = "0.10.2"
rocket = { version = "0.4.10", default-features = false }
rocket_contrib = { version = "0.4.10", default-features = false, features = ["json"] }
rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
Expand Down
28 changes: 15 additions & 13 deletions admin-http-gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ use mc_common::logger::{create_app_logger, log, o};
use mc_util_grpc::{admin, admin_grpc::AdminApiClient, ConnectionUriGrpcioChannel, Empty};
use mc_util_uri::AdminUri;
use rocket::{
form::Form,
get, post,
request::Form,
response::{content, Redirect},
routes, FromForm,
routes,
serde::json::Json,
FromForm,
};
use rocket_contrib::json::Json;
use serde_derive::Serialize;
use std::{convert::TryFrom, sync::Arc};

Expand Down Expand Up @@ -79,7 +80,7 @@ impl TryFrom<&admin::GetInfoResponse> for JsonInfoResponse {
}

#[get("/info")]
fn info(state: rocket::State<State>) -> Result<Json<JsonInfoResponse>, String> {
fn info(state: &rocket::State<State>) -> Result<Json<JsonInfoResponse>, String> {
let info = state
.admin_api_client
.get_info(&Empty::new())
Expand All @@ -95,7 +96,7 @@ struct SetRustLogForm {

#[post("/set-rust-log", data = "<form>")]
fn set_rust_log(
state: rocket::State<State>,
state: &rocket::State<State>,
form: Form<SetRustLogForm>,
) -> Result<Redirect, String> {
let mut req = admin::SetRustLogRequest::new();
Expand All @@ -110,15 +111,16 @@ fn set_rust_log(
}

#[get("/metrics")]
fn metrics(state: rocket::State<State>) -> Result<String, String> {
fn metrics(state: &rocket::State<State>) -> Result<String, String> {
let resp = state
.admin_api_client
.get_prometheus_metrics(&Empty::new())
.map_err(|err| format!("failed getting metrics: {}", err))?;
Ok(resp.metrics)
}

fn main() {
#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
mc_common::setup_panic_handler();
let _sentry_guard = mc_common::sentry::init();

Expand All @@ -138,13 +140,13 @@ fn main() {
ChannelBuilder::default_channel_builder(env).connect_to_uri(&config.admin_uri, &logger);
let admin_api_client = AdminApiClient::new(ch);

let rocket_config = rocket::Config::build(rocket::config::Environment::Production)
.address(&config.listen_host)
.port(config.listen_port)
.unwrap();
let figment = rocket::Config::figment()
.merge(("port", config.listen_port))
.merge(("address", config.listen_host.clone()));

rocket::custom(rocket_config)
rocket::custom(figment)
.mount("/", routes![index, info, set_rust_log, metrics])
.manage(State { admin_api_client })
.launch();
.launch()
.await
}
3 changes: 1 addition & 2 deletions fog/overseer/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ grpcio = "0.10.2"
lazy_static = "1.4"
prometheus = "0.13.0"
retry = "1.3"
rocket = { version = "0.4.5", default-features = false }
rocket_contrib = { version = "0.4.5", default-features = false, features = ["json"] }
rocket = { version = "0.5.0-rc.1", features = ["json"] }
serde = "1"

# mc
Expand Down
13 changes: 6 additions & 7 deletions fog/overseer/server/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use mc_fog_overseer_server::{config::OverseerConfig, server, service::OverseerSe
use mc_fog_sql_recovery_db::SqlRecoveryDb;
use mc_util_cli::ParserWithBuildInfo;

fn main() {
#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
mc_common::setup_panic_handler();
let _sentry_guard = sentry::init();
let config = OverseerConfig::parse();
Expand All @@ -36,12 +37,10 @@ fn main() {

let overseer_state = server::OverseerState { overseer_service };

let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
.address(config.overseer_listen_host)
.port(config.overseer_listen_port)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", config.overseer_listen_port))
.merge(("address", config.overseer_listen_host.clone()));

let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
rocket.launch();
rocket.launch().await
}
19 changes: 9 additions & 10 deletions fog/overseer/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ use crate::{
};
use mc_fog_recovery_db_iface::RecoveryDb;
use mc_fog_sql_recovery_db::SqlRecoveryDb;
use rocket::{get, post, routes};
use rocket_contrib::json::Json;
use rocket::{get, post, routes, serde::json::Json};

#[post("/enable")]
fn enable(state: rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
fn enable(state: &rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
state.overseer_service.enable()
}

#[post("/disable")]
fn disable(state: rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
fn disable(state: &rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
state.overseer_service.disable()
}

#[get("/status")]
fn get_status(state: rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
fn get_status(state: &rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
state.overseer_service.get_status()
}

#[get("/ingest_summaries")]
fn get_ingest_summaries(
state: rocket::State<OverseerState<SqlRecoveryDb>>,
state: &rocket::State<OverseerState<SqlRecoveryDb>>,
) -> Result<Json<GetIngestSummariesResponse>, String> {
state.overseer_service.get_ingest_summaries().map(Json)
}
Expand All @@ -39,7 +38,7 @@ fn get_ingest_summaries(
///
/// Meant to be called only by the Prometheus pull mechanism.
#[get("/metrics")]
fn get_metrics(state: rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
fn get_metrics(state: &rocket::State<OverseerState<SqlRecoveryDb>>) -> Result<String, String> {
state.overseer_service.get_metrics()
}

Expand All @@ -56,10 +55,10 @@ where

/// Returns an instance of a Rocket server.
#[must_use = "Use with a Client or call launch"]
pub fn initialize_rocket_server(
rocket_config: rocket::Config,
pub fn initialize_rocket_server<T: rocket::figment::Provider>(
rocket_config: T,
state: OverseerState<SqlRecoveryDb>,
) -> rocket::Rocket {
) -> rocket::Rocket<rocket::Build> {
rocket::custom(rocket_config)
.mount(
"/",
Expand Down
17 changes: 7 additions & 10 deletions fog/overseer/server/tests/get_ingest_summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mc_watcher::watcher_db::WatcherDB;
use rand_core::SeedableRng;
use rand_hc::Hc128Rng;
use regex::Regex;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::time::Duration;
use tempdir::TempDir;

Expand Down Expand Up @@ -100,22 +100,19 @@ fn one_active_node_produces_ingest_summaries(logger: Logger) {
// Set up the Rocket instance
let overseer_state = OverseerState { overseer_service };
// TODO: Consider testing the CLI here instead.
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
client.post("/enable").dispatch();

// Give overseer time to perform its logic.
std::thread::sleep(Duration::from_secs(10));

let mut response = client.get("/ingest_summaries").dispatch();
let response = client.get("/ingest_summaries").dispatch();

let body = response.body_string().unwrap();
let body = response.into_string().unwrap();
let active_pattern = Regex::new("ACTIVE").unwrap();
active_pattern.captures(&body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mc_transaction_core::{Block, BlockContents};
use mc_watcher::watcher_db::WatcherDB;
use rand_core::SeedableRng;
use rand_hc::Hc128Rng;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::{convert::TryFrom, str::FromStr, time::Duration};
use tempdir::TempDir;
use url::Url;
Expand Down Expand Up @@ -116,14 +116,11 @@ fn inactive_oustanding_key_idle_node_does_not_have_key_idle_node_is_activated_an
// Set up the Rocket instance
let overseer_state = OverseerState { overseer_service };
// TODO: Consider testing the CLI here instead.
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
client.post("/enable").dispatch();

// Add 11 test blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mc_transaction_core::{Block, BlockContents};
use mc_watcher::watcher_db::WatcherDB;
use rand_core::SeedableRng;
use rand_hc::Hc128Rng;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::{convert::TryFrom, str::FromStr, time::Duration};
use tempdir::TempDir;
use url::Url;
Expand Down Expand Up @@ -123,14 +123,11 @@ fn inactive_oustanding_key_idle_node_has_original_key_node_is_activated_and_key_
// Set up the Rocket instance
let overseer_state = OverseerState { overseer_service };
// TODO: Consider testng the CLI here instead
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
client.post("/enable").dispatch();

// Add 11 test blocks.
Expand Down
13 changes: 5 additions & 8 deletions fog/overseer/server/tests/one_active_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mc_fog_recovery_db_iface::RecoveryDb;
use mc_fog_sql_recovery_db::test_utils::SqlRecoveryDbTestContext;
use mc_ledger_db::LedgerDB;
use mc_watcher::watcher_db::WatcherDB;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::{convert::TryFrom, str::FromStr, time::Duration};
use tempdir::TempDir;
use url::Url;
Expand Down Expand Up @@ -92,12 +92,9 @@ fn one_active_node_cluster_state_does_not_change(logger: Logger) {

// Consider testing the CLI here instead
// Initialize an OverSeerService object...
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));

let mut overseer_service = OverseerService::new(
vec![client_listen_uri0, client_listen_uri1, client_listen_uri2],
Expand All @@ -107,7 +104,7 @@ fn one_active_node_cluster_state_does_not_change(logger: Logger) {
overseer_service.start().unwrap();
let overseer_state = OverseerState { overseer_service };
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
let _req = client.post("/enable").dispatch();

// Give Overseer time to perform logic
Expand Down
17 changes: 7 additions & 10 deletions fog/overseer/server/tests/prometheus_produces_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mc_watcher::watcher_db::WatcherDB;
use rand_core::SeedableRng;
use rand_hc::Hc128Rng;
use regex::Regex;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::time::Duration;
use tempdir::TempDir;

Expand Down Expand Up @@ -104,22 +104,19 @@ fn one_active_node_idle_nodes_different_keys_produces_prometheus_metrics(logger:
// Set up the Rocket instance
let overseer_state = OverseerState { overseer_service };
// TODO: Consider testing the CLI here instead.
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
client.post("/enable").dispatch();

// Give overseer time to perform its logic.
std::thread::sleep(Duration::from_secs(10));

let mut response = client.get("/metrics").dispatch();
let response = client.get("/metrics").dispatch();

let body = response.body_string().unwrap();
let body = response.into_string().unwrap();

let correct_active_node_count = Regex::new(r#"active_node_count"} 1"#).unwrap();
assert!(correct_active_node_count.is_match(&body));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use mc_transaction_core::{Block, BlockContents};
use mc_watcher::watcher_db::WatcherDB;
use rand_core::SeedableRng;
use rand_hc::Hc128Rng;
use rocket::local::Client;
use rocket::local::blocking::Client;
use std::{convert::TryFrom, str::FromStr, time::Duration};
use tempdir::TempDir;
use url::Url;
Expand Down Expand Up @@ -123,14 +123,11 @@ fn active_key_is_retired_not_outstanding_idle_nodes_have_different_keys_new_key_
// Set up the Rocket instance
let overseer_state = OverseerState { overseer_service };
// Consider testng the CLI here instead
let rocket_config: rocket::Config =
rocket::Config::build(rocket::config::Environment::Development)
// TODO: Make these either passed from CLI or in a Rocket.toml.
.address("127.0.0.1")
.port(PORT_NUMBER)
.unwrap();
let rocket_config = rocket::Config::figment()
.merge(("port", PORT_NUMBER))
.merge(("address", "127.0.0.1"));
let rocket = server::initialize_rocket_server(rocket_config, overseer_state);
let client = Client::new(rocket).expect("valid rocket instance");
let client = Client::tracked(rocket).expect("valid rocket instance");
let _req = client.post("/enable").dispatch();

// Retire the current active node.
Expand Down
Loading