separate signal-gateway binary from the library, and its deps
This commit is contained in:
Generated
+3
@@ -1645,6 +1645,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|||||||
name = "signal-gateway"
|
name = "signal-gateway"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
"chrono-tz",
|
"chrono-tz",
|
||||||
"conf",
|
"conf",
|
||||||
@@ -1652,6 +1653,8 @@ dependencies = [
|
|||||||
"displaydoc",
|
"displaydoc",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"http",
|
||||||
|
"http-body",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"humantime",
|
"humantime",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
|||||||
+4
-1
@@ -24,6 +24,7 @@ result_large_err = "allow"
|
|||||||
prometheus-http-client = { path = "prometheus-http-client", default-features = false }
|
prometheus-http-client = { path = "prometheus-http-client", default-features = false }
|
||||||
|
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
bytes = "1"
|
||||||
chrono = { version = "0.4", default-features = false, features = ["clock", "serde", "std"] }
|
chrono = { version = "0.4", default-features = false, features = ["clock", "serde", "std"] }
|
||||||
chrono-tz = "0.10"
|
chrono-tz = "0.10"
|
||||||
conf = "0.4"
|
conf = "0.4"
|
||||||
@@ -31,6 +32,8 @@ conf-extra = "0.1"
|
|||||||
displaydoc = "0.2"
|
displaydoc = "0.2"
|
||||||
dotenvy = "0.15"
|
dotenvy = "0.15"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
|
http = "1"
|
||||||
|
http-body = "1"
|
||||||
http-body-util = "0.1"
|
http-body-util = "0.1"
|
||||||
humantime = "2"
|
humantime = "2"
|
||||||
hyper = { version = "1.7", features = ["server", "http1", "http2"] }
|
hyper = { version = "1.7", features = ["server", "http1", "http2"] }
|
||||||
@@ -43,7 +46,7 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
syslog_rfc5424 = "0.10"
|
syslog_rfc5424 = "0.10"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync", "time"] }
|
tokio = { version = "1", features = ["io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] }
|
||||||
tokio-util = { version = "0.7", features = ["codec"] }
|
tokio-util = { version = "0.7", features = ["codec"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
|
|||||||
@@ -10,20 +10,26 @@ workspace = true
|
|||||||
default = ["plot"]
|
default = ["plot"]
|
||||||
plot = ["prometheus-http-client/plot", "dep:chrono-tz", "dep:rand", "dep:walkdir"]
|
plot = ["prometheus-http-client/plot", "dep:chrono-tz", "dep:rand", "dep:walkdir"]
|
||||||
rustls-tls = ["prometheus-http-client/rustls-tls"]
|
rustls-tls = ["prometheus-http-client/rustls-tls"]
|
||||||
|
bin = ["dep:dotenvy", "dep:hyper", "dep:hyper-util", "dep:tracing-subscriber"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "signal-gateway"
|
||||||
|
path = "src/bin/main.rs"
|
||||||
|
required-features = ["bin"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
prometheus-http-client = { workspace = true, default-features = false }
|
prometheus-http-client = { workspace = true, default-features = false }
|
||||||
|
|
||||||
|
bytes = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
conf = { workspace = true }
|
conf = { workspace = true }
|
||||||
conf-extra = { workspace = true }
|
conf-extra = { workspace = true }
|
||||||
displaydoc = { workspace = true }
|
displaydoc = { workspace = true }
|
||||||
dotenvy = { workspace = true }
|
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
|
http = { workspace = true }
|
||||||
|
http-body = { workspace = true }
|
||||||
http-body-util = { workspace = true }
|
http-body-util = { workspace = true }
|
||||||
humantime = { workspace = true }
|
humantime = { workspace = true }
|
||||||
hyper = { workspace = true }
|
|
||||||
hyper-util = { workspace = true }
|
|
||||||
jsonrpsee = { workspace = true }
|
jsonrpsee = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
@@ -32,9 +38,15 @@ thiserror = { workspace = true }
|
|||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
tokio-util = { workspace = true }
|
tokio-util = { workspace = true }
|
||||||
tracing = { workspace = true }
|
tracing = { workspace = true }
|
||||||
tracing-subscriber = { workspace = true }
|
|
||||||
url = { workspace = true }
|
url = { workspace = true }
|
||||||
|
|
||||||
|
# Optional dependencies for bin feature
|
||||||
|
dotenvy = { workspace = true, optional = true }
|
||||||
|
hyper = { workspace = true, optional = true }
|
||||||
|
hyper-util = { workspace = true, optional = true }
|
||||||
|
tracing-subscriber = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
# Optional dependencies for plot feature
|
||||||
chrono-tz = { workspace = true, optional = true }
|
chrono-tz = { workspace = true, optional = true }
|
||||||
rand = { workspace = true, optional = true }
|
rand = { workspace = true, optional = true }
|
||||||
walkdir = { workspace = true, optional = true }
|
walkdir = { workspace = true, optional = true }
|
||||||
|
|||||||
@@ -2,27 +2,60 @@ use conf::Conf;
|
|||||||
use hyper::service::service_fn;
|
use hyper::service::service_fn;
|
||||||
use hyper_util::rt::TokioIo;
|
use hyper_util::rt::TokioIo;
|
||||||
use hyper_util::server::conn::auto;
|
use hyper_util::server::conn::auto;
|
||||||
use std::{str::FromStr, sync::Arc, time::Duration};
|
use signal_gateway::{Gateway, GatewayConfig};
|
||||||
|
use std::{net::SocketAddr, str::FromStr, sync::Arc, time::Duration};
|
||||||
use syslog_rfc5424::SyslogMessage;
|
use syslog_rfc5424::SyslogMessage;
|
||||||
use tokio::net::{TcpListener, UdpSocket};
|
use tokio::net::{TcpListener, UdpSocket};
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
pub mod config;
|
#[derive(Conf, Debug)]
|
||||||
pub mod gateway;
|
struct Config {
|
||||||
pub mod http;
|
/// If true, just validate config and don't start
|
||||||
mod human_duration;
|
#[conf(long)]
|
||||||
mod init_logging;
|
dry_run: bool,
|
||||||
pub mod jsonrpc;
|
/// Socket to listen for HTTP requests (GET /health, POST /alert)
|
||||||
pub mod prometheus;
|
#[conf(long, env, default_value = "0.0.0.0:8000")]
|
||||||
pub mod transports;
|
http_listen_addr: SocketAddr,
|
||||||
|
/// Socket to listen for UDP messages, in syslog RFC 5424 format
|
||||||
|
#[conf(long, env, default_value = "0.0.0.0:5424")]
|
||||||
|
udp_listen_addr: SocketAddr,
|
||||||
|
#[conf(flatten)]
|
||||||
|
gateway: GatewayConfig,
|
||||||
|
}
|
||||||
|
|
||||||
use config::Config;
|
fn init_logging() {
|
||||||
use gateway::Gateway;
|
// Build a default tracing subscriber, writing to STDERR
|
||||||
|
// Uses RUST_LOG env var for filtering, defaults to "info" if not set
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_writer(std::io::stderr)
|
||||||
|
.with_file(true)
|
||||||
|
.with_line_number(true)
|
||||||
|
.with_env_filter(
|
||||||
|
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
|
||||||
|
)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
// load dotenv file
|
||||||
|
match dotenvy::dotenv() {
|
||||||
|
Ok(path) => info!("Read dotenv file from: {}", path.display()),
|
||||||
|
Err(dotenvy::Error::Io(io_error)) => {
|
||||||
|
if matches!(io_error.kind(), std::io::ErrorKind::NotFound) {
|
||||||
|
info!("Couldn't find a dotenv file");
|
||||||
|
} else {
|
||||||
|
panic!("Io error when reading dot env file: {io_error}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
panic!("Error reading dotenv file: {err}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
init_logging::init_logging();
|
init_logging();
|
||||||
|
|
||||||
let config = Config::parse();
|
let config = Config::parse();
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
use crate::gateway::GatewayConfig;
|
|
||||||
use conf::Conf;
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
|
|
||||||
#[derive(Conf, Debug)]
|
|
||||||
pub struct Config {
|
|
||||||
/// If true, just validate config and don't start
|
|
||||||
#[conf(long)]
|
|
||||||
pub dry_run: bool,
|
|
||||||
/// Socket to listen for HTTP requests (GET /health, POST /alert)
|
|
||||||
#[conf(long, env, default_value = "0.0.0.0:8000")]
|
|
||||||
pub http_listen_addr: SocketAddr,
|
|
||||||
/// Socket to listen for UDP messages, in syslog RFC 5424 format
|
|
||||||
#[conf(long, env, default_value = "0.0.0.0:5424")]
|
|
||||||
pub udp_listen_addr: SocketAddr,
|
|
||||||
#[conf(flatten)]
|
|
||||||
pub gateway: GatewayConfig,
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,12 @@ use crate::{
|
|||||||
jsonrpc::{Envelope, RpcClient, RpcClientError, SignalMessage, connect_tcp},
|
jsonrpc::{Envelope, RpcClient, RpcClientError, SignalMessage, connect_tcp},
|
||||||
prometheus::{Prometheus, PrometheusConfig},
|
prometheus::{Prometheus, PrometheusConfig},
|
||||||
};
|
};
|
||||||
|
use bytes::Buf;
|
||||||
use conf::{Conf, Subcommands};
|
use conf::{Conf, Subcommands};
|
||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
|
pub use http::{Method, Request, Response, StatusCode};
|
||||||
|
use http_body::Body;
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
use hyper::{Method, Request, Response, StatusCode, body::Incoming};
|
|
||||||
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
||||||
//use jsonrpsee::async_client::{Client as JsonRpcClient, Error as JsonRpcError};
|
//use jsonrpsee::async_client::{Client as JsonRpcClient, Error as JsonRpcError};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
@@ -393,10 +395,12 @@ impl Gateway {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handler function that processes incoming http requests (push's from alertmanager expected)
|
// Handler function that processes incoming http requests (push's from alertmanager expected)
|
||||||
pub async fn handle_http_request(
|
pub async fn handle_http_request<B>(&self, req: Request<B>) -> Result<Response<String>, String>
|
||||||
&self,
|
where
|
||||||
req: Request<Incoming>,
|
B: Body + Send,
|
||||||
) -> Result<Response<String>, String> {
|
B::Data: Buf + Send,
|
||||||
|
B::Error: std::fmt::Display,
|
||||||
|
{
|
||||||
info!(
|
info!(
|
||||||
"Received http request: {} {} (version: {:?})",
|
"Received http request: {} {} (version: {:?})",
|
||||||
req.method(),
|
req.method(),
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
//! Logging initialization for signal-gateway
|
|
||||||
|
|
||||||
use tracing::info;
|
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
pub fn init_logging() {
|
|
||||||
// Build a default tracing subscriber, writing to STDERR
|
|
||||||
// Uses RUST_LOG env var for filtering, defaults to "info" if not set
|
|
||||||
tracing_subscriber::fmt()
|
|
||||||
.with_writer(std::io::stderr)
|
|
||||||
.with_file(true)
|
|
||||||
.with_line_number(true)
|
|
||||||
.with_env_filter(
|
|
||||||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
|
|
||||||
)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
// load dotenv file
|
|
||||||
match dotenvy::dotenv() {
|
|
||||||
Ok(path) => info!("Read dotenv file from: {}", path.display()),
|
|
||||||
Err(dotenvy::Error::Io(io_error)) => {
|
|
||||||
if matches!(io_error.kind(), std::io::ErrorKind::NotFound) {
|
|
||||||
info!("Couldn't find a dotenv file");
|
|
||||||
} else {
|
|
||||||
panic!("Io error when reading dot env file: {io_error}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
panic!("Error reading dotenv file: {err}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
pub mod gateway;
|
||||||
|
pub mod http;
|
||||||
|
pub mod human_duration;
|
||||||
|
pub mod jsonrpc;
|
||||||
|
pub mod prometheus;
|
||||||
|
pub mod transports;
|
||||||
|
|
||||||
|
pub use gateway::{Gateway, GatewayConfig};
|
||||||
Reference in New Issue
Block a user