switched to tracing
This commit is contained in:
parent
4e56ae770e
commit
645744e08c
11 changed files with 70 additions and 22 deletions
|
@ -18,9 +18,12 @@ hilbert_index = "0.2.0"
|
||||||
hyper = "1.0.1"
|
hyper = "1.0.1"
|
||||||
hyper-util = "0.1.1"
|
hyper-util = "0.1.1"
|
||||||
indoc = "2.0.4"
|
indoc = "2.0.4"
|
||||||
log = "0.4.20"
|
|
||||||
log4rs = "1.2.0"
|
|
||||||
nalgebra = { version = "0.32.3", features = ["serde-serialize"] }
|
nalgebra = { version = "0.32.3", features = ["serde-serialize"] }
|
||||||
|
opentelemetry = "0.21.0"
|
||||||
|
opentelemetry-appender-tracing = "0.2.0"
|
||||||
|
opentelemetry-otlp = { version = "0.14.0", features = ["logs", "http-proto", "reqwest-client"] }
|
||||||
|
opentelemetry-semantic-conventions = "0.13.0"
|
||||||
|
opentelemetry_sdk = { version = "0.21.1", features = ["logs", "rt-tokio"] }
|
||||||
parking_lot = { version = "0.11", features = ["serde"] }
|
parking_lot = { version = "0.11", features = ["serde"] }
|
||||||
pathfinding = "4.6.0"
|
pathfinding = "4.6.0"
|
||||||
rstar = { version = "0.11.0", features = ["serde"] }
|
rstar = { version = "0.11.0", features = ["serde"] }
|
||||||
|
@ -28,7 +31,7 @@ rustmatica = "0.1.1"
|
||||||
serde = { version = "1.0.193", features = ["rc", "derive"] }
|
serde = { version = "1.0.193", features = ["rc", "derive"] }
|
||||||
serde_json = "1.0.108"
|
serde_json = "1.0.108"
|
||||||
time = { version = "0.3.31", features = ["serde"] }
|
time = { version = "0.3.31", features = ["serde"] }
|
||||||
tokio = { version = "1.0", features = ["full"] }
|
tokio = { version = "1.0", features = ["full", "tracing"] }
|
||||||
tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] }
|
tower = { version = "0.4", features = ["util", "timeout", "load-shed", "limit"] }
|
||||||
tower-http = { version = "0.5.0", features = [
|
tower-http = { version = "0.5.0", features = [
|
||||||
"add-extension",
|
"add-extension",
|
||||||
|
@ -39,6 +42,6 @@ tower-http = { version = "0.5.0", features = [
|
||||||
] }
|
] }
|
||||||
tower-layer = "0.3.2"
|
tower-layer = "0.3.2"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["registry", "std"] }
|
||||||
typetag = "0.2.14"
|
typetag = "0.2.14"
|
||||||
ucnlnav = { git = "https://github.com/ucnl/UCNLNav.git", version = "0.1.0" }
|
ucnlnav = { git = "https://github.com/ucnl/UCNLNav.git", version = "0.1.0" }
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{turtle::TurtleCommand, paths::{self, TRANSPARENT}};
|
||||||
|
|
||||||
pub type WorldReadLock = OwnedRwLockReadGuard<RTree<Block>>;
|
pub type WorldReadLock = OwnedRwLockReadGuard<RTree<Block>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct World {
|
pub struct World {
|
||||||
state: Arc<RwLock<RTree<Block>>>, // interior mutability to get around the
|
state: Arc<RwLock<RTree<Block>>>, // interior mutability to get around the
|
||||||
// questionable architecture of this project
|
// questionable architecture of this project
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use log::{warn, info, trace};
|
use tracing::{warn, info, trace};
|
||||||
use tokio::sync::{Mutex, OwnedMutexGuard};
|
use tokio::sync::{Mutex, OwnedMutexGuard};
|
||||||
|
|
||||||
use crate::{blocks::Position, turtle::TurtleCommander};
|
use crate::{blocks::Position, turtle::TurtleCommander};
|
||||||
|
@ -11,7 +11,7 @@ use crate::turtle::{TurtleCommand::*, TurtleCommandResponse};
|
||||||
///
|
///
|
||||||
/// below the specified position is an output chest of infinite capacity
|
/// below the specified position is an output chest of infinite capacity
|
||||||
/// ahead of the specified position is a chest of combustibles
|
/// ahead of the specified position is a chest of combustibles
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Depots {
|
pub struct Depots {
|
||||||
depots: Arc<Mutex<Vec<Arc<Mutex<Position>>>>>
|
depots: Arc<Mutex<Vec<Arc<Mutex<Position>>>>>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::{Mul, Add};
|
use std::ops::{Mul, Add};
|
||||||
|
|
||||||
use log::{trace, warn, info, error};
|
use tracing::{trace, warn, info, error};
|
||||||
use nalgebra::Vector2;
|
use nalgebra::Vector2;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
|
@ -9,6 +9,7 @@ use typetag::serde;
|
||||||
|
|
||||||
use crate::{blocks::{Vec3, Position, Direction}, turtle::{TurtleCommander, TurtleCommand, TurtleCommandResponse, InventorySlot}, tasks::{Task, TaskState}, depot::Depots, mine::fill, paths::TRANSPARENT};
|
use crate::{blocks::{Vec3, Position, Direction}, turtle::{TurtleCommander, TurtleCommand, TurtleCommandResponse, InventorySlot}, tasks::{Task, TaskState}, depot::Depots, mine::fill, paths::TRANSPARENT};
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn fell_tree(turtle: TurtleCommander, bottom: Vec3) -> Option<()> {
|
pub async fn fell_tree(turtle: TurtleCommander, bottom: Vec3) -> Option<()> {
|
||||||
let mut log = bottom;
|
let mut log = bottom;
|
||||||
loop {
|
loop {
|
||||||
|
@ -25,7 +26,7 @@ pub async fn fell_tree(turtle: TurtleCommander, bottom: Vec3) -> Option<()> {
|
||||||
/// Minutes before checking
|
/// Minutes before checking
|
||||||
const SWEEP_DELAY: i64 = 16;
|
const SWEEP_DELAY: i64 = 16;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct TreeFarm {
|
pub struct TreeFarm {
|
||||||
position: Vec3,
|
position: Vec3,
|
||||||
size: Vec3,
|
size: Vec3,
|
||||||
|
@ -41,6 +42,7 @@ impl TreeFarm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn sweep(&self, turtle: TurtleCommander) -> Option<()> {
|
pub async fn sweep(&self, turtle: TurtleCommander) -> Option<()> {
|
||||||
let trees = self.size.product();
|
let trees = self.size.product();
|
||||||
let spacing = Vec3::new(2, 32, 2);
|
let spacing = Vec3::new(2, 32, 2);
|
||||||
|
@ -139,6 +141,7 @@ impl TreeFarm {
|
||||||
|
|
||||||
#[serde]
|
#[serde]
|
||||||
impl Task for TreeFarm {
|
impl Task for TreeFarm {
|
||||||
|
#[tracing::instrument]
|
||||||
fn run(&mut self,turtle:TurtleCommander) -> AbortHandle {
|
fn run(&mut self,turtle:TurtleCommander) -> AbortHandle {
|
||||||
let frozen = self.clone();
|
let frozen = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use axum::{
|
||||||
};
|
};
|
||||||
use blocks::{World, Position, };
|
use blocks::{World, Position, };
|
||||||
use depot::Depots;
|
use depot::Depots;
|
||||||
use log::info;
|
use tracing::info;
|
||||||
use rstar::RTree;
|
use rstar::RTree;
|
||||||
|
|
||||||
use names::Name;
|
use names::Name;
|
||||||
|
@ -21,6 +21,14 @@ use tokio::{sync::{
|
||||||
use turtle::{Turtle, TurtleCommander};
|
use turtle::{Turtle, TurtleCommander};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use indoc::formatdoc;
|
use indoc::formatdoc;
|
||||||
|
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge;
|
||||||
|
use tracing_subscriber::prelude::*;
|
||||||
|
use opentelemetry_otlp::WithExportConfig;
|
||||||
|
use opentelemetry::{global, KeyValue};
|
||||||
|
use opentelemetry_sdk::logs as sdklogs;
|
||||||
|
use opentelemetry_sdk::metrics as sdkmetrics;
|
||||||
|
use opentelemetry_sdk::resource;
|
||||||
|
use opentelemetry_sdk::trace as sdktrace;
|
||||||
|
|
||||||
use crate::blocks::Block;
|
use crate::blocks::Block;
|
||||||
|
|
||||||
|
@ -52,7 +60,35 @@ async fn main() -> Result<(), Error> {
|
||||||
None => "save".into(),
|
None => "save".into(),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
log4rs::init_file(SAVE.get().unwrap().join("log.yml"), Default::default())?;
|
opentelemetry_otlp::new_pipeline()
|
||||||
|
.logging()
|
||||||
|
.with_log_config(
|
||||||
|
sdklogs::Config::default().with_resource(resource::Resource::new(vec![KeyValue::new(
|
||||||
|
opentelemetry_semantic_conventions::resource::SERVICE_NAME,
|
||||||
|
"avarus",
|
||||||
|
)])),
|
||||||
|
)
|
||||||
|
.with_exporter(
|
||||||
|
opentelemetry_otlp::new_exporter()
|
||||||
|
.http()
|
||||||
|
.with_endpoint("http://localhost:4318"),
|
||||||
|
)
|
||||||
|
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
|
||||||
|
|
||||||
|
opentelemetry_otlp::new_pipeline()
|
||||||
|
.tracing()
|
||||||
|
.with_exporter(
|
||||||
|
opentelemetry_otlp::new_exporter()
|
||||||
|
.http()
|
||||||
|
.with_endpoint("http://localhost:4318/v1/traces"),
|
||||||
|
)
|
||||||
|
.install_batch(opentelemetry_sdk::runtime::Tokio)?;
|
||||||
|
|
||||||
|
let tracer = global::tracer("avarus/basic");
|
||||||
|
|
||||||
|
let logger_provider = opentelemetry::global::logger_provider();
|
||||||
|
let layer = OpenTelemetryTracingBridge::new(&logger_provider);
|
||||||
|
tracing_subscriber::registry().with(layer).init();
|
||||||
|
|
||||||
let (kill_send, kill_recv) = watch::channel(());
|
let (kill_send, kill_recv) = watch::channel(());
|
||||||
|
|
||||||
|
@ -75,6 +111,9 @@ async fn main() -> Result<(), Error> {
|
||||||
write_to_disk(&*state.read().await).await?;
|
write_to_disk(&*state.read().await).await?;
|
||||||
info!("written");
|
info!("written");
|
||||||
|
|
||||||
|
global::shutdown_tracer_provider();
|
||||||
|
global::shutdown_logger_provider();
|
||||||
|
|
||||||
state.write().await.kill.closed().await;
|
state.write().await.kill.closed().await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::sync::{Arc, atomic::{AtomicUsize, Ordering, AtomicI32}};
|
use std::sync::{Arc, atomic::{AtomicUsize, Ordering, AtomicI32}};
|
||||||
|
|
||||||
use log::{info, warn, error};
|
use tracing::{info, warn, error};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use tokio::task::{JoinHandle, AbortHandle};
|
use tokio::task::{JoinHandle, AbortHandle};
|
||||||
use typetag::serde;
|
use typetag::serde;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
blocks::{World, Position, Direction, Vec3, WorldReadLock},
|
blocks::{World, Position, Direction, Vec3, WorldReadLock},
|
||||||
};
|
};
|
||||||
use log::{trace, error};
|
use tracing::{trace, error};
|
||||||
use pathfinding::prelude::astar;
|
use pathfinding::prelude::astar;
|
||||||
|
|
||||||
const LOOKUP_LIMIT: usize = 10_000_000;
|
const LOOKUP_LIMIT: usize = 10_000_000;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use log::{error, info};
|
use tracing::{error, info};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::signal;
|
use tokio::signal;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use log::{info, trace};
|
use tracing::{info, trace};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use tokio::task::{JoinHandle, AbortHandle};
|
use tokio::task::{JoinHandle, AbortHandle};
|
||||||
|
|
|
@ -10,9 +10,9 @@ use anyhow::Ok;
|
||||||
|
|
||||||
use anyhow;
|
use anyhow;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use log::trace;
|
use tracing::trace;
|
||||||
use log::warn;
|
use tracing::warn;
|
||||||
use log::info;
|
use tracing::info;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
@ -139,7 +139,7 @@ impl Turtle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct TurtleCommander {
|
pub struct TurtleCommander {
|
||||||
sender: Arc<Sender>,
|
sender: Arc<Sender>,
|
||||||
world: World,
|
world: World,
|
||||||
|
@ -179,6 +179,7 @@ impl TurtleCommander {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn execute(&self, command: TurtleCommand) -> TurtleInfo {
|
pub async fn execute(&self, command: TurtleCommand) -> TurtleInfo {
|
||||||
let (send, recv) = oneshot::channel::<TurtleInfo>();
|
let (send, recv) = oneshot::channel::<TurtleInfo>();
|
||||||
|
|
||||||
|
@ -211,6 +212,7 @@ impl TurtleCommander {
|
||||||
self.world.clone()
|
self.world.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn dock(&self) -> usize {
|
pub async fn dock(&self) -> usize {
|
||||||
let mut wait = 1;
|
let mut wait = 1;
|
||||||
loop {
|
loop {
|
||||||
|
@ -229,6 +231,7 @@ impl TurtleCommander {
|
||||||
self.depots.dock(self.clone()).await
|
self.depots.dock(self.clone()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn goto(&self, pos: Position) -> Option<()> {
|
pub async fn goto(&self, pos: Position) -> Option<()> {
|
||||||
let mut recent = self.pos().await;
|
let mut recent = self.pos().await;
|
||||||
let world = self.world.clone();
|
let world = self.world.clone();
|
||||||
|
@ -277,6 +280,7 @@ impl TurtleCommander {
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument]
|
||||||
pub async fn goto_adjacent(&self, pos: Vec3) -> Option<Position> {
|
pub async fn goto_adjacent(&self, pos: Vec3) -> Option<Position> {
|
||||||
let mut recent = self.pos().await;
|
let mut recent = self.pos().await;
|
||||||
let world = self.world.clone();
|
let world = self.world.clone();
|
||||||
|
@ -325,7 +329,6 @@ impl TurtleCommander {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub(crate) async fn process_turtle_update(
|
pub(crate) async fn process_turtle_update(
|
||||||
id: u32,
|
id: u32,
|
||||||
state: &LiveState,
|
state: &LiveState,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use log::trace;
|
use tracing::trace;
|
||||||
use tokio;
|
use tokio;
|
||||||
use blocks::Vec3;
|
use blocks::Vec3;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
@ -12,7 +12,7 @@ use crate::turtle::TurtleInfo;
|
||||||
use axum::extract::Path;
|
use axum::extract::Path;
|
||||||
use crate::turtle::TurtleCommand;
|
use crate::turtle::TurtleCommand;
|
||||||
use crate::names::Name;
|
use crate::names::Name;
|
||||||
use log::info;
|
use tracing::info;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use blocks::Position;
|
use blocks::Position;
|
||||||
use crate::turtle::Turtle;
|
use crate::turtle::Turtle;
|
||||||
|
|
Loading…
Reference in a new issue