summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-08-04 20:43:22 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-08-30 13:54:49 +0200
commit3cdc2ca0a19e962d128dabc92158d8245c4387e5 (patch)
treecfe11d3228deb66cecefa8071e0f1770a2c2fcf8
parent08a32f3294d65b4011e54838fc67c792cf8f3ff0 (diff)
Add grafana-loki tracing backendpost-merge/tracing-loki
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--Cargo.lock216
-rw-r--r--tedge/Cargo.toml2
-rw-r--r--tedge/src/cli.rs7
-rw-r--r--tedge/src/logging.rs26
-rw-r--r--tedge/src/main.rs6
5 files changed, 255 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0aa66dcb..e6fb1225 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -743,6 +743,16 @@ dependencies = [
]
[[package]]
+name = "core-foundation"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
name = "core-foundation-sys"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1221,6 +1231,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
+name = "foreign-types"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
+dependencies = [
+ "foreign-types-shared",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+
+[[package]]
name = "form_urlencoded"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1592,6 +1617,19 @@ dependencies = [
]
[[package]]
+name = "hyper-tls"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
+dependencies = [
+ "bytes",
+ "hyper",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+]
+
+[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1794,6 +1832,16 @@ dependencies = [
]
[[package]]
+name = "loki-api"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d1b21fa6bc76e25acb47396ec0a66901c895a42b69de12ae48c68c6ce9172ca2"
+dependencies = [
+ "prost",
+ "prost-types",
+]
+
+[[package]]
name = "loom"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2045,6 +2093,24 @@ dependencies = [
]
[[package]]
+name = "native-tls"
+version = "0.2.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
+dependencies = [
+ "lazy_static",
+ "libc",
+ "log",
+ "openssl",
+ "openssl-probe",
+ "openssl-sys",
+ "schannel",
+ "security-framework",
+ "security-framework-sys",
+ "tempfile",
+]
+
+[[package]]
name = "nix"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2235,6 +2301,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
+name = "openssl"
+version = "0.10.41"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0"
+dependencies = [
+ "bitflags",
+ "cfg-if 1.0.0",
+ "foreign-types",
+ "libc",
+ "once_cell",
+ "openssl-macros",
+ "openssl-sys",
+]
+
+[[package]]
+name = "openssl-macros"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
+dependencies = [
+ "proc-macro2 1.0.43",
+ "quote 1.0.21",
+ "syn 1.0.99",
+]
+
+[[package]]
+name = "openssl-probe"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
+
+[[package]]
name = "openssl-sys"
version = "0.9.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2754,6 +2852,39 @@ dependencies = [
]
[[package]]
+name = "prost"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001"
+dependencies = [
+ "bytes",
+ "prost-derive",
+]
+
+[[package]]
+name = "prost-derive"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe"
+dependencies = [
+ "anyhow",
+ "itertools",
+ "proc-macro2 1.0.43",
+ "quote 1.0.21",
+ "syn 1.0.99",
+]
+
+[[package]]
+name = "prost-types"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "534b7a0e836e3c482d2693070f982e39e7611da9695d4d1f5a4b186b51faef0a"
+dependencies = [
+ "bytes",
+ "prost",
+]
+
+[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2930,11 +3061,13 @@ dependencies = [
"http-body",
"hyper",
"hyper-rustls",
+ "hyper-tls",
"ipnet",
"js-sys",
"lazy_static",
"log",
"mime",
+ "native-tls",
"percent-encoding",
"pin-project-lite",
"rustls 0.20.6",
@@ -2943,6 +3076,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"tokio",
+ "tokio-native-tls",
"tokio-rustls 0.23.4",
"tokio-util 0.7.3",
"tower-service",
@@ -3140,6 +3274,16 @@ dependencies = [
]
[[package]]
+name = "schannel"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
+dependencies = [
+ "lazy_static",
+ "windows-sys",
+]
+
+[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3172,6 +3316,29 @@ dependencies = [
]
[[package]]
+name = "security-framework"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc"
+dependencies = [
+ "bitflags",
+ "core-foundation",
+ "core-foundation-sys",
+ "libc",
+ "security-framework-sys",
+]
+
+[[package]]
+name = "security-framework-sys"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
name = "segments"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3375,6 +3542,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
+name = "snap"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "45456094d1983e2ee2a18fdfebce3189fa451699d0502cb8e3b49dba5ba41451"
+
+[[package]]
name = "socket2"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3563,8 +3736,10 @@ dependencies = [
"toml",
"tracing",
"tracing-chrome",
+ "tracing-loki",
"tracing-subscriber",
"tracing-tracy",
+ "url",
]
[[package]]
@@ -4061,6 +4236,16 @@ dependencies = [
]
[[package]]
+name = "tokio-native-tls"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
+dependencies = [
+ "native-tls",
+ "tokio",
+]
+
+[[package]]
name = "tokio-rustls"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -4221,6 +4406,37 @@ dependencies = [
]
[[package]]
+name = "tracing-loki"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14c616d5f020d7e61c504c3458f76188fcc91cfdd67dc6e33533d50779a9d743"
+dependencies = [
+ "loki-api",
+ "reqwest",
+ "serde",
+ "serde_json",
+ "snap",
+ "tokio",
+ "tokio-stream",
+ "tracing",
+ "tracing-core",
+ "tracing-log",
+ "tracing-serde",
+ "tracing-subscriber",
+ "url",
+]
+
+[[package]]
+name = "tracing-serde"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1"
+dependencies = [
+ "serde",
+ "tracing-core",
+]
+
+[[package]]
name = "tracing-subscriber"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/tedge/Cargo.toml b/tedge/Cargo.toml
index 9e81f7cd..5927c460 100644
--- a/tedge/Cargo.toml
+++ b/tedge/Cargo.toml
@@ -22,6 +22,7 @@ cfg-if = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
tracing-chrome = "0.6"
+tracing-loki = "0.2.1"
tracing-tracy = "0.9"
cfg_table = "1.0.0"
nu-ansi-term = "0.45.1"
@@ -31,6 +32,7 @@ termimad = "0.20.1"
term_size = "0.3.2"
owo-colors = "3.4.0"
textwrap = "0.15.0"
+url = "2.2.2"
tedge_api = { path = "../crates/core/tedge_api" }
tedge_core = { path = "../crates/core/tedge_core" }
diff --git a/tedge/src/cli.rs b/tedge/src/cli.rs
index e01bc313..75310218 100644
--- a/tedge/src/cli.rs
+++ b/tedge/src/cli.rs
@@ -22,6 +22,13 @@ pub struct Cli {
#[clap(long)]
pub chrome_logging: Option<PathBuf>,
+ /// Enable loki compatible tracing output
+ ///
+ /// If set, grafana loki compatible tracing output will be produced
+ #[clap(long, value_name = "URL")]
+ #[clap(parse(try_from_str = url::Url::try_from))]
+ pub loki_logging: Option<url::Url>,
+
/// Enable tracy compatible tracing output
///
/// If set, "tracy" compatible tracing output will be produced
diff --git a/tedge/src/logging.rs b/tedge/src/logging.rs
index a2d60e76..eb0f968b 100644
--- a/tedge/src/logging.rs
+++ b/tedge/src/logging.rs
@@ -1,5 +1,6 @@
use std::path::PathBuf;
+use miette::IntoDiagnostic;
use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::layer::SubscriberExt;
@@ -11,6 +12,7 @@ pub fn setup_logging(
spec: Option<LoggingSpec>,
chrome_logging: Option<&PathBuf>,
tracy_logging: bool,
+ loki_logging: Option<&url::Url>,
) -> miette::Result<LogGuard> {
let env_filter = match spec {
None => {
@@ -60,11 +62,30 @@ pub fn setup_logging(
.unwrap_or_default();
let opt_tracy_layer = tracy_logging.then(tracing_tracy::TracyLayer::new);
+ let (opt_loki_layer, loki_background_task) = {
+ let opt_tupl = loki_logging
+ .map(|url| {
+ tracing_loki::layer(
+ url.clone(),
+ vec![("host".into(), "mine".into())].into_iter().collect(),
+ vec![].into_iter().collect(),
+ )
+ })
+ .transpose()
+ .into_diagnostic()?;
+
+ if let Some((opt_loki_layer, opt_loki_bg_task)) = opt_tupl {
+ (Some(opt_loki_layer), Some(opt_loki_bg_task))
+ } else {
+ (None, None)
+ }
+ };
let stdout_log = env_filter.map(|f| tracing_subscriber::fmt::layer().with_filter(f));
let subscriber = tracing_subscriber::registry::Registry::default()
.with(opt_chrome_layer)
+ .with(opt_loki_layer)
.with(opt_tracy_layer)
.with(stdout_log);
@@ -75,7 +96,7 @@ pub fn setup_logging(
tracing::warn!("Logging level set to WARN. Only warnings and errors will be reported.");
}
- Ok(LogGuard { chrome_log_guard })
+ Ok(LogGuard { chrome_log_guard, loki_background_task })
}
/// Helper type for keeping the tracing_chrome::FlushGuard alive if we trace with tracing_chrome
@@ -84,4 +105,7 @@ pub fn setup_logging(
pub struct LogGuard {
#[allow(dead_code)]
chrome_log_guard: Option<tracing_chrome::FlushGuard>,
+
+ /// Background Task that needs to be tokio::spawned() for loki tracing backend to work
+ pub loki_background_task: Option<tracing_loki::BackgroundTask>,
}
diff --git a/tedge/src/main.rs b/tedge/src/main.rs
index 18ffc316..e009cbd3 100644
--- a/tedge/src/main.rs
+++ b/tedge/src/main.rs
@@ -10,10 +10,11 @@ use tedge_lib::notification::Notification;
#[tracing::instrument]
async fn main() -> miette::Result<()> {
let args = tedge_cli::cli::Cli::parse();
- let _guard = tedge_cli::logging::setup_logging(
+ let guard = tedge_cli::logging::setup_logging(
args.logging,
args.chrome_logging.as_ref(),
args.tracy_logging,
+ args.loki_logging.as_ref(),
)?;
info!("Tedge booting...");
debug!(?args, "Tedge CLI");
@@ -112,5 +113,8 @@ async fn main() -> miette::Result<()> {
}
);
+ if let Some(bg_task) = guard.loki_background_task {
+ tokio::spawn(bg_task);
+ }
tedge_cli::run_app(args, registry).await
}