diff --git a/.dryrunsecurity.yaml b/.dryrunsecurity.yaml index 19b3cf0f..b15f1560 100644 --- a/.dryrunsecurity.yaml +++ b/.dryrunsecurity.yaml @@ -1,10 +1,12 @@ sensitiveCodepaths: # Files only allowed authors can modify - - '.github/**/*' + - ".github/**/*" allowedAuthors: usernames: # GitHub username - - 'sporkmonger' + - "sporkmonger" + - "dependabot" + - "dependabot[bot]" notificationList: # GitHub username or team name - - '@sporkmonger' + - "@sporkmonger" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5c753458..c842e9c1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -17,3 +17,19 @@ updates: directory: "/" schedule: interval: "weekly" + + - package-ecosystem: "pip" + directory: "/crates/ext-processor/protobuf/protoc-gen-validate" + schedule: + interval: "monthly" + labels: [] + ignore: + - dependency-name: "*" + + - package-ecosystem: "gomod" + directory: "/crates/ext-processor/protobuf/protoc-gen-validate" + schedule: + interval: "monthly" + labels: [] + ignore: + - dependency-name: "*" diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index e538cad5..ffc1341a 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: 'cargo deny' - uses: EmbarkStudios/cargo-deny-action@v1 + uses: EmbarkStudios/cargo-deny-action@v2 with: command: check command-arguments: all diff --git a/.github/workflows/publish-crate.yml b/.github/workflows/publish-crate.yml index e8b2a3bb..a23a710a 100644 --- a/.github/workflows/publish-crate.yml +++ b/.github/workflows/publish-crate.yml @@ -18,14 +18,14 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy target: wasm32-wasi - name: Ensure generated files are available - uses: clechasseur/rs-cargo@5cd564345ef5b1136392a1dc943b33a3a888b873 # v2.0.2 + uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2.0.2 with: command: test args: -p bulwark-config -p bulwark-sdk diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 3c411a74..9dda01a3 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy @@ -27,7 +27,7 @@ jobs: run: /usr/bin/sudo /usr/bin/apt install -y protobuf-compiler - name: Build release target - uses: clechasseur/rs-cargo@5cd564345ef5b1136392a1dc943b33a3a888b873 # v2.0.2 + uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2.0.2 with: command: build args: --release --target=x86_64-unknown-linux-gnu @@ -64,7 +64,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy @@ -78,7 +78,7 @@ jobs: run: brew install protobuf - name: Build release target - uses: clechasseur/rs-cargo@5cd564345ef5b1136392a1dc943b33a3a888b873 # v2.0.2 + uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2.0.2 with: command: build args: --release --target=x86_64-apple-darwin @@ -115,7 +115,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy @@ -129,7 +129,7 @@ jobs: run: brew install protobuf - name: Build release target - uses: clechasseur/rs-cargo@5cd564345ef5b1136392a1dc943b33a3a888b873 # v2.0.2 + uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2.0.2 with: command: build args: --release --target=aarch64-apple-darwin diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index e421289b..6f3e3c0c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + - uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: rustfmt @@ -30,7 +30,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy @@ -56,7 +56,7 @@ jobs: uses: actions/checkout@v4 - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: stable components: clippy @@ -119,7 +119,7 @@ jobs: run: /usr/bin/docker run -d --name envoy --network "${{ job.container.network }}" --network-alias envoy -p 4080:4080 -e GITHUB_ACTIONS=true -e CI=true -v "./tests/gha_envoy.yaml":"/etc/envoy/envoy.yaml" envoyproxy/envoy:v${{ matrix.envoy-version }}-latest envoy -l debug -c /etc/envoy/envoy.yaml - name: Install Rust - uses: dtolnay/rust-toolchain@21dc36fb71dd22e3317045c0c31a3f4249868b17 + uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a with: toolchain: ${{ matrix.rust_version }} components: clippy @@ -135,7 +135,7 @@ jobs: run: /usr/bin/docker ps - name: Run bulwark tests - uses: clechasseur/rs-cargo@5cd564345ef5b1136392a1dc943b33a3a888b873 # v2.0.2 + uses: clechasseur/rs-cargo@34eb9ee3e4186e5c7820a54393fbf081f78bc102 # v2.0.2 with: command: test args: -p bulwark-cli -p bulwark-build -p bulwark-config -p bulwark-decision -p bulwark-ext-processor -p bulwark-host -p bulwark-sdk -p bulwark-sdk-macros -- --include-ignored diff --git a/Cargo.lock b/Cargo.lock index 4eb5db31..56e150f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -410,7 +410,7 @@ dependencies = [ "deadpool-redis", "http 1.1.0", "hyper 1.3.1", - "metrics 0.21.1", + "metrics", "metrics-exporter-prometheus", "metrics-exporter-statsd", "quoted-string", @@ -482,7 +482,7 @@ dependencies = [ "futures", "http 1.1.0", "matchit 0.8.2", - "metrics 0.21.1", + "metrics", "prost", "prost-types", "redis", @@ -512,7 +512,7 @@ dependencies = [ "hex", "http 1.1.0", "http-body-util", - "metrics 0.21.1", + "metrics", "redis", "redis-test", "reqwest", @@ -574,15 +574,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cadence" -version = "0.29.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f39286bc075b023101dccdb79456a1334221c768b8faede0c2aff7ed29a9482d" +checksum = "2f338b979d9ebfff4bb9801ae8f3af0dc3615f7f1ca963f2e4782bcf9acb3753" dependencies = [ "crossbeam-channel", ] @@ -2036,17 +2036,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "metrics" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fde3af1a009ed76a778cb84fdef9e7dbbdf5775ae3e4cc1f434a6a307f6f76c5" -dependencies = [ - "ahash", - "metrics-macros", - "portable-atomic", -] - [[package]] name = "metrics" version = "0.23.0" @@ -2059,9 +2048,9 @@ dependencies = [ [[package]] name = "metrics-exporter-prometheus" -version = "0.15.1" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf0af7a0d7ced10c0151f870e5e3f3f8bc9ffc5992d32873566ca1f9169ae776" +checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6" dependencies = [ "base64 0.22.1", "http-body-util", @@ -2070,7 +2059,7 @@ dependencies = [ "hyper-util", "indexmap 2.2.6", "ipnet", - "metrics 0.23.0", + "metrics", "metrics-util", "quanta", "thiserror", @@ -2080,26 +2069,15 @@ dependencies = [ [[package]] name = "metrics-exporter-statsd" -version = "0.6.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e34a620eecf9e4321ebbef8f2f8e7cd22e098f11b65f2d987ce66faaa8918418" +checksum = "a0905009f54328c743a2046a86c88157621f473a2202cfa922cb716615c4b292" dependencies = [ "cadence", - "metrics 0.21.1", + "metrics", "thiserror", ] -[[package]] -name = "metrics-macros" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "metrics-util" version = "0.17.0" @@ -2109,7 +2087,7 @@ dependencies = [ "crossbeam-epoch", "crossbeam-utils", "hashbrown 0.14.5", - "metrics 0.23.0", + "metrics", "num_cpus", "quanta", "sketches-ddsketch", @@ -2256,9 +2234,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -2288,9 +2266,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", diff --git a/Cargo.toml b/Cargo.toml index 02b16d3b..36f138ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,8 +34,8 @@ clap = { version = "4.4.3", features = ["derive"] } clap_complete = "4.5.2" color-eyre = "0.6.2" hyper = { version = "1.2.0", features = ["server"] } -metrics-exporter-prometheus = "0.15.0" -metrics-exporter-statsd = "0.6.0" +metrics-exporter-prometheus = "0.15.3" +metrics-exporter-statsd = "0.8.0" quoted-string = "0.6.1" tower = { version = "0.4.13", features = ["tokio", "tracing"] } tower-http = { version = "0.5.0", features = [ @@ -119,7 +119,7 @@ futures = "0.3" hex = "0.4.3" http = "1.0" matchit = "0.8.2" -metrics = "0.21.1" +metrics = "0.23.0" owo-colors = "3.5.0" redis = { version = "0.25", features = [ "tokio-comp", diff --git a/crates/ext-processor/src/protobuf.rs b/crates/ext-processor/src/protobuf.rs index 1c48d12a..0defb16d 100644 --- a/crates/ext-processor/src/protobuf.rs +++ b/crates/ext-processor/src/protobuf.rs @@ -11,6 +11,7 @@ pub mod envoy { } } pub mod core { + #[allow(clippy::doc_lazy_continuation)] #[allow(clippy::large_enum_variant)] pub mod v3 { include!(concat!(env!("OUT_DIR"), "/envoy.config.core.v3.rs")); @@ -21,6 +22,7 @@ pub mod envoy { pub mod filters { pub mod http { pub mod ext_authz { + #[allow(clippy::doc_lazy_continuation)] #[allow(clippy::large_enum_variant)] pub mod v3 { include!(concat!( @@ -30,6 +32,7 @@ pub mod envoy { } } pub mod ext_proc { + #[allow(clippy::doc_lazy_continuation)] pub mod v3 { include!(concat!( env!("OUT_DIR"), @@ -52,6 +55,7 @@ pub mod envoy { } pub mod service { pub mod auth { + #[allow(clippy::doc_lazy_continuation)] pub mod v3 { include!(concat!(env!("OUT_DIR"), "/envoy.service.auth.v3.rs")); } diff --git a/crates/ext-processor/src/service.rs b/crates/ext-processor/src/service.rs index f5d3abbe..7fb3e0a6 100644 --- a/crates/ext-processor/src/service.rs +++ b/crates/ext-processor/src/service.rs @@ -232,23 +232,35 @@ impl BulwarkProcessor { /// * `config` - The root of the Bulwark configuration structure to be used to initialize the service. pub async fn new(config: Config) -> Result { // Get all outcomes registered even if those outcomes don't happen immediately. - metrics::register_counter!( + metrics::counter!( "combined_decision", "outcome" => "trusted", - ); - metrics::register_counter!( + ) + .absolute(0); + metrics::counter!( "combined_decision", "outcome" => "accepted", - ); - metrics::register_counter!( + ) + .absolute(0); + metrics::counter!( "combined_decision", "outcome" => "suspected", - ); - metrics::register_counter!( + ) + .absolute(0); + metrics::counter!( "combined_decision", "outcome" => "restricted", + ) + .absolute(0); + metrics::describe_counter!( + "combined_decision", + "Counters for each combined decision outcome." + ); + metrics::histogram!("combined_decision_score").record(0.0); + metrics::describe_histogram!( + "combined_decision_score", + "A histogram over the combined decision scores for all requests processed." ); - metrics::register_histogram!("combined_decision_score"); let redis_pool: Option> = if let Some(redis_addr) = config.state.redis_uri.as_ref() { @@ -344,16 +356,18 @@ impl BulwarkProcessor { let mut plugin_instance = plugin_instance.lock().await; let result = plugin_instance.handle_init().await; match result { - Ok(_) => metrics::increment_counter!( + Ok(_) => metrics::counter!( "plugin_wasm_on_init", "ref" => plugin_instance.plugin_reference(), "result" => "ok" - ), - Err(_) => metrics::increment_counter!( + ) + .increment(1), + Err(_) => metrics::counter!( "plugin_wasm_on_init", "ref" => plugin_instance.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } result } @@ -368,16 +382,18 @@ impl BulwarkProcessor { .handle_request_enrichment(request, labels) .await; match result { - Ok(_) => metrics::increment_counter!( + Ok(_) => metrics::counter!( "plugin_wasm_on_request", "ref" => plugin_instance.plugin_reference(), "result" => "ok" - ), - Err(_) => metrics::increment_counter!( + ) + .increment(1), + Err(_) => metrics::counter!( "plugin_wasm_on_request", "ref" => plugin_instance.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } result } @@ -392,16 +408,18 @@ impl BulwarkProcessor { .handle_request_decision(request, labels) .await; match result { - Ok(_) => metrics::increment_counter!( + Ok(_) => metrics::counter!( "plugin_wasm_on_request_decision", "ref" => plugin_instance.plugin_reference(), "result" => "ok" - ), - Err(_) => metrics::increment_counter!( + ) + .increment(1), + Err(_) => metrics::counter!( "plugin_wasm_on_request_decision", "ref" => plugin_instance.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } result } @@ -417,16 +435,18 @@ impl BulwarkProcessor { .handle_response_decision(request, response, labels) .await; match result { - Ok(_) => metrics::increment_counter!( + Ok(_) => metrics::counter!( "plugin_wasm_on_response_decision", "ref" => plugin_instance.plugin_reference(), "result" => "ok" - ), - Err(_) => metrics::increment_counter!( + ) + .increment(1), + Err(_) => metrics::counter!( "plugin_wasm_on_response_decision", "ref" => plugin_instance.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } result } @@ -443,16 +463,18 @@ impl BulwarkProcessor { .handle_decision_feedback(request, response, labels, verdict) .await; match result { - Ok(_) => metrics::increment_counter!( + Ok(_) => metrics::counter!( "plugin_wasm_on_decision_feedback", "ref" => plugin_instance.plugin_reference(), "result" => "ok" - ), - Err(_) => metrics::increment_counter!( + ) + .increment(1), + Err(_) => metrics::counter!( "plugin_wasm_on_decision_feedback", "ref" => plugin_instance.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } result } @@ -873,14 +895,13 @@ impl ProcessorContext { .verdict .as_ref() .expect("cannot execute feedback phase without verdict"); - metrics::increment_counter!( + metrics::counter!( "combined_decision", "outcome" => verdict.outcome.to_string(), - ); - metrics::histogram!( - "combined_decision_score", - verdict.decision.pignistic().restrict - ); + ) + .increment(1); + metrics::histogram!("combined_decision_score",) + .record(verdict.decision.pignistic().restrict); let mut decisions: Vec = Vec::with_capacity(self.plugin_instances.len()); let mut feedback_phase_tasks = JoinSet::new(); @@ -910,15 +931,26 @@ impl ProcessorContext { }); metrics::histogram!( "decision_score", - decision.pignistic().restrict, + "ref" => plugin_instance.plugin_reference(), + ) + .record(decision.pignistic().restrict); + metrics::describe_histogram!( + "decision_score", + "A histogram over the individual plugin decision scores for all requests processed." ); + // Measure the conflict between each individual decision and the combined decision metrics::histogram!( "decision_conflict", - Decision::conflict(&[decision, verdict.decision]), "ref" => plugin_instance.plugin_reference(), + ) + .record(Decision::conflict(&[decision, verdict.decision])); + metrics::describe_histogram!( + "decision_conflict", + "A histogram over the individual plugin disagreement values for all requests processed." ); + decisions.push(decision); } let request = self.request.clone(); @@ -948,7 +980,11 @@ impl ProcessorContext { join_all(feedback_phase_tasks, |_| {}).await; // Measure total conflict in the combined decision - metrics::histogram!("combined_conflict", Decision::conflict(&decisions)); + metrics::histogram!("combined_conflict").record(Decision::conflict(&decisions)); + metrics::describe_histogram!( + "combined_conflict", + "A histogram over the combined disagreement values for all requests processed." + ); // Capturing stdio is always the last thing that happens and feedback should always be the second-to-last. self.capture_stdio().await; @@ -982,11 +1018,12 @@ impl ProcessorContext { .to_vec() .join(","), ); - metrics::increment_counter!( + metrics::counter!( "plugin_request_phase_decision", "outcome" => outcome.to_string(), "observe_only" => self.thresholds.observe_only.to_string(), - ); + ) + .increment(1); let mut restricted = false; let end_of_stream = self.request.body().is_empty(); @@ -1084,11 +1121,12 @@ impl ProcessorContext { .to_vec() .join(","), ); - metrics::increment_counter!( + metrics::counter!( "plugin_response_phase_decision", "outcome" => outcome.to_string(), "observe_only" => self.thresholds.observe_only.to_string(), - ); + ) + .increment(1); let response = self .response diff --git a/crates/host/src/plugin.rs b/crates/host/src/plugin.rs index dd85d4e9..dda5ac6d 100644 --- a/crates/host/src/plugin.rs +++ b/crates/host/src/plugin.rs @@ -436,14 +436,16 @@ impl PluginInstance { .call_handle_init(self.store.as_context_mut()) .await; match result { - Ok(Ok(_)) => metrics::increment_counter!( + Ok(Ok(_)) => metrics::counter!( "plugin_on_init", "ref" => self.plugin_reference(), "result" => "ok" - ), - Ok(Err(_)) | Err(_) => metrics::increment_counter!( + ) + .increment(1), + Ok(Err(_)) | Err(_) => metrics::counter!( "plugin_on_init", "ref" => self.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } // Initialization doesn't return anything unless there's an error @@ -483,14 +485,16 @@ impl PluginInstance { ) .await; match result { - Ok(Ok(_)) => metrics::increment_counter!( + Ok(Ok(_)) => metrics::counter!( "plugin_on_request", "ref" => self.plugin_reference(), "result" => "ok" - ), - Ok(Err(_)) | Err(_) => metrics::increment_counter!( + ) + .increment(1), + Ok(Err(_)) | Err(_) => metrics::counter!( "plugin_on_request", "ref" => self.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } let labels: HashMap = result??.into_iter().collect(); @@ -528,14 +532,16 @@ impl PluginInstance { ) .await; match result { - Ok(Ok(_)) => metrics::increment_counter!( + Ok(Ok(_)) => metrics::counter!( "plugin_on_request_decision", "ref" => self.plugin_reference(), "result" => "ok" - ), - Ok(Err(_)) | Err(_) => metrics::increment_counter!( + ) + .increment(1), + Ok(Err(_)) | Err(_) => metrics::counter!( "plugin_on_request_decision", "ref" => self.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } Ok(result??.into()) @@ -594,14 +600,16 @@ impl PluginInstance { ) .await; match result { - Ok(Ok(_)) => metrics::increment_counter!( + Ok(Ok(_)) => metrics::counter!( "plugin_on_request_body_decision", "ref" => self.plugin_reference(), "result" => "ok" - ), - Ok(Err(_)) | Err(_) => metrics::increment_counter!( + ) + .increment(1), + Ok(Err(_)) | Err(_) => metrics::counter!( "plugin_on_request_body_decision", "ref" => self.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } Ok(result??.into()) @@ -661,14 +669,16 @@ impl PluginInstance { ) .await; match result { - Ok(Ok(_)) => metrics::increment_counter!( + Ok(Ok(_)) => metrics::counter!( "plugin_on_decision_feedback", "ref" => self.plugin_reference(), "result" => "ok" - ), - Ok(Err(_)) | Err(_) => metrics::increment_counter!( + ) + .increment(1), + Ok(Err(_)) | Err(_) => metrics::counter!( "plugin_on_decision_feedback", "ref" => self.plugin_reference(), "result" => "error" - ), + ) + .increment(1), } // Decision feedback doesn't return anything unless there's an error diff --git a/src/admin.rs b/src/admin.rs index e2cb9700..ebbd26c7 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -3,6 +3,7 @@ use super::*; use http::{HeaderMap, HeaderValue}; pub(super) use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle}; use std::fmt; +use tracing::warn; /// Axum state for the admin service. pub(super) struct AdminState { @@ -97,6 +98,9 @@ pub(super) async fn metrics_handler( let metrics = prometheus_handle.render(); // TODO: Add gzip compression support. body = metrics.into(); + if body.is_empty() { + warn!("exporting empty prometheus metrics"); + } } else { body = vec![]; } diff --git a/src/errors.rs b/src/errors.rs index 1b8baff7..ef192f88 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -20,8 +20,8 @@ pub enum MetricsError { Prometheus(#[from] metrics_exporter_prometheus::BuildError), #[error("failed to install StatsD metrics exporter: {0}")] Statsd(#[from] metrics_exporter_statsd::StatsdError), - #[error("failed to install metrics exporter: {0}")] - Install(#[from] metrics::SetRecorderError), + #[error("failed to install StatsD metrics exporter: {0}")] + SetStatsd(#[from] metrics::SetRecorderError), } #[derive(thiserror::Error, Debug)] diff --git a/src/main.rs b/src/main.rs index d2770a5e..232acb85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,7 +183,7 @@ async fn main() -> Result<(), Box> { .build(prefix) .map_err(MetricsError::from)?; - metrics::set_boxed_recorder(Box::new(recorder)).map_err(MetricsError::from)?; + metrics::set_global_recorder(recorder).map_err(MetricsError::from)?; } else { let thresholds = config_root.thresholds; prometheus_handle = Some(