Skip to content

Commit

Permalink
feat: Adding qualificator util (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaMilosa authored Jul 24, 2024
1 parent 9adc280 commit 40dc9bc
Show file tree
Hide file tree
Showing 19 changed files with 716 additions and 39 deletions.
87 changes: 76 additions & 11 deletions Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "dc05b0d5d14def9120f2bdfa82aec1fac3b5e388003989fd56263827f1fab85b",
"checksum": "0a147d75b6943fe7fce1c7d185a8c1576d83eebf42e9e15a9f046cae1ff72dbb",
"crates": {
"actix-codec 0.5.2": {
"name": "actix-codec",
Expand Down Expand Up @@ -28565,35 +28565,29 @@
],
"crate_features": {
"common": [
"elf",
"errno",
"general",
"ioctl",
"no_std"
],
"selects": {
"aarch64-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"arm-unknown-linux-gnueabi": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"armv7-unknown-linux-gnueabi": [
"elf",
"errno",
"prctl",
"std",
"system"
],
"i686-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
Expand All @@ -28609,8 +28603,6 @@
"system"
],
"x86_64-unknown-linux-gnu": [
"elf",
"errno",
"prctl",
"std",
"system"
Expand Down Expand Up @@ -35831,6 +35823,78 @@
},
"license": "MIT"
},
"qualifier 0.4.3": {
"name": "qualifier",
"version": "0.4.3",
"repository": null,
"targets": [],
"library_target_name": null,
"common_attrs": {
"compile_data_glob": [
"**"
],
"deps": {
"common": [
{
"id": "anyhow 1.0.86",
"target": "anyhow"
},
{
"id": "clap 4.5.9",
"target": "clap"
},
{
"id": "dirs 5.0.1",
"target": "dirs"
},
{
"id": "ic-nervous-system-common-test-keys 0.9.0",
"target": "ic_nervous_system_common_test_keys"
},
{
"id": "itertools 0.13.0",
"target": "itertools"
},
{
"id": "log 0.4.22",
"target": "log"
},
{
"id": "pretty_env_logger 0.5.0",
"target": "pretty_env_logger"
},
{
"id": "reqwest 0.12.5",
"target": "reqwest"
},
{
"id": "serde 1.0.204",
"target": "serde"
},
{
"id": "serde_json 1.0.120",
"target": "serde_json"
},
{
"id": "tokio 1.38.1",
"target": "tokio"
},
{
"id": "tokio-util 0.7.11",
"target": "tokio_util"
},
{
"id": "url 2.5.2",
"target": "url"
}
],
"selects": {}
},
"edition": "2021",
"version": "0.4.3"
},
"license": null
},
"quick-xml 0.23.1": {
"name": "quick-xml",
"version": "0.23.1",
Expand Down Expand Up @@ -50321,6 +50385,7 @@
"np-notifications 0.4.3": "rs/np-notifications",
"obs-canister-clients 0.4.3": "rs/ic-observability/obs-canister-clients",
"prometheus-config-updater 0.4.3": "rs/ic-observability/prometheus-config-updater",
"qualifier 0.4.3": "rs/qualifier",
"rollout-controller 0.4.3": "rs/rollout-controller",
"service-discovery 0.4.3": "rs/ic-observability/service-discovery",
"slack-notifications 0.4.3": "rs/slack-notifications",
Expand Down
23 changes: 23 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"rs/rollout-controller",
"rs/slack-notifications",
"rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics",
"rs/qualifier",
"rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics-types",
]

Expand Down Expand Up @@ -109,6 +110,7 @@ ic-base-types = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175
ic-canister-client = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-canister-client-sender = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-canisters = { path = "rs/ic-canisters" }
ic-nervous-system-common-test-keys = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-cdk = "0.15.0"
ic-config = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
ic-crypto-utils-threshold-sig-der = { git = "https://github.com/dfinity/ic.git", rev = "5ba1412f9175d987661ae3c0d8dbd1ac3e092b7d" }
Expand Down
1 change: 1 addition & 0 deletions bazel/external_crates.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def external_crates_repository():
"//rs/slack-notifications:Cargo.toml",
"//rs/rollout-controller:Cargo.toml",
"//rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics:Cargo.toml",
"//rs/qualifier:Cargo.toml",
"//rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics-types:Cargo.toml",
],
splicing_config = splicing_config(
Expand Down
6 changes: 3 additions & 3 deletions rs/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ mod api_boundary_nodes;
mod completions;
mod der_to_principal;
mod firewall;
mod get;
pub mod get;
mod heal;
pub mod hostos;
mod node_metrics;
mod nodes;
mod proposals;
mod propose;
mod qualify;
pub mod qualify;
mod registry;
mod subnet;
mod update_unassigned_nodes;
Expand Down Expand Up @@ -170,7 +170,7 @@ pub trait ExecutableCommand {

fn validate(&self, cmd: &mut Command);

async fn execute(&self, ctx: DreContext) -> anyhow::Result<()>;
fn execute(&self, ctx: DreContext) -> impl std::future::Future<Output = anyhow::Result<()>>;

fn validate_min_nakamoto_coefficients(cmd: &mut clap::Command, min_nakamoto_coefficients: &[String]) {
let _ = Self::_parse_min_nakamoto_coefficients_inner(Some(cmd), min_nakamoto_coefficients);
Expand Down
10 changes: 5 additions & 5 deletions rs/cli/src/commands/qualify/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ use crate::{
pub struct Execute {
/// Version which is to be qualified
#[clap(long, short)]
version: String,
pub version: String,

/// Starting version for the network.
///
/// If left empty, the tool will use the current NNS version
#[clap(long, short)]
from_version: Option<String>,
pub from_version: Option<String>,

/// Specify the steps to run
/// A range can be: `4`, `3..`, `..3, `1..3`
#[clap(long)]
step_range: Option<String>,
pub step_range: Option<String>,

/// Name of the deployment used for prometheus querying of `ic` label: `staging`, `from-config`...
#[clap(long)]
deployment_name: String,
pub deployment_name: String,

/// Prometheus compliant endpoint
#[clap(long)]
prometheus_endpoint: String,
pub prometheus_endpoint: String,
}

impl ExecutableCommand for Execute {
Expand Down
6 changes: 3 additions & 3 deletions rs/cli/src/commands/qualify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use list::List;

use super::ExecutableCommand;

mod execute;
pub mod execute;
mod list;

#[derive(Args, Debug)]
pub struct QualifyCmd {
#[clap(subcommand)]
subcommand: QualifyCommands,
pub subcommand: QualifyCommands,
}

#[derive(Subcommand, Debug)]
enum QualifyCommands {
pub enum QualifyCommands {
/// List all steps present in the qualification
List(List),
/// Execute the qualification
Expand Down
6 changes: 1 addition & 5 deletions rs/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tokio::task::JoinHandle;

use super::{ExecutableCommand, IcAdminRequirement};

#[derive(Args, Debug)]
#[derive(Args, Debug, Default)]
pub struct Upgrade {
/// Version to which the tool should be upgraded, if omitted
/// the latest version will be used
Expand All @@ -15,10 +15,6 @@ pub struct Upgrade {
}

impl Upgrade {
pub fn new() -> Self {
Self { version: None }
}

pub async fn run(&self) -> anyhow::Result<UpdateStatus> {
let version = self.version.clone();
tokio::task::spawn_blocking(move || Self::check_latest_release(env!("CARGO_PKG_VERSION"), true, version)).await?
Expand Down
6 changes: 6 additions & 0 deletions rs/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![allow(dead_code)]
pub mod auth;
pub mod commands;
pub mod ctx;
pub mod ic_admin;
mod operations;
mod qualification;
mod runner;
mod subnet_manager;
2 changes: 1 addition & 1 deletion rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<()> {

let r = args.execute(ctx).await;

let handle = Upgrade::new().check();
let handle = Upgrade::default().check();
let maybe_update_status = handle.await?;
match maybe_update_status {
Ok(s) => match s {
Expand Down
2 changes: 1 addition & 1 deletion rs/cli/src/operations/hostos_rollout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ pub mod test {

let open_proposals: Vec<UpdateNodesHostosVersionsProposal> = vec![];

let network = Network::new("mainnet", &vec![]).await.unwrap();
let network = Network::new("mainnet", &[]).await.unwrap();
let nns_urls = network.get_nns_urls();
let hostos_rollout = HostosRollout::new(
Arc::new(union.clone()),
Expand Down
12 changes: 10 additions & 2 deletions rs/cli/src/qualification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,22 @@ impl QualificationExecutor {
}
print_text(format!("Executing step {}: `{}`", ordered_step.index, ordered_step.step.name()));

ordered_step.step.execute(&self.dre_ctx).await?;
let step_future = || async { ordered_step.step.execute(&self.dre_ctx).await };
step_future.retry(&ExponentialBuilder::default()).await?;

print_text(format!("Executed step {}: `{}`", ordered_step.index, ordered_step.step.name()));

let registry = self.dre_ctx.registry().await;
print_text(format!("Syncing with registry after step {}", ordered_step.index));
let sync_registry = || async { registry.sync_with_nns().await };
sync_registry.retry(&ExponentialBuilder::default()).await?;
// If the system subnet downgraded it could be some time until it boots up
sync_registry
.retry(
&ExponentialBuilder::default()
.with_max_times(10)
.with_max_delay(Duration::from_secs(5 * 60)),
)
.await?;
}

print_text(format!("Qualification of {} finished successfully!", self.to_version));
Expand Down
13 changes: 5 additions & 8 deletions rs/cli/src/qualification/run_workload_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,13 @@ async fn ensure_finalization_rate_for_subnet(
common_labels
);
let query = format!("avg(rate({}[{}s]))", query_selector, duration);
print_text(format!("Running query: {}", query));
let response = client
let request = client
.get(prom_endpoint)
.header("Accept", "application/json")
.query(&[("time", end_timestamp.to_string()), ("query", query)])
.send()
.await?
.error_for_status()?
.json::<Value>()
.await?;
.query(&[("time", end_timestamp.to_string()), ("query", query)]);
print_text(format!("Running query: {:?}", request));
let response = request.send().await?.error_for_status()?.json::<Value>().await?;
print_text(format!("Received response: \n{}", serde_json::to_string_pretty(&response)?));

let finalization_rate = response["data"]["result"][0]["value"][1]
.as_str()
Expand Down
23 changes: 23 additions & 0 deletions rs/qualifier/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@crate_index_dre//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test")
load("@//rs:oci_images.bzl", "rust_binary_oci_image_rules")

DEPS = [
"//rs/cli:dre-lib",
"//rs/ic-canisters",
"//rs/ic-management-types",
"//rs/ic-management-backend:ic-management-backend-lib"
]

rust_binary(
name = "qualifier",
srcs = glob(["src/**/*.rs"]),
aliases = aliases(),
proc_macro_deps = all_crate_deps(
proc_macro = True,
),
stamp = 1,
deps = all_crate_deps(
normal = True,
) + DEPS,
)
Loading

0 comments on commit 40dc9bc

Please sign in to comment.