Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ jobs:
matrix:
target:
- armv7-unknown-linux-gnueabihf
- mipsel-unknown-linux-gnu
- powerpc-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Expose `Encoder` methods. See [PR 41].

### Changed

- Use `AtomicU32` on platforms that don't support `AtomicU64`. See [PR 42].

[PR 41]: https://github.com/prometheus/client_rust/pull/41
[PR 42]: https://github.com/prometheus/client_rust/pull/42

## [0.15.0] - 2022-01-16

Expand Down
14 changes: 13 additions & 1 deletion src/metrics/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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

/// Open Metrics [`Counter`] to measure discrete events.
Expand Down Expand Up @@ -36,11 +38,18 @@ use std::sync::Arc;
/// counter.inc();
/// let _value: f64 = counter.get();
/// ```
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
pub struct Counter<N = u64, A = AtomicU64> {
value: Arc<A>,
phantom: PhantomData<N>,
}

#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
pub struct Counter<N = u32, A = AtomicU32> {
value: Arc<A>,
phantom: PhantomData<N>,
}

impl<N, A> Clone for Counter<N, A> {
fn clone(&self) -> Self {
Self {
Expand Down Expand Up @@ -96,6 +105,7 @@ pub trait Atomic<N> {
fn get(&self) -> N;
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<u64> for AtomicU64 {
fn inc(&self) -> u64 {
self.inc_by(1)
Expand Down Expand Up @@ -124,6 +134,7 @@ impl Atomic<u32> for AtomicU32 {
}
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<f64> for AtomicU64 {
fn inc(&self) -> f64 {
self.inc_by(1.0)
Expand Down Expand Up @@ -165,6 +176,7 @@ mod tests {
assert_eq!(1, counter.get());
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
#[test]
fn f64_stored_in_atomic_u64() {
fn prop(fs: Vec<f64>) {
Expand Down
9 changes: 9 additions & 0 deletions src/metrics/exemplar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use super::counter::{self, Counter};
use super::histogram::Histogram;
use owning_ref::OwningRef;
use std::collections::HashMap;
#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
use std::sync::atomic::AtomicU32;
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
use std::sync::atomic::AtomicU64;
use std::sync::{Arc, RwLock, RwLockReadGuard};

Expand All @@ -26,10 +29,16 @@ pub struct Exemplar<S, V> {
/// counter_with_exemplar.inc_by(1, Some(vec![("user_id".to_string(), "42".to_string())]));
/// let _value: (u64, _) = counter_with_exemplar.get();
/// ```
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
pub struct CounterWithExemplar<S, N = u64, A = AtomicU64> {
pub(crate) inner: Arc<RwLock<CounterWithExemplarInner<S, N, A>>>,
}

#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
pub struct CounterWithExemplar<S, N = u32, A = AtomicU32> {
pub(crate) inner: Arc<RwLock<CounterWithExemplarInner<S, N, A>>>,
}

impl<S, N, A> Clone for CounterWithExemplar<S, N, A> {
fn clone(&self) -> Self {
CounterWithExemplar {
Expand Down
13 changes: 12 additions & 1 deletion src/metrics/gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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

/// Open Metrics [`Gauge`] to record current measurements.
Expand Down Expand Up @@ -36,11 +38,18 @@ use std::sync::Arc;
/// gauge.set(42.0);
/// let _value: f64 = gauge.get();
/// ```
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
pub struct Gauge<N = u64, A = AtomicU64> {
value: Arc<A>,
phantom: PhantomData<N>,
}

#[cfg(any(target_arch = "mips", target_arch = "powerpc"))]
pub struct Gauge<N = u32, A = AtomicU32> {
value: Arc<A>,
phantom: PhantomData<N>,
}

impl<N, A> Clone for Gauge<N, A> {
fn clone(&self) -> Self {
Self {
Expand Down Expand Up @@ -113,6 +122,7 @@ pub trait Atomic<N> {
fn get(&self) -> N;
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<u64> for AtomicU64 {
fn inc(&self) -> u64 {
self.inc_by(1)
Expand Down Expand Up @@ -165,6 +175,7 @@ impl Atomic<u32> for AtomicU32 {
}
}

#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))]
impl Atomic<f64> for AtomicU64 {
fn inc(&self) -> f64 {
self.inc_by(1.0)
Expand Down