diff -Nru rust-prometheus-client-0.22.2/Cargo.toml rust-prometheus-client-0.22.3/Cargo.toml --- rust-prometheus-client-0.22.2/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 +++ rust-prometheus-client-0.22.3/Cargo.toml 1970-01-01 00:00:01.000000000 +0000 @@ -12,7 +12,7 @@ [package] edition = "2021" name = "prometheus-client" -version = "0.22.2" +version = "0.22.3" authors = ["Max Inden "] description = "Open Metrics client library allowing users to natively instrument applications." homepage = "https://github.com/prometheus/client_rust" @@ -28,6 +28,9 @@ license = "Apache-2.0 OR MIT" repository = "https://github.com/prometheus/client_rust" +[package.metadata.docs.rs] +all-features = true + [[bench]] name = "baseline" harness = false @@ -78,17 +81,23 @@ [dev-dependencies.criterion] version = "0.5" +[dev-dependencies.http-body-util] +version = "0.1.1" + [dev-dependencies.http-types] version = "2" [dev-dependencies.hyper] -version = "0.14.16" +version = "1.3.1" features = [ "server", "http1", - "tcp", ] +[dev-dependencies.hyper-util] +version = "0.1.3" +features = ["tokio"] + [dev-dependencies.pyo3] version = "0.20" diff -Nru rust-prometheus-client-0.22.2/Cargo.toml.orig rust-prometheus-client-0.22.3/Cargo.toml.orig --- rust-prometheus-client-0.22.2/Cargo.toml.orig 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/Cargo.toml.orig 2006-07-24 01:21:28.000000000 +0000 @@ -1,6 +1,6 @@ [package] name = "prometheus-client" -version = "0.22.2" +version = "0.22.3" authors = ["Max Inden "] edition = "2021" description = "Open Metrics client library allowing users to natively instrument applications." @@ -35,7 +35,9 @@ tide = "0.16" actix-web = "4" tokio = { version = "1", features = ["rt-multi-thread", "net", "macros", "signal"] } -hyper = { version = "0.14.16", features = ["server", "http1", "tcp"] } +hyper = { version = "1.3.1", features = ["server", "http1"] } +hyper-util = { version = "0.1.3", features = ["tokio"] } +http-body-util = "0.1.1" [build-dependencies] prost-build = { version = "0.11.0", optional = true } @@ -59,3 +61,8 @@ path = "benches/encoding/proto.rs" harness = false required-features = ["protobuf"] + +# Passing arguments to the docsrs builder in order to properly document cfg's. +# More information: https://docs.rs/about/builds#cross-compiling +[package.metadata.docs.rs] +all-features = true diff -Nru rust-prometheus-client-0.22.2/.cargo_vcs_info.json rust-prometheus-client-0.22.3/.cargo_vcs_info.json --- rust-prometheus-client-0.22.2/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 +++ rust-prometheus-client-0.22.3/.cargo_vcs_info.json 1970-01-01 00:00:01.000000000 +0000 @@ -1,6 +1,6 @@ { "git": { - "sha1": "de2723402f9f7604e1d4a7419ae11c3f14e9803d" + "sha1": "7f570f3f6057be5bdab3da4c817ff8b1a962c483" }, "path_in_vcs": "" } \ No newline at end of file diff -Nru rust-prometheus-client-0.22.2/CHANGELOG.md rust-prometheus-client-0.22.3/CHANGELOG.md --- rust-prometheus-client-0.22.2/CHANGELOG.md 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/CHANGELOG.md 2006-07-24 01:21:28.000000000 +0000 @@ -4,6 +4,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.22.3] + +### Added + +- Added `encode_registry` and `encode_eof` functions to `text` module. + See [PR 205]. + + [PR 205]: https://github.com/prometheus/client_rust/pull/205 + +- Support all platforms with 32 bit atomics lacking 64 bit atomics. + See [PR 203]. + +[PR 203]: https://github.com/prometheus/client_rust/pull/203 + ## [0.22.2] ### Added diff -Nru rust-prometheus-client-0.22.2/debian/changelog rust-prometheus-client-0.22.3/debian/changelog --- rust-prometheus-client-0.22.2/debian/changelog 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/changelog 2025-04-10 20:27:24.000000000 +0000 @@ -1,3 +1,10 @@ +rust-prometheus-client (0.22.3-1) UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; urgency=medium + + * Team upload. + * Package prometheus-client 0.22.3 from crates.io using debcargo 2.7.8 + + -- Blair Noctis Thu, 10 Apr 2025 20:27:24 +0000 + rust-prometheus-client (0.22.2-1) unstable; urgency=medium * Team upload. diff -Nru rust-prometheus-client-0.22.2/debian/compat rust-prometheus-client-0.22.3/debian/compat --- rust-prometheus-client-0.22.2/debian/compat 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/compat 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -12 diff -Nru rust-prometheus-client-0.22.2/debian/control rust-prometheus-client-0.22.3/debian/control --- rust-prometheus-client-0.22.2/debian/control 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/control 2025-04-10 20:27:24.000000000 +0000 @@ -1,9 +1,9 @@ Source: rust-prometheus-client Section: rust Priority: optional -Build-Depends: debhelper (>= 12), - dh-cargo (>= 25), - cargo:native , +Build-Depends: debhelper-compat (= 13), + dh-sequence-cargo +Build-Depends-Arch: cargo:native , rustc:native , libstd-rust-dev , librust-dtoa-1+default-dev , @@ -13,7 +13,7 @@ Maintainer: Debian Rust Maintainers Uploaders: Sylvestre Ledru -Standards-Version: 4.6.2 +Standards-Version: 4.7.0 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/prometheus-client] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/prometheus-client Homepage: https://github.com/prometheus/client_rust @@ -29,9 +29,9 @@ librust-itoa-1+default-dev, librust-parking-lot-0.12+default-dev, librust-prometheus-client-derive-encode-0.4+default-dev (>= 0.4.1-~~), - librust-prost-0.12+default-dev, - librust-prost-build-0.12+default-dev, - librust-prost-types-0.12+default-dev + librust-prost-0.13+default-dev, + librust-prost-build-0.13+default-dev, + librust-prost-types-0.13+default-dev Provides: librust-prometheus-client+default-dev (= ${binary:Version}), librust-prometheus-client+protobuf-dev (= ${binary:Version}), @@ -41,8 +41,8 @@ librust-prometheus-client-0.22-dev (= ${binary:Version}), librust-prometheus-client-0.22+default-dev (= ${binary:Version}), librust-prometheus-client-0.22+protobuf-dev (= ${binary:Version}), - librust-prometheus-client-0.22.2-dev (= ${binary:Version}), - librust-prometheus-client-0.22.2+default-dev (= ${binary:Version}), - librust-prometheus-client-0.22.2+protobuf-dev (= ${binary:Version}) + librust-prometheus-client-0.22.3-dev (= ${binary:Version}), + librust-prometheus-client-0.22.3+default-dev (= ${binary:Version}), + librust-prometheus-client-0.22.3+protobuf-dev (= ${binary:Version}) Description: Open Metrics client library allowing users to natively instrument applications - Rust source code Source code for Debianized Rust crate "prometheus-client" diff -Nru rust-prometheus-client-0.22.2/debian/copyright.debcargo.hint rust-prometheus-client-0.22.3/debian/copyright.debcargo.hint --- rust-prometheus-client-0.22.2/debian/copyright.debcargo.hint 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/copyright.debcargo.hint 2025-04-10 20:27:24.000000000 +0000 @@ -21,8 +21,8 @@ Files: debian/* Copyright: - 2023-2024 Debian Rust Maintainers - 2023-2024 Sylvestre Ledru + 2023-2025 Debian Rust Maintainers + 2023-2025 Sylvestre Ledru License: Apache-2.0 or MIT License: Apache-2.0 diff -Nru rust-prometheus-client-0.22.2/debian/patches/disable-unused-deps.patch rust-prometheus-client-0.22.3/debian/patches/disable-unused-deps.patch --- rust-prometheus-client-0.22.2/debian/patches/disable-unused-deps.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/patches/disable-unused-deps.patch 2025-04-10 20:27:23.000000000 +0000 @@ -0,0 +1,8 @@ +Forwarded: not-needed +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -109,3 +109,3 @@ + +-[dev-dependencies.tide] ++[disabled.dev-dependencies.tide] + version = "0.16" diff -Nru rust-prometheus-client-0.22.2/debian/patches/relax-deps.patch rust-prometheus-client-0.22.3/debian/patches/relax-deps.patch --- rust-prometheus-client-0.22.2/debian/patches/relax-deps.patch 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/patches/relax-deps.patch 2025-04-10 20:27:23.000000000 +0000 @@ -1,60 +1,23 @@ -Index: prometheus-client/Cargo.toml -=================================================================== ---- prometheus-client.orig/Cargo.toml -+++ prometheus-client/Cargo.toml -@@ -61,16 +61,13 @@ version = "0.12" - version = "0.4.1" - +Forwarded: not-needed +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -66,3 +66,3 @@ [dependencies.prost] -version = "0.11.0" -+version = "0.12" ++version = "0.13" optional = true - +@@ -70,3 +70,3 @@ [dependencies.prost-types] -version = "0.11.0" -+version = "0.12" ++version = "0.13" optional = true - --[dev-dependencies.actix-web] --version = "4" -- - [dev-dependencies.async-std] - version = "1" - features = ["attributes"] -@@ -78,17 +75,6 @@ features = ["attributes"] - [dev-dependencies.criterion] - version = "0.5" - --[dev-dependencies.http-types] --version = "2" -- --[dev-dependencies.hyper] --version = "0.14.16" --features = [ -- "server", -- "http1", -- "tcp", --] -- +@@ -101,3 +101,3 @@ [dev-dependencies.pyo3] - version = "0.20" - -@@ -98,9 +84,6 @@ version = "1" - [dev-dependencies.rand] - version = "0.8.4" - --[dev-dependencies.tide] --version = "0.16" -- - [dev-dependencies.tokio] - version = "1" - features = [ -@@ -111,7 +94,7 @@ features = [ - ] +-version = "0.20" ++version = "0.22" +@@ -122,3 +122,3 @@ [build-dependencies.prost-build] -version = "0.11.0" -+version = "0.12" ++version = "0.13" optional = true - - [features] diff -Nru rust-prometheus-client-0.22.2/debian/patches/series rust-prometheus-client-0.22.3/debian/patches/series --- rust-prometheus-client-0.22.2/debian/patches/series 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/patches/series 2025-04-10 20:27:23.000000000 +0000 @@ -1 +1,2 @@ relax-deps.patch +disable-unused-deps.patch diff -Nru rust-prometheus-client-0.22.2/debian/tests/control rust-prometheus-client-0.22.3/debian/tests/control --- rust-prometheus-client-0.22.2/debian/tests/control 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/tests/control 2025-04-10 20:27:24.000000000 +0000 @@ -1,19 +1,19 @@ -Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.2 --all-targets --all-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.3 --all-targets --all-features Features: test-name=rust-prometheus-client:@ -Depends: dh-cargo (>= 18), librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-pyo3-0.20+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ +Depends: dh-cargo (>= 31), rustc, librust-actix-web-4+default-dev, librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-http-body-util-0.1+default-dev (>= 0.1.1-~~), librust-http-types-2+default-dev, librust-hyper-1+default-dev (>= 1.3.1-~~), librust-hyper-1+http1-dev (>= 1.3.1-~~), librust-hyper-1+server-dev (>= 1.3.1-~~), librust-hyper-util-0.1+default-dev (>= 0.1.3-~~), librust-hyper-util-0.1+tokio-dev (>= 0.1.3-~~), librust-pyo3-0.22+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ Restrictions: allow-stderr, skip-not-installable, flaky -Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.2 --all-targets +Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.3 --all-targets Features: test-name=librust-prometheus-client-dev:default -Depends: dh-cargo (>= 18), librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-pyo3-0.20+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ +Depends: dh-cargo (>= 31), rustc, librust-actix-web-4+default-dev, librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-http-body-util-0.1+default-dev (>= 0.1.1-~~), librust-http-types-2+default-dev, librust-hyper-1+default-dev (>= 1.3.1-~~), librust-hyper-1+http1-dev (>= 1.3.1-~~), librust-hyper-1+server-dev (>= 1.3.1-~~), librust-hyper-util-0.1+default-dev (>= 0.1.3-~~), librust-hyper-util-0.1+tokio-dev (>= 0.1.3-~~), librust-pyo3-0.22+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ Restrictions: allow-stderr, skip-not-installable, flaky -Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.2 --all-targets --no-default-features --features protobuf +Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.3 --all-targets --no-default-features --features protobuf Features: test-name=librust-prometheus-client-dev:protobuf -Depends: dh-cargo (>= 18), librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-pyo3-0.20+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ +Depends: dh-cargo (>= 31), rustc, librust-actix-web-4+default-dev, librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-http-body-util-0.1+default-dev (>= 0.1.1-~~), librust-http-types-2+default-dev, librust-hyper-1+default-dev (>= 1.3.1-~~), librust-hyper-1+http1-dev (>= 1.3.1-~~), librust-hyper-1+server-dev (>= 1.3.1-~~), librust-hyper-util-0.1+default-dev (>= 0.1.3-~~), librust-hyper-util-0.1+tokio-dev (>= 0.1.3-~~), librust-pyo3-0.22+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ Restrictions: allow-stderr, skip-not-installable, flaky -Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.2 --all-targets --no-default-features +Test-Command: /usr/share/cargo/bin/cargo-auto-test prometheus-client 0.22.3 --all-targets --no-default-features Features: test-name=librust-prometheus-client-dev: -Depends: dh-cargo (>= 18), librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-pyo3-0.20+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ +Depends: dh-cargo (>= 31), rustc, librust-actix-web-4+default-dev, librust-async-std-1+attributes-dev, librust-async-std-1+default-dev, librust-criterion-0.5+default-dev, librust-http-body-util-0.1+default-dev (>= 0.1.1-~~), librust-http-types-2+default-dev, librust-hyper-1+default-dev (>= 1.3.1-~~), librust-hyper-1+http1-dev (>= 1.3.1-~~), librust-hyper-1+server-dev (>= 1.3.1-~~), librust-hyper-util-0.1+default-dev (>= 0.1.3-~~), librust-hyper-util-0.1+tokio-dev (>= 0.1.3-~~), librust-pyo3-0.22+default-dev, librust-quickcheck-1+default-dev, librust-rand-0.8+default-dev (>= 0.8.4-~~), librust-tokio-1+default-dev, librust-tokio-1+macros-dev, librust-tokio-1+net-dev, librust-tokio-1+rt-multi-thread-dev, librust-tokio-1+signal-dev, @ Restrictions: allow-stderr, skip-not-installable, flaky diff -Nru rust-prometheus-client-0.22.2/debian/watch rust-prometheus-client-0.22.3/debian/watch --- rust-prometheus-client-0.22.2/debian/watch 2024-07-06 23:24:05.000000000 +0000 +++ rust-prometheus-client-0.22.3/debian/watch 2025-04-10 20:27:24.000000000 +0000 @@ -1,4 +1,4 @@ version=4 opts=filenamemangle=s/.*\/(.*)\/download/prometheus-client-$1\.tar\.gz/g,\ -uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\d*)$/$1~$2/ \ +uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\.?\d*)$/$1~$2/ \ https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/prometheus-client .*/crates/prometheus-client/@ANY_VERSION@/download diff -Nru rust-prometheus-client-0.22.2/src/encoding/text.rs rust-prometheus-client-0.22.3/src/encoding/text.rs --- rust-prometheus-client-0.22.2/src/encoding/text.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/encoding/text.rs 2006-07-24 01:21:28.000000000 +0000 @@ -1,7 +1,7 @@ //! Open Metrics text format implementation. //! //! ``` -//! # use prometheus_client::encoding::text::encode; +//! # use prometheus_client::encoding::text::{encode, encode_registry, encode_eof}; //! # use prometheus_client::metrics::counter::Counter; //! # use prometheus_client::registry::Registry; //! # @@ -15,13 +15,26 @@ //! # ); //! # counter.inc(); //! let mut buffer = String::new(); +//! +//! // Encode the complete OpenMetrics exposition into the message buffer //! encode(&mut buffer, ®istry).unwrap(); +//! let expected_msg = "# HELP my_counter This is my counter.\n".to_owned() + +//! "# TYPE my_counter counter\n" + +//! "my_counter_total 1\n" + +//! "# EOF\n"; +//! assert_eq!(expected_msg, buffer); +//! buffer.clear(); +//! +//! // Encode just the registry into the message buffer +//! encode_registry(&mut buffer, ®istry).unwrap(); +//! let expected_reg = "# HELP my_counter This is my counter.\n".to_owned() + +//! "# TYPE my_counter counter\n" + +//! "my_counter_total 1\n"; +//! assert_eq!(expected_reg, buffer); //! -//! let expected = "# HELP my_counter This is my counter.\n".to_owned() + -//! "# TYPE my_counter counter\n" + -//! "my_counter_total 1\n" + -//! "# EOF\n"; -//! assert_eq!(expected, buffer); +//! // Encode EOF marker into message buffer to complete the OpenMetrics exposition +//! encode_eof(&mut buffer).unwrap(); +//! assert_eq!(expected_msg, buffer); //! ``` use crate::encoding::{EncodeExemplarValue, EncodeLabelSet}; @@ -33,15 +46,140 @@ use std::collections::HashMap; use std::fmt::Write; +/// Encode both the metrics registered with the provided [`Registry`] and the +/// EOF marker into the provided [`Write`]r using the OpenMetrics text format. +/// +/// Note: This function encodes the **complete** OpenMetrics exposition. +/// +/// Use [`encode_registry`] or [`encode_eof`] if partial encoding is needed. +/// +/// See [OpenMetrics exposition format](https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#text-format) +/// for additional details. +/// +/// # Examples +/// +/// ```no_run +/// # use prometheus_client::encoding::text::encode; +/// # use prometheus_client::metrics::counter::Counter; +/// # use prometheus_client::metrics::gauge::Gauge; +/// # use prometheus_client::registry::Registry; +/// # +/// // Initialize registry with metric families +/// let mut registry = Registry::default(); +/// let counter: Counter = Counter::default(); +/// registry.register( +/// "my_counter", +/// "This is my counter", +/// counter.clone(), +/// ); +/// let gauge: Gauge = Gauge::default(); +/// registry.register( +/// "my_gauge", +/// "This is my gauge", +/// gauge.clone(), +/// ); +/// +/// // Encode the complete OpenMetrics exposition into the buffer +/// let mut buffer = String::new(); +/// encode(&mut buffer, ®istry)?; +/// # Ok::<(), std::fmt::Error>(()) +/// ``` +pub fn encode(writer: &mut W, registry: &Registry) -> Result<(), std::fmt::Error> +where + W: Write, +{ + encode_registry(writer, registry)?; + encode_eof(writer) +} + /// Encode the metrics registered with the provided [`Registry`] into the /// provided [`Write`]r using the OpenMetrics text format. -pub fn encode(writer: &mut W, registry: &Registry) -> Result<(), std::fmt::Error> +/// +/// Note: The OpenMetrics exposition requires that a complete message must end +/// with an EOF marker. +/// +/// This function may be called repeatedly for the HTTP scrape response until +/// [`encode_eof`] signals the end of the response. +/// +/// This may also be used to compose a partial message with metrics assembled +/// from multiple registries. +/// +/// # Examples +/// +/// ```no_run +/// # use prometheus_client::encoding::text::encode_registry; +/// # use prometheus_client::metrics::counter::Counter; +/// # use prometheus_client::metrics::gauge::Gauge; +/// # use prometheus_client::registry::Registry; +/// # +/// // Initialize registry with a counter +/// let mut reg_counter = Registry::default(); +/// let counter: Counter = Counter::default(); +/// reg_counter.register( +/// "my_counter", +/// "This is my counter", +/// counter.clone(), +/// ); +/// +/// // Encode the counter registry into the buffer +/// let mut buffer = String::new(); +/// encode_registry(&mut buffer, ®_counter)?; +/// +/// // Initialize another registry but with a gauge +/// let mut reg_gauge = Registry::default(); +/// let gauge: Gauge = Gauge::default(); +/// reg_gauge.register( +/// "my_gauge", +/// "This is my gauge", +/// gauge.clone(), +/// ); +/// +/// // Encode the gauge registry into the buffer +/// encode_registry(&mut buffer, ®_gauge)?; +/// # Ok::<(), std::fmt::Error>(()) +/// ``` +pub fn encode_registry(writer: &mut W, registry: &Registry) -> Result<(), std::fmt::Error> +where + W: Write, +{ + registry.encode(&mut DescriptorEncoder::new(writer).into()) +} + +/// Encode the EOF marker into the provided [`Write`]r using the OpenMetrics +/// text format. +/// +/// Note: This function is used to mark/signal the end of the exposition. +/// +/// # Examples +/// +/// ```no_run +/// # use prometheus_client::encoding::text::{encode_registry, encode_eof}; +/// # use prometheus_client::metrics::counter::Counter; +/// # use prometheus_client::metrics::gauge::Gauge; +/// # use prometheus_client::registry::Registry; +/// # +/// // Initialize registry with a counter +/// let mut registry = Registry::default(); +/// let counter: Counter = Counter::default(); +/// registry.register( +/// "my_counter", +/// "This is my counter", +/// counter.clone(), +/// ); +/// +/// // Encode registry into the buffer +/// let mut buffer = String::new(); +/// encode_registry(&mut buffer, ®istry)?; +/// +/// // Encode EOF marker to complete the message +/// encode_eof(&mut buffer)?; +/// # Ok::<(), std::fmt::Error>(()) +/// ``` +pub fn encode_eof(writer: &mut W) -> Result<(), std::fmt::Error> where W: Write, { - registry.encode(&mut DescriptorEncoder::new(writer).into())?; - writer.write_str("# EOF\n")?; - Ok(()) + writer.write_str("# EOF\n") } pub(crate) struct DescriptorEncoder<'a> { @@ -915,6 +1053,52 @@ parse_with_python_client(encoded); } + #[test] + fn encode_registry_eof() { + let mut orders_registry = Registry::default(); + + let total_orders: Counter = Default::default(); + orders_registry.register("orders", "Total orders received", total_orders.clone()); + total_orders.inc(); + + let processing_times = Histogram::new(exponential_buckets(1.0, 2.0, 10)); + orders_registry.register_with_unit( + "processing_times", + "Order times", + Unit::Seconds, + processing_times.clone(), + ); + processing_times.observe(2.4); + + let mut user_auth_registry = Registry::default(); + + let successful_logins: Counter = Default::default(); + user_auth_registry.register( + "successful_logins", + "Total successful logins", + successful_logins.clone(), + ); + successful_logins.inc(); + + let failed_logins: Counter = Default::default(); + user_auth_registry.register( + "failed_logins", + "Total failed logins", + failed_logins.clone(), + ); + + let mut response = String::new(); + + encode_registry(&mut response, &orders_registry).unwrap(); + assert_eq!(&response[response.len() - 20..], "bucket{le=\"+Inf\"} 1\n"); + + encode_registry(&mut response, &user_auth_registry).unwrap(); + assert_eq!(&response[response.len() - 20..], "iled_logins_total 0\n"); + + encode_eof(&mut response).unwrap(); + assert_eq!(&response[response.len() - 20..], "ogins_total 0\n# EOF\n"); + } + fn parse_with_python_client(input: String) { pyo3::prepare_freethreaded_python(); diff -Nru rust-prometheus-client-0.22.2/src/encoding.rs rust-prometheus-client-0.22.3/src/encoding.rs --- rust-prometheus-client-0.22.2/src/encoding.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/encoding.rs 2006-07-24 01:21:28.000000000 +0000 @@ -13,6 +13,7 @@ use std::sync::Arc; #[cfg(feature = "protobuf")] +#[cfg_attr(docsrs, doc(cfg(feature = "protobuf")))] pub mod protobuf; pub mod text; diff -Nru rust-prometheus-client-0.22.2/src/lib.rs rust-prometheus-client-0.22.3/src/lib.rs --- rust-prometheus-client-0.22.2/src/lib.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/lib.rs 2006-07-24 01:21:28.000000000 +0000 @@ -3,6 +3,7 @@ #![deny(unused)] #![forbid(unsafe_code)] #![warn(missing_debug_implementations)] +#![cfg_attr(docsrs, feature(doc_cfg))] //! Client library implementation of the [Open Metrics //! specification](https://github.com/OpenObservability/OpenMetrics). Allows diff -Nru rust-prometheus-client-0.22.2/src/metrics/counter.rs rust-prometheus-client-0.22.3/src/metrics/counter.rs --- rust-prometheus-client-0.22.2/src/metrics/counter.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/metrics/counter.rs 2006-07-24 01:21:28.000000000 +0000 @@ -6,7 +6,7 @@ use super::{MetricType, TypedMetric}; use std::marker::PhantomData; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::Arc; @@ -40,7 +40,7 @@ /// counter.inc(); /// let _value: f64 = counter.get(); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct Counter { value: Arc, @@ -48,7 +48,7 @@ } /// Open Metrics [`Counter`] to measure discrete events. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct Counter { value: Arc, @@ -114,7 +114,7 @@ fn get(&self) -> N; } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> u64 { self.inc_by(1) @@ -143,7 +143,7 @@ } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0) @@ -231,7 +231,7 @@ assert_eq!(1, counter.get()); } - #[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] + #[cfg(target_has_atomic = "64")] #[test] fn f64_stored_in_atomic_u64() { fn prop(fs: Vec) { diff -Nru rust-prometheus-client-0.22.2/src/metrics/exemplar.rs rust-prometheus-client-0.22.3/src/metrics/exemplar.rs --- rust-prometheus-client-0.22.2/src/metrics/exemplar.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/metrics/exemplar.rs 2006-07-24 01:21:28.000000000 +0000 @@ -11,9 +11,9 @@ use super::{MetricType, TypedMetric}; use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard}; use std::collections::HashMap; -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] use std::sync::atomic::AtomicU32; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::AtomicU64; use std::sync::Arc; @@ -65,7 +65,7 @@ /// }), /// ); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct CounterWithExemplar { pub(crate) inner: Arc>>, @@ -77,7 +77,7 @@ /// Open Metrics [`Counter`] with an [`Exemplar`] to both measure discrete /// events and track references to data outside of the metric set. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct CounterWithExemplar { pub(crate) inner: Arc>>, diff -Nru rust-prometheus-client-0.22.2/src/metrics/gauge.rs rust-prometheus-client-0.22.3/src/metrics/gauge.rs --- rust-prometheus-client-0.22.2/src/metrics/gauge.rs 2006-07-24 01:21:28.000000000 +0000 +++ rust-prometheus-client-0.22.3/src/metrics/gauge.rs 2006-07-24 01:21:28.000000000 +0000 @@ -7,7 +7,7 @@ use super::{MetricType, TypedMetric}; use std::marker::PhantomData; use std::sync::atomic::{AtomicI32, AtomicU32, Ordering}; -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] use std::sync::atomic::{AtomicI64, AtomicU64}; use std::sync::Arc; @@ -40,7 +40,7 @@ /// gauge.set(42.0); /// let _value: f64 = gauge.get(); /// ``` -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] #[derive(Debug)] pub struct Gauge { value: Arc, @@ -48,7 +48,7 @@ } /// Open Metrics [`Gauge`] to record current measurements. -#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] +#[cfg(not(target_has_atomic = "64"))] #[derive(Debug)] pub struct Gauge { value: Arc, @@ -186,7 +186,7 @@ } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicI64 { fn inc(&self) -> i64 { self.inc_by(1) @@ -213,7 +213,7 @@ } } -#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +#[cfg(target_has_atomic = "64")] impl Atomic for AtomicU64 { fn inc(&self) -> f64 { self.inc_by(1.0)