diff --git a/Cargo.toml b/Cargo.toml index 33727266..b95f823c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ push = ["reqwest", "libc", "protobuf"] [dependencies] cfg-if = "^1.0" fnv = "^1.0" -lazy_static = "^1.4" +once_cell = "^1.0" libc = { version = "^0.2", optional = true } parking_lot = "^0.12" protobuf = { version = "^2.0", optional = true } diff --git a/examples/example_custom_registry.rs b/examples/example_custom_registry.rs index 0c99cb31..5a7c2b4c 100644 --- a/examples/example_custom_registry.rs +++ b/examples/example_custom_registry.rs @@ -7,12 +7,12 @@ use std::collections::HashMap; use prometheus::{Encoder, IntCounter, Registry}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; -lazy_static! { - static ref DEFAULT_COUNTER: IntCounter = IntCounter::new("default", "generic counter").unwrap(); - static ref CUSTOM_COUNTER: IntCounter = IntCounter::new("custom", "dedicated counter").unwrap(); -} +static DEFAULT_COUNTER: Lazy = + Lazy::new(|| IntCounter::new("default", "generic counter").unwrap()); +static CUSTOM_COUNTER: Lazy = + Lazy::new(|| IntCounter::new("custom", "dedicated counter").unwrap()); fn main() { // Register default metrics. diff --git a/examples/example_hyper.rs b/examples/example_hyper.rs index 1a3cea28..539dffa8 100644 --- a/examples/example_hyper.rs +++ b/examples/example_hyper.rs @@ -7,29 +7,33 @@ use hyper::{ }; use prometheus::{Counter, Encoder, Gauge, HistogramVec, TextEncoder}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::{labels, opts, register_counter, register_gauge, register_histogram_vec}; -lazy_static! { - static ref HTTP_COUNTER: Counter = register_counter!(opts!( +static HTTP_COUNTER: Lazy = Lazy::new(|| { + register_counter!(opts!( "example_http_requests_total", "Number of HTTP requests made.", labels! {"handler" => "all",} )) - .unwrap(); - static ref HTTP_BODY_GAUGE: Gauge = register_gauge!(opts!( + .unwrap() +}); +static HTTP_BODY_GAUGE: Lazy = Lazy::new(|| { + register_gauge!(opts!( "example_http_response_size_bytes", "The HTTP response sizes in bytes.", labels! {"handler" => "all",} )) - .unwrap(); - static ref HTTP_REQ_HISTOGRAM: HistogramVec = register_histogram_vec!( + .unwrap() +}); +static HTTP_REQ_HISTOGRAM: Lazy = Lazy::new(|| { + register_histogram_vec!( "example_http_request_duration_seconds", "The HTTP request latencies in seconds.", &["handler"] ) - .unwrap(); -} + .unwrap() +}); async fn serve_req(_req: Request) -> Result, hyper::Error> { let encoder = TextEncoder::new(); diff --git a/examples/example_int_metrics.rs b/examples/example_int_metrics.rs index 05e57e81..0b5ea1f4 100644 --- a/examples/example_int_metrics.rs +++ b/examples/example_int_metrics.rs @@ -2,20 +2,19 @@ use prometheus::{IntCounter, IntCounterVec, IntGauge, IntGaugeVec}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::{ register_int_counter, register_int_counter_vec, register_int_gauge, register_int_gauge_vec, }; -lazy_static! { - static ref A_INT_COUNTER: IntCounter = - register_int_counter!("A_int_counter", "foobar").unwrap(); - static ref A_INT_COUNTER_VEC: IntCounterVec = - register_int_counter_vec!("A_int_counter_vec", "foobar", &["a", "b"]).unwrap(); - static ref A_INT_GAUGE: IntGauge = register_int_gauge!("A_int_gauge", "foobar").unwrap(); - static ref A_INT_GAUGE_VEC: IntGaugeVec = - register_int_gauge_vec!("A_int_gauge_vec", "foobar", &["a", "b"]).unwrap(); -} +static A_INT_COUNTER: Lazy = + Lazy::new(|| register_int_counter!("A_int_counter", "foobar").unwrap()); +static A_INT_COUNTER_VEC: Lazy = + Lazy::new(|| register_int_counter_vec!("A_int_counter_vec", "foobar", &["a", "b"]).unwrap()); +static A_INT_GAUGE: Lazy = + Lazy::new(|| register_int_gauge!("A_int_gauge", "foobar").unwrap()); +static A_INT_GAUGE_VEC: Lazy = + Lazy::new(|| register_int_gauge_vec!("A_int_gauge_vec", "foobar", &["a", "b"]).unwrap()); fn main() { A_INT_COUNTER.inc(); diff --git a/examples/example_push.rs b/examples/example_push.rs index 22d01953..c8f1e366 100644 --- a/examples/example_push.rs +++ b/examples/example_push.rs @@ -9,21 +9,23 @@ use std::time; use getopts::Options; use prometheus::{Counter, Histogram}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::{labels, register_counter, register_histogram}; -lazy_static! { - static ref PUSH_COUNTER: Counter = register_counter!( +static PUSH_COUNTER: Lazy = Lazy::new(|| { + register_counter!( "example_push_total", "Total number of prometheus client pushed." ) - .unwrap(); - static ref PUSH_REQ_HISTOGRAM: Histogram = register_histogram!( + .unwrap() +}); +static PUSH_REQ_HISTOGRAM: Lazy = Lazy::new(|| { + register_histogram!( "example_push_request_duration_seconds", "The push request latencies in seconds." ) - .unwrap(); -} + .unwrap() +}); #[cfg(feature = "push")] fn main() { @@ -47,7 +49,9 @@ fn main() { } println!("Pushing, please start Pushgateway first."); - let address = matches.opt_str("A").unwrap_or("127.0.0.1:9091".to_owned()); + let address = matches + .opt_str("A") + .unwrap_or_else(|| "127.0.0.1:9091".to_owned()); for _ in 0..5 { thread::sleep(time::Duration::from_secs(2)); PUSH_COUNTER.inc(); diff --git a/proto/proto_model.rs b/proto/proto_model.rs index c67aa4af..88b65c7b 100644 --- a/proto/proto_model.rs +++ b/proto/proto_model.rs @@ -1,11 +1,12 @@ -// This file is generated by rust-protobuf 2.2.5. Do not edit +// This file is generated by rust-protobuf 2.27.1. Do not edit // @generated -// https://github.com/Manishearth/rust-clippy/issues/702 +// https://github.com/rust-lang/rust-clippy/issues/702 #![allow(unknown_lints)] -#![allow(clippy)] +#![allow(clippy::all)] -#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] #![allow(box_pointers)] #![allow(dead_code)] @@ -14,12 +15,13 @@ #![allow(non_snake_case)] #![allow(non_upper_case_globals)] #![allow(trivial_casts)] -#![allow(unsafe_code)] #![allow(unused_imports)] #![allow(unused_results)] +//! Generated file from `proto_model.proto` -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_27_1; #[derive(PartialEq,Clone,Default)] pub struct LabelPair { @@ -31,6 +33,12 @@ pub struct LabelPair { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a LabelPair { + fn default() -> &'a LabelPair { + ::default_instance() + } +} + impl LabelPair { pub fn new() -> LabelPair { ::std::default::Default::default() @@ -38,6 +46,13 @@ impl LabelPair { // optional string name = 1; + + pub fn get_name(&self) -> &str { + match self.name.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_name(&mut self) { self.name.clear(); } @@ -65,15 +80,15 @@ impl LabelPair { self.name.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_name(&self) -> &str { - match self.name.as_ref() { + // optional string value = 2; + + + pub fn get_value(&self) -> &str { + match self.value.as_ref() { Some(v) => &v, None => "", } } - - // optional string value = 2; - pub fn clear_value(&mut self) { self.value.clear(); } @@ -100,13 +115,6 @@ impl LabelPair { pub fn take_value(&mut self) -> ::std::string::String { self.value.take().unwrap_or_else(|| ::std::string::String::new()) } - - pub fn get_value(&self) -> &str { - match self.value.as_ref() { - Some(v) => &v, - None => "", - } - } } impl ::protobuf::Message for LabelPair { @@ -170,13 +178,13 @@ impl ::protobuf::Message for LabelPair { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -189,47 +197,37 @@ impl ::protobuf::Message for LabelPair { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "name", - |m: &LabelPair| { &m.name }, - |m: &mut LabelPair| { &mut m.name }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "value", - |m: &LabelPair| { &m.value }, - |m: &mut LabelPair| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "LabelPair", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &LabelPair| { &m.name }, + |m: &mut LabelPair| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "value", + |m: &LabelPair| { &m.value }, + |m: &mut LabelPair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "LabelPair", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static LabelPair { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const LabelPair, - }; - unsafe { - instance.get(LabelPair::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(LabelPair::new) } } impl ::protobuf::Clear for LabelPair { fn clear(&mut self) { - self.clear_name(); - self.clear_value(); + self.name.clear(); + self.value.clear(); self.unknown_fields.clear(); } } @@ -241,8 +239,8 @@ impl ::std::fmt::Debug for LabelPair { } impl ::protobuf::reflect::ProtobufValue for LabelPair { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -255,6 +253,12 @@ pub struct Gauge { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Gauge { + fn default() -> &'a Gauge { + ::default_instance() + } +} + impl Gauge { pub fn new() -> Gauge { ::std::default::Default::default() @@ -262,6 +266,10 @@ impl Gauge { // optional double value = 1; + + pub fn get_value(&self) -> f64 { + self.value.unwrap_or(0.) + } pub fn clear_value(&mut self) { self.value = ::std::option::Option::None; } @@ -274,10 +282,6 @@ impl Gauge { pub fn set_value(&mut self, v: f64) { self.value = ::std::option::Option::Some(v); } - - pub fn get_value(&self) -> f64 { - self.value.unwrap_or(0.) - } } impl ::protobuf::Message for Gauge { @@ -336,13 +340,13 @@ impl ::protobuf::Message for Gauge { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -355,41 +359,31 @@ impl ::protobuf::Message for Gauge { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "value", - |m: &Gauge| { &m.value }, - |m: &mut Gauge| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Gauge", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "value", + |m: &Gauge| { &m.value }, + |m: &mut Gauge| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Gauge", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Gauge { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Gauge, - }; - unsafe { - instance.get(Gauge::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Gauge::new) } } impl ::protobuf::Clear for Gauge { fn clear(&mut self) { - self.clear_value(); + self.value = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -401,8 +395,8 @@ impl ::std::fmt::Debug for Gauge { } impl ::protobuf::reflect::ProtobufValue for Gauge { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -415,6 +409,12 @@ pub struct Counter { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Counter { + fn default() -> &'a Counter { + ::default_instance() + } +} + impl Counter { pub fn new() -> Counter { ::std::default::Default::default() @@ -422,6 +422,10 @@ impl Counter { // optional double value = 1; + + pub fn get_value(&self) -> f64 { + self.value.unwrap_or(0.) + } pub fn clear_value(&mut self) { self.value = ::std::option::Option::None; } @@ -434,10 +438,6 @@ impl Counter { pub fn set_value(&mut self, v: f64) { self.value = ::std::option::Option::Some(v); } - - pub fn get_value(&self) -> f64 { - self.value.unwrap_or(0.) - } } impl ::protobuf::Message for Counter { @@ -496,13 +496,13 @@ impl ::protobuf::Message for Counter { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -515,41 +515,31 @@ impl ::protobuf::Message for Counter { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "value", - |m: &Counter| { &m.value }, - |m: &mut Counter| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Counter", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "value", + |m: &Counter| { &m.value }, + |m: &mut Counter| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Counter", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Counter { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Counter, - }; - unsafe { - instance.get(Counter::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Counter::new) } } impl ::protobuf::Clear for Counter { fn clear(&mut self) { - self.clear_value(); + self.value = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -561,8 +551,8 @@ impl ::std::fmt::Debug for Counter { } impl ::protobuf::reflect::ProtobufValue for Counter { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -576,6 +566,12 @@ pub struct Quantile { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Quantile { + fn default() -> &'a Quantile { + ::default_instance() + } +} + impl Quantile { pub fn new() -> Quantile { ::std::default::Default::default() @@ -583,6 +579,10 @@ impl Quantile { // optional double quantile = 1; + + pub fn get_quantile(&self) -> f64 { + self.quantile.unwrap_or(0.) + } pub fn clear_quantile(&mut self) { self.quantile = ::std::option::Option::None; } @@ -596,12 +596,12 @@ impl Quantile { self.quantile = ::std::option::Option::Some(v); } - pub fn get_quantile(&self) -> f64 { - self.quantile.unwrap_or(0.) - } - // optional double value = 2; + + pub fn get_value(&self) -> f64 { + self.value.unwrap_or(0.) + } pub fn clear_value(&mut self) { self.value = ::std::option::Option::None; } @@ -614,10 +614,6 @@ impl Quantile { pub fn set_value(&mut self, v: f64) { self.value = ::std::option::Option::Some(v); } - - pub fn get_value(&self) -> f64 { - self.value.unwrap_or(0.) - } } impl ::protobuf::Message for Quantile { @@ -689,13 +685,13 @@ impl ::protobuf::Message for Quantile { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -708,47 +704,37 @@ impl ::protobuf::Message for Quantile { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "quantile", - |m: &Quantile| { &m.quantile }, - |m: &mut Quantile| { &mut m.quantile }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "value", - |m: &Quantile| { &m.value }, - |m: &mut Quantile| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Quantile", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "quantile", + |m: &Quantile| { &m.quantile }, + |m: &mut Quantile| { &mut m.quantile }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "value", + |m: &Quantile| { &m.value }, + |m: &mut Quantile| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Quantile", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Quantile { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Quantile, - }; - unsafe { - instance.get(Quantile::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Quantile::new) } } impl ::protobuf::Clear for Quantile { fn clear(&mut self) { - self.clear_quantile(); - self.clear_value(); + self.quantile = ::std::option::Option::None; + self.value = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -760,8 +746,8 @@ impl ::std::fmt::Debug for Quantile { } impl ::protobuf::reflect::ProtobufValue for Quantile { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -770,12 +756,18 @@ pub struct Summary { // message fields sample_count: ::std::option::Option, sample_sum: ::std::option::Option, - quantile: ::protobuf::RepeatedField, + pub quantile: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Summary { + fn default() -> &'a Summary { + ::default_instance() + } +} + impl Summary { pub fn new() -> Summary { ::std::default::Default::default() @@ -783,6 +775,10 @@ impl Summary { // optional uint64 sample_count = 1; + + pub fn get_sample_count(&self) -> u64 { + self.sample_count.unwrap_or(0) + } pub fn clear_sample_count(&mut self) { self.sample_count = ::std::option::Option::None; } @@ -796,12 +792,12 @@ impl Summary { self.sample_count = ::std::option::Option::Some(v); } - pub fn get_sample_count(&self) -> u64 { - self.sample_count.unwrap_or(0) - } - // optional double sample_sum = 2; + + pub fn get_sample_sum(&self) -> f64 { + self.sample_sum.unwrap_or(0.) + } pub fn clear_sample_sum(&mut self) { self.sample_sum = ::std::option::Option::None; } @@ -815,12 +811,12 @@ impl Summary { self.sample_sum = ::std::option::Option::Some(v); } - pub fn get_sample_sum(&self) -> f64 { - self.sample_sum.unwrap_or(0.) - } - // repeated .io.prometheus.client.Quantile quantile = 3; + + pub fn get_quantile(&self) -> &[Quantile] { + &self.quantile + } pub fn clear_quantile(&mut self) { self.quantile.clear(); } @@ -839,10 +835,6 @@ impl Summary { pub fn take_quantile(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.quantile, ::protobuf::RepeatedField::new()) } - - pub fn get_quantile(&self) -> &[Quantile] { - &self.quantile - } } impl ::protobuf::Message for Summary { @@ -931,13 +923,13 @@ impl ::protobuf::Message for Summary { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -950,53 +942,43 @@ impl ::protobuf::Message for Summary { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "sample_count", - |m: &Summary| { &m.sample_count }, - |m: &mut Summary| { &mut m.sample_count }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "sample_sum", - |m: &Summary| { &m.sample_sum }, - |m: &mut Summary| { &mut m.sample_sum }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "quantile", - |m: &Summary| { &m.quantile }, - |m: &mut Summary| { &mut m.quantile }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Summary", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "sample_count", + |m: &Summary| { &m.sample_count }, + |m: &mut Summary| { &mut m.sample_count }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "sample_sum", + |m: &Summary| { &m.sample_sum }, + |m: &mut Summary| { &mut m.sample_sum }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "quantile", + |m: &Summary| { &m.quantile }, + |m: &mut Summary| { &mut m.quantile }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Summary", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Summary { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Summary, - }; - unsafe { - instance.get(Summary::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Summary::new) } } impl ::protobuf::Clear for Summary { fn clear(&mut self) { - self.clear_sample_count(); - self.clear_sample_sum(); - self.clear_quantile(); + self.sample_count = ::std::option::Option::None; + self.sample_sum = ::std::option::Option::None; + self.quantile.clear(); self.unknown_fields.clear(); } } @@ -1008,8 +990,8 @@ impl ::std::fmt::Debug for Summary { } impl ::protobuf::reflect::ProtobufValue for Summary { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -1022,6 +1004,12 @@ pub struct Untyped { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Untyped { + fn default() -> &'a Untyped { + ::default_instance() + } +} + impl Untyped { pub fn new() -> Untyped { ::std::default::Default::default() @@ -1029,6 +1017,10 @@ impl Untyped { // optional double value = 1; + + pub fn get_value(&self) -> f64 { + self.value.unwrap_or(0.) + } pub fn clear_value(&mut self) { self.value = ::std::option::Option::None; } @@ -1041,10 +1033,6 @@ impl Untyped { pub fn set_value(&mut self, v: f64) { self.value = ::std::option::Option::Some(v); } - - pub fn get_value(&self) -> f64 { - self.value.unwrap_or(0.) - } } impl ::protobuf::Message for Untyped { @@ -1103,13 +1091,13 @@ impl ::protobuf::Message for Untyped { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1122,41 +1110,31 @@ impl ::protobuf::Message for Untyped { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "value", - |m: &Untyped| { &m.value }, - |m: &mut Untyped| { &mut m.value }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Untyped", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "value", + |m: &Untyped| { &m.value }, + |m: &mut Untyped| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Untyped", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Untyped { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Untyped, - }; - unsafe { - instance.get(Untyped::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Untyped::new) } } impl ::protobuf::Clear for Untyped { fn clear(&mut self) { - self.clear_value(); + self.value = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -1168,8 +1146,8 @@ impl ::std::fmt::Debug for Untyped { } impl ::protobuf::reflect::ProtobufValue for Untyped { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -1178,12 +1156,18 @@ pub struct Histogram { // message fields sample_count: ::std::option::Option, sample_sum: ::std::option::Option, - bucket: ::protobuf::RepeatedField, + pub bucket: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Histogram { + fn default() -> &'a Histogram { + ::default_instance() + } +} + impl Histogram { pub fn new() -> Histogram { ::std::default::Default::default() @@ -1191,6 +1175,10 @@ impl Histogram { // optional uint64 sample_count = 1; + + pub fn get_sample_count(&self) -> u64 { + self.sample_count.unwrap_or(0) + } pub fn clear_sample_count(&mut self) { self.sample_count = ::std::option::Option::None; } @@ -1204,12 +1192,12 @@ impl Histogram { self.sample_count = ::std::option::Option::Some(v); } - pub fn get_sample_count(&self) -> u64 { - self.sample_count.unwrap_or(0) - } - // optional double sample_sum = 2; + + pub fn get_sample_sum(&self) -> f64 { + self.sample_sum.unwrap_or(0.) + } pub fn clear_sample_sum(&mut self) { self.sample_sum = ::std::option::Option::None; } @@ -1223,12 +1211,12 @@ impl Histogram { self.sample_sum = ::std::option::Option::Some(v); } - pub fn get_sample_sum(&self) -> f64 { - self.sample_sum.unwrap_or(0.) - } - // repeated .io.prometheus.client.Bucket bucket = 3; + + pub fn get_bucket(&self) -> &[Bucket] { + &self.bucket + } pub fn clear_bucket(&mut self) { self.bucket.clear(); } @@ -1247,10 +1235,6 @@ impl Histogram { pub fn take_bucket(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.bucket, ::protobuf::RepeatedField::new()) } - - pub fn get_bucket(&self) -> &[Bucket] { - &self.bucket - } } impl ::protobuf::Message for Histogram { @@ -1339,13 +1323,13 @@ impl ::protobuf::Message for Histogram { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1358,53 +1342,43 @@ impl ::protobuf::Message for Histogram { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "sample_count", - |m: &Histogram| { &m.sample_count }, - |m: &mut Histogram| { &mut m.sample_count }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "sample_sum", - |m: &Histogram| { &m.sample_sum }, - |m: &mut Histogram| { &mut m.sample_sum }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "bucket", - |m: &Histogram| { &m.bucket }, - |m: &mut Histogram| { &mut m.bucket }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Histogram", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "sample_count", + |m: &Histogram| { &m.sample_count }, + |m: &mut Histogram| { &mut m.sample_count }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "sample_sum", + |m: &Histogram| { &m.sample_sum }, + |m: &mut Histogram| { &mut m.sample_sum }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "bucket", + |m: &Histogram| { &m.bucket }, + |m: &mut Histogram| { &mut m.bucket }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Histogram", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Histogram { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Histogram, - }; - unsafe { - instance.get(Histogram::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Histogram::new) } } impl ::protobuf::Clear for Histogram { fn clear(&mut self) { - self.clear_sample_count(); - self.clear_sample_sum(); - self.clear_bucket(); + self.sample_count = ::std::option::Option::None; + self.sample_sum = ::std::option::Option::None; + self.bucket.clear(); self.unknown_fields.clear(); } } @@ -1416,8 +1390,8 @@ impl ::std::fmt::Debug for Histogram { } impl ::protobuf::reflect::ProtobufValue for Histogram { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -1431,6 +1405,12 @@ pub struct Bucket { pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Bucket { + fn default() -> &'a Bucket { + ::default_instance() + } +} + impl Bucket { pub fn new() -> Bucket { ::std::default::Default::default() @@ -1438,6 +1418,10 @@ impl Bucket { // optional uint64 cumulative_count = 1; + + pub fn get_cumulative_count(&self) -> u64 { + self.cumulative_count.unwrap_or(0) + } pub fn clear_cumulative_count(&mut self) { self.cumulative_count = ::std::option::Option::None; } @@ -1451,12 +1435,12 @@ impl Bucket { self.cumulative_count = ::std::option::Option::Some(v); } - pub fn get_cumulative_count(&self) -> u64 { - self.cumulative_count.unwrap_or(0) - } - // optional double upper_bound = 2; + + pub fn get_upper_bound(&self) -> f64 { + self.upper_bound.unwrap_or(0.) + } pub fn clear_upper_bound(&mut self) { self.upper_bound = ::std::option::Option::None; } @@ -1469,10 +1453,6 @@ impl Bucket { pub fn set_upper_bound(&mut self, v: f64) { self.upper_bound = ::std::option::Option::Some(v); } - - pub fn get_upper_bound(&self) -> f64 { - self.upper_bound.unwrap_or(0.) - } } impl ::protobuf::Message for Bucket { @@ -1544,13 +1524,13 @@ impl ::protobuf::Message for Bucket { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -1563,47 +1543,37 @@ impl ::protobuf::Message for Bucket { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "cumulative_count", - |m: &Bucket| { &m.cumulative_count }, - |m: &mut Bucket| { &mut m.cumulative_count }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( - "upper_bound", - |m: &Bucket| { &m.upper_bound }, - |m: &mut Bucket| { &mut m.upper_bound }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Bucket", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "cumulative_count", + |m: &Bucket| { &m.cumulative_count }, + |m: &mut Bucket| { &mut m.cumulative_count }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeDouble>( + "upper_bound", + |m: &Bucket| { &m.upper_bound }, + |m: &mut Bucket| { &mut m.upper_bound }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Bucket", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Bucket { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Bucket, - }; - unsafe { - instance.get(Bucket::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Bucket::new) } } impl ::protobuf::Clear for Bucket { fn clear(&mut self) { - self.clear_cumulative_count(); - self.clear_upper_bound(); + self.cumulative_count = ::std::option::Option::None; + self.upper_bound = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -1615,26 +1585,32 @@ impl ::std::fmt::Debug for Bucket { } impl ::protobuf::reflect::ProtobufValue for Bucket { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] pub struct Metric { // message fields - label: ::protobuf::RepeatedField, - gauge: ::protobuf::SingularPtrField, - counter: ::protobuf::SingularPtrField, - summary: ::protobuf::SingularPtrField, - untyped: ::protobuf::SingularPtrField, - histogram: ::protobuf::SingularPtrField, + pub label: ::protobuf::RepeatedField, + pub gauge: ::protobuf::SingularPtrField, + pub counter: ::protobuf::SingularPtrField, + pub summary: ::protobuf::SingularPtrField, + pub untyped: ::protobuf::SingularPtrField, + pub histogram: ::protobuf::SingularPtrField, timestamp_ms: ::std::option::Option, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a Metric { + fn default() -> &'a Metric { + ::default_instance() + } +} + impl Metric { pub fn new() -> Metric { ::std::default::Default::default() @@ -1642,6 +1618,10 @@ impl Metric { // repeated .io.prometheus.client.LabelPair label = 1; + + pub fn get_label(&self) -> &[LabelPair] { + &self.label + } pub fn clear_label(&mut self) { self.label.clear(); } @@ -1661,12 +1641,12 @@ impl Metric { ::std::mem::replace(&mut self.label, ::protobuf::RepeatedField::new()) } - pub fn get_label(&self) -> &[LabelPair] { - &self.label - } - // optional .io.prometheus.client.Gauge gauge = 2; + + pub fn get_gauge(&self) -> &Gauge { + self.gauge.as_ref().unwrap_or_else(|| ::default_instance()) + } pub fn clear_gauge(&mut self) { self.gauge.clear(); } @@ -1694,12 +1674,12 @@ impl Metric { self.gauge.take().unwrap_or_else(|| Gauge::new()) } - pub fn get_gauge(&self) -> &Gauge { - self.gauge.as_ref().unwrap_or_else(|| Gauge::default_instance()) - } - // optional .io.prometheus.client.Counter counter = 3; + + pub fn get_counter(&self) -> &Counter { + self.counter.as_ref().unwrap_or_else(|| ::default_instance()) + } pub fn clear_counter(&mut self) { self.counter.clear(); } @@ -1727,12 +1707,12 @@ impl Metric { self.counter.take().unwrap_or_else(|| Counter::new()) } - pub fn get_counter(&self) -> &Counter { - self.counter.as_ref().unwrap_or_else(|| Counter::default_instance()) - } - // optional .io.prometheus.client.Summary summary = 4; + + pub fn get_summary(&self) -> &Summary { + self.summary.as_ref().unwrap_or_else(|| ::default_instance()) + } pub fn clear_summary(&mut self) { self.summary.clear(); } @@ -1760,12 +1740,12 @@ impl Metric { self.summary.take().unwrap_or_else(|| Summary::new()) } - pub fn get_summary(&self) -> &Summary { - self.summary.as_ref().unwrap_or_else(|| Summary::default_instance()) - } - // optional .io.prometheus.client.Untyped untyped = 5; + + pub fn get_untyped(&self) -> &Untyped { + self.untyped.as_ref().unwrap_or_else(|| ::default_instance()) + } pub fn clear_untyped(&mut self) { self.untyped.clear(); } @@ -1793,12 +1773,12 @@ impl Metric { self.untyped.take().unwrap_or_else(|| Untyped::new()) } - pub fn get_untyped(&self) -> &Untyped { - self.untyped.as_ref().unwrap_or_else(|| Untyped::default_instance()) - } - // optional .io.prometheus.client.Histogram histogram = 7; + + pub fn get_histogram(&self) -> &Histogram { + self.histogram.as_ref().unwrap_or_else(|| ::default_instance()) + } pub fn clear_histogram(&mut self) { self.histogram.clear(); } @@ -1826,12 +1806,12 @@ impl Metric { self.histogram.take().unwrap_or_else(|| Histogram::new()) } - pub fn get_histogram(&self) -> &Histogram { - self.histogram.as_ref().unwrap_or_else(|| Histogram::default_instance()) - } - // optional int64 timestamp_ms = 6; + + pub fn get_timestamp_ms(&self) -> i64 { + self.timestamp_ms.unwrap_or(0) + } pub fn clear_timestamp_ms(&mut self) { self.timestamp_ms = ::std::option::Option::None; } @@ -1844,10 +1824,6 @@ impl Metric { pub fn set_timestamp_ms(&mut self, v: i64) { self.timestamp_ms = ::std::option::Option::Some(v); } - - pub fn get_timestamp_ms(&self) -> i64 { - self.timestamp_ms.unwrap_or(0) - } } impl ::protobuf::Message for Metric { @@ -2008,13 +1984,13 @@ impl ::protobuf::Message for Metric { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -2027,77 +2003,67 @@ impl ::protobuf::Message for Metric { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "label", - |m: &Metric| { &m.label }, - |m: &mut Metric| { &mut m.label }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "gauge", - |m: &Metric| { &m.gauge }, - |m: &mut Metric| { &mut m.gauge }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "counter", - |m: &Metric| { &m.counter }, - |m: &mut Metric| { &mut m.counter }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "summary", - |m: &Metric| { &m.summary }, - |m: &mut Metric| { &mut m.summary }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "untyped", - |m: &Metric| { &m.untyped }, - |m: &mut Metric| { &mut m.untyped }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "histogram", - |m: &Metric| { &m.histogram }, - |m: &mut Metric| { &mut m.histogram }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeInt64>( - "timestamp_ms", - |m: &Metric| { &m.timestamp_ms }, - |m: &mut Metric| { &mut m.timestamp_ms }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Metric", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "label", + |m: &Metric| { &m.label }, + |m: &mut Metric| { &mut m.label }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "gauge", + |m: &Metric| { &m.gauge }, + |m: &mut Metric| { &mut m.gauge }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "counter", + |m: &Metric| { &m.counter }, + |m: &mut Metric| { &mut m.counter }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "summary", + |m: &Metric| { &m.summary }, + |m: &mut Metric| { &mut m.summary }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "untyped", + |m: &Metric| { &m.untyped }, + |m: &mut Metric| { &mut m.untyped }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "histogram", + |m: &Metric| { &m.histogram }, + |m: &mut Metric| { &mut m.histogram }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeInt64>( + "timestamp_ms", + |m: &Metric| { &m.timestamp_ms }, + |m: &mut Metric| { &mut m.timestamp_ms }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Metric", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static Metric { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Metric, - }; - unsafe { - instance.get(Metric::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Metric::new) } } impl ::protobuf::Clear for Metric { fn clear(&mut self) { - self.clear_label(); - self.clear_gauge(); - self.clear_counter(); - self.clear_summary(); - self.clear_untyped(); - self.clear_histogram(); - self.clear_timestamp_ms(); + self.label.clear(); + self.gauge.clear(); + self.counter.clear(); + self.summary.clear(); + self.untyped.clear(); + self.histogram.clear(); + self.timestamp_ms = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -2109,8 +2075,8 @@ impl ::std::fmt::Debug for Metric { } impl ::protobuf::reflect::ProtobufValue for Metric { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -2120,12 +2086,18 @@ pub struct MetricFamily { name: ::protobuf::SingularField<::std::string::String>, help: ::protobuf::SingularField<::std::string::String>, field_type: ::std::option::Option, - metric: ::protobuf::RepeatedField, + pub metric: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } +impl<'a> ::std::default::Default for &'a MetricFamily { + fn default() -> &'a MetricFamily { + ::default_instance() + } +} + impl MetricFamily { pub fn new() -> MetricFamily { ::std::default::Default::default() @@ -2133,6 +2105,13 @@ impl MetricFamily { // optional string name = 1; + + pub fn get_name(&self) -> &str { + match self.name.as_ref() { + Some(v) => &v, + None => "", + } + } pub fn clear_name(&mut self) { self.name.clear(); } @@ -2160,15 +2139,15 @@ impl MetricFamily { self.name.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_name(&self) -> &str { - match self.name.as_ref() { + // optional string help = 2; + + + pub fn get_help(&self) -> &str { + match self.help.as_ref() { Some(v) => &v, None => "", } } - - // optional string help = 2; - pub fn clear_help(&mut self) { self.help.clear(); } @@ -2196,15 +2175,12 @@ impl MetricFamily { self.help.take().unwrap_or_else(|| ::std::string::String::new()) } - pub fn get_help(&self) -> &str { - match self.help.as_ref() { - Some(v) => &v, - None => "", - } - } - // optional .io.prometheus.client.MetricType type = 3; + + pub fn get_field_type(&self) -> MetricType { + self.field_type.unwrap_or(MetricType::COUNTER) + } pub fn clear_field_type(&mut self) { self.field_type = ::std::option::Option::None; } @@ -2218,12 +2194,12 @@ impl MetricFamily { self.field_type = ::std::option::Option::Some(v); } - pub fn get_field_type(&self) -> MetricType { - self.field_type.unwrap_or(MetricType::COUNTER) - } - // repeated .io.prometheus.client.Metric metric = 4; + + pub fn get_metric(&self) -> &[Metric] { + &self.metric + } pub fn clear_metric(&mut self) { self.metric.clear(); } @@ -2242,10 +2218,6 @@ impl MetricFamily { pub fn take_metric(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.metric, ::protobuf::RepeatedField::new()) } - - pub fn get_metric(&self) -> &[Metric] { - &self.metric - } } impl ::protobuf::Message for MetricFamily { @@ -2312,7 +2284,7 @@ impl ::protobuf::Message for MetricFamily { os.write_string(2, &v)?; } if let Some(v) = self.field_type { - os.write_enum(3, v.value())?; + os.write_enum(3, ::protobuf::ProtobufEnum::value(&v))?; } for v in &self.metric { os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; @@ -2335,13 +2307,13 @@ impl ::protobuf::Message for MetricFamily { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { self } @@ -2354,59 +2326,49 @@ impl ::protobuf::Message for MetricFamily { } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, - }; - unsafe { - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "name", - |m: &MetricFamily| { &m.name }, - |m: &mut MetricFamily| { &mut m.name }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "help", - |m: &MetricFamily| { &m.help }, - |m: &mut MetricFamily| { &mut m.help }, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( - "type", - |m: &MetricFamily| { &m.field_type }, - |m: &mut MetricFamily| { &mut m.field_type }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "metric", - |m: &MetricFamily| { &m.metric }, - |m: &mut MetricFamily| { &mut m.metric }, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "MetricFamily", - fields, - file_descriptor_proto() - ) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &MetricFamily| { &m.name }, + |m: &mut MetricFamily| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "help", + |m: &MetricFamily| { &m.help }, + |m: &mut MetricFamily| { &mut m.help }, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeEnum>( + "type", + |m: &MetricFamily| { &m.field_type }, + |m: &mut MetricFamily| { &mut m.field_type }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "metric", + |m: &MetricFamily| { &m.metric }, + |m: &mut MetricFamily| { &mut m.metric }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "MetricFamily", + fields, + file_descriptor_proto() + ) + }) } fn default_instance() -> &'static MetricFamily { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const MetricFamily, - }; - unsafe { - instance.get(MetricFamily::new) - } + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(MetricFamily::new) } } impl ::protobuf::Clear for MetricFamily { fn clear(&mut self) { - self.clear_name(); - self.clear_help(); - self.clear_field_type(); - self.clear_metric(); + self.name.clear(); + self.help.clear(); + self.field_type = ::std::option::Option::None; + self.metric.clear(); self.unknown_fields.clear(); } } @@ -2418,8 +2380,8 @@ impl ::std::fmt::Debug for MetricFamily { } impl ::protobuf::reflect::ProtobufValue for MetricFamily { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) } } @@ -2460,73 +2422,71 @@ impl ::protobuf::ProtobufEnum for MetricType { } fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::EnumDescriptor> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::reflect::EnumDescriptor, - }; - unsafe { - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new("MetricType", file_descriptor_proto()) - }) - } + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + ::protobuf::reflect::EnumDescriptor::new_pb_name::("MetricType", file_descriptor_proto()) + }) } } impl ::std::marker::Copy for MetricType { } +impl ::std::default::Default for MetricType { + fn default() -> Self { + MetricType::COUNTER + } +} + impl ::protobuf::reflect::ProtobufValue for MetricType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) } } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x11proto_model.proto\x12\x14io.prometheus.client\"0\n\tLabelPair\x12\ - \x10\n\x04name\x18\x01\x20\x01(\tB\x02\x18\0\x12\x11\n\x05value\x18\x02\ - \x20\x01(\tB\x02\x18\0\"\x1a\n\x05Gauge\x12\x11\n\x05value\x18\x01\x20\ - \x01(\x01B\x02\x18\0\"\x1c\n\x07Counter\x12\x11\n\x05value\x18\x01\x20\ - \x01(\x01B\x02\x18\0\"3\n\x08Quantile\x12\x14\n\x08quantile\x18\x01\x20\ - \x01(\x01B\x02\x18\0\x12\x11\n\x05value\x18\x02\x20\x01(\x01B\x02\x18\0\ - \"q\n\x07Summary\x12\x18\n\x0csample_count\x18\x01\x20\x01(\x04B\x02\x18\ - \0\x12\x16\n\nsample_sum\x18\x02\x20\x01(\x01B\x02\x18\0\x124\n\x08quant\ - ile\x18\x03\x20\x03(\x0b2\x1e.io.prometheus.client.QuantileB\x02\x18\0\"\ - \x1c\n\x07Untyped\x12\x11\n\x05value\x18\x01\x20\x01(\x01B\x02\x18\0\"o\ - \n\tHistogram\x12\x18\n\x0csample_count\x18\x01\x20\x01(\x04B\x02\x18\0\ - \x12\x16\n\nsample_sum\x18\x02\x20\x01(\x01B\x02\x18\0\x120\n\x06bucket\ - \x18\x03\x20\x03(\x0b2\x1c.io.prometheus.client.BucketB\x02\x18\0\"?\n\ - \x06Bucket\x12\x1c\n\x10cumulative_count\x18\x01\x20\x01(\x04B\x02\x18\0\ - \x12\x17\n\x0bupper_bound\x18\x02\x20\x01(\x01B\x02\x18\0\"\xda\x02\n\ - \x06Metric\x122\n\x05label\x18\x01\x20\x03(\x0b2\x1f.io.prometheus.clien\ - t.LabelPairB\x02\x18\0\x12.\n\x05gauge\x18\x02\x20\x01(\x0b2\x1b.io.prom\ - etheus.client.GaugeB\x02\x18\0\x122\n\x07counter\x18\x03\x20\x01(\x0b2\ - \x1d.io.prometheus.client.CounterB\x02\x18\0\x122\n\x07summary\x18\x04\ - \x20\x01(\x0b2\x1d.io.prometheus.client.SummaryB\x02\x18\0\x122\n\x07unt\ - yped\x18\x05\x20\x01(\x0b2\x1d.io.prometheus.client.UntypedB\x02\x18\0\ - \x126\n\thistogram\x18\x07\x20\x01(\x0b2\x1f.io.prometheus.client.Histog\ - ramB\x02\x18\0\x12\x18\n\x0ctimestamp_ms\x18\x06\x20\x01(\x03B\x02\x18\0\ - \"\x98\x01\n\x0cMetricFamily\x12\x10\n\x04name\x18\x01\x20\x01(\tB\x02\ - \x18\0\x12\x10\n\x04help\x18\x02\x20\x01(\tB\x02\x18\0\x122\n\x04type\ - \x18\x03\x20\x01(\x0e2\x20.io.prometheus.client.MetricTypeB\x02\x18\0\ - \x120\n\x06metric\x18\x04\x20\x03(\x0b2\x1c.io.prometheus.client.MetricB\ - \x02\x18\0*Q\n\nMetricType\x12\x0b\n\x07COUNTER\x10\0\x12\t\n\x05GAUGE\ - \x10\x01\x12\x0b\n\x07SUMMARY\x10\x02\x12\x0b\n\x07UNTYPED\x10\x03\x12\r\ - \n\tHISTOGRAM\x10\x04\x1a\x02\x10\0B\0b\x06proto2\ + \n\x11proto_model.proto\x12\x14io.prometheus.client\";\n\tLabelPair\x12\ + \x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x16\n\x05value\x18\x02\ + \x20\x01(\tR\x05valueB\0:\0\"!\n\x05Gauge\x12\x16\n\x05value\x18\x01\x20\ + \x01(\x01R\x05valueB\0:\0\"#\n\x07Counter\x12\x16\n\x05value\x18\x01\x20\ + \x01(\x01R\x05valueB\0:\0\"B\n\x08Quantile\x12\x1c\n\x08quantile\x18\x01\ + \x20\x01(\x01R\x08quantileB\0\x12\x16\n\x05value\x18\x02\x20\x01(\x01R\ + \x05valueB\0:\0\"\x8f\x01\n\x07Summary\x12#\n\x0csample_count\x18\x01\ + \x20\x01(\x04R\x0bsampleCountB\0\x12\x1f\n\nsample_sum\x18\x02\x20\x01(\ + \x01R\tsampleSumB\0\x12<\n\x08quantile\x18\x03\x20\x03(\x0b2\x1e.io.prom\ + etheus.client.QuantileR\x08quantileB\0:\0\"#\n\x07Untyped\x12\x16\n\x05v\ + alue\x18\x01\x20\x01(\x01R\x05valueB\0:\0\"\x8b\x01\n\tHistogram\x12#\n\ + \x0csample_count\x18\x01\x20\x01(\x04R\x0bsampleCountB\0\x12\x1f\n\nsamp\ + le_sum\x18\x02\x20\x01(\x01R\tsampleSumB\0\x126\n\x06bucket\x18\x03\x20\ + \x03(\x0b2\x1c.io.prometheus.client.BucketR\x06bucketB\0:\0\"Z\n\x06Buck\ + et\x12+\n\x10cumulative_count\x18\x01\x20\x01(\x04R\x0fcumulativeCountB\ + \0\x12!\n\x0bupper_bound\x18\x02\x20\x01(\x01R\nupperBoundB\0:\0\"\x8f\ + \x03\n\x06Metric\x127\n\x05label\x18\x01\x20\x03(\x0b2\x1f.io.prometheus\ + .client.LabelPairR\x05labelB\0\x123\n\x05gauge\x18\x02\x20\x01(\x0b2\x1b\ + .io.prometheus.client.GaugeR\x05gaugeB\0\x129\n\x07counter\x18\x03\x20\ + \x01(\x0b2\x1d.io.prometheus.client.CounterR\x07counterB\0\x129\n\x07sum\ + mary\x18\x04\x20\x01(\x0b2\x1d.io.prometheus.client.SummaryR\x07summaryB\ + \0\x129\n\x07untyped\x18\x05\x20\x01(\x0b2\x1d.io.prometheus.client.Unty\ + pedR\x07untypedB\0\x12?\n\thistogram\x18\x07\x20\x01(\x0b2\x1f.io.promet\ + heus.client.HistogramR\thistogramB\0\x12#\n\x0ctimestamp_ms\x18\x06\x20\ + \x01(\x03R\x0btimestampMsB\0:\0\"\xac\x01\n\x0cMetricFamily\x12\x14\n\ + \x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x14\n\x04help\x18\x02\x20\ + \x01(\tR\x04helpB\0\x126\n\x04type\x18\x03\x20\x01(\x0e2\x20.io.promethe\ + us.client.MetricTypeR\x04typeB\0\x126\n\x06metric\x18\x04\x20\x03(\x0b2\ + \x1c.io.prometheus.client.MetricR\x06metricB\0:\0*O\n\nMetricType\x12\ + \x0b\n\x07COUNTER\x10\0\x12\t\n\x05GAUGE\x10\x01\x12\x0b\n\x07SUMMARY\ + \x10\x02\x12\x0b\n\x07UNTYPED\x10\x03\x12\r\n\tHISTOGRAM\x10\x04\x1a\0B\ + \0b\x06proto2\ "; -static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, -}; +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() } pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - unsafe { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) - } + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) } diff --git a/src/desc.rs b/src/desc.rs index f97b123d..c024306e 100644 --- a/src/desc.rs +++ b/src/desc.rs @@ -254,7 +254,7 @@ mod tests { HashMap::new(), ) .err() - .expect(format!("expected error for {}", name).as_ref()); + .unwrap_or_else(|| panic!("expected error for {}", name)); match res { Error::Msg(msg) => assert_eq!(msg, format!("'{}' is not a valid label name", name)), other => panic!("{}", other), @@ -269,7 +269,7 @@ mod tests { labels.insert(name.into(), "value".into()); let res = Desc::new("name".into(), "help".into(), vec![], labels) .err() - .expect(format!("expected error for {}", name).as_ref()); + .unwrap_or_else(|| panic!("expected error for {}", name)); match res { Error::Msg(msg) => assert_eq!(msg, format!("'{}' is not a valid label name", name)), other => panic!("{}", other), @@ -282,7 +282,7 @@ mod tests { for &name in &["-dash", "9gag", "has space"] { let res = Desc::new(name.into(), "help".into(), vec![], HashMap::new()) .err() - .expect(format!("expected error for {}", name).as_ref()); + .unwrap_or_else(|| panic!("expected error for {}", name)); match res { Error::Msg(msg) => { assert_eq!(msg, format!("'{}' is not a valid metric name", name)) diff --git a/src/encoder/text.rs b/src/encoder/text.rs index cd30ea74..a33a5e1a 100644 --- a/src/encoder/text.rs +++ b/src/encoder/text.rs @@ -431,7 +431,7 @@ test_histogram_count{a="1"} 1 let mut writer = Vec::::new(); let encoder = TextEncoder::new(); - let res = encoder.encode(&vec![metric_family], &mut writer); + let res = encoder.encode(&[metric_family], &mut writer); assert!(res.is_ok()); let ans = r##"# HELP test_summary This is a test summary statistic diff --git a/src/histogram.rs b/src/histogram.rs index 78480541..f26fddbb 100644 --- a/src/histogram.rs +++ b/src/histogram.rs @@ -1413,7 +1413,7 @@ mod tests { fn test_histogram_local() { let buckets = vec![1.0, 2.0, 3.0]; let opts = HistogramOpts::new("test_histogram_local", "test histogram local help") - .buckets(buckets.clone()); + .buckets(buckets); let histogram = Histogram::with_opts(opts).unwrap(); let local = histogram.local(); diff --git a/src/lib.rs b/src/lib.rs index 7991d8ff..7505abe3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,20 +48,18 @@ You can find more examples within # Static Metrics -This crate supports staticly built metrics. You can use it with -[`lazy_static`](https://docs.rs/lazy_static/) to quickly build up and collect +This crate supports statically built metrics. You can use it with +[`once_cell`](https://docs.rs/once_cell/) to quickly build up and collect some metrics. ```rust use prometheus::{self, IntCounter, TextEncoder, Encoder}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::register_int_counter; -lazy_static! { - static ref HIGH_FIVE_COUNTER: IntCounter = - register_int_counter!("highfives", "Number of high fives received").unwrap(); -} +static HIGH_FIVE_COUNTER: Lazy = + Lazy::new(|| register_int_counter!("highfives", "Number of high fives received").unwrap()); HIGH_FIVE_COUNTER.inc(); assert_eq!(HIGH_FIVE_COUNTER.get(), 1); @@ -69,20 +67,18 @@ assert_eq!(HIGH_FIVE_COUNTER.get(), 1); By default, this registers with a default registry. To make a report, you can call [`gather`](fn.gather.html). This will return a family of metrics you can then feed through an -[`Encoder`](trait.Encoder.html) and report to Promethus. +[`Encoder`](trait.Encoder.html) and report to Prometheus. ``` # use prometheus::IntCounter; use prometheus::{self, TextEncoder, Encoder}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::register_int_counter; // Register & measure some metrics. -# lazy_static! { -# static ref HIGH_FIVE_COUNTER: IntCounter = -# register_int_counter!("highfives", "Number of high fives received").unwrap(); -# } +# static HIGH_FIVE_COUNTER: Lazy = +# Lazy::new(|| register_int_counter!("highfives", "Number of high fives received").unwrap()); # HIGH_FIVE_COUNTER.inc(); let mut buffer = Vec::new(); diff --git a/src/process_collector.rs b/src/process_collector.rs index 128e6b1a..a3b6992f 100644 --- a/src/process_collector.rs +++ b/src/process_collector.rs @@ -4,7 +4,7 @@ //! //! This module only supports **Linux** platform. -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::counter::IntCounter; use crate::desc::Desc; @@ -187,21 +187,11 @@ impl Collector for ProcessCollector { } } -lazy_static! { - // getconf CLK_TCK - static ref CLK_TCK: i64 = { - unsafe { - libc::sysconf(libc::_SC_CLK_TCK) - }.into() - }; - - // getconf PAGESIZE - static ref PAGESIZE: i64 = { - unsafe { - libc::sysconf(libc::_SC_PAGESIZE) - }.into() - }; -} +// getconf CLK_TCK +static CLK_TCK: Lazy = Lazy::new(|| unsafe { libc::sysconf(libc::_SC_CLK_TCK) }.into()); + +// getconf PAGESIZE +static PAGESIZE: Lazy = Lazy::new(|| unsafe { libc::sysconf(libc::_SC_PAGESIZE) }.into()); #[cfg(test)] mod tests { diff --git a/src/push.rs b/src/push.rs index 525b3421..a0cb4f6d 100644 --- a/src/push.rs +++ b/src/push.rs @@ -10,7 +10,7 @@ use reqwest::blocking::Client; use reqwest::header::CONTENT_TYPE; use reqwest::{Method, StatusCode, Url}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use crate::encoder::{Encoder, ProtobufEncoder}; use crate::errors::{Error, Result}; @@ -20,12 +20,12 @@ use crate::registry::Registry; const REQWEST_TIMEOUT_SEC: Duration = Duration::from_secs(10); -lazy_static! { - static ref HTTP_CLIENT: Client = Client::builder() +static HTTP_CLIENT: Lazy = Lazy::new(|| { + Client::builder() .timeout(REQWEST_TIMEOUT_SEC) .build() - .unwrap(); -} + .unwrap() +}); /// `BasicAuthentication` holder for supporting `push` to Pushgateway endpoints /// using Basic access authentication. diff --git a/src/registry.rs b/src/registry.rs index a4be61f1..e7651816 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -13,7 +13,7 @@ use crate::metrics::Collector; use crate::proto; use cfg_if::cfg_if; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; #[derive(Default)] struct RegistryCore { @@ -293,20 +293,17 @@ cfg_if! { } // Default registry for rust-prometheus. -lazy_static! { - static ref DEFAULT_REGISTRY: Registry = { - let reg = Registry::default(); +static DEFAULT_REGISTRY: Lazy = Lazy::new(|| { + let reg = Registry::default(); - // Register a default process collector. - register_default_process_collector(®).unwrap(); + // Register a default process collector. + register_default_process_collector(®).unwrap(); - reg - }; -} + reg +}); /// Default registry (global static). pub fn default_registry() -> &'static Registry { - lazy_static::initialize(&DEFAULT_REGISTRY); &DEFAULT_REGISTRY } @@ -362,7 +359,7 @@ mod tests { assert!(r.register(Box::new(counter.clone())).is_err()); assert!(r.unregister(Box::new(counter.clone())).is_ok()); assert!(r.unregister(Box::new(counter.clone())).is_err()); - assert!(r.register(Box::new(counter.clone())).is_ok()); + assert!(r.register(Box::new(counter)).is_ok()); let counter_vec = CounterVec::new(Opts::new("test_vec", "test vec help"), &["a", "b"]).unwrap(); @@ -385,7 +382,7 @@ mod tests { assert!(default_registry() .unregister(Box::new(counter.clone())) .is_err()); - assert!(register(Box::new(counter.clone())).is_ok()); + assert!(register(Box::new(counter)).is_ok()); } #[test] @@ -395,9 +392,9 @@ mod tests { let counter_a = Counter::new("test_a_counter", "test help").unwrap(); let counter_b = Counter::new("test_b_counter", "test help").unwrap(); let counter_2 = Counter::new("test_2_counter", "test help").unwrap(); - r.register(Box::new(counter_b.clone())).unwrap(); - r.register(Box::new(counter_2.clone())).unwrap(); - r.register(Box::new(counter_a.clone())).unwrap(); + r.register(Box::new(counter_b)).unwrap(); + r.register(Box::new(counter_2)).unwrap(); + r.register(Box::new(counter_a)).unwrap(); let mfs = r.gather(); assert_eq!(mfs.len(), 3); @@ -469,7 +466,7 @@ mod tests { let r = Registry::new_custom(Some("common_prefix".to_string()), None).unwrap(); let counter_a = Counter::new("test_a_counter", "test help").unwrap(); - r.register(Box::new(counter_a.clone())).unwrap(); + r.register(Box::new(counter_a)).unwrap(); let mfs = r.gather(); assert_eq!(mfs.len(), 1); @@ -483,7 +480,7 @@ mod tests { let r = Registry::new_custom(None, Some(labels)).unwrap(); let counter_a = Counter::new("test_a_counter", "test help").unwrap(); - r.register(Box::new(counter_a.clone())).unwrap(); + r.register(Box::new(counter_a)).unwrap(); let counter_vec = CounterVec::new(Opts::new("test_vec", "test vec help"), &["a", "b"]).unwrap(); r.register(Box::new(counter_vec.clone())).unwrap(); diff --git a/src/timer.rs b/src/timer.rs index 7530c72d..74872fe4 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -2,13 +2,11 @@ use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::thread; use std::time::{Duration, Instant}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; /// Milliseconds since ANCHOR. static RECENT: AtomicU64 = AtomicU64::new(0); -lazy_static! { - static ref ANCHOR: Instant = Instant::now(); -} +static ANCHOR: Lazy = Lazy::new(|| Instant::now()); /// Convert a duration to millisecond. #[inline] @@ -39,9 +37,7 @@ pub fn recent_millis() -> u64 { RECENT.load(Ordering::Relaxed) } -lazy_static! { - static ref UPDATER_IS_RUNNING: AtomicBool = AtomicBool::new(false); -} +static UPDATER_IS_RUNNING: Lazy = Lazy::new(|| AtomicBool::new(false)); const CHECK_UPDATE_INTERVAL: Duration = Duration::from_millis(200); diff --git a/static-metric/Cargo.toml b/static-metric/Cargo.toml index 7827b183..6063b122 100644 --- a/static-metric/Cargo.toml +++ b/static-metric/Cargo.toml @@ -16,7 +16,7 @@ proc-macro = true syn = { version = "1.0", features = ["full", "extra-traits"] } proc-macro2 = "1.0" quote = "1.0" -lazy_static = "1.4" +once_cell = "^1.0" [dev-dependencies] criterion = "0.4" diff --git a/static-metric/Makefile b/static-metric/Makefile index a8b99a92..09b4edc4 100644 --- a/static-metric/Makefile +++ b/static-metric/Makefile @@ -29,4 +29,4 @@ examples: cargo build --example metric_enum cargo build --example register_integration cargo build --example simple - cargo build --example with_lazy_static + cargo build --example with_once_cell diff --git a/static-metric/README.md b/static-metric/README.md index cdf66a1e..6c05188d 100644 --- a/static-metric/README.md +++ b/static-metric/README.md @@ -91,7 +91,7 @@ For heavier scenario that a global shared static-metric might not be effecient e ```rust use prometheus::*; -use lazy_static:lazy_static; +use once_cell::sync::Lazy; use prometheus_static_metric::{auto_flush_from, make_auto_flush_static_metric}; make_auto_flush_static_metric! { @@ -118,20 +118,19 @@ make_auto_flush_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER_VEC: IntCounterVec = - register_int_counter_vec ! ( - "http_requests_total", - "Number of HTTP requests.", - & ["product", "method", "version"] // it doesn't matter for the label order - ).unwrap(); -} - -lazy_static! { - // You can also use default flush duration which is 1 second. - // pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs); - pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs, std::time::Duration::from_secs(1)); -} +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "http_requests_total", + "Number of HTTP requests.", + &["product", "method", "version"] // it doesn't matter for the label order + ) + .unwrap() +}); + +// You can also use default flush duration which is 1 second. +// pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs); +static TLS_HTTP_COUNTER: Lazy = + Lazy::new(|| auto_flush_from!(HTTP_COUNTER_VEC, Lhrs, std::time::Duration::from_secs(1))); fn main() { TLS_HTTP_COUNTER.foo.post.http1.inc(); diff --git a/static-metric/examples/advanced.rs b/static-metric/examples/advanced.rs index 5a788e71..5d9703e6 100644 --- a/static-metric/examples/advanced.rs +++ b/static-metric/examples/advanced.rs @@ -2,7 +2,7 @@ use prometheus::IntCounterVec; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::register_int_counter_vec; use prometheus_static_metric::make_static_metric; @@ -25,17 +25,17 @@ make_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER_VEC: IntCounterVec = - register_int_counter_vec!( - "http_requests_total", - "Number of HTTP requests.", - &["product", "method", "version"] // it doesn't matter for the label order - ).unwrap(); +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "http_requests_total", + "Number of HTTP requests.", + &["product", "method", "version"] // it doesn't matter for the label order + ) + .unwrap() +}); - pub static ref HTTP_COUNTER: HttpRequestStatistics = HttpRequestStatistics - ::from(&HTTP_COUNTER_VEC); -} +static HTTP_COUNTER: Lazy = + Lazy::new(|| HttpRequestStatistics::from(&HTTP_COUNTER_VEC)); /// This example demonstrates the usage of: /// 1. using alternative metric types (i.e. IntCounter) diff --git a/static-metric/examples/local.rs b/static-metric/examples/local.rs index 5ea9247f..38beb423 100644 --- a/static-metric/examples/local.rs +++ b/static-metric/examples/local.rs @@ -4,7 +4,7 @@ use std::cell::Cell; use prometheus::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus_static_metric::make_static_metric; make_static_metric! { @@ -28,14 +28,14 @@ make_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER_VEC: IntCounterVec = - register_int_counter_vec!( - "http_requests_total", - "Number of HTTP requests.", - &["product", "method", "version"] // it doesn't matter for the label order - ).unwrap(); -} +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "http_requests_total", + "Number of HTTP requests.", + &["product", "method", "version"] // it doesn't matter for the label order + ) + .unwrap() +}); thread_local! { static THREAD_LAST_TICK_TIME: Cell = Cell::new(timer::now_millis()); diff --git a/static-metric/examples/make_auto_flush_static_counter.rs b/static-metric/examples/make_auto_flush_static_counter.rs index 4c6fa1bb..cf342230 100644 --- a/static-metric/examples/make_auto_flush_static_counter.rs +++ b/static-metric/examples/make_auto_flush_static_counter.rs @@ -7,7 +7,7 @@ Use metric enums to reuse possible values of a label. */ use prometheus::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus_static_metric::{auto_flush_from, make_auto_flush_static_metric}; make_auto_flush_static_metric! { @@ -34,31 +34,28 @@ make_auto_flush_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER_VEC: IntCounterVec = - register_int_counter_vec ! ( - "http_requests_total", - "Number of HTTP requests.", - & ["product", "method", "version"] // it doesn't matter for the label order - ).unwrap(); -} +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { + register_int_counter_vec!( + "http_requests_total", + "Number of HTTP requests.", + &["product", "method", "version"] // it doesn't matter for the label order + ) + .unwrap() +}); // Macro expanded code of auto_flush_from! -// lazy_static! { -// pub static ref TLS_HTTP_COUNTER: Lhrs = { -// thread_local! { -// pub static TLS_HTTP_COUNTER_INNER: LhrsInner = LhrsInner::from(& HTTP_COUNTER_VEC); -// } -// Lhrs::from(&TLS_HTTP_COUNTER_INNER) -// }; -// } +// static TLS_HTTP_COUNTER: Lazy = Lazy::new(|| { +// thread_local! { +// pub static TLS_HTTP_COUNTER_INNER: LhrsInner = LhrsInner::from(& HTTP_COUNTER_VEC); +// } +// Lhrs::from(&TLS_HTTP_COUNTER_INNER) +// }); // -lazy_static! { - // You can also use default flush duration which is 1 second. - // pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs); - pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs, std::time::Duration::from_secs(1)); -} +// You can also use default flush duration which is 1 second. +// pub static ref TLS_HTTP_COUNTER: Lhrs = auto_flush_from!(HTTP_COUNTER_VEC, Lhrs); +static TLS_HTTP_COUNTER: Lazy = + Lazy::new(|| auto_flush_from!(HTTP_COUNTER_VEC, Lhrs, std::time::Duration::from_secs(1))); fn main() { TLS_HTTP_COUNTER.foo.post.http1.inc(); @@ -101,7 +98,7 @@ use std::mem; use std::mem::MaybeUninit; use std::thread::LocalKey; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; #[allow(dead_code)] #[allow(non_camel_case_types)] @@ -367,22 +364,20 @@ impl Lhrs { } } -lazy_static! { -pub static ref HTTP_COUNTER_VEC: IntCounterVec = +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { register_int_counter_vec ! ( "http_requests_total", "Number of HTTP requests.", & ["product", "method", "version"] // it doesn't matter for the label order -).unwrap(); -} +).unwrap() +}); thread_local! { pub static TLS_HTTP_COUNTER_INNER: LhrsInner = LhrsInner::from(& HTTP_COUNTER_VEC); } -lazy_static! { - pub static ref TLS_HTTP_COUNTER: Lhrs = Lhrs::from(&TLS_HTTP_COUNTER_INNER); -} +static TLS_HTTP_COUNTER: Lazy = Lazy::new(|| + Lazy::new(|| Lhrs::from(&TLS_HTTP_COUNTER_INNER)); fn main() { TLS_HTTP_COUNTER.foo.post.http1.inc(); diff --git a/static-metric/examples/make_auto_flush_static_metric_histogram.rs b/static-metric/examples/make_auto_flush_static_metric_histogram.rs index 9ae3247f..5e106443 100644 --- a/static-metric/examples/make_auto_flush_static_metric_histogram.rs +++ b/static-metric/examples/make_auto_flush_static_metric_histogram.rs @@ -8,7 +8,7 @@ Use metric enums to reuse possible values of a label. use prometheus::*; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus_static_metric::{auto_flush_from, make_auto_flush_static_metric}; make_auto_flush_static_metric! { @@ -35,19 +35,17 @@ make_auto_flush_static_metric! { } } -lazy_static! { - pub static ref HTTP_HISTO_VEC: HistogramVec = - register_histogram_vec ! ( - "http_requests_total", - "Number of HTTP requests.", - & ["product", "method", "version"] // it doesn't matter for the label order - ).unwrap(); -} +static HTTP_HISTO_VEC: Lazy = Lazy::new(|| { + register_histogram_vec!( + "http_requests_total", + "Number of HTTP requests.", + &["product", "method", "version"] // it doesn't matter for the label order + ) + .unwrap() +}); -lazy_static! { - pub static ref TLS_HTTP_COUNTER: Lhrs = - auto_flush_from!(HTTP_HISTO_VEC, Lhrs, std::time::Duration::from_secs(1)); -} +static TLS_HTTP_COUNTER: Lazy = + Lazy::new(|| auto_flush_from!(HTTP_HISTO_VEC, Lhrs, std::time::Duration::from_secs(1))); fn main() { TLS_HTTP_COUNTER.foo.post.http1.observe(1.0); @@ -97,7 +95,7 @@ use std::mem; use std::mem::MaybeUninit; use std::thread::LocalKey; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; #[allow(dead_code)] #[allow(non_camel_case_types)] @@ -362,22 +360,20 @@ impl Lhrs { } } -lazy_static! { -pub static ref HTTP_HISTO_VEC: HistogramVec = +static HTTP_HISTO_VEC: Lazy = Lazy::new(|| { register_histogram_vec ! ( "http_requests_total", "Number of HTTP requests.", & ["product", "method", "version"] // it doesn't matter for the label order -).unwrap(); -} +).unwrap() +}); thread_local! { pub static TLS_HTTP_COUNTER_INNER: LhrsInner = LhrsInner::from(& HTTP_HISTO_VEC); } -lazy_static! { - pub static ref TLS_HTTP_COUNTER: Lhrs = Lhrs::from(&TLS_HTTP_COUNTER_INNER); -} +static TLS_HTTP_COUNTER: Lazy = Lazy::new(|| + Lazy::new(|| Lhrs::from(&TLS_HTTP_COUNTER_INNER)); fn main() { TLS_HTTP_COUNTER.foo.post.http1.observe(1.0); diff --git a/static-metric/examples/register_integration.rs b/static-metric/examples/register_integration.rs index 6c0627a7..60e1a3bd 100644 --- a/static-metric/examples/register_integration.rs +++ b/static-metric/examples/register_integration.rs @@ -9,7 +9,7 @@ by using the `register_static_xxx!` macro provided by this crate. use prometheus::exponential_buckets; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::{register_counter_vec, register_histogram_vec}; use prometheus_static_metric::{ make_static_metric, register_static_counter_vec, register_static_histogram_vec, @@ -38,23 +38,25 @@ make_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER: HttpRequestStatistics = register_static_counter_vec!( +static HTTP_COUNTER: Lazy = Lazy::new(|| { + register_static_counter_vec!( HttpRequestStatistics, "http_requests_total", "Number of HTTP requests.", &["method", "product"] ) - .unwrap(); - pub static ref HTTP_DURATION: HttpRequestDuration = register_static_histogram_vec!( + .unwrap() +}); +static HTTP_DURATION: Lazy = Lazy::new(|| { + register_static_histogram_vec!( HttpRequestDuration, "http_request_duration", "Duration of each HTTP request.", &["method"], exponential_buckets(0.0005, 2.0, 20).unwrap() ) - .unwrap(); -} + .unwrap() +}); fn main() { HTTP_COUNTER.post.foo.inc(); diff --git a/static-metric/examples/with_lazy_static.rs b/static-metric/examples/with_once_cell.rs similarity index 78% rename from static-metric/examples/with_lazy_static.rs rename to static-metric/examples/with_once_cell.rs index 198a1c39..32d5942f 100644 --- a/static-metric/examples/with_lazy_static.rs +++ b/static-metric/examples/with_once_cell.rs @@ -2,7 +2,7 @@ use prometheus::CounterVec; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::register_counter_vec; use prometheus_static_metric::make_static_metric; @@ -21,16 +21,16 @@ make_static_metric! { } } -lazy_static! { - pub static ref HTTP_COUNTER_VEC: CounterVec = register_counter_vec!( +static HTTP_COUNTER_VEC: Lazy = Lazy::new(|| { + register_counter_vec!( "http_requests_total", "Number of HTTP requests.", &["method", "product"] ) - .unwrap(); - pub static ref HTTP_COUNTER: HttpRequestStatistics = - HttpRequestStatistics::from(&HTTP_COUNTER_VEC); -} + .unwrap() +}); +static HTTP_COUNTER: Lazy = + Lazy::new(|| HttpRequestStatistics::from(&HTTP_COUNTER_VEC)); fn main() { HTTP_COUNTER.post.foo.inc(); diff --git a/static-metric/src/lib.rs b/static-metric/src/lib.rs index fdb70b4f..f3ee23d6 100644 --- a/static-metric/src/lib.rs +++ b/static-metric/src/lib.rs @@ -8,13 +8,11 @@ This is useful since it reduces the amount of branching and processing needed at ```rust use prometheus::{self, IntCounter, TextEncoder, Encoder}; -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use prometheus::register_int_counter; -lazy_static! { - static ref HIGH_FIVE_COUNTER: IntCounter = - register_int_counter!("highfives", "Number of high fives recieved").unwrap(); -} +static HIGH_FIVE_COUNTER: Lazy = + Lazy::new(|| register_int_counter!("highfives", "Number of high fives recieved").unwrap()); HIGH_FIVE_COUNTER.inc(); assert_eq!(HIGH_FIVE_COUNTER.get(), 1); diff --git a/static-metric/tests/metric.rs b/static-metric/tests/metric.rs index df45be68..55c83777 100644 --- a/static-metric/tests/metric.rs +++ b/static-metric/tests/metric.rs @@ -44,7 +44,7 @@ make_static_metric! { fn get_labels(counter: &Counter) -> Vec { counter.collect()[0].get_metric()[0] .get_label() - .into_iter() + .iter() .map(|label| label.get_value().to_string()) .collect() } @@ -96,11 +96,11 @@ fn test_try_get() { vec!["get", "bar"] ); assert_eq!( - get_labels(&metric.get.try_get("bar").unwrap()), + get_labels(metric.get.try_get("bar").unwrap()), vec!["get", "bar"] ); assert_eq!( - get_labels(&metric.try_get("get").unwrap().try_get("bar").unwrap()), + get_labels(metric.try_get("get").unwrap().try_get("bar").unwrap()), vec!["get", "bar"] ); assert!(metric.try_get("get_foo").is_none()); @@ -116,12 +116,12 @@ fn test_try_get_with_field_value() { vec!["get_name", "bar_name"] ); assert_eq!( - get_labels(&metric.get.try_get("bar_name").unwrap()), + get_labels(metric.get.try_get("bar_name").unwrap()), vec!["get_name", "bar_name"] ); assert_eq!( get_labels( - &metric + metric .try_get("get_name") .unwrap() .try_get("bar_name")