Skip to content

Commit

Permalink
*: Fix lints and *32 on powerpc
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Nov 28, 2022
1 parent cc2e87c commit e87ef4b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 56 deletions.
6 changes: 3 additions & 3 deletions derive-encode/src/lib.rs
Expand Up @@ -4,14 +4,14 @@
#![forbid(unsafe_code)]
#![warn(missing_debug_implementations)]

//! Derive crate for [`prometheus_client`].
//! Derive crate for `prometheus_client`.

use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::DeriveInput;

/// Derive [`prometheus_client::encoding::EncodeLabelSet`].
/// Derive `prometheus_client::encoding::EncodeLabelSet`.
#[proc_macro_derive(EncodeLabelSet)]
pub fn derive_encode_label_set(input: TokenStream) -> TokenStream {
let ast: DeriveInput = syn::parse(input).unwrap();
Expand Down Expand Up @@ -69,7 +69,7 @@ pub fn derive_encode_label_set(input: TokenStream) -> TokenStream {
gen.into()
}

/// Derive [`prometheus_client::encoding::EncodeLabelValue`].
/// Derive `prometheus_client::encoding::EncodeLabelValue`.
#[proc_macro_derive(EncodeLabelValue)]
pub fn derive_encode_label_value(input: TokenStream) -> TokenStream {
let ast: DeriveInput = syn::parse(input).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion src/encoding.rs
Expand Up @@ -13,7 +13,9 @@ use std::ops::Deref;
pub mod protobuf;
pub mod text;

/// Trait implemented by each metric type, e.g. [`Counter`], to implement its encoding in the OpenMetric text format.
/// Trait implemented by each metric type, e.g.
/// [`Counter`](crate::metrics::counter::Counter), to implement its encoding in
/// the OpenMetric text format.
pub trait EncodeMetric {
/// Encode the given instance in the OpenMetrics text encoding.
fn encode(&self, encoder: MetricEncoder<'_, '_>) -> Result<(), std::fmt::Error>;
Expand Down
5 changes: 2 additions & 3 deletions src/encoding/protobuf.rs
Expand Up @@ -177,7 +177,7 @@ impl<'a> MetricEncoder<'a> {
) -> Result<MetricEncoder<'b>, std::fmt::Error> {
label_set.encode(
LabelSetEncoder {
labels: &mut self.labels,
labels: self.labels,
}
.into(),
)?;
Expand All @@ -197,7 +197,7 @@ impl<'a> MetricEncoder<'a> {
exemplars: Option<&HashMap<usize, Exemplar<S, f64>>>,
) -> Result<(), std::fmt::Error> {
let buckets = buckets
.into_iter()
.iter()
.enumerate()
.map(|(i, (upper_bound, count))| {
Ok(openmetrics_data_model::histogram_value::Bucket {
Expand All @@ -206,7 +206,6 @@ impl<'a> MetricEncoder<'a> {
exemplar: exemplars
.and_then(|exemplars| exemplars.get(&i).map(|exemplar| exemplar.try_into()))
.transpose()?,
..Default::default()
})
})
.collect::<Result<Vec<_>, std::fmt::Error>>()?;
Expand Down
3 changes: 2 additions & 1 deletion src/encoding/text.rs
Expand Up @@ -171,7 +171,8 @@ impl<'a, 'b> MetricEncoder<'a, 'b> {
Ok(())
}

/// Encode a set of labels. Used by wrapper metric types like [`Family`].
/// Encode a set of labels. Used by wrapper metric types like
/// [`Family`](crate::metrics::family::Family).
pub fn encode_family<'c, 'd, S: EncodeLabelSet>(
&'c mut self,
label_set: &'d S,
Expand Down
5 changes: 3 additions & 2 deletions src/metrics/family.rs
Expand Up @@ -55,8 +55,9 @@ use std::sync::Arc;
///
/// ### [`Family`] with custom type for performance and/or type safety
///
/// Using `Encode` derive macro to generate
/// [`Encode`](crate::encoding::text::Encode) implementation.
/// Using `EncodeLabelSet` and `EncodeLabelValue` derive macro to generate
/// [`EncodeLabelSet`] for `struct`s and
/// [`EncodeLabelValue`](crate::encoding::EncodeLabelValue) for `enum`s.
///
/// ```
/// # use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
Expand Down
63 changes: 18 additions & 45 deletions src/metrics/gauge.rs
Expand Up @@ -6,9 +6,9 @@ use crate::encoding::{EncodeGaugeValue, EncodeMetric, MetricEncoder};

use super::{MetricType, TypedMetric};
use std::marker::PhantomData;
use std::sync::atomic::{AtomicI32, Ordering};
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
use std::sync::atomic::{AtomicI64, AtomicU64};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;

/// Open Metrics [`Gauge`] to record current measurements.
Expand All @@ -17,12 +17,12 @@ use std::sync::Arc;
///
/// [`Gauge`] is generic over the actual data type tracking the [`Gauge`] state
/// as well as the data type used to interact with the [`Gauge`]. Out of
/// convenience the generic type parameters are set to use an [`AtomicU64`] as a
/// storage and [`u64`] on the interface by default.
/// convenience the generic type parameters are set to use an [`AtomicI64`] as a
/// storage and [`i64`] on the interface by default.
///
/// # Examples
///
/// ## Using [`AtomicU64`] as storage and [`u64`] on the interface
/// ## Using [`AtomicI64`] as storage and [`i64`] on the interface
///
/// ```
/// # use prometheus_client::metrics::gauge::Gauge;
Expand Down Expand Up @@ -135,54 +135,54 @@ pub trait Atomic<N> {
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<u64> for AtomicU64 {
fn inc(&self) -> u64 {
impl Atomic<i64> for AtomicI64 {
fn inc(&self) -> i64 {
self.inc_by(1)
}

fn inc_by(&self, v: u64) -> u64 {
fn inc_by(&self, v: i64) -> i64 {
self.fetch_add(v, Ordering::Relaxed)
}

fn dec(&self) -> u64 {
fn dec(&self) -> i64 {
self.dec_by(1)
}

fn dec_by(&self, v: u64) -> u64 {
fn dec_by(&self, v: i64) -> i64 {
self.fetch_sub(v, Ordering::Relaxed)
}

fn set(&self, v: u64) -> u64 {
fn set(&self, v: i64) -> i64 {
self.swap(v, Ordering::Relaxed)
}

fn get(&self) -> u64 {
fn get(&self) -> i64 {
self.load(Ordering::Relaxed)
}
}

impl Atomic<u32> for AtomicU32 {
fn inc(&self) -> u32 {
impl Atomic<i32> for AtomicI32 {
fn inc(&self) -> i32 {
self.inc_by(1)
}

fn inc_by(&self, v: u32) -> u32 {
fn inc_by(&self, v: i32) -> i32 {
self.fetch_add(v, Ordering::Relaxed)
}

fn dec(&self) -> u32 {
fn dec(&self) -> i32 {
self.dec_by(1)
}

fn dec_by(&self, v: u32) -> u32 {
fn dec_by(&self, v: i32) -> i32 {
self.fetch_sub(v, Ordering::Relaxed)
}

fn set(&self, v: u32) -> u32 {
fn set(&self, v: i32) -> i32 {
self.swap(v, Ordering::Relaxed)
}

fn get(&self) -> u32 {
fn get(&self) -> i32 {
self.load(Ordering::Relaxed)
}
}
Expand Down Expand Up @@ -236,33 +236,6 @@ impl Atomic<f64> for AtomicU64 {
}
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<i64> for AtomicI64 {
fn inc(&self) -> i64 {
self.inc_by(1)
}

fn inc_by(&self, v: i64) -> i64 {
self.fetch_add(v, Ordering::Relaxed)
}

fn dec(&self) -> i64 {
self.dec_by(1)
}

fn dec_by(&self, v: i64) -> i64 {
self.fetch_sub(v, Ordering::Relaxed)
}

fn set(&self, v: i64) -> i64 {
self.swap(v, Ordering::Relaxed)
}

fn get(&self) -> i64 {
self.load(Ordering::Relaxed)
}
}

impl<N, A> TypedMetric for Gauge<N, A> {
const TYPE: MetricType = MetricType::Gauge;
}
Expand Down
2 changes: 1 addition & 1 deletion src/registry.rs
Expand Up @@ -408,7 +408,7 @@ mod tests {
let prefix_3 = "prefix_3";
let prefix_3_metric_name = "my_prefix_3_metric";
let sub_registry = registry.sub_registry_with_prefix(prefix_3);
sub_registry.register(prefix_3_metric_name, "some help", counter.clone());
sub_registry.register(prefix_3_metric_name, "some help", counter);

let mut metric_iter = registry
.iter()
Expand Down

0 comments on commit e87ef4b

Please sign in to comment.