From 81aa33698dcf5dd172684569c241c8f44fe45266 Mon Sep 17 00:00:00 2001 From: Luong Tran Date: Sat, 16 Nov 2024 16:18:42 +0700 Subject: [PATCH 1/3] fix: AtomicI64, AtomicU64 for build mipsel processor --- Cargo.toml | 1 + opentelemetry-sdk/Cargo.toml | 1 + opentelemetry-sdk/src/metrics/internal/mod.rs | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e123b901e..3d05416596 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,3 +48,4 @@ tracing = { version = "0.1", default-features = false } tracing-core = { version = "0.1", default-features = false } tracing-subscriber = { version = "0.3", default-features = false } url = { version = "2.5.2", default-features = false } #https://github.com/servo/rust-url/issues/992 +portable-atomic = "1.9.0" diff --git a/opentelemetry-sdk/Cargo.toml b/opentelemetry-sdk/Cargo.toml index 39928fecb3..1e023eeb48 100644 --- a/opentelemetry-sdk/Cargo.toml +++ b/opentelemetry-sdk/Cargo.toml @@ -29,6 +29,7 @@ tokio = { workspace = true, features = ["rt", "time"], optional = true } tokio-stream = { workspace = true, optional = true } http = { workspace = true, optional = true } tracing = {workspace = true, optional = true} +portable-atomic = {workspace = true} [package.metadata.docs.rs] all-features = true diff --git a/opentelemetry-sdk/src/metrics/internal/mod.rs b/opentelemetry-sdk/src/metrics/internal/mod.rs index 8b6136d7ce..3eacfafed8 100644 --- a/opentelemetry-sdk/src/metrics/internal/mod.rs +++ b/opentelemetry-sdk/src/metrics/internal/mod.rs @@ -9,7 +9,7 @@ use core::fmt; use std::collections::{HashMap, HashSet}; use std::mem::take; use std::ops::{Add, AddAssign, DerefMut, Sub}; -use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::Ordering; use std::sync::{Arc, RwLock}; use aggregate::is_under_cardinality_limit; @@ -17,6 +17,7 @@ pub(crate) use aggregate::{AggregateBuilder, ComputeAggregation, Measure}; pub(crate) use exponential_histogram::{EXPO_MAX_SCALE, EXPO_MIN_SCALE}; use once_cell::sync::Lazy; use opentelemetry::{otel_warn, KeyValue}; +use portable_atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize}; use crate::metrics::AttributeSet; @@ -410,8 +411,8 @@ mod tests { #[test] fn can_add_and_get_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15); - atomic.add(10); + atomic.add(15, Ordering::Relaxed); + atomic.add(10, Ordering::Relaxed); let value = atomic.get_value(); assert_eq!(value, 25); @@ -420,7 +421,7 @@ mod tests { #[test] fn can_reset_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15); + atomic.add(15, Ordering::Relaxed); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value(); @@ -449,8 +450,8 @@ mod tests { #[test] fn can_add_and_get_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15); - atomic.add(-10); + atomic.add(15, Ordering::Relaxed); + atomic.add(-10, Ordering::Relaxed); let value = atomic.get_value(); assert_eq!(value, 5); @@ -459,7 +460,7 @@ mod tests { #[test] fn can_reset_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15); + atomic.add(15, Ordering::Relaxed); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value(); From 2fe42ebce0ccfa54678a53b632b16dea441c1561 Mon Sep 17 00:00:00 2001 From: Luong Tran Date: Sat, 16 Nov 2024 16:54:53 +0700 Subject: [PATCH 2/3] fix: use add function of mod.rs --- opentelemetry-sdk/src/metrics/internal/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/internal/mod.rs b/opentelemetry-sdk/src/metrics/internal/mod.rs index 3eacfafed8..5abbfc3f6f 100644 --- a/opentelemetry-sdk/src/metrics/internal/mod.rs +++ b/opentelemetry-sdk/src/metrics/internal/mod.rs @@ -411,8 +411,8 @@ mod tests { #[test] fn can_add_and_get_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15, Ordering::Relaxed); - atomic.add(10, Ordering::Relaxed); + atomic.add(15); + atomic.add(10); let value = atomic.get_value(); assert_eq!(value, 25); @@ -421,7 +421,7 @@ mod tests { #[test] fn can_reset_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15, Ordering::Relaxed); + atomic.add(15); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value(); @@ -450,8 +450,8 @@ mod tests { #[test] fn can_add_and_get_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15, Ordering::Relaxed); - atomic.add(-10, Ordering::Relaxed); + atomic.add(15); + atomic.add(-10); let value = atomic.get_value(); assert_eq!(value, 5); @@ -460,7 +460,7 @@ mod tests { #[test] fn can_reset_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15, Ordering::Relaxed); + atomic.add(15); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value(); From c7d289694b237b2ee4f6c9f61e92cf74da28ccf5 Mon Sep 17 00:00:00 2001 From: Luong Tran Date: Sat, 16 Nov 2024 17:52:10 +0700 Subject: [PATCH 3/3] fix: check arch to use atomic --- opentelemetry-sdk/Cargo.toml | 2 ++ opentelemetry-sdk/src/metrics/internal/mod.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/Cargo.toml b/opentelemetry-sdk/Cargo.toml index 1e023eeb48..602860e5eb 100644 --- a/opentelemetry-sdk/Cargo.toml +++ b/opentelemetry-sdk/Cargo.toml @@ -29,6 +29,8 @@ tokio = { workspace = true, features = ["rt", "time"], optional = true } tokio-stream = { workspace = true, optional = true } http = { workspace = true, optional = true } tracing = {workspace = true, optional = true} + +[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies] portable-atomic = {workspace = true} [package.metadata.docs.rs] diff --git a/opentelemetry-sdk/src/metrics/internal/mod.rs b/opentelemetry-sdk/src/metrics/internal/mod.rs index 5abbfc3f6f..1bc260f739 100644 --- a/opentelemetry-sdk/src/metrics/internal/mod.rs +++ b/opentelemetry-sdk/src/metrics/internal/mod.rs @@ -17,8 +17,13 @@ pub(crate) use aggregate::{AggregateBuilder, ComputeAggregation, Measure}; pub(crate) use exponential_histogram::{EXPO_MAX_SCALE, EXPO_MIN_SCALE}; use once_cell::sync::Lazy; use opentelemetry::{otel_warn, KeyValue}; + +#[cfg(any(target_arch = "mips", target_arch = "powerpc"))] use portable_atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize}; +#[cfg(not(any(target_arch = "mips", target_arch = "powerpc")))] +use std::sync::atomic::{AtomicBool, AtomicI64, AtomicU64, AtomicUsize}; + use crate::metrics::AttributeSet; pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: Lazy> = @@ -411,8 +416,8 @@ mod tests { #[test] fn can_add_and_get_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15); - atomic.add(10); + AtomicTracker::add(&atomic, 15); + AtomicTracker::add(&atomic, 10); let value = atomic.get_value(); assert_eq!(value, 25); @@ -421,7 +426,7 @@ mod tests { #[test] fn can_reset_u64_atomic_value() { let atomic = u64::new_atomic_tracker(0); - atomic.add(15); + AtomicTracker::add(&atomic, 15); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value(); @@ -450,8 +455,8 @@ mod tests { #[test] fn can_add_and_get_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15); - atomic.add(-10); + AtomicTracker::add(&atomic, 15); + AtomicTracker::add(&atomic, -10); let value = atomic.get_value(); assert_eq!(value, 5); @@ -460,7 +465,7 @@ mod tests { #[test] fn can_reset_i64_atomic_value() { let atomic = i64::new_atomic_tracker(0); - atomic.add(15); + AtomicTracker::add(&atomic, 15); let value = atomic.get_and_reset_value(); let value2 = atomic.get_value();