Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prometric-derive/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl MetricBuilder {

if let MetricType::Histogram(_) = &self.ty {
let buckets = if let Some(buckets_expr) = buckets {
quote! { Some(#buckets_expr) }
quote! { Some(#buckets_expr.into()) }
} else {
quote! { None }
};
Expand Down
2 changes: 2 additions & 0 deletions prometric-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,13 @@ mod utils;
/// the current process.
///
/// ```rust
/// # #[cfg(feature = "process")] {
/// use prometric::process::ProcessCollector;
/// use prometric_derive::metrics;
///
/// let mut collector = ProcessCollector::default();
/// collector.collect();
/// # }
/// ```
///
/// #### Output
Expand Down
25 changes: 25 additions & 0 deletions prometric-derive/tests/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,28 @@ fn bucket_expressions_work() {

assert!(output.contains("test_hist"));
}

#[test]
fn bucket_defaults_work() {
#[prometric_derive::metrics(scope = "test")]
struct BucketMetrics {
/// Test histogram metric with bucket expression.
#[metric()]
hist: prometric::Histogram,
}

let registry = prometheus::default_registry();
let app_metrics = BucketMetrics::builder().with_registry(registry).build();

let duration = Duration::from_secs(1);
app_metrics.hist().observe(duration.as_secs_f64());

let encoder = prometheus::TextEncoder::new();
let metric_families = registry.gather(); // Wait, need to expose registry

let mut buffer = vec![];
encoder.encode(&metric_families, &mut buffer).unwrap();
let output = String::from_utf8(buffer).unwrap();

assert!(output.contains("test_hist"));
}
6 changes: 3 additions & 3 deletions prometric/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ impl Clone for Histogram {
}

impl Histogram {
pub fn new<B: Into<Vec<f64>>>(
pub fn new(
registry: &prometheus::Registry,
name: &str,
help: &str,
labels: &[&str],
const_labels: HashMap<String, String>,
buckets: Option<B>,
buckets: Option<Vec<f64>>,
) -> Self {
let buckets = buckets.map(Into::into).unwrap_or(prometheus::DEFAULT_BUCKETS.to_vec());
let buckets = buckets.unwrap_or(prometheus::DEFAULT_BUCKETS.to_vec());
let opts =
prometheus::HistogramOpts::new(name, help).const_labels(const_labels).buckets(buckets);
let metric = prometheus::HistogramVec::new(opts, labels).unwrap();
Expand Down
Loading