Skip to content

Commit

Permalink
Valuable work
Browse files Browse the repository at this point in the history
  • Loading branch information
randomairborne committed May 29, 2024
1 parent 8b9c393 commit 88990f3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 115 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
rustflags = ["--cfg=tracing_unstable"]
137 changes: 55 additions & 82 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ reqwest = { version = "0.12", features = ["json", "trust-dns", "rustls-tls-webpk
axum = { version = "0.7", features = ["tokio", "http1", "http2", "query"], default-features = false }
tower-http = { version = "0.5", default-features = false, features = ["tracing", "fs"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-subscriber = { version = "0.3", features = ["json"] }
askama = { version = "0.12", features = ["with-axum"] }
valuable = { version = "0.1", features = ["derive"] }
bustdir = { version = "0.1", features = ["askama"] }
serde = { version = "1", features = ["derive"] }
pyng = { path = "pyng" }
Expand Down
21 changes: 6 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use serde::{Deserialize, Serialize};
use tokio::net::TcpListener;
use tower::ServiceBuilder;
use tower_http::services::ServeDir;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use valuable::Valuable;

use crate::{
executor::{ping_bedrock, ping_java},
Expand All @@ -47,7 +47,7 @@ const DEFAULT_PORT: u16 = 8080;

#[tokio::main]
async fn main() {
start_tracing();
tracing_subscriber::fmt().json().init();
let asset_dir = std::env::var("ASSET_DIR").unwrap_or_else(|_| "./assets/".to_owned());
let root_url = valk_utils::get_var("ROOT_URL");
let root_url = root_url.trim_end_matches('/').to_owned();
Expand All @@ -70,7 +70,10 @@ async fn main() {
info!("Fetching minecraft server status");
let current_mcstatus: Arc<RwLock<ServicesResponse>> =
Arc::new(RwLock::new(get_mcstatus(http_client.clone()).await));
info!(?current_mcstatus, "Got minecraft server status");
info!(
status = current_mcstatus.read().as_value(),
"Got mojang service status"
);
tokio::spawn(refresh_mcstatus(http_client, Arc::clone(&current_mcstatus)));

let state = AppState {
Expand Down Expand Up @@ -464,15 +467,3 @@ impl IntoResponse for Png {
(headers, self.0).into_response()
}
}

fn start_tracing() {
let env_filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(concat!(env!("CARGO_PKG_NAME"), "=debug").parse().unwrap())
.with_env_var("LOG")
.from_env()
.expect("failed to parse env");
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(env_filter)
.init();
}
3 changes: 2 additions & 1 deletion src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use axum::extract::State;
use parking_lot::RwLock;
use reqwest::Client;
use tokio::{join, select};
use tracing_core::field::valuable;

use crate::{
structures::{
Expand Down Expand Up @@ -178,7 +179,7 @@ async fn get_minecraft(client: Client) -> Status {
if data.as_slice() == expected {
Status::Operational
} else {
warn!(expected = ?expected, data = ?data, "Got non-matching Minecraft API data");
warn!(expected = ?expected, data = valuable(&data), "Got non-matching Minecraft API data");
Status::PossibleProblems
}
}
Loading

0 comments on commit 88990f3

Please sign in to comment.