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

Bump NS agent to 1.1.5 #5089

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion nym-node-status-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[package]
name = "nym-node-status-agent"
version = "0.1.4"
version = "0.1.5"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
Expand Down
37 changes: 25 additions & 12 deletions nym-node-status-agent/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::bail;
use clap::{Parser, Subcommand};
use nym_bin_common::bin_info;
use nym_common_models::ns_api::TestrunAssignment;
Expand Down Expand Up @@ -51,11 +52,13 @@ impl Args {
let version = probe.version().await;
tracing::info!("Probe version:\n{}", version);

let testrun = request_testrun(&server_address).await?;
if let Some(testrun) = request_testrun(&server_address).await? {
let log = probe.run_and_get_log(&Some(testrun.gateway_identity_key));

let log = probe.run_and_get_log(&Some(testrun.gateway_identity_key));

submit_results(&server_address, testrun.testrun_id, log).await?;
submit_results(&server_address, testrun.testrun_id, log).await?;
} else {
tracing::info!("No testruns available, exiting")
}

Ok(())
}
Expand All @@ -64,16 +67,26 @@ impl Args {
const URL_BASE: &str = "internal/testruns";

#[instrument(level = "debug", skip_all)]
async fn request_testrun(server_addr: &str) -> anyhow::Result<TestrunAssignment> {
async fn request_testrun(server_addr: &str) -> anyhow::Result<Option<TestrunAssignment>> {
let target_url = format!("{}/{}", server_addr, URL_BASE);
let client = reqwest::Client::new();
let res = client
.get(target_url)
.send()
.await
.and_then(|response| response.error_for_status())?;
res.json()
.await
let res = client.get(target_url).send().await?;
let status = res.status();
let response_text = res.text().await?;

if status.is_client_error() {
bail!("{}: {}", status, response_text);
} else if status.is_server_error() {
if matches!(status, reqwest::StatusCode::SERVICE_UNAVAILABLE)
&& response_text.contains("No testruns available")
{
return Ok(None);
} else {
bail!("{}: {}", status, response_text);
}
}

serde_json::from_str(&response_text)
.map(|testrun| {
tracing::info!("Received testrun assignment: {:?}", testrun);
testrun
Expand Down
10 changes: 2 additions & 8 deletions nym-node-status-api/src/http/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use anyhow::anyhow;
use axum::{response::Redirect, Router};
use tokio::net::ToSocketAddrs;
use tower_http::{
cors::CorsLayer,
trace::{DefaultOnResponse, TraceLayer},
};
use tower_http::{cors::CorsLayer, trace::TraceLayer};
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;

Expand Down Expand Up @@ -61,10 +58,7 @@ impl RouterBuilder {
// CORS layer needs to wrap other API layers
.layer(setup_cors())
// logger should be outermost layer
.layer(
TraceLayer::new_for_http()
.on_response(DefaultOnResponse::new().level(tracing::Level::DEBUG)),
)
.layer(TraceLayer::new_for_http())
}
}

Expand Down
3 changes: 2 additions & 1 deletion nym-node-status-api/src/http/api/testruns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async fn request_testrun(State(state): State<AppState>) -> HttpResult<Json<Testr
);
Ok(Json(testrun))
} else {
Err(HttpError::no_available_testruns())
tracing::debug!("No testruns available for agent");
Err(HttpError::no_testruns_available())
}
}
Err(err) => Err(HttpError::internal_with_logging(err)),
Expand Down
4 changes: 2 additions & 2 deletions nym-node-status-api/src/http/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl HttpError {
}
}

pub(crate) fn no_available_testruns() -> Self {
pub(crate) fn no_testruns_available() -> Self {
Self {
message: serde_json::json!({"message": "No available testruns"}).to_string(),
message: serde_json::json!({"message": "No testruns available"}).to_string(),
status: axum::http::StatusCode::SERVICE_UNAVAILABLE,
}
}
Expand Down
Loading