Skip to content

Commit

Permalink
feat: add tokio-console support
Browse files Browse the repository at this point in the history
Adds ability (via feature) to enable tokio-console exporting to debug
the runner or operator.

Also a few misc fixes found when writing expirements.
  • Loading branch information
nathanielc committed Dec 21, 2023
1 parent 9527f05 commit 643e78a
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 34 deletions.
154 changes: 144 additions & 10 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 @@ -5,6 +5,7 @@ resolver = "2"
[workspace.dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive", "env"] }
console-subscriber = "0.2"
env_logger = "0.10.0"
expect-patch = { path = "./expect-patch/" }
keramik-common = { path = "./common/", default-features = false }
Expand All @@ -25,7 +26,7 @@ reqwest = { version = "0.11", features = ["json", "multipart"] }
schemars = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
tokio = { version = "1", features = ["full", "tracing"] }
tonic = { version = "0.8" }
tracing = "0.1.37"
tracing-opentelemetry = "0.18"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CARGO = CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse RUSTFLAGS="-D warnings" cargo
CARGO = CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse RUSTFLAGS="--cfg tokio_unstable -D warnings" cargo

.PHONY: all
all: build check-fmt check-clippy test
Expand Down
12 changes: 7 additions & 5 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ edition = "2021"
[features]
default = []
telemetry = [
"opentelemetry",
"opentelemetry-otlp",
"tracing-opentelemetry",
"tracing-subscriber",
"tracing",
"dep:opentelemetry",
"dep:opentelemetry-otlp",
"dep:tracing-opentelemetry",
"dep:tracing-subscriber",
"dep:tracing",
]
tokio-console = ["telemetry", "dep:console-subscriber"]

[dependencies]
anyhow.workspace = true
console-subscriber = { workspace = true, optional = true }
gethostname = "0.4.2"
opentelemetry-otlp = { workspace = true, optional = true }
opentelemetry = { workspace = true, optional = true }
Expand Down
33 changes: 25 additions & 8 deletions common/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use opentelemetry::{
},
};
use opentelemetry_otlp::WithExportConfig;
use tracing_subscriber::{prelude::*, EnvFilter, Registry};
use tracing_subscriber::{filter::LevelFilter, prelude::*, EnvFilter, Registry};

/// Initialize tracing and metrics
pub async fn init(otlp_endpoint: String) -> Result<BasicController> {
Expand Down Expand Up @@ -60,15 +60,32 @@ pub async fn init(otlp_endpoint: String) -> Result<BasicController> {
// Build starts the meter and sets it as the global meter provider
.build()?;

// Setup filters
// Default to INFO if no env is specified
let log_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env()?;
let otlp_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env()?;

// Setup tracing layers
let telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
let logger = tracing_subscriber::fmt::layer().with_ansi(true).compact();
let env_filter = EnvFilter::try_from_default_env().or_else(|_| EnvFilter::try_new("info"))?;
let telemetry = tracing_opentelemetry::layer()
.with_tracer(tracer)
.with_filter(otlp_filter);
let logger = tracing_subscriber::fmt::layer()
.with_ansi(true)
.compact()
.with_filter(log_filter);

let collector = Registry::default().with(telemetry).with(logger);

let collector = Registry::default()
.with(telemetry)
.with(logger)
.with(env_filter);
#[cfg(feature = "tokio-console")]
let collector = {
let console_filter = EnvFilter::builder().parse("tokio=trace,runtime=trace")?;
let console_layer = console_subscriber::spawn().with_filter(console_filter);
collector.with(console_layer)
};

// Initialize tracing
tracing::subscriber::set_global_default(collector)?;
Expand Down
2 changes: 1 addition & 1 deletion k8s/operator/manifests/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ spec:
- name: OPERATOR_OTLP_ENDPOINT
value: "https://otel:4317"
- name: RUST_LOG
value: "info,kube=debug,keramik_operator=debug"
value: "info"
#readinessProbe:
# httpGet:
# path: /health
Expand Down
4 changes: 4 additions & 0 deletions operator/src/network/cas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ pub fn cas_ipfs_stateful_set_spec(
template: PodTemplateSpec {
metadata: Some(ObjectMeta {
labels: selector_labels(CAS_IPFS_APP),
annotations: Some(BTreeMap::from_iter(vec![(
"prometheus/path".to_owned(),
"/metrics".to_owned(),
)])),
..Default::default()
}),
spec: Some(PodSpec {
Expand Down
Loading

0 comments on commit 643e78a

Please sign in to comment.