cmd/mincatcher: more work to make it play nice with tailscaled

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-09-09 20:23:26 -04:00
parent 36832af7ad
commit 5239861683
4 changed files with 43 additions and 30 deletions

48
Cargo.lock generated
View File

@ -706,30 +706,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "logcatcher"
version = "0.1.0"
dependencies = [
"anyhow",
"axum",
"chrono",
"futures",
"headers",
"hyper",
"lazy_static",
"logtail",
"prometheus",
"serde",
"serde_json",
"structopt",
"tokio",
"tower",
"tower-http",
"tracing",
"tracing-subscriber",
"zstd",
]
[[package]] [[package]]
name = "logtail" name = "logtail"
version = "0.1.0" version = "0.1.0"
@ -805,6 +781,30 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mincatcher"
version = "0.1.0"
dependencies = [
"anyhow",
"axum",
"chrono",
"futures",
"headers",
"hyper",
"lazy_static",
"logtail",
"prometheus",
"serde",
"serde_json",
"structopt",
"tokio",
"tower",
"tower-http",
"tracing",
"tracing-subscriber",
"zstd",
]
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.4.4" version = "0.4.4"

View File

@ -1,5 +1,5 @@
[package] [package]
name = "logcatcher" name = "mincatcher"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"

View File

@ -36,7 +36,10 @@ async fn main() -> Result<()> {
tracing_subscriber::fmt::init(); tracing_subscriber::fmt::init();
let cfg = Config::from_args(); let cfg = Config::from_args();
println!("{:?}", cfg); info!(
"listening on http://{} for logs and http://{} for metrics",
cfg.http_host, cfg.debug_host
);
let server = Server::new(cfg)?; let server = Server::new(cfg)?;
server.run().await?; server.run().await?;

View File

@ -9,9 +9,13 @@ use headers::{Header, HeaderName, HeaderValue};
use hyper::http::StatusCode; use hyper::http::StatusCode;
use logtail::PublicID; use logtail::PublicID;
use prometheus::{Encoder, IntCounterVec, IntGauge}; use prometheus::{Encoder, IntCounterVec, IntGauge};
use std::{convert::TryInto, net::SocketAddr}; use std::net::SocketAddr;
use tokio::sync::Semaphore; use tokio::sync::Semaphore;
use tower_http::trace::TraceLayer; use tower_http::{
trace::{DefaultOnResponse, TraceLayer},
LatencyUnit,
};
use tracing::Level;
const BYTE_MAX: usize = 1048576000; const BYTE_MAX: usize = 1048576000;
@ -57,7 +61,13 @@ impl Server {
let router = Router::new() let router = Router::new()
.route("/c/:collection/:private_id", post(put_logs)) .route("/c/:collection/:private_id", post(put_logs))
.layer(TraceLayer::new_for_http()); .layer(
TraceLayer::new_for_http().on_response(
DefaultOnResponse::new()
.level(Level::INFO)
.latency_unit(LatencyUnit::Micros),
),
);
hyper::Server::bind(&self.http_host) hyper::Server::bind(&self.http_host)
.serve(router.into_make_service()) .serve(router.into_make_service())
@ -145,7 +155,7 @@ async fn put_logs(
.inc(); .inc();
} }
StatusCode::NO_CONTENT StatusCode::OK
} }
async fn metrics(addr: SocketAddr) -> Result<()> { async fn metrics(addr: SocketAddr) -> Result<()> {