cargo: upgrade to protobuf 3.7 (#541)

* feat!: upgrade to protobuf 3.7

- keep some of the `get_` and `set_` methods around and mark them as deprecated
- keep api changes to a minimal

Signed-off-by: Sven Kanoldt <sven+oss@d34dl0ck.me>

* fix: fix all issues related to api combatibility when the protobuf feature is not enabled

Signed-off-by: Sven Kanoldt <sven+oss@d34dl0ck.me>

* implement review feedback and close all minor remarks

Signed-off-by: Sven Kanoldt <sven+oss@d34dl0ck.me>

* fix ci errors

Signed-off-by: Sven Kanoldt <sven@d34dl0ck.me>

---------

Signed-off-by: Sven Kanoldt <sven+oss@d34dl0ck.me>
Signed-off-by: Sven Kanoldt <sven@d34dl0ck.me>
This commit is contained in:
Sven Kanoldt 2025-03-19 10:21:43 +01:00 committed by GitHub
parent 7e4e6f2d33
commit c3865f3c40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 1426 additions and 1529 deletions

View File

@ -17,7 +17,7 @@ features = ["nightly"]
[features]
default = ["protobuf"]
gen = ["protobuf-codegen-pure"]
gen = ["protobuf-codegen"]
nightly = ["libc"]
process = ["libc", "procfs"]
push = ["reqwest", "libc", "protobuf"]
@ -28,7 +28,7 @@ fnv = "^1.0"
lazy_static = "^1.4"
libc = { version = "^0.2", optional = true }
parking_lot = "^0.12"
protobuf = { version = "^2.0", optional = true }
protobuf = { version = "^3.7.2", optional = true }
memchr = "^2.3"
reqwest = { version = "^0.12", features = ["blocking"], optional = true }
thiserror = "^2.0"
@ -43,7 +43,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 }
protobuf-codegen = { version = "^3.7.2", optional = true }
[workspace]
members = ["static-metric"]

View File

@ -2,13 +2,12 @@
#[cfg(feature = "gen")]
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();
protobuf_codegen::Codegen::new()
.out_dir("proto")
.inputs(["proto/proto_model.proto"])
.includes(["proto"])
.run()
.expect("Protobuf codegen failed");
}
#[cfg(not(feature = "gen"))]

3
proto/mod.rs Normal file
View File

@ -0,0 +1,3 @@
// @generated
pub mod proto_model;

File diff suppressed because it is too large Load Diff

View File

@ -327,6 +327,8 @@ mod tests {
use super::*;
use crate::metrics::{Collector, Opts};
#[cfg(feature = "protobuf")]
use crate::proto_ext::MessageFieldExt;
#[test]
fn test_counter() {

View File

@ -30,7 +30,7 @@ fn check_metric_family(mf: &MetricFamily) -> Result<()> {
if mf.get_metric().is_empty() {
return Err(Error::Msg(format!("MetricFamily has no metrics: {:?}", mf)));
}
if mf.get_name().is_empty() {
if mf.name().is_empty() {
return Err(Error::Msg(format!("MetricFamily has no name: {:?}", mf)));
}
Ok(())

View File

@ -6,6 +6,8 @@ use std::io::{self, Write};
use crate::errors::Result;
use crate::histogram::BUCKET_LABEL;
use crate::proto::{self, MetricFamily, MetricType};
#[cfg(feature = "protobuf")]
use crate::proto_ext::MessageFieldExt;
use super::{check_metric_family, Encoder};
@ -55,8 +57,8 @@ impl TextEncoder {
check_metric_family(mf)?;
// Write `# HELP` header.
let name = mf.get_name();
let help = mf.get_help();
let name = mf.name();
let help = mf.help();
if !help.is_empty() {
writer.write_all("# HELP ")?;
writer.write_all(name)?;
@ -87,14 +89,14 @@ impl TextEncoder {
let mut inf_seen = false;
for b in h.get_bucket() {
let upper_bound = b.get_upper_bound();
let upper_bound = b.upper_bound();
write_sample(
writer,
name,
Some("_bucket"),
m,
Some((BUCKET_LABEL, &upper_bound.to_string())),
b.get_cumulative_count() as f64,
b.cumulative_count() as f64,
)?;
if upper_bound.is_sign_positive() && upper_bound.is_infinite() {
inf_seen = true;
@ -125,18 +127,18 @@ impl TextEncoder {
MetricType::SUMMARY => {
let s = m.get_summary();
for q in s.get_quantile() {
for q in s.get_quantile().iter() {
write_sample(
writer,
name,
None,
m,
Some((QUANTILE, &q.get_quantile().to_string())),
q.get_value(),
Some((QUANTILE, &q.quantile().to_string())),
q.value(),
)?;
}
write_sample(writer, name, Some("_sum"), m, None, s.get_sample_sum())?;
write_sample(writer, name, Some("_sum"), m, None, s.sample_sum())?;
write_sample(
writer,
@ -144,7 +146,7 @@ impl TextEncoder {
Some("_count"),
m,
None,
s.get_sample_count() as f64,
s.sample_count() as f64,
)?;
}
MetricType::UNTYPED => {
@ -191,7 +193,7 @@ fn write_sample(
writer.write_all(" ")?;
writer.write_all(&value.to_string())?;
let timestamp = mc.get_timestamp_ms();
let timestamp = mc.timestamp_ms();
if timestamp != 0 {
writer.write_all(" ")?;
writer.write_all(&timestamp.to_string())?;
@ -221,9 +223,9 @@ fn label_pairs_to_text(
let mut separator = "{";
for lp in pairs {
writer.write_all(separator)?;
writer.write_all(lp.get_name())?;
writer.write_all(lp.name())?;
writer.write_all("=\"")?;
writer.write_all(&escape_string(lp.get_value(), true))?;
writer.write_all(&escape_string(lp.value(), true))?;
writer.write_all("\"")?;
separator = ",";
@ -423,11 +425,11 @@ test_histogram_count{a="1"} 1
quantile2.set_quantile(100.0);
quantile2.set_value(5.0);
summary.set_quantile(from_vec!(vec!(quantile1, quantile2)));
summary.set_quantile(vec![quantile1, quantile2]);
let mut metric = Metric::default();
metric.set_summary(summary);
metric_family.set_metric(from_vec!(vec!(metric)));
metric_family.set_metric(vec![metric]);
let mut writer = Vec::<u8>::new();
let encoder = TextEncoder::new();

View File

@ -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 [`protobuf::Error`].
#[cfg(feature = "protobuf")]
#[error("Protobuf error: {0}")]
Protobuf(#[from] protobuf::error::ProtobufError),
Protobuf(#[from] protobuf::Error),
}
/// A specialized Result type for prometheus.

View File

@ -166,6 +166,8 @@ mod tests {
use super::*;
use crate::metrics::{Collector, Opts};
#[cfg(feature = "protobuf")]
use crate::proto_ext::MessageFieldExt;
#[test]
fn test_gauge() {

View File

@ -334,7 +334,7 @@ impl HistogramCore {
check_bucket_label(name)?;
}
for pair in &desc.const_label_pairs {
check_bucket_label(pair.get_name())?;
check_bucket_label(pair.name())?;
}
let label_pairs = make_label_pairs(&desc, label_values)?;
@ -453,7 +453,7 @@ impl HistogramCore {
b.set_upper_bound(*upper_bound);
buckets.push(b);
}
h.set_bucket(from_vec!(buckets));
h.set_bucket(buckets);
// Update the hot shard.
hot_shard.count.inc_by(overall_count);
@ -750,8 +750,7 @@ 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 mut m = proto::Metric::from_label(self.core.label_pairs.clone());
let h = self.core.proto();
m.set_histogram(h);
@ -770,7 +769,7 @@ impl Collector for Histogram {
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()]));
m.set_metric(vec![self.metric()]);
vec![m]
}
@ -1520,7 +1519,7 @@ mod tests {
sample_count = proto.get_sample_count();
sample_sum = proto.get_sample_sum() as u64;
// There is only one bucket thus the `[0]`.
cumulative_count = proto.get_bucket()[0].get_cumulative_count();
cumulative_count = proto.get_bucket()[0].cumulative_count();
if sample_count != cumulative_count {
break;

View File

@ -129,23 +129,12 @@ This library supports four features:
#[path = "../proto/proto_model.rs"]
pub mod proto;
#[cfg(feature = "protobuf")]
macro_rules! from_vec {
($e: expr) => {
::protobuf::RepeatedField::from_vec($e)
};
}
#[cfg(not(feature = "protobuf"))]
#[path = "plain_model.rs"]
pub mod proto;
#[cfg(not(feature = "protobuf"))]
macro_rules! from_vec {
($e: expr) => {
$e
};
}
#[cfg(feature = "protobuf")]
mod proto_ext;
#[macro_use]
mod macros;

View File

@ -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())
}
}

View File

@ -29,7 +29,13 @@ impl LabelPair {
self.name = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
pub fn get_name(&self) -> &str {
self.name()
}
/// Returns the name of this label pair.
pub fn name(&self) -> &str {
&self.name
}
@ -37,7 +43,13 @@ impl LabelPair {
self.value = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
pub fn get_value(&self) -> &str {
self.value()
}
/// Returns the value of this label pair.
pub fn value(&self) -> &str {
&self.value
}
}
@ -99,7 +111,13 @@ impl Quantile {
self.quantile = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.quantile()` instead")]
pub fn get_quantile(&self) -> f64 {
self.quantile()
}
/// Returns the quantile of this quantile.
pub fn quantile(&self) -> f64 {
self.quantile
}
@ -107,7 +125,13 @@ impl Quantile {
self.value = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
pub fn get_value(&self) -> f64 {
self.value()
}
/// Returns the value of this quantile.
pub fn value(&self) -> f64 {
self.value
}
}
@ -129,15 +153,27 @@ impl Summary {
self.sample_count = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.sample_count()` instead")]
pub fn get_sample_count(&self) -> u64 {
self.sample_count
}
/// Returns the sample count of this summary.
pub fn sample_count(&self) -> u64 {
self.sample_count
}
pub fn set_sample_sum(&mut self, v: f64) {
self.sample_sum = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.sample_sum()` instead")]
pub fn get_sample_sum(&self) -> f64 {
self.sample_sum()
}
/// Returns the sample sum of this summary.
pub fn sample_sum(&self) -> f64 {
self.sample_sum
}
@ -232,7 +268,13 @@ impl Bucket {
self.cumulative_count = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.cumulative_count()` instead")]
pub fn get_cumulative_count(&self) -> u64 {
self.cumulative_count()
}
/// Returns the cumulative count of this bucket.
pub fn cumulative_count(&self) -> u64 {
self.cumulative_count
}
@ -240,7 +282,13 @@ impl Bucket {
self.upper_bound = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.upper_bound()` instead")]
pub fn get_upper_bound(&self) -> f64 {
self.upper_bound()
}
/// Returns the upper bound of this bucket.
pub fn upper_bound(&self) -> f64 {
self.upper_bound
}
}
@ -263,6 +311,22 @@ impl Metric {
Default::default()
}
/// Creates a new metric with the specified label pairs.
pub fn from_label(label: Vec<LabelPair>) -> Self {
Metric {
label,
..Default::default()
}
}
/// Creates a new metric with the specified gauge value.
pub fn from_gauge(gauge: Gauge) -> Self {
Metric {
gauge: gauge.into(),
..Default::default()
}
}
pub fn set_label(&mut self, v: Vec<LabelPair>) {
self.label = v;
}
@ -331,7 +395,13 @@ impl Metric {
self.timestamp_ms = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.timestamp_ms()` instead")]
pub fn get_timestamp_ms(&self) -> i64 {
self.timestamp_ms()
}
/// Returns the timestamp of this metric.
pub fn timestamp_ms(&self) -> i64 {
self.timestamp_ms
}
}
@ -373,7 +443,13 @@ impl MetricFamily {
self.name = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
pub fn get_name(&self) -> &str {
self.name()
}
/// Returns the name of this metric family.
pub fn name(&self) -> &str {
&self.name
}
@ -381,7 +457,13 @@ impl MetricFamily {
self.help = v;
}
#[deprecated(since = "0.14.0", note = "Please use `.help()` instead")]
pub fn get_help(&self) -> &str {
self.help()
}
/// Returns the help text of this metric family.
pub fn help(&self) -> &str {
&self.help
}

265
src/proto_ext.rs Normal file
View File

@ -0,0 +1,265 @@
use protobuf::{EnumOrUnknown, MessageField};
use crate::proto::{
Bucket, Counter, Gauge, Histogram, LabelPair, Metric, MetricFamily, MetricType, Quantile,
Summary,
};
impl Metric {
/// Creates a new metric with the specified label pairs.
pub fn from_label(label: Vec<LabelPair>) -> Self {
Metric {
label,
..Default::default()
}
}
/// Creates a new metric with the specified gauge value.
pub fn from_gauge(gauge: Gauge) -> Self {
Metric {
gauge: gauge.into(),
..Default::default()
}
}
#[deprecated(since = "0.14.0", note = "Please use `.timestamp_ms()` instead")]
/// Returns the timestamp of this metric.
pub fn get_timestamp_ms(&self) -> i64 {
self.timestamp_ms()
}
/// Returns the summary of this metric.
pub fn get_summary(&self) -> &MessageField<Summary> {
&self.summary
}
/// Sets the summary of this metric to the specified summary.
pub fn set_summary(&mut self, summary: Summary) {
self.summary = summary.into();
}
/// Returns the value of the counter for this metric.
pub fn get_counter(&self) -> &MessageField<Counter> {
&self.counter
}
/// Sets the counter of this metric to the specified counter.
pub fn set_counter(&mut self, counter: Counter) {
self.counter = counter.into();
}
/// Returns all label pairs associated with this metric.
pub fn get_label(&self) -> &[LabelPair] {
&self.label
}
/// Sets the label pairs associated with this metric.
pub fn set_label(&mut self, label: Vec<LabelPair>) {
self.label = label;
}
/// Returns all label pairs associated with ownership.
pub fn take_label(&mut self) -> Vec<LabelPair> {
std::mem::take(&mut self.label)
}
/// Returns the gauge of this metric.
pub fn get_gauge(&self) -> &MessageField<Gauge> {
&self.gauge
}
/// Sets the gauge of this metric to the specified gauge.
pub fn set_gauge(&mut self, gauge: Gauge) {
self.gauge = gauge.into();
}
/// Returns the histogram of this metric.
pub fn get_histogram(&self) -> &MessageField<Histogram> {
&self.histogram
}
/// Sets the histogram of this metric to the specified histogram.
pub fn set_histogram(&mut self, histogram: Histogram) {
self.histogram = histogram.into();
}
}
impl MetricFamily {
#[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
/// Returns the name of this metric family.
pub fn get_name(&self) -> &str {
self.name()
}
#[deprecated(since = "0.14.0", note = "Please use `.help()` instead")]
/// Returns the help text of this metric family.
pub fn get_help(&self) -> &str {
self.help()
}
/// Sets the metric for this metric family (replaces any existing metrics).
pub fn set_metric(&mut self, metric: Vec<Metric>) {
self.metric = metric;
}
/// Returns the type of this metric family.
pub fn get_field_type(&self) -> MetricType {
self.type_()
}
/// Sets the type of this metric family.
pub fn set_field_type(&mut self, t: MetricType) {
self.type_ = t.into();
}
/// Returns all metrics in this metric family.
pub fn get_metric(&self) -> &[Metric] {
&self.metric
}
/// Returns all metrics in this metric family mutably.
pub fn mut_metric(&mut self) -> &mut Vec<Metric> {
&mut self.metric
}
/// Returns all metrics in this metric family with taking ownership.
pub fn take_metric(&mut self) -> Vec<Metric> {
std::mem::take(&mut self.metric)
}
}
impl Summary {
/// Sets the quantiles for this summary.
pub fn set_quantile(&mut self, quantiles: Vec<Quantile>) {
self.quantile = quantiles;
}
/// Returns the quantiles of this summary.
pub fn get_quantile(&self) -> &[Quantile] {
&self.quantile
}
#[deprecated(since = "0.14.0", note = "Please use `.sample_count()` instead")]
/// Returns the sample count of this summary.
pub fn get_sample_count(&self) -> u64 {
self.sample_count()
}
#[deprecated(since = "0.14.0", note = "Please use `.sample_sum()` instead")]
/// Returns the sample sum of this summary.
pub fn get_sample_sum(&self) -> f64 {
self.sample_sum()
}
}
impl Quantile {
#[deprecated(since = "0.14.0", note = "Please use `.quantile()` instead")]
/// Returns the quantile of this quantile.
pub fn get_quantile(&self) -> f64 {
self.quantile()
}
#[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
/// Returns the value of this quantile.
pub fn get_value(&self) -> f64 {
self.value()
}
}
pub trait MessageFieldExt {
/// Returns the value of the wrapped gauge.
#[allow(dead_code)]
fn get_value(&self) -> f64;
}
impl MessageFieldExt for MessageField<Gauge> {
fn get_value(&self) -> f64 {
self.value()
}
}
impl MessageFieldExt for MessageField<Counter> {
fn get_value(&self) -> f64 {
self.value()
}
}
impl Histogram {
/// Returns the sample count of this histogram.
pub fn get_sample_count(&self) -> u64 {
self.sample_count.unwrap_or_default()
}
/// Returns the sample sum of this histogram.
pub fn get_sample_sum(&self) -> f64 {
self.sample_sum.unwrap_or_default()
}
/// Returns all buckets in this histogram.
pub fn get_bucket(&self) -> &[Bucket] {
&self.bucket
}
/// Sets the buckets of this histogram.
pub fn set_bucket(&mut self, bucket: Vec<Bucket>) {
self.bucket = bucket;
}
}
impl Bucket {
#[deprecated(since = "0.14.0", note = "Please use `.cumulative_count()` instead")]
/// Returns the cumulative count of this bucket.
pub fn get_cumulative_count(&self) -> u64 {
self.cumulative_count()
}
#[deprecated(since = "0.14.0", note = "Please use `.upper_bound()` instead")]
/// Returns the upper bound of this bucket.
pub fn get_upper_bound(&self) -> f64 {
self.upper_bound()
}
}
impl LabelPair {
#[deprecated(since = "0.14.0", note = "Please use `.value()` instead")]
/// Returns the value of this label pair.
pub fn get_value(&self) -> &str {
self.value()
}
#[deprecated(since = "0.14.0", note = "Please use `.name()` instead")]
/// Returns the name of this label pair.
pub fn get_name(&self) -> &str {
self.name()
}
}
impl From<Counter> for MessageField<Counter> {
fn from(value: Counter) -> Self {
MessageField::some(value)
}
}
impl From<Gauge> for MessageField<Gauge> {
fn from(value: Gauge) -> Self {
MessageField::some(value)
}
}
impl From<Histogram> for MessageField<Histogram> {
fn from(value: Histogram) -> Self {
MessageField::some(value)
}
}
impl From<Summary> for MessageField<Summary> {
fn from(value: Summary) -> Self {
MessageField::some(value)
}
}
impl From<MetricType> for Option<EnumOrUnknown<MetricType>> {
fn from(value: MetricType) -> Self {
Some(EnumOrUnknown::from(value))
}
}

View File

@ -58,10 +58,7 @@ impl PullingGauge {
let getter = &self.value;
gauge.set_value(getter());
let mut metric = Metric::default();
metric.set_gauge(gauge);
metric
Metric::from_gauge(gauge)
}
}
@ -75,7 +72,7 @@ impl Collector for PullingGauge {
m.set_name(self.desc.fq_name.clone());
m.set_help(self.desc.help.clone());
m.set_field_type(MetricType::GAUGE);
m.set_metric(from_vec!(vec![self.metric()]));
m.set_metric(vec![self.metric()]);
vec![m]
}
}
@ -84,6 +81,8 @@ impl Collector for PullingGauge {
mod tests {
use super::*;
use crate::metrics::Collector;
#[cfg(feature = "protobuf")]
use crate::proto_ext::MessageFieldExt;
#[test]
fn test_pulling_gauge() {

View File

@ -277,9 +277,9 @@ mod tests {
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]));
m.set_label(vec![l]);
let mut mf = proto::MetricFamily::new();
mf.set_metric(from_vec!(vec![m]));
mf.set_metric(vec![m]);
let res = push_metrics("test", hostname_grouping_key(), "mockurl", vec![mf], None);
assert!(format!("{}", res.unwrap_err()).contains(case.1));
}

View File

@ -127,7 +127,7 @@ impl RegistryCore {
continue;
}
let name = mf.get_name().to_owned();
let name = mf.name().to_owned();
match mf_by_name.entry(name) {
BEntry::Vacant(entry) => {
entry.insert(mf);
@ -166,8 +166,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());
}
}
@ -177,7 +177,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())
});
}
@ -187,7 +187,7 @@ 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());
let prefixed = format!("{}_{}", namespace, m.name());
m.set_name(prefixed);
}
@ -204,9 +204,9 @@ impl RegistryCore {
.collect();
for metric in m.mut_metric().iter_mut() {
let mut labels: Vec<_> = metric.take_label().into();
let mut labels: Vec<_> = metric.take_label();
labels.append(&mut pairs.clone());
metric.set_label(labels.into());
metric.set_label(labels);
}
}
m
@ -341,7 +341,10 @@ mod tests {
use crate::counter::{Counter, CounterVec};
use crate::desc::Desc;
use crate::metrics::{Collector, Opts};
#[cfg(feature = "protobuf")]
use crate::proto;
#[cfg(feature = "protobuf")]
use crate::proto_ext::MessageFieldExt;
#[test]
fn test_registry() {
@ -401,9 +404,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(), "test_2_counter");
assert_eq!(mfs[1].name(), "test_a_counter");
assert_eq!(mfs[2].name(), "test_b_counter");
let r = Registry::new();
let opts = Opts::new("test", "test help")
@ -473,7 +476,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(), "common_prefix_test_a_counter");
}
#[test]
@ -493,8 +496,8 @@ 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(), "test_a_counter");
assert_eq!(mfs[1].name(), "test_vec");
let mut needle = proto::LabelPair::default();
needle.set_name("tkey".to_string());

View File

@ -85,8 +85,7 @@ impl<P: Atomic> Value<P> {
}
pub fn metric(&self) -> Metric {
let mut m = Metric::default();
m.set_label(from_vec!(self.label_pairs.clone()));
let mut m = Metric::from_label(self.label_pairs.clone());
let val = self.get();
match self.val_type {
@ -110,7 +109,7 @@ impl<P: Atomic> Value<P> {
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.set_metric(vec![self.metric()]);
m
}
}

View File

@ -45,7 +45,7 @@ impl<T: MetricVecBuilder> MetricVecCore<T> {
for child in children.values() {
metrics.push(child.metric());
}
m.set_metric(from_vec!(metrics));
m.set_metric(metrics);
m
}
@ -428,7 +428,7 @@ mod tests {
let label_pairs = m.get_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(), labels[lp.name()]);
}
}
}