@@ -12,6 +12,7 @@ use std::sync::Arc;
1212use std:: time:: Duration ;
1313use tokio:: time:: sleep;
1414
15+ #[ allow( clippy:: declare_interior_mutable_const) ]
1516const DATADOG_AGENT_STATE : HeaderName = HeaderName :: from_static ( "datadog-agent-state" ) ;
1617
1718#[ derive( Debug ) ]
@@ -54,8 +55,8 @@ async fn fetch_info_with_state(
5455
5556/// Fetch the info endpoint once and return the info.
5657///
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.
5960///
6061/// # Example
6162/// ```no_run
@@ -69,15 +70,15 @@ async fn fetch_info_with_state(
6970/// println!("Agent version is {}", agent_info.info.version.unwrap());
7071/// # Ok(())
7172/// # }
72- /// ``
73+ /// ```
7374pub async fn fetch_info ( info_endpoint : & Endpoint ) -> Result < Box < AgentInfo > > {
7475 match fetch_info_with_state ( info_endpoint, None ) . await ? {
7576 FetchInfoStatus :: NewState ( info) => Ok ( info) ,
7677 FetchInfoStatus :: SameState => Err ( anyhow ! ( "Invalid state header" ) ) ,
7778 }
7879}
7980
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 .
8182///
8283/// Once the fetcher has been created you can get an Arc of the config by calling `get_info`.
8384/// You can then start the run method, the fetcher will update the AgentInfoArc based on the
@@ -119,17 +120,18 @@ pub struct AgentInfoFetcher {
119120impl AgentInfoFetcher {
120121 /// Return a new `AgentInfoFetcher` fetching the `info_endpoint` on each `refresh_interval`
121122 /// 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 {
123124 Self {
124125 info_endpoint,
125126 info : Arc :: new ( ArcSwapOption :: new ( None ) ) ,
126- refresh_interval : fetch_interval ,
127+ refresh_interval,
127128 }
128129 }
129130
130131 /// Start fetching the info endpoint with the given interval.
131132 ///
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.
133135 pub async fn run ( & self ) {
134136 loop {
135137 let current_info = self . info . load ( ) ;
@@ -207,6 +209,7 @@ mod tests {
207209
208210 const TEST_INFO_HASH : & str = "8c732aba385d605b010cd5bd12c03fef402eaefce989f0055aa4c7e92fe30077" ;
209211
212+ #[ cfg_attr( miri, ignore) ]
210213 #[ tokio:: test]
211214 async fn test_fetch_info_without_state ( ) {
212215 let server = MockServer :: start ( ) ;
@@ -215,7 +218,7 @@ mod tests {
215218 when. path ( "/info" ) ;
216219 then. status ( 200 )
217220 . header ( "content-type" , "application/json" )
218- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
221+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
219222 . body ( TEST_INFO ) ;
220223 } )
221224 . await ;
@@ -232,6 +235,7 @@ mod tests {
232235 ) ;
233236 }
234237
238+ #[ cfg_attr( miri, ignore) ]
235239 #[ tokio:: test]
236240 async fn test_fetch_info_with_state ( ) {
237241 let server = MockServer :: start ( ) ;
@@ -240,7 +244,7 @@ mod tests {
240244 when. path ( "/info" ) ;
241245 then. status ( 200 )
242246 . header ( "content-type" , "application/json" )
243- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
247+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
244248 . body ( TEST_INFO ) ;
245249 } )
246250 . await ;
@@ -264,6 +268,7 @@ mod tests {
264268 assert ! ( matches!( same_state_info_status, FetchInfoStatus :: SameState ) ) ;
265269 }
266270
271+ #[ cfg_attr( miri, ignore) ]
267272 #[ tokio:: test]
268273 async fn test_fetch_info ( ) {
269274 let server = MockServer :: start ( ) ;
@@ -272,7 +277,7 @@ mod tests {
272277 when. path ( "/info" ) ;
273278 then. status ( 200 )
274279 . header ( "content-type" , "application/json" )
275- . header ( DATADOG_AGENT_STATE . to_string ( ) , TEST_INFO_HASH )
280+ . header ( "datadog-agent-state" , TEST_INFO_HASH )
276281 . body ( TEST_INFO ) ;
277282 } )
278283 . await ;
@@ -289,6 +294,7 @@ mod tests {
289294 ) ;
290295 }
291296
297+ #[ cfg_attr( miri, ignore) ]
292298 #[ tokio:: test]
293299 async fn test_agent_info_fetcher_run ( ) {
294300 let server = MockServer :: start ( ) ;
@@ -297,7 +303,7 @@ mod tests {
297303 when. path ( "/info" ) ;
298304 then. status ( 200 )
299305 . header ( "content-type" , "application/json" )
300- . header ( DATADOG_AGENT_STATE . to_string ( ) , "1" )
306+ . header ( "datadog-agent-state" , "1" )
301307 . body ( r#"{"version":"1"}"# ) ;
302308 } )
303309 . await ;
@@ -323,7 +329,7 @@ mod tests {
323329 when. path ( "/info" ) ;
324330 then. status ( 200 )
325331 . header ( "content-type" , "application/json" )
326- . header ( DATADOG_AGENT_STATE . to_string ( ) , "2" )
332+ . header ( "datadog-agent-state" , "2" )
327333 . body ( r#"{"version":"2"}"# ) ;
328334 } )
329335 . await ;
0 commit comments