8
8
//! retries. The function uses error classification to determine retry behavior and can honor
9
9
//! server-provided throttling hints.
10
10
11
- #[ cfg( feature = "experimental_async_runtime" ) ]
11
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
12
12
use opentelemetry:: otel_warn;
13
- #[ cfg( feature = "experimental_async_runtime" ) ]
13
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
14
14
use std:: future:: Future ;
15
+ use std:: hash:: DefaultHasher ;
15
16
use std:: time:: Duration ;
16
- #[ cfg( feature = "experimental_async_runtime" ) ]
17
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
17
18
use std:: time:: SystemTime ;
18
19
19
- #[ cfg( feature = "experimental_async_runtime" ) ]
20
- use crate :: runtime:: Runtime ;
20
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
21
+ use opentelemetry_sdk :: runtime:: Runtime ;
21
22
22
23
/// Classification of errors for retry purposes.
23
24
#[ derive( Debug , Clone , PartialEq ) ]
@@ -46,11 +47,11 @@ pub struct RetryPolicy {
46
47
47
48
/// A runtime stub for when experimental_async_runtime is not enabled.
48
49
/// This allows retry policy to be configured but no actual retries occur.
49
- #[ cfg( not( feature = "experimental_async_runtime" ) ) ]
50
+ #[ cfg( not( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ) ]
50
51
#[ derive( Debug , Clone , Default ) ]
51
52
pub struct NoOpRuntime ;
52
53
53
- #[ cfg( not( feature = "experimental_async_runtime" ) ) ]
54
+ #[ cfg( not( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ) ]
54
55
impl NoOpRuntime {
55
56
/// Creates a new no-op runtime.
56
57
pub fn new ( ) -> Self {
@@ -59,13 +60,16 @@ impl NoOpRuntime {
59
60
}
60
61
61
62
// Generates a random jitter value up to max_jitter
62
- #[ cfg( feature = "experimental_async_runtime" ) ]
63
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
63
64
fn generate_jitter ( max_jitter : u64 ) -> u64 {
64
65
let now = SystemTime :: now ( ) ;
65
66
let nanos = now
66
67
. duration_since ( SystemTime :: UNIX_EPOCH )
67
68
. unwrap ( )
68
69
. subsec_nanos ( ) ;
70
+
71
+ let hasher = DefaultHasher :: default ( ) ;
72
+
69
73
nanos as u64 % ( max_jitter + 1 )
70
74
}
71
75
@@ -86,7 +90,7 @@ fn generate_jitter(max_jitter: u64) -> u64 {
86
90
///
87
91
/// A `Result` containing the operation's result or an error if max retries are reached
88
92
/// or a non-retryable error occurs.
89
- #[ cfg( feature = "experimental_async_runtime" ) ]
93
+ #[ cfg( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ]
90
94
pub async fn retry_with_backoff < R , F , Fut , T , E , C > (
91
95
runtime : R ,
92
96
policy : RetryPolicy ,
@@ -147,7 +151,7 @@ where
147
151
148
152
/// No-op retry function for when experimental_async_runtime is not enabled.
149
153
/// This function will execute the operation exactly once without any retries.
150
- #[ cfg( not( feature = "experimental_async_runtime" ) ) ]
154
+ #[ cfg( not( any ( feature = "experimental-grpc-retry" , feature = "experimental-http-retry" ) ) ) ]
151
155
pub async fn retry_with_backoff < R , F , Fut , T , E , C > (
152
156
_runtime : R ,
153
157
_policy : RetryPolicy ,
@@ -163,10 +167,10 @@ where
163
167
operation ( ) . await
164
168
}
165
169
166
- #[ cfg( all( test, feature = "experimental_async_runtime" , feature = "rt-tokio ") ) ]
170
+ #[ cfg( all( test, feature = "experimental-grpc-retry " ) ) ]
167
171
mod tests {
168
172
use super :: * ;
169
- use crate :: runtime:: Tokio ;
173
+ use opentelemetry_sdk :: runtime:: Tokio ;
170
174
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
171
175
use std:: time:: Duration ;
172
176
use tokio:: time:: timeout;
0 commit comments