diff --git a/Cargo.toml b/Cargo.toml index 9c6d93df..a84e0e3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ features = ["nightly"] [features] default = ["protobuf"] -gen = ["protobuf-codegen-pure"] nightly = ["libc"] process = ["libc", "procfs"] +protobuf = ["prost", "prost-build"] push = ["reqwest", "libc", "protobuf"] [dependencies] @@ -30,7 +30,7 @@ fnv = "^1.0" lazy_static = "^1.4" libc = { version = "^0.2", optional = true } parking_lot = "^0.11" -protobuf = { version = "^2.0", optional = true } +prost = { version = "^0.7", optional = true } memchr = "^2.3" reqwest = { version = "^0.11", features = ["blocking"], optional = true } thiserror = "^1.0" @@ -45,7 +45,7 @@ hyper = { version = "^0.14", features = ["server", "http1", "tcp"] } tokio = { version = "^1.0", features = ["macros", "rt-multi-thread"] } [build-dependencies] -protobuf-codegen-pure = { version = "^2.0", optional = true } +prost-build = { version = "^0.7", optional = true } [workspace] members = ["static-metric"] diff --git a/README.md b/README.md index e91d3109..555c6b6f 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,9 @@ Find the latest documentation at . This crate provides several optional components which can be enabled via [Cargo `[features]`](https://doc.rust-lang.org/cargo/reference/features.html): -- `gen`: To generate protobuf client with the latest protobuf version instead of - using the pre-generated client. +- `protobuf`: Enable [Protocol Buffers](https://developers.google.com/protocol-buffers/) (aka Protobuf) based exposition format. (Enabled by default) + +> Notice: Since version 2.0, Prometheus no longer supports the Protobuf-based format. You can read about the reasoning behind this change in [this document](https://github.com/OpenObservability/OpenMetrics/blob/master/legacy/markdown/protobuf_vs_text.md). - `nightly`: Enable nightly only features. diff --git a/build.rs b/build.rs index b556f0b3..edad0145 100644 --- a/build.rs +++ b/build.rs @@ -1,17 +1,11 @@ // Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0. -#[cfg(feature = "gen")] +#[cfg(feature = "protobuf")] fn generate_protobuf_binding_file() { - protobuf_codegen_pure::run(protobuf_codegen_pure::Args { - out_dir: "proto", - input: &["proto/proto_model.proto"], - includes: &["proto"], - ..Default::default() - }) - .unwrap(); + prost_build::compile_protos(&["proto/proto_model.proto"], &["proto"]).unwrap(); } -#[cfg(not(feature = "gen"))] +#[cfg(not(feature = "protobuf"))] fn generate_protobuf_binding_file() {} fn main() { diff --git a/proto/proto_model.rs b/proto/proto_model.rs deleted file mode 100644 index c67aa4af..00000000 --- a/proto/proto_model.rs +++ /dev/null @@ -1,2532 +0,0 @@ -// This file is generated by rust-protobuf 2.2.5. Do not edit -// @generated - -// https://github.com/Manishearth/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy)] - -#![cfg_attr(rustfmt, rustfmt_skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unsafe_code)] -#![allow(unused_imports)] -#![allow(unused_results)] - -use protobuf::Message as Message_imported_for_functions; -use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; - -#[derive(PartialEq,Clone,Default)] -pub struct LabelPair { - // message fields - name: ::protobuf::SingularField<::std::string::String>, - value: ::protobuf::SingularField<::std::string::String>, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl LabelPair { - pub fn new() -> LabelPair { - ::std::default::Default::default() - } - - // optional string name = 1; - - pub fn clear_name(&mut self) { - self.name.clear(); - } - - pub fn has_name(&self) -> bool { - self.name.is_some() - } - - // Param is passed by value, moved - pub fn set_name(&mut self, v: ::std::string::String) { - self.name = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_name(&mut self) -> &mut ::std::string::String { - if self.name.is_none() { - self.name.set_default(); - } - self.name.as_mut().unwrap() - } - - // Take field - pub fn take_name(&mut self) -> ::std::string::String { - self.name.take().unwrap_or_else(|| ::std::string::String::new()) - } - - pub fn get_name(&self) -> &str { - match self.name.as_ref() { - Some(v) => &v, - None => "", - } - } - - // optional string value = 2; - - pub fn clear_value(&mut self) { - self.value.clear(); - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - pub fn set_value(&mut self, v: ::std::string::String) { - self.value = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_value(&mut self) -> &mut ::std::string::String { - if self.value.is_none() { - self.value.set_default(); - } - self.value.as_mut().unwrap() - } - - // Take field - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.name)?; - }, - 2 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.value)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(ref v) = self.name.as_ref() { - my_size += ::protobuf::rt::string_size(1, &v); - } - if let Some(ref v) = self.value.as_ref() { - my_size += ::protobuf::rt::string_size(2, &v); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.name.as_ref() { - os.write_string(1, &v)?; - } - if let Some(ref v) = self.value.as_ref() { - os.write_string(2, &v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> LabelPair { - LabelPair::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for LabelPair { - fn clear(&mut self) { - self.clear_name(); - self.clear_value(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for LabelPair { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for LabelPair { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Gauge { - // message fields - value: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Gauge { - pub fn new() -> Gauge { - ::std::default::Default::default() - } - - // optional double value = 1; - - pub fn clear_value(&mut self) { - self.value = ::std::option::Option::None; - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.value = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.value { - my_size += 9; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.value { - os.write_double(1, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Gauge { - Gauge::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Gauge { - fn clear(&mut self) { - self.clear_value(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Gauge { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Gauge { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Counter { - // message fields - value: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Counter { - pub fn new() -> Counter { - ::std::default::Default::default() - } - - // optional double value = 1; - - pub fn clear_value(&mut self) { - self.value = ::std::option::Option::None; - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.value = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.value { - my_size += 9; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.value { - os.write_double(1, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Counter { - Counter::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Counter { - fn clear(&mut self) { - self.clear_value(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Counter { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Counter { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Quantile { - // message fields - quantile: ::std::option::Option, - value: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Quantile { - pub fn new() -> Quantile { - ::std::default::Default::default() - } - - // optional double quantile = 1; - - pub fn clear_quantile(&mut self) { - self.quantile = ::std::option::Option::None; - } - - pub fn has_quantile(&self) -> bool { - self.quantile.is_some() - } - - // Param is passed by value, moved - pub fn set_quantile(&mut self, v: f64) { - self.quantile = ::std::option::Option::Some(v); - } - - pub fn get_quantile(&self) -> f64 { - self.quantile.unwrap_or(0.) - } - - // optional double value = 2; - - pub fn clear_value(&mut self) { - self.value = ::std::option::Option::None; - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.quantile = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.value = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.quantile { - my_size += 9; - } - if let Some(v) = self.value { - my_size += 9; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.quantile { - os.write_double(1, v)?; - } - if let Some(v) = self.value { - os.write_double(2, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Quantile { - Quantile::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Quantile { - fn clear(&mut self) { - self.clear_quantile(); - self.clear_value(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Quantile { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Quantile { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Summary { - // message fields - sample_count: ::std::option::Option, - sample_sum: ::std::option::Option, - quantile: ::protobuf::RepeatedField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Summary { - pub fn new() -> Summary { - ::std::default::Default::default() - } - - // optional uint64 sample_count = 1; - - pub fn clear_sample_count(&mut self) { - self.sample_count = ::std::option::Option::None; - } - - pub fn has_sample_count(&self) -> bool { - self.sample_count.is_some() - } - - // Param is passed by value, moved - pub fn set_sample_count(&mut self, v: u64) { - 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 clear_sample_sum(&mut self) { - self.sample_sum = ::std::option::Option::None; - } - - pub fn has_sample_sum(&self) -> bool { - self.sample_sum.is_some() - } - - // Param is passed by value, moved - pub fn set_sample_sum(&mut self, v: f64) { - 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 clear_quantile(&mut self) { - self.quantile.clear(); - } - - // Param is passed by value, moved - pub fn set_quantile(&mut self, v: ::protobuf::RepeatedField) { - self.quantile = v; - } - - // Mutable pointer to the field. - pub fn mut_quantile(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.quantile - } - - // Take field - 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 { - fn is_initialized(&self) -> bool { - for v in &self.quantile { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.sample_count = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.sample_sum = ::std::option::Option::Some(tmp); - }, - 3 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.quantile)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.sample_count { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.sample_sum { - my_size += 9; - } - for value in &self.quantile { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.sample_count { - os.write_uint64(1, v)?; - } - if let Some(v) = self.sample_sum { - os.write_double(2, v)?; - } - for v in &self.quantile { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Summary { - Summary::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Summary { - fn clear(&mut self) { - self.clear_sample_count(); - self.clear_sample_sum(); - self.clear_quantile(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Summary { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Summary { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Untyped { - // message fields - value: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Untyped { - pub fn new() -> Untyped { - ::std::default::Default::default() - } - - // optional double value = 1; - - pub fn clear_value(&mut self) { - self.value = ::std::option::Option::None; - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.value = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.value { - my_size += 9; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.value { - os.write_double(1, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Untyped { - Untyped::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Untyped { - fn clear(&mut self) { - self.clear_value(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Untyped { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Untyped { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Histogram { - // message fields - sample_count: ::std::option::Option, - sample_sum: ::std::option::Option, - bucket: ::protobuf::RepeatedField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Histogram { - pub fn new() -> Histogram { - ::std::default::Default::default() - } - - // optional uint64 sample_count = 1; - - pub fn clear_sample_count(&mut self) { - self.sample_count = ::std::option::Option::None; - } - - pub fn has_sample_count(&self) -> bool { - self.sample_count.is_some() - } - - // Param is passed by value, moved - pub fn set_sample_count(&mut self, v: u64) { - 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 clear_sample_sum(&mut self) { - self.sample_sum = ::std::option::Option::None; - } - - pub fn has_sample_sum(&self) -> bool { - self.sample_sum.is_some() - } - - // Param is passed by value, moved - pub fn set_sample_sum(&mut self, v: f64) { - 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 clear_bucket(&mut self) { - self.bucket.clear(); - } - - // Param is passed by value, moved - pub fn set_bucket(&mut self, v: ::protobuf::RepeatedField) { - self.bucket = v; - } - - // Mutable pointer to the field. - pub fn mut_bucket(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.bucket - } - - // Take field - 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 { - fn is_initialized(&self) -> bool { - for v in &self.bucket { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.sample_count = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.sample_sum = ::std::option::Option::Some(tmp); - }, - 3 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.bucket)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.sample_count { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.sample_sum { - my_size += 9; - } - for value in &self.bucket { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.sample_count { - os.write_uint64(1, v)?; - } - if let Some(v) = self.sample_sum { - os.write_double(2, v)?; - } - for v in &self.bucket { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Histogram { - Histogram::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Histogram { - fn clear(&mut self) { - self.clear_sample_count(); - self.clear_sample_sum(); - self.clear_bucket(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Histogram { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Histogram { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Bucket { - // message fields - cumulative_count: ::std::option::Option, - upper_bound: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Bucket { - pub fn new() -> Bucket { - ::std::default::Default::default() - } - - // optional uint64 cumulative_count = 1; - - pub fn clear_cumulative_count(&mut self) { - self.cumulative_count = ::std::option::Option::None; - } - - pub fn has_cumulative_count(&self) -> bool { - self.cumulative_count.is_some() - } - - // Param is passed by value, moved - pub fn set_cumulative_count(&mut self, v: u64) { - 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 clear_upper_bound(&mut self) { - self.upper_bound = ::std::option::Option::None; - } - - pub fn has_upper_bound(&self) -> bool { - self.upper_bound.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.cumulative_count = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeFixed64 { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_double()?; - self.upper_bound = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(v) = self.cumulative_count { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.upper_bound { - my_size += 9; - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(v) = self.cumulative_count { - os.write_uint64(1, v)?; - } - if let Some(v) = self.upper_bound { - os.write_double(2, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Bucket { - Bucket::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for Bucket { - fn clear(&mut self) { - self.clear_cumulative_count(); - self.clear_upper_bound(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Bucket { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Bucket { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::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, - timestamp_ms: ::std::option::Option, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl Metric { - pub fn new() -> Metric { - ::std::default::Default::default() - } - - // repeated .io.prometheus.client.LabelPair label = 1; - - pub fn clear_label(&mut self) { - self.label.clear(); - } - - // Param is passed by value, moved - pub fn set_label(&mut self, v: ::protobuf::RepeatedField) { - self.label = v; - } - - // Mutable pointer to the field. - pub fn mut_label(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.label - } - - // Take field - pub fn take_label(&mut self) -> ::protobuf::RepeatedField { - ::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 clear_gauge(&mut self) { - self.gauge.clear(); - } - - pub fn has_gauge(&self) -> bool { - self.gauge.is_some() - } - - // Param is passed by value, moved - pub fn set_gauge(&mut self, v: Gauge) { - self.gauge = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_gauge(&mut self) -> &mut Gauge { - if self.gauge.is_none() { - self.gauge.set_default(); - } - self.gauge.as_mut().unwrap() - } - - // Take field - pub fn take_gauge(&mut self) -> Gauge { - 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 clear_counter(&mut self) { - self.counter.clear(); - } - - pub fn has_counter(&self) -> bool { - self.counter.is_some() - } - - // Param is passed by value, moved - pub fn set_counter(&mut self, v: Counter) { - self.counter = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_counter(&mut self) -> &mut Counter { - if self.counter.is_none() { - self.counter.set_default(); - } - self.counter.as_mut().unwrap() - } - - // Take field - pub fn take_counter(&mut self) -> Counter { - 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 clear_summary(&mut self) { - self.summary.clear(); - } - - pub fn has_summary(&self) -> bool { - self.summary.is_some() - } - - // Param is passed by value, moved - pub fn set_summary(&mut self, v: Summary) { - self.summary = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_summary(&mut self) -> &mut Summary { - if self.summary.is_none() { - self.summary.set_default(); - } - self.summary.as_mut().unwrap() - } - - // Take field - pub fn take_summary(&mut self) -> Summary { - 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 clear_untyped(&mut self) { - self.untyped.clear(); - } - - pub fn has_untyped(&self) -> bool { - self.untyped.is_some() - } - - // Param is passed by value, moved - pub fn set_untyped(&mut self, v: Untyped) { - self.untyped = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_untyped(&mut self) -> &mut Untyped { - if self.untyped.is_none() { - self.untyped.set_default(); - } - self.untyped.as_mut().unwrap() - } - - // Take field - pub fn take_untyped(&mut self) -> Untyped { - 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 clear_histogram(&mut self) { - self.histogram.clear(); - } - - pub fn has_histogram(&self) -> bool { - self.histogram.is_some() - } - - // Param is passed by value, moved - pub fn set_histogram(&mut self, v: Histogram) { - self.histogram = ::protobuf::SingularPtrField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_histogram(&mut self) -> &mut Histogram { - if self.histogram.is_none() { - self.histogram.set_default(); - } - self.histogram.as_mut().unwrap() - } - - // Take field - pub fn take_histogram(&mut self) -> Histogram { - 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 clear_timestamp_ms(&mut self) { - self.timestamp_ms = ::std::option::Option::None; - } - - pub fn has_timestamp_ms(&self) -> bool { - self.timestamp_ms.is_some() - } - - // Param is passed by value, moved - 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 { - fn is_initialized(&self) -> bool { - for v in &self.label { - if !v.is_initialized() { - return false; - } - }; - for v in &self.gauge { - if !v.is_initialized() { - return false; - } - }; - for v in &self.counter { - if !v.is_initialized() { - return false; - } - }; - for v in &self.summary { - if !v.is_initialized() { - return false; - } - }; - for v in &self.untyped { - if !v.is_initialized() { - return false; - } - }; - for v in &self.histogram { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.label)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.gauge)?; - }, - 3 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.counter)?; - }, - 4 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.summary)?; - }, - 5 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.untyped)?; - }, - 7 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.histogram)?; - }, - 6 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_int64()?; - self.timestamp_ms = ::std::option::Option::Some(tmp); - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - for value in &self.label { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - if let Some(ref v) = self.gauge.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.counter.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.summary.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.untyped.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.histogram.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(v) = self.timestamp_ms { - my_size += ::protobuf::rt::value_size(6, v, ::protobuf::wire_format::WireTypeVarint); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.label { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - if let Some(ref v) = self.gauge.as_ref() { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.counter.as_ref() { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.summary.as_ref() { - os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.untyped.as_ref() { - os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(ref v) = self.histogram.as_ref() { - os.write_tag(7, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - } - if let Some(v) = self.timestamp_ms { - os.write_int64(6, v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Metric { - Metric::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -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.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Metric { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Metric { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct MetricFamily { - // message fields - name: ::protobuf::SingularField<::std::string::String>, - help: ::protobuf::SingularField<::std::string::String>, - field_type: ::std::option::Option, - metric: ::protobuf::RepeatedField, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl MetricFamily { - pub fn new() -> MetricFamily { - ::std::default::Default::default() - } - - // optional string name = 1; - - pub fn clear_name(&mut self) { - self.name.clear(); - } - - pub fn has_name(&self) -> bool { - self.name.is_some() - } - - // Param is passed by value, moved - pub fn set_name(&mut self, v: ::std::string::String) { - self.name = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_name(&mut self) -> &mut ::std::string::String { - if self.name.is_none() { - self.name.set_default(); - } - self.name.as_mut().unwrap() - } - - // Take field - pub fn take_name(&mut self) -> ::std::string::String { - self.name.take().unwrap_or_else(|| ::std::string::String::new()) - } - - pub fn get_name(&self) -> &str { - match self.name.as_ref() { - Some(v) => &v, - None => "", - } - } - - // optional string help = 2; - - pub fn clear_help(&mut self) { - self.help.clear(); - } - - pub fn has_help(&self) -> bool { - self.help.is_some() - } - - // Param is passed by value, moved - pub fn set_help(&mut self, v: ::std::string::String) { - self.help = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_help(&mut self) -> &mut ::std::string::String { - if self.help.is_none() { - self.help.set_default(); - } - self.help.as_mut().unwrap() - } - - // Take field - pub fn take_help(&mut self) -> ::std::string::String { - 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 clear_field_type(&mut self) { - self.field_type = ::std::option::Option::None; - } - - pub fn has_field_type(&self) -> bool { - self.field_type.is_some() - } - - // Param is passed by value, moved - pub fn set_field_type(&mut self, v: MetricType) { - 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 clear_metric(&mut self) { - self.metric.clear(); - } - - // Param is passed by value, moved - pub fn set_metric(&mut self, v: ::protobuf::RepeatedField) { - self.metric = v; - } - - // Mutable pointer to the field. - pub fn mut_metric(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.metric - } - - // Take field - 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 { - fn is_initialized(&self) -> bool { - for v in &self.metric { - if !v.is_initialized() { - return false; - } - }; - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.name)?; - }, - 2 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.help)?; - }, - 3 => { - ::protobuf::rt::read_proto2_enum_with_unknown_fields_into(wire_type, is, &mut self.field_type, 3, &mut self.unknown_fields)? - }, - 4 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.metric)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(ref v) = self.name.as_ref() { - my_size += ::protobuf::rt::string_size(1, &v); - } - if let Some(ref v) = self.help.as_ref() { - my_size += ::protobuf::rt::string_size(2, &v); - } - if let Some(v) = self.field_type { - my_size += ::protobuf::rt::enum_size(3, v); - } - for value in &self.metric { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.name.as_ref() { - os.write_string(1, &v)?; - } - if let Some(ref v) = self.help.as_ref() { - os.write_string(2, &v)?; - } - if let Some(v) = self.field_type { - os.write_enum(3, v.value())?; - } - for v in &self.metric { - os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any - } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any - } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> MetricFamily { - MetricFamily::new() - } - - 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() - ) - }) - } - } - - 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) - } - } -} - -impl ::protobuf::Clear for MetricFamily { - fn clear(&mut self) { - self.clear_name(); - self.clear_help(); - self.clear_field_type(); - self.clear_metric(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for MetricFamily { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for MetricFamily { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum MetricType { - COUNTER = 0, - GAUGE = 1, - SUMMARY = 2, - UNTYPED = 3, - HISTOGRAM = 4, -} - -impl ::protobuf::ProtobufEnum for MetricType { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(MetricType::COUNTER), - 1 => ::std::option::Option::Some(MetricType::GAUGE), - 2 => ::std::option::Option::Some(MetricType::SUMMARY), - 3 => ::std::option::Option::Some(MetricType::UNTYPED), - 4 => ::std::option::Option::Some(MetricType::HISTOGRAM), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [MetricType] = &[ - MetricType::COUNTER, - MetricType::GAUGE, - MetricType::SUMMARY, - MetricType::UNTYPED, - MetricType::HISTOGRAM, - ]; - values - } - - 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()) - }) - } - } -} - -impl ::std::marker::Copy for MetricType { -} - -impl ::protobuf::reflect::ProtobufValue for MetricType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { - ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) - } -} - -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\ -"; - -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, -}; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::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() - }) - } -} diff --git a/src/counter.rs b/src/counter.rs index 239e2982..2691c741 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -152,7 +152,7 @@ impl GenericCounterVec

{ let variable_names = label_names.iter().map(|s| (*s).to_owned()).collect(); let opts = opts.variable_labels(variable_names); let metric_vec = - MetricVec::create(proto::MetricType::COUNTER, CounterVecBuilder::new(), opts)?; + MetricVec::create(proto::MetricType::Counter, CounterVecBuilder::new(), opts)?; Ok(metric_vec as Self) } @@ -343,9 +343,9 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - assert_eq!(m.get_label().len(), 2); - assert_eq!(m.get_counter().get_value() as u64, 43); + let m = mf.metric.get(0).unwrap(); + assert_eq!(m.label.len(), 2); + assert_eq!(m.counter.as_ref().unwrap().value.unwrap_or(0.0) as u64, 43); counter.reset(); assert_eq!(counter.get() as u64, 0); @@ -363,9 +363,9 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - assert_eq!(m.get_label().len(), 0); - assert_eq!(m.get_counter().get_value() as u64, 12); + let m = mf.metric.get(0).unwrap(); + assert_eq!(m.label.len(), 0); + assert_eq!(m.counter.as_ref().unwrap().value.unwrap_or(0.0) as u64, 12); counter.reset(); assert_eq!(counter.get() as u64, 0); diff --git a/src/desc.rs b/src/desc.rs index e5c0f9a0..aba935f8 100644 --- a/src/desc.rs +++ b/src/desc.rs @@ -174,9 +174,10 @@ impl Desc { desc.dim_hash = lh.finish(); for (key, value) in const_labels { - let mut label_pair = LabelPair::default(); - label_pair.set_name(key); - label_pair.set_value(value); + let label_pair = LabelPair { + name: Some(key), + value: Some(value), + }; desc.const_label_pairs.push(label_pair); } diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index f38ad544..b25307c1 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -28,10 +28,10 @@ pub trait Encoder { } fn check_metric_family(mf: &MetricFamily) -> Result<()> { - if mf.get_metric().is_empty() { + if mf.metric.is_empty() { return Err(Error::Msg(format!("MetricFamily has no metrics: {:?}", mf))); } - if mf.get_name().is_empty() { + if mf.name.is_none() { return Err(Error::Msg(format!("MetricFamily has no name: {:?}", mf))); } Ok(()) @@ -67,7 +67,7 @@ mod tests { let mut mfs = cv.collect(); // Empty name - (&mut mfs[0]).clear_name(); + (&mut mfs[0]).name.take(); check_metric_family(&mfs[0]).unwrap_err(); pb_encoder.encode(&mfs, &mut writer).unwrap_err(); assert_eq!(writer.len(), 0); @@ -94,7 +94,7 @@ mod tests { let mut mfs = cv.collect(); // Empty name - (&mut mfs[0]).clear_name(); + (&mut mfs[0]).name.take(); check_metric_family(&mfs[0]).unwrap_err(); text_encoder.encode(&mfs, &mut writer).unwrap_err(); assert_eq!(writer.len(), 0); diff --git a/src/encoder/pb.rs b/src/encoder/pb.rs index 7f09bcab..dcf635b2 100644 --- a/src/encoder/pb.rs +++ b/src/encoder/pb.rs @@ -2,7 +2,7 @@ use std::io::Write; -use protobuf::Message; +use prost::Message; use crate::errors::Result; use crate::proto::MetricFamily; @@ -31,7 +31,9 @@ impl Encoder for ProtobufEncoder { for mf in metric_families { // Fail-fast checks. check_metric_family(mf)?; - mf.write_length_delimited_to_writer(writer)?; + let mut buf = vec![]; + mf.encode_length_delimited(&mut buf)?; + writer.write_all(buf.as_slice())?; } Ok(()) } diff --git a/src/encoder/text.rs b/src/encoder/text.rs index 17516bc0..0b42f74d 100644 --- a/src/encoder/text.rs +++ b/src/encoder/text.rs @@ -34,9 +34,11 @@ impl Encoder for TextEncoder { check_metric_family(mf)?; // Write `# HELP` header. - let name = mf.get_name(); - let help = mf.get_help(); - if !help.is_empty() { + let name = match &mf.name { + Some(v) => &**v, + None => "", + }; + if let Some(help) = &mf.help { writer.write_all(b"# HELP ")?; writer.write_all(name.as_bytes())?; writer.write_all(b" ")?; @@ -45,7 +47,11 @@ impl Encoder for TextEncoder { } // Write `# TYPE` header. - let metric_type = mf.get_field_type(); + let metric_type = mf + .r#type + .map(MetricType::from_i32) + .flatten() + .unwrap_or_default(); let lowercase_type = format!("{:?}", metric_type).to_lowercase(); writer.write_all(b"# TYPE ")?; writer.write_all(name.as_bytes())?; @@ -53,80 +59,102 @@ impl Encoder for TextEncoder { writer.write_all(lowercase_type.as_bytes())?; writer.write_all(b"\n")?; - for m in mf.get_metric() { + for m in &mf.metric { match metric_type { - MetricType::COUNTER => { - write_sample(writer, name, None, m, None, m.get_counter().get_value())?; + MetricType::Counter => { + let value = match &m.counter { + Some(v) => v.value.unwrap_or_default(), + None => 0.0, + }; + write_sample(writer, &name, None, m, None, value)?; } - MetricType::GAUGE => { - write_sample(writer, name, None, m, None, m.get_gauge().get_value())?; + MetricType::Gauge => { + let value = match &m.gauge { + Some(v) => v.value.unwrap_or_default(), + None => 0.0, + }; + write_sample(writer, &name, None, m, None, value)?; } - MetricType::HISTOGRAM => { - let h = m.get_histogram(); + MetricType::Histogram => { + if let Some(h) = &m.histogram { + let mut inf_seen = false; + for b in &h.bucket { + let upper_bound = b.upper_bound.unwrap_or_default(); + write_sample( + writer, + &name, + Some("_bucket"), + m, + Some((BUCKET_LABEL, &upper_bound.to_string())), + b.cumulative_count.unwrap_or_default() as f64, + )?; + if upper_bound.is_sign_positive() && upper_bound.is_infinite() { + inf_seen = true; + } + } + if !inf_seen { + write_sample( + writer, + &name, + Some("_bucket"), + m, + Some((BUCKET_LABEL, POSITIVE_INF)), + h.sample_count.unwrap_or_default() as f64, + )?; + } - let mut inf_seen = false; - for b in h.get_bucket() { - let upper_bound = b.get_upper_bound(); write_sample( writer, - name, - Some("_bucket"), + &name, + Some("_sum"), m, - Some((BUCKET_LABEL, &upper_bound.to_string())), - b.get_cumulative_count() as f64, + None, + h.sample_sum.unwrap_or_default(), )?; - if upper_bound.is_sign_positive() && upper_bound.is_infinite() { - inf_seen = true; - } - } - if !inf_seen { + write_sample( writer, - name, - Some("_bucket"), + &name, + Some("_count"), m, - Some((BUCKET_LABEL, POSITIVE_INF)), - h.get_sample_count() as f64, + None, + h.sample_count.unwrap_or_default() as f64, )?; } - - write_sample(writer, name, Some("_sum"), m, None, h.get_sample_sum())?; - - write_sample( - writer, - name, - Some("_count"), - m, - None, - h.get_sample_count() as f64, - )?; } - MetricType::SUMMARY => { - let s = m.get_summary(); + MetricType::Summary => { + if let Some(s) = &m.summary { + for q in &s.quantile { + write_sample( + writer, + &name, + None, + m, + Some((QUANTILE, &q.quantile.unwrap_or_default().to_string())), + q.value.unwrap_or_default(), + )?; + } - for q in s.get_quantile() { write_sample( writer, - name, + &name, + Some("_sum"), + m, None, + s.sample_sum.unwrap_or_default(), + )?; + + write_sample( + writer, + &name, + Some("_count"), m, - Some((QUANTILE, &q.get_quantile().to_string())), - q.get_value(), + None, + s.sample_count.unwrap_or_default() as f64, )?; } - - write_sample(writer, name, Some("_sum"), m, None, s.get_sample_sum())?; - - write_sample( - writer, - name, - Some("_count"), - m, - None, - s.get_sample_count() as f64, - )?; } - MetricType::UNTYPED => { + MetricType::Untyped => { unimplemented!(); } } @@ -159,13 +187,12 @@ fn write_sample( writer.write_all(postfix.as_bytes())?; } - label_pairs_to_text(mc.get_label(), additional_label, writer)?; + label_pairs_to_text(&*mc.label, additional_label, writer)?; writer.write_all(b" ")?; writer.write_all(value.to_string().as_bytes())?; - let timestamp = mc.get_timestamp_ms(); - if timestamp != 0 { + if let Some(timestamp) = mc.timestamp_ms { writer.write_all(b" ")?; writer.write_all(timestamp.to_string().as_bytes())?; } @@ -193,10 +220,18 @@ fn label_pairs_to_text( let mut separator = b"{"; for lp in pairs { + let name = match &lp.name { + Some(v) => &**v, + None => "", + }; + let value = match &lp.value { + Some(v) => &**v, + None => "", + }; writer.write_all(separator)?; - writer.write_all(lp.get_name().as_bytes())?; + writer.write_all(name.as_bytes())?; writer.write_all(b"=\"")?; - writer.write_all(escape_string(lp.get_value(), true).as_bytes())?; + writer.write_all(escape_string(value, true).as_bytes())?; writer.write_all(b"\"")?; separator = b","; @@ -261,7 +296,6 @@ fn escape_string(v: &str, include_double_quote: bool) -> Cow<'_, str> { #[cfg(test)] mod tests { - use super::*; use crate::counter::Counter; use crate::gauge::Gauge; @@ -359,27 +393,27 @@ test_histogram_count{a="1"} 1 use std::str; let mut metric_family = MetricFamily::default(); - metric_family.set_name("test_summary".to_string()); - metric_family.set_help("This is a test summary statistic".to_string()); - metric_family.set_field_type(MetricType::SUMMARY); + metric_family.name = Some("test_summary".to_string()); + metric_family.help = Some("This is a test summary statistic".to_string()); + metric_family.r#type = Some(MetricType::Summary.into()); let mut summary = Summary::default(); - summary.set_sample_count(5.0 as u64); - summary.set_sample_sum(15.0); + summary.sample_count = Some(5.0 as u64); + summary.sample_sum = Some(15.0); let mut quantile1 = Quantile::default(); - quantile1.set_quantile(50.0); - quantile1.set_value(3.0); + quantile1.quantile = Some(50.0); + quantile1.value = Some(3.0); let mut quantile2 = Quantile::default(); - quantile2.set_quantile(100.0); - quantile2.set_value(5.0); + quantile2.quantile = Some(100.0); + quantile2.value = Some(5.0); - summary.set_quantile(from_vec!(vec!(quantile1, quantile2))); + summary.quantile = vec![quantile1, quantile2]; let mut metric = Metric::default(); - metric.set_summary(summary); - metric_family.set_metric(from_vec!(vec!(metric))); + metric.summary = Some(summary); + metric_family.metric = vec![metric]; let mut writer = Vec::::new(); let encoder = TextEncoder::new(); diff --git a/src/errors.rs b/src/errors.rs index d7298dd9..6bf47d04 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -22,10 +22,10 @@ pub enum Error { /// An error containing a [`std::io::Error`]. #[error("Io error: {0}")] Io(#[from] std::io::Error), - /// An error containing a [`protobuf::error::ProtobufError`]. + /// An error containing a [`prost::EncodeError`]. #[cfg(feature = "protobuf")] #[error("Protobuf error: {0}")] - Protobuf(#[from] protobuf::error::ProtobufError), + Protobuf(#[from] prost::EncodeError), } /// A specialized Result type for prometheus. diff --git a/src/gauge.rs b/src/gauge.rs index 83eba2b1..d09ccec2 100644 --- a/src/gauge.rs +++ b/src/gauge.rs @@ -154,7 +154,7 @@ impl GenericGaugeVec

{ pub fn new(opts: Opts, label_names: &[&str]) -> Result { let variable_names = label_names.iter().map(|s| (*s).to_owned()).collect(); let opts = opts.variable_labels(variable_names); - let metric_vec = MetricVec::create(proto::MetricType::GAUGE, GaugeVecBuilder::new(), opts)?; + let metric_vec = MetricVec::create(proto::MetricType::Gauge, GaugeVecBuilder::new(), opts)?; Ok(metric_vec as Self) } @@ -188,9 +188,9 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - assert_eq!(m.get_label().len(), 2); - assert_eq!(m.get_gauge().get_value() as u64, 42); + let m = mf.metric.get(0).unwrap(); + assert_eq!(m.label.len(), 2); + assert_eq!(m.gauge.as_ref().unwrap().value.unwrap_or(0.0) as u64, 42); } #[test] diff --git a/src/histogram.rs b/src/histogram.rs index a11e7026..30ac0a07 100644 --- a/src/histogram.rs +++ b/src/histogram.rs @@ -334,7 +334,9 @@ impl HistogramCore { check_bucket_label(name)?; } for pair in &desc.const_label_pairs { - check_bucket_label(pair.get_name())?; + if let Some(name) = &pair.name { + check_bucket_label(name)?; + } } let label_pairs = make_label_pairs(&desc, label_values)?; @@ -433,9 +435,11 @@ impl HistogramCore { // interfere with previous or upcoming collect calls. let cold_shard_sum = cold_shard.sum.swap(0.0, Ordering::AcqRel); - let mut h = proto::Histogram::default(); - h.set_sample_sum(cold_shard_sum); - h.set_sample_count(overall_count); + let mut h = proto::Histogram { + sample_sum: Some(cold_shard_sum), + sample_count: Some(overall_count), + ..Default::default() + }; let mut cumulative_count = 0; let mut buckets = Vec::with_capacity(self.upper_bounds.len()); @@ -448,12 +452,12 @@ impl HistogramCore { hot_shard.buckets[i].inc_by(cold_bucket_count); cumulative_count += cold_bucket_count; - let mut b = proto::Bucket::default(); - b.set_cumulative_count(cumulative_count); - b.set_upper_bound(*upper_bound); - buckets.push(b); + buckets.push(proto::Bucket { + cumulative_count: Some(cumulative_count), + upper_bound: Some(*upper_bound), + }); } - h.set_bucket(from_vec!(buckets)); + h.bucket = buckets; // Update the hot shard. hot_shard.count.inc_by(overall_count); @@ -749,13 +753,11 @@ impl Histogram { impl Metric for Histogram { fn metric(&self) -> proto::Metric { - let mut m = proto::Metric::default(); - m.set_label(from_vec!(self.core.label_pairs.clone())); - - let h = self.core.proto(); - m.set_histogram(h); - - m + proto::Metric { + label: self.core.label_pairs.clone(), + histogram: Some(self.core.proto()), + ..Default::default() + } } } @@ -765,11 +767,12 @@ impl Collector for Histogram { } fn collect(&self) -> Vec { - let mut m = proto::MetricFamily::default(); - m.set_name(self.core.desc.fq_name.clone()); - m.set_help(self.core.desc.help.clone()); - m.set_field_type(proto::MetricType::HISTOGRAM); - m.set_metric(from_vec!(vec![self.metric()])); + let m = proto::MetricFamily { + name: Some(self.core.desc.fq_name.clone()), + help: Some(self.core.desc.help.clone()), + r#type: Some(proto::MetricType::Histogram.into()), + metric: vec![self.metric()], + }; vec![m] } @@ -801,7 +804,7 @@ impl HistogramVec { let variable_names = label_names.iter().map(|s| (*s).to_owned()).collect(); let opts = opts.variable_labels(variable_names); let metric_vec = - MetricVec::create(proto::MetricType::HISTOGRAM, HistogramVecBuilder {}, opts)?; + MetricVec::create(proto::MetricType::Histogram, HistogramVecBuilder {}, opts)?; Ok(metric_vec as HistogramVec) } @@ -1236,12 +1239,12 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - assert_eq!(m.get_label().len(), 2); - let proto_histogram = m.get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), 3); - assert!(proto_histogram.get_sample_sum() >= 1.5); - assert_eq!(proto_histogram.get_bucket().len(), DEFAULT_BUCKETS.len()); + let m = mf.metric.get(0).unwrap(); + assert_eq!(m.label.len(), 2); + let proto_histogram = m.histogram.as_ref().unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), 3); + assert!(proto_histogram.sample_sum.unwrap_or(0.0) >= 1.5); + assert_eq!(proto_histogram.bucket.len(), DEFAULT_BUCKETS.len()); let buckets = vec![1.0, 2.0, 3.0]; let opts = HistogramOpts::new("test2", "test help").buckets(buckets.clone()); @@ -1250,12 +1253,12 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - assert_eq!(m.get_label().len(), 0); - let proto_histogram = m.get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), 0); - assert!((proto_histogram.get_sample_sum() - 0.0) < EPSILON); - assert_eq!(proto_histogram.get_bucket().len(), buckets.len()) + let m = mf.metric.get(0).unwrap(); + assert_eq!(m.label.len(), 0); + let proto_histogram = m.histogram.as_ref().unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), 0); + assert!((proto_histogram.sample_sum.unwrap_or(0.0) - 0.0) < EPSILON); + assert_eq!(proto_histogram.bucket.len(), buckets.len()) } #[test] @@ -1283,10 +1286,10 @@ mod tests { assert_eq!(mfs.len(), 1); let mf = mfs.pop().unwrap(); - let m = mf.get_metric().get(0).unwrap(); - let proto_histogram = m.get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), 3); - assert!((proto_histogram.get_sample_sum() - 0.0) > EPSILON); + let m = mf.metric.get(0).unwrap(); + let proto_histogram = m.histogram.as_ref().unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), 3); + assert!((proto_histogram.sample_sum.unwrap_or(0.0) - 0.0) > EPSILON); } #[test] @@ -1400,12 +1403,12 @@ mod tests { histogram.observe(1.0); let m = histogram.metric(); - assert_eq!(m.get_label().len(), labels.len()); + assert_eq!(m.label.len(), labels.len()); - let proto_histogram = m.get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), 1); - assert!((proto_histogram.get_sample_sum() - 1.0) < EPSILON); - assert_eq!(proto_histogram.get_bucket().len(), buckets.len()) + let proto_histogram = m.histogram.unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), 1); + assert!((proto_histogram.sample_sum.unwrap_or(0.0) - 1.0) < EPSILON); + assert_eq!(proto_histogram.bucket.len(), buckets.len()) } #[test] @@ -1418,9 +1421,9 @@ mod tests { let check = |count, sum| { let m = histogram.metric(); - let proto_histogram = m.get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), count); - assert!((proto_histogram.get_sample_sum() - sum) < EPSILON); + let proto_histogram = m.histogram.unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), count); + assert!((proto_histogram.sample_sum.unwrap_or(0.0) - sum) < EPSILON); }; local.observe(1.0); @@ -1452,10 +1455,10 @@ mod tests { local_vec.remove_label_values(&["v1", "v2"]).unwrap_err(); let check = |count, sum| { - let ms = vec.collect()[0].take_metric(); - let proto_histogram = ms[0].get_histogram(); - assert_eq!(proto_histogram.get_sample_count(), count); - assert!((proto_histogram.get_sample_sum() - sum) < EPSILON); + let ms = &vec.collect()[0].metric; + let proto_histogram = &ms[0].histogram.as_ref().unwrap(); + assert_eq!(proto_histogram.sample_count.unwrap_or(0), count); + assert!((proto_histogram.sample_sum.unwrap_or(0.0) - sum) < EPSILON); }; { @@ -1509,13 +1512,13 @@ mod tests { let mut cumulative_count = 0; let mut sample_sum = 0; for _ in 0..1_000_000 { - let metric = &histogram.collect()[0].take_metric()[0]; - let proto = metric.get_histogram(); + let metric = &histogram.collect()[0].metric[0]; + let proto = metric.histogram.as_ref().unwrap(); - sample_count = proto.get_sample_count(); - sample_sum = proto.get_sample_sum() as u64; + sample_count = proto.sample_count.unwrap_or(0); + sample_sum = proto.sample_sum.unwrap_or(0.0) as u64; // There is only one bucket thus the `[0]`. - cumulative_count = proto.get_bucket()[0].get_cumulative_count(); + cumulative_count = proto.bucket[0].cumulative_count.unwrap_or(0); if sample_count != cumulative_count { break; diff --git a/src/lib.rs b/src/lib.rs index a3bb9f68..451ba0bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,8 +104,10 @@ additional functionality. This library supports four features: -* `gen`: To generate protobuf client with the latest protobuf version instead of - using the pre-generated client. +* `protobuf`: Enable [Protocol Buffers](https://developers.google.com/protocol-buffers/) (aka Protobuf) based exposition format. (Enabled by default) + +> Notice: Since version 2.0, Prometheus no longer supports the Protobuf-based format. You can read about the reasoning behind this change in [this document](https://github.com/OpenObservability/OpenMetrics/blob/master/legacy/markdown/protobuf_vs_text.md). + * `nightly`: Enable nightly only features. * `process`: For collecting process info. * `push`: Enable push support. @@ -123,28 +125,15 @@ This library supports four features: /// Protocol buffers format of metrics. #[cfg(feature = "protobuf")] #[allow(warnings)] -#[rustfmt::skip] -#[path = "../proto/proto_model.rs"] -pub mod proto; - -#[cfg(feature = "protobuf")] -macro_rules! from_vec { - ($e: expr) => { - ::protobuf::RepeatedField::from_vec($e) - }; +#[allow(missing_docs)] +pub mod proto { + include!(concat!(env!("OUT_DIR"), "/io.prometheus.client.rs")); } #[cfg(not(feature = "protobuf"))] #[path = "plain_model.rs"] pub mod proto; -#[cfg(not(feature = "protobuf"))] -macro_rules! from_vec { - ($e: expr) => { - $e - }; -} - #[macro_use] extern crate cfg_if; #[macro_use] diff --git a/src/metrics.rs b/src/metrics.rs index e3337b81..f4a3fbc2 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -177,7 +177,7 @@ impl Describer for Opts { impl Ord for LabelPair { fn cmp(&self, other: &LabelPair) -> Ordering { - self.get_name().cmp(other.get_name()) + self.name.cmp(&other.name) } } @@ -221,8 +221,8 @@ mod tests { fn new_label_pair(name: &str, value: &str) -> LabelPair { let mut l = LabelPair::default(); - l.set_name(name.to_owned()); - l.set_value(value.to_owned()); + l.name = Some(name.to_owned()); + l.value = Some(value.to_owned()); l } diff --git a/src/plain_model.rs b/src/plain_model.rs index 868a9eed..e65908b9 100644 --- a/src/plain_model.rs +++ b/src/plain_model.rs @@ -7,413 +7,101 @@ #[derive(PartialEq, Clone, Default, Debug)] pub struct LabelPair { - name: String, - value: String, -} - -impl LabelPair { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> LabelPair { - Default::default() - } - - #[deprecated( - note = "This method is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn clear_name(&mut self) { - self.name.clear(); - } - - pub fn set_name(&mut self, v: String) { - self.name = v; - } - - pub fn get_name(&self) -> &str { - &self.name - } - - pub fn set_value(&mut self, v: String) { - self.value = v; - } - - pub fn get_value(&self) -> &str { - &self.value - } + pub name: Option, + pub value: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Gauge { - value: f64, -} - -impl Gauge { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Gauge { - Default::default() - } - - pub fn set_value(&mut self, v: f64) { - self.value = v; - } - - pub fn get_value(&self) -> f64 { - self.value - } + pub value: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Counter { - value: f64, -} - -impl Counter { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Counter { - Default::default() - } - - // Param is passed by value, moved - pub fn set_value(&mut self, v: f64) { - self.value = v; - } - - pub fn get_value(&self) -> f64 { - self.value - } + pub value: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Quantile { - quantile: f64, - value: f64, -} - -impl Quantile { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Quantile { - Default::default() - } - - pub fn set_quantile(&mut self, v: f64) { - self.quantile = v; - } - - pub fn get_quantile(&self) -> f64 { - self.quantile - } - - pub fn set_value(&mut self, v: f64) { - self.value = v; - } - - pub fn get_value(&self) -> f64 { - self.value - } + pub quantile: Option, + pub value: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Summary { - sample_count: u64, - sample_sum: f64, - quantile: Vec, -} - -impl Summary { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Summary { - Default::default() - } - - pub fn set_sample_count(&mut self, v: u64) { - self.sample_count = v; - } - - pub fn get_sample_count(&self) -> u64 { - self.sample_count - } - - pub fn set_sample_sum(&mut self, v: f64) { - self.sample_sum = v; - } - - pub fn get_sample_sum(&self) -> f64 { - self.sample_sum - } - - pub fn set_quantile(&mut self, v: Vec) { - self.quantile = v; - } - - pub fn get_quantile(&self) -> &[Quantile] { - &self.quantile - } + pub sample_count: Option, + pub sample_sum: Option, + pub quantile: Vec, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Untyped { - value: f64, -} - -impl Untyped { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Untyped { - Default::default() - } - - #[deprecated( - note = "Untyped struct is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn set_value(&mut self, v: f64) { - self.value = v; - } - - #[deprecated( - note = "Untyped struct is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn get_value(&self) -> f64 { - self.value - } + pub value: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Histogram { - sample_count: u64, - sample_sum: f64, - bucket: Vec, -} - -impl Histogram { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Histogram { - Default::default() - } - - pub fn set_sample_count(&mut self, v: u64) { - self.sample_count = v; - } - - pub fn get_sample_count(&self) -> u64 { - self.sample_count - } - - pub fn set_sample_sum(&mut self, v: f64) { - self.sample_sum = v; - } - - pub fn get_sample_sum(&self) -> f64 { - self.sample_sum - } - - pub fn set_bucket(&mut self, v: Vec) { - self.bucket = v; - } - - pub fn get_bucket(&self) -> &[Bucket] { - &self.bucket - } + pub sample_count: Option, + pub sample_sum: Option, + pub bucket: Vec, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Bucket { - cumulative_count: u64, - upper_bound: f64, -} - -impl Bucket { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Bucket { - Default::default() - } - - pub fn set_cumulative_count(&mut self, v: u64) { - self.cumulative_count = v; - } - - pub fn get_cumulative_count(&self) -> u64 { - self.cumulative_count - } - - pub fn set_upper_bound(&mut self, v: f64) { - self.upper_bound = v; - } - - pub fn get_upper_bound(&self) -> f64 { - self.upper_bound - } + pub cumulative_count: Option, + pub upper_bound: Option, } #[derive(PartialEq, Clone, Default, Debug)] pub struct Metric { // message fields - label: Vec, - gauge: Gauge, - counter: Counter, - summary: Summary, - untyped: Untyped, - histogram: Histogram, - timestamp_ms: i64, -} - -impl Metric { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> Metric { - Default::default() - } - - pub fn set_label(&mut self, v: Vec) { - self.label = v; - } - - pub fn mut_label(&mut self) -> &mut [LabelPair] { - &mut self.label - } - - pub fn take_label(&mut self) -> Vec { - ::std::mem::replace(&mut self.label, Vec::new()) - } - - pub fn get_label(&self) -> &[LabelPair] { - &self.label - } - - pub fn set_gauge(&mut self, v: Gauge) { - self.gauge = v; - } - - pub fn get_gauge(&self) -> &Gauge { - &self.gauge - } - - pub fn set_counter(&mut self, v: Counter) { - self.counter = v; - } - - pub fn get_counter(&self) -> &Counter { - &self.counter - } - - pub fn set_summary(&mut self, v: Summary) { - self.summary = v; - } - - pub fn get_summary(&self) -> &Summary { - &self.summary - } - - #[deprecated( - note = "This method is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn set_untyped(&mut self, v: Untyped) { - self.untyped = v; - } - - #[deprecated( - note = "This method is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn get_untyped(&self) -> &Untyped { - &self.untyped - } - - pub fn set_histogram(&mut self, v: Histogram) { - self.histogram = v; - } - - pub fn get_histogram(&self) -> &Histogram { - &self.histogram - } - - pub fn set_timestamp_ms(&mut self, v: i64) { - self.timestamp_ms = v; - } - - pub fn get_timestamp_ms(&self) -> i64 { - self.timestamp_ms - } + pub label: Vec, + pub gauge: Option, + pub counter: Option, + pub summary: Option

, + pub untyped: Option, + pub histogram: Option, + pub timestamp_ms: Option, } #[derive(Clone, PartialEq, Eq, Debug, Hash, Copy)] pub enum MetricType { - COUNTER, - GAUGE, - SUMMARY, - UNTYPED, - HISTOGRAM, + Counter = 0, + Gauge = 1, + Summary = 2, + Untyped = 3, + Histogram = 4, } -impl Default for MetricType { - fn default() -> Self { - MetricType::COUNTER +impl MetricType { + pub fn from_i32(value: i32) -> Option { + match value { + 0 => Some(Self::Counter), + 1 => Some(Self::Gauge), + 2 => Some(Self::Summary), + 3 => Some(Self::Untyped), + 4 => Some(Self::Histogram), + _ => None, + } } } -#[derive(PartialEq, Clone, Default, Debug)] -pub struct MetricFamily { - name: String, - help: String, - field_type: MetricType, - metric: Vec, -} - -impl MetricFamily { - #[deprecated(note = "Use default()", since = "0.5.1")] - pub fn new() -> MetricFamily { - Default::default() - } - - pub fn clear_name(&mut self) { - self.name.clear(); - } - - pub fn set_name(&mut self, v: String) { - self.name = v; - } - - pub fn get_name(&self) -> &str { - &self.name - } - - pub fn set_help(&mut self, v: String) { - self.help = v; - } - - pub fn get_help(&self) -> &str { - &self.help - } - - pub fn set_field_type(&mut self, v: MetricType) { - self.field_type = v; - } - - pub fn get_field_type(&self) -> MetricType { - self.field_type - } - - #[deprecated( - note = "This method is protobuf specific and will be removed in a future version", - since = "0.5.1" - )] - pub fn clear_metric(&mut self) { - self.metric.clear(); - } - - pub fn set_metric(&mut self, v: Vec) { - self.metric = v; - } - - pub fn mut_metric(&mut self) -> &mut Vec { - &mut self.metric +impl Default for MetricType { + fn default() -> Self { + MetricType::Counter } +} - pub fn take_metric(&mut self) -> Vec { - ::std::mem::replace(&mut self.metric, Vec::new()) +impl From for i32 { + fn from(value: MetricType) -> Self { + value as i32 } +} - pub fn get_metric(&self) -> &[Metric] { - &self.metric - } +#[derive(PartialEq, Clone, Default, Debug)] +pub struct MetricFamily { + pub name: Option, + pub help: Option, + pub r#type: Option, + pub metric: Vec, } diff --git a/src/push.rs b/src/push.rs index 80a253a6..587d739c 100644 --- a/src/push.rs +++ b/src/push.rs @@ -123,22 +123,25 @@ fn push( for mf in mfs { // Check for pre-existing grouping labels: - for m in mf.get_metric() { - for lp in m.get_label() { - if lp.get_name() == LABEL_NAME_JOB { - return Err(Error::Msg(format!( - "pushed metric {} already contains a \ - job label", - mf.get_name() - ))); - } - if grouping.contains_key(lp.get_name()) { - return Err(Error::Msg(format!( - "pushed metric {} already contains \ - grouping label {}", - mf.get_name(), - lp.get_name() - ))); + for m in &mf.metric { + for lp in &m.label { + if let Some(name) = &lp.name { + if name == LABEL_NAME_JOB { + return Err(Error::Msg(format!( + "pushed metric {} already contains a \ + job label", + mf.name.unwrap_or("".into()), + ))); + } + + if grouping.contains_key(name.as_str()) { + return Err(Error::Msg(format!( + "pushed metric {} already contains \ + grouping label {}", + mf.name.unwrap_or("".into()), + name, + ))); + } } } } @@ -272,12 +275,12 @@ mod tests { ]; for case in table { - let mut l = proto::LabelPair::new(); - l.set_name(case.0.to_owned()); - let mut m = proto::Metric::new(); - m.set_label(from_vec!(vec![l])); - let mut mf = proto::MetricFamily::new(); - mf.set_metric(from_vec!(vec![m])); + let mut l = proto::LabelPair::default(); + l.name = Some(case.0.to_owned()); + let mut m = proto::Metric::default(); + m.label = vec![l]; + let mut mf = proto::MetricFamily::default(); + mf.metric = vec![m]; let res = push_metrics("test", hostname_grouping_key(), "mockurl", vec![mf], None); assert!(format!("{}", res.unwrap_err()).contains(case.1)); } diff --git a/src/registry.rs b/src/registry.rs index 97528e69..f7522f7a 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -117,24 +117,27 @@ impl RegistryCore { for c in self.collectors_by_id.values() { let mfs = c.collect(); - for mut mf in mfs { + for mf in mfs { // Prune empty MetricFamilies. - if mf.get_metric().is_empty() { + if mf.metric.is_empty() { continue; } - let name = mf.get_name().to_owned(); + let name = match &mf.name { + Some(v) => v.to_owned(), + None => "".to_owned(), + }; match mf_by_name.entry(name) { BEntry::Vacant(entry) => { entry.insert(mf); } BEntry::Occupied(mut entry) => { let existent_mf = entry.get_mut(); - let existent_metrics = existent_mf.mut_metric(); + let existent_metrics = &mut existent_mf.metric; // TODO: check type. // TODO: check consistency. - for metric in mf.take_metric().into_iter() { + for metric in mf.metric.into_iter() { existent_metrics.push(metric); } } @@ -147,9 +150,9 @@ impl RegistryCore { // Now that MetricFamilies are all set, sort their Metrics // lexicographically by their label values. for mf in mf_by_name.values_mut() { - mf.mut_metric().sort_by(|m1, m2| { - let lps1 = m1.get_label(); - let lps2 = m2.get_label(); + mf.metric.sort_by(|m1, m2| { + let lps1 = &m1.label; + let lps2 = &m2.label; if lps1.len() != lps2.len() { // This should not happen. The metrics are @@ -162,8 +165,8 @@ impl RegistryCore { } for (lp1, lp2) in lps1.iter().zip(lps2.iter()) { - if lp1.get_value() != lp2.get_value() { - return lp1.get_value().cmp(lp2.get_value()); + if lp1.value != lp2.value { + return lp1.value.cmp(&lp2.value); } } @@ -173,7 +176,7 @@ impl RegistryCore { // here, even for inconsistent metrics. So sort equal metrics // by their timestamp, with missing timestamps (implying "now") // coming last. - m1.get_timestamp_ms().cmp(&m2.get_timestamp_ms()) + m1.timestamp_ms.cmp(&m2.timestamp_ms) }); } @@ -183,26 +186,24 @@ impl RegistryCore { .map(|(_, mut m)| { // Add registry namespace prefix, if any. if let Some(ref namespace) = self.prefix { - let prefixed = format!("{}_{}", namespace, m.get_name()); - m.set_name(prefixed); + let prefixed = format!("{}_{}", namespace, m.name.unwrap_or_default()); + m.name = Some(prefixed); } // Add registry common labels, if any. if let Some(ref hmap) = self.labels { let pairs: Vec = hmap .iter() - .map(|(k, v)| { - let mut label = proto::LabelPair::default(); - label.set_name(k.to_string()); - label.set_value(v.to_string()); - label + .map(|(k, v)| proto::LabelPair { + name: Some(k.to_string()), + value: Some(v.to_string()), }) .collect(); - for metric in m.mut_metric().iter_mut() { - let mut labels: Vec<_> = metric.take_label().into(); + for metric in &mut m.metric.iter_mut() { + let mut labels: Vec<_> = std::mem::replace(&mut metric.label, Vec::new()); labels.append(&mut pairs.clone()); - metric.set_label(labels.into()); + metric.label = labels; } } m @@ -413,9 +414,9 @@ mod tests { let mfs = r.gather(); assert_eq!(mfs.len(), 3); - assert_eq!(mfs[0].get_name(), "test_2_counter"); - assert_eq!(mfs[1].get_name(), "test_a_counter"); - assert_eq!(mfs[2].get_name(), "test_b_counter"); + assert_eq!(mfs[0].name, Some("test_2_counter".into())); + assert_eq!(mfs[1].name, Some("test_a_counter".into())); + assert_eq!(mfs[2].name, Some("test_b_counter".into())); let r = Registry::new(); let opts = Opts::new("test", "test help") @@ -467,12 +468,12 @@ mod tests { let mfs = r.gather(); assert_eq!(mfs.len(), 1); - let ms = mfs[0].get_metric(); + let ms = &mfs[0].metric; assert_eq!(ms.len(), 4); - assert_eq!(ms[0].get_counter().get_value() as u64, 2); - assert_eq!(ms[1].get_counter().get_value() as u64, 1); - assert_eq!(ms[2].get_counter().get_value() as u64, 3); - assert_eq!(ms[3].get_counter().get_value() as u64, 4); + assert_eq!(ms[0].counter.as_ref().unwrap().value.unwrap() as u64, 2); + assert_eq!(ms[1].counter.as_ref().unwrap().value.unwrap() as u64, 1); + assert_eq!(ms[2].counter.as_ref().unwrap().value.unwrap() as u64, 3); + assert_eq!(ms[3].counter.as_ref().unwrap().value.unwrap() as u64, 4); } #[test] @@ -485,7 +486,7 @@ mod tests { let mfs = r.gather(); assert_eq!(mfs.len(), 1); - assert_eq!(mfs[0].get_name(), "common_prefix_test_a_counter"); + assert_eq!(mfs[0].name, Some("common_prefix_test_a_counter".into())); } #[test] @@ -505,19 +506,19 @@ mod tests { let mfs = r.gather(); assert_eq!(mfs.len(), 2); - assert_eq!(mfs[0].get_name(), "test_a_counter"); - assert_eq!(mfs[1].get_name(), "test_vec"); + assert_eq!(mfs[0].name, Some("test_a_counter".into())); + assert_eq!(mfs[1].name, Some("test_vec".into())); let mut needle = proto::LabelPair::default(); - needle.set_name("tkey".to_string()); - needle.set_value("tvalue".to_string()); - let metrics = mfs[0].get_metric(); + needle.name = Some("tkey".to_string()); + needle.value = Some("tvalue".to_string()); + let metrics = &mfs[0].metric; for m in metrics { - assert!(m.get_label().contains(&needle)); + assert!(m.label.contains(&needle)); } - let metrics = mfs[1].get_metric(); + let metrics = &mfs[1].metric; for m in metrics { - assert!(m.get_label().contains(&needle)); + assert!(m.label.contains(&needle)); } } diff --git a/src/value.rs b/src/value.rs index 87b2ede2..2de74341 100644 --- a/src/value.rs +++ b/src/value.rs @@ -18,8 +18,8 @@ impl ValueType { /// `metric_type` returns the corresponding proto metric type. pub fn metric_type(self) -> MetricType { match self { - ValueType::Counter => MetricType::COUNTER, - ValueType::Gauge => MetricType::GAUGE, + ValueType::Counter => MetricType::Counter, + ValueType::Gauge => MetricType::Gauge, } } } @@ -85,20 +85,22 @@ impl Value

{ } pub fn metric(&self) -> Metric { - let mut m = Metric::default(); - m.set_label(from_vec!(self.label_pairs.clone())); + let mut m = Metric { + label: self.label_pairs.clone(), + ..Default::default() + }; let val = self.get(); match self.val_type { ValueType::Counter => { - let mut counter = Counter::default(); - counter.set_value(val.into_f64()); - m.set_counter(counter); + m.counter = Some(Counter { + value: Some(val.into_f64()), + }); } ValueType::Gauge => { - let mut gauge = Gauge::default(); - gauge.set_value(val.into_f64()); - m.set_gauge(gauge); + m.gauge = Some(Gauge { + value: Some(val.into_f64()), + }); } } @@ -106,12 +108,12 @@ impl Value

{ } pub fn collect(&self) -> MetricFamily { - let mut m = MetricFamily::default(); - m.set_name(self.desc.fq_name.clone()); - m.set_help(self.desc.help.clone()); - m.set_field_type(self.val_type.metric_type()); - m.set_metric(from_vec!(vec![self.metric()])); - m + MetricFamily { + name: Some(self.desc.fq_name.clone()), + help: Some(self.desc.help.clone()), + r#type: Some(self.val_type.metric_type().into()), + metric: vec![self.metric()], + } } } @@ -134,10 +136,10 @@ pub fn make_label_pairs(desc: &Desc, label_values: &[&str]) -> Result { impl MetricVecCore { pub fn collect(&self) -> MetricFamily { - let mut m = MetricFamily::default(); - m.set_name(self.desc.fq_name.clone()); - m.set_help(self.desc.help.clone()); - m.set_field_type(self.metric_type); - let children = self.children.read(); let mut metrics = Vec::with_capacity(children.len()); for child in children.values() { metrics.push(child.metric()); } - m.set_metric(from_vec!(metrics)); - m + MetricFamily { + name: Some(self.desc.fq_name.clone()), + help: Some(self.desc.help.clone()), + r#type: Some(self.metric_type.into()), + metric: metrics, + } } pub fn get_metric_with_label_values(&self, vals: &[&str]) -> Result { @@ -425,10 +424,13 @@ mod tests { labels.insert("c", "a"); let c = vec.get_metric_with(&labels).unwrap(); let m = c.metric(); - let label_pairs = m.get_label(); + let label_pairs = m.label; assert_eq!(label_pairs.len(), labels.len()); for lp in label_pairs.iter() { - assert_eq!(lp.get_value(), labels[lp.get_name()]); + assert_eq!( + lp.value.as_ref().unwrap(), + labels[lp.name.as_ref().unwrap().as_str()] + ); } } }