@@ -12,6 +12,7 @@ use std::sync::Arc;
12
12
use std:: time:: Duration ;
13
13
use tokio:: time:: sleep;
14
14
15
+ #[ allow( clippy:: declare_interior_mutable_const) ]
15
16
const DATADOG_AGENT_STATE : HeaderName = HeaderName :: from_static ( "datadog-agent-state" ) ;
16
17
17
18
#[ derive( Debug ) ]
@@ -54,8 +55,8 @@ async fn fetch_info_with_state(
54
55
55
56
/// Fetch the info endpoint once and return the info.
56
57
///
57
- /// Can be used for one-time access to the agent's info. If you need to access the info over
58
- /// long period use `AgentInfoFetcher` to keep the info up-to-date.
58
+ /// Can be used for one-time access to the agent's info. If you need to access the info several
59
+ /// times use `AgentInfoFetcher` to keep the info up-to-date.
59
60
///
60
61
/// # Example
61
62
/// ```no_run
@@ -69,15 +70,15 @@ async fn fetch_info_with_state(
69
70
/// println!("Agent version is {}", agent_info.info.version.unwrap());
70
71
/// # Ok(())
71
72
/// # }
72
- /// ``
73
+ /// ```
73
74
pub async fn fetch_info ( info_endpoint : & Endpoint ) -> Result < Box < AgentInfo > > {
74
75
match fetch_info_with_state ( info_endpoint, None ) . await ? {
75
76
FetchInfoStatus :: NewState ( info) => Ok ( info) ,
76
77
FetchInfoStatus :: SameState => Err ( anyhow ! ( "Invalid state header" ) ) ,
77
78
}
78
79
}
79
80
80
- /// Fetch the info endpoint and update an ArcSwap based on a given time interval .
81
+ /// Fetch the info endpoint and update an ArcSwap keeping it up-to-date .
81
82
///
82
83
/// Once the fetcher has been created you can get an Arc of the config by calling `get_info`.
83
84
/// You can then start the run method, the fetcher will update the AgentInfoArc based on the
@@ -119,17 +120,18 @@ pub struct AgentInfoFetcher {
119
120
impl AgentInfoFetcher {
120
121
/// Return a new `AgentInfoFetcher` fetching the `info_endpoint` on each `refresh_interval`
121
122
/// and updating the stored info.
122
- pub fn new ( info_endpoint : Endpoint , fetch_interval : Duration ) -> Self {
123
+ pub fn new ( info_endpoint : Endpoint , refresh_interval : Duration ) -> Self {
123
124
Self {
124
125
info_endpoint,
125
126
info : Arc :: new ( ArcSwapOption :: new ( None ) ) ,
126
- refresh_interval : fetch_interval ,
127
+ refresh_interval,
127
128
}
128
129
}
129
130
130
131
/// Start fetching the info endpoint with the given interval.
131
132
///
132
- /// Warning: This method does not return and should be called within a dedicated task.
133
+ /// # Warning
134
+ /// This method does not return and should be called within a dedicated task.
133
135
pub async fn run ( & self ) {
134
136
loop {
135
137
let current_info = self . info . load ( ) ;
@@ -207,6 +209,7 @@ mod tests {
207
209
208
210
const TEST_INFO_HASH : & str = "8c732aba385d605b010cd5bd12c03fef402eaefce989f0055aa4c7e92fe30077" ;
209
211
212
+ #[ cfg_attr( miri, ignore) ]
210
213
#[ tokio:: test]
211
214
async fn test_fetch_info_without_state ( ) {
212
215
let server = MockServer :: start ( ) ;
@@ -215,7 +218,7 @@ mod tests {
215
218
when. path ( "/info" ) ;
216
219
then. status ( 200 )
217
220
. header ( "content-type" , "application/json" )
218
- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
221
+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
219
222
. body ( TEST_INFO ) ;
220
223
} )
221
224
. await ;
@@ -232,6 +235,7 @@ mod tests {
232
235
) ;
233
236
}
234
237
238
+ #[ cfg_attr( miri, ignore) ]
235
239
#[ tokio:: test]
236
240
async fn test_fetch_info_with_state ( ) {
237
241
let server = MockServer :: start ( ) ;
@@ -240,7 +244,7 @@ mod tests {
240
244
when. path ( "/info" ) ;
241
245
then. status ( 200 )
242
246
. header ( "content-type" , "application/json" )
243
- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
247
+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
244
248
. body ( TEST_INFO ) ;
245
249
} )
246
250
. await ;
@@ -264,6 +268,7 @@ mod tests {
264
268
assert ! ( matches!( same_state_info_status, FetchInfoStatus :: SameState ) ) ;
265
269
}
266
270
271
+ #[ cfg_attr( miri, ignore) ]
267
272
#[ tokio:: test]
268
273
async fn test_fetch_info ( ) {
269
274
let server = MockServer :: start ( ) ;
@@ -272,7 +277,7 @@ mod tests {
272
277
when. path ( "/info" ) ;
273
278
then. status ( 200 )
274
279
. header ( "content-type" , "application/json" )
275
- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
280
+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
276
281
. body ( TEST_INFO ) ;
277
282
} )
278
283
. await ;
@@ -289,6 +294,7 @@ mod tests {
289
294
) ;
290
295
}
291
296
297
+ #[ cfg_attr( miri, ignore) ]
292
298
#[ tokio:: test]
293
299
async fn test_agent_info_fetcher_run ( ) {
294
300
let server = MockServer :: start ( ) ;
@@ -297,7 +303,7 @@ mod tests {
297
303
when. path ( "/info" ) ;
298
304
then. status ( 200 )
299
305
. header ( "content-type" , "application/json" )
300
- . header ( DATADOG_AGENT_STATE . to_string ( ) , "1" )
306
+ . header ( "datadog-agent-state" , "1" )
301
307
. body ( r#"{"version":"1"}"# ) ;
302
308
} )
303
309
. await ;
@@ -323,7 +329,7 @@ mod tests {
323
329
when. path ( "/info" ) ;
324
330
then. status ( 200 )
325
331
. header ( "content-type" , "application/json" )
326
- . header ( DATADOG_AGENT_STATE . to_string ( ) , "2" )
332
+ . header ( "datadog-agent-state" , "2" )
327
333
. body ( r#"{"version":"2"}"# ) ;
328
334
} )
329
335
. await ;
0 commit comments