Skip to content

Commit

Permalink
Graceful agent 1.1.5 (#5093)
Browse files Browse the repository at this point in the history
* Bump NS agent to 0.1.5

* API improvements
- agent exits gracefully when no testrun available
- API doesn't log every error

* Bump NSAPI to 0.1.6
  • Loading branch information
dynco-nym authored Nov 5, 2024
1 parent 69e97b3 commit d03c5b3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions 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
2 changes: 1 addition & 1 deletion nym-node-status-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "nym-node-status-api"
version = "0.1.5"
version = "0.1.6"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
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

0 comments on commit d03c5b3

Please sign in to comment.