@@ -281,26 +281,75 @@ mod tests {
281281 use tokio:: spawn;
282282
283283 use crate :: {
284- config:: { BasicAuth , MetricInterval , MetricsConfig , UrlPort } ,
285- metrics:: consumer_loop,
286- metrics_core:: prometheus:: { Label , Sample , TimeSeries } ,
284+ config:: {
285+ BasicAuth , IngestorConfig , LokiConfig , MetricInterval , MetricsConfig , RedisConfig ,
286+ UrlPort ,
287+ } ,
288+ metrics:: { consumer_loop, metric_definitions} ,
289+ metrics_core:: {
290+ MetricDefinition ,
291+ prometheus:: { Label , Sample , TimeSeries } ,
292+ } ,
287293 } ;
288294
289- fn test_config ( url : String ) -> MetricsConfig {
295+ fn test_config (
296+ url : String ,
297+ intervals : Option < HashMap < String , MetricInterval > > ,
298+ ) -> MetricsConfig {
290299 MetricsConfig {
291300 user_config_path : None ,
292301 auth : BasicAuth {
293302 username : "user" . into ( ) ,
294303 password : "pass" . into ( ) ,
295304 } ,
296305 url : url,
297- intervals : HashMap :: new ( ) ,
306+ intervals : intervals . unwrap_or ( HashMap :: new ( ) ) ,
298307 dynamic : HashMap :: new ( ) ,
299308 watchdog_interval : MetricInterval :: Daily ( 1 ) ,
300309 publish_interval : MetricInterval :: Millis ( 1 ) ,
301310 }
302311 }
303312
313+ #[ test]
314+ fn test_definitions ( ) {
315+ let intervals: HashMap < String , MetricInterval > = HashMap :: from ( [ ] ) ;
316+ let config = IngestorConfig {
317+ redis : RedisConfig {
318+ url : UrlPort {
319+ url : "" . into ( ) ,
320+ port : 12345 ,
321+ } ,
322+ chunk_size : 5 ,
323+ blocktime_millis : 5 ,
324+ consumer_group : "" . into ( ) ,
325+ consumer_id : "" . into ( ) ,
326+ } ,
327+ loki : LokiConfig {
328+ url : "" . into ( ) ,
329+ auth : BasicAuth {
330+ username : "user" . into ( ) ,
331+ password : "pass" . into ( ) ,
332+ } ,
333+ chunk_size : 5 ,
334+ beamline_name : "test" . into ( ) ,
335+ } ,
336+ metrics : test_config ( "" . into ( ) , Some ( intervals. clone ( ) ) ) ,
337+ enable_metrics : false ,
338+ enable_logging : false ,
339+ } ;
340+ let defs = metric_definitions ( Box :: leak ( Box :: new ( config) ) ) ;
341+ if let MetricDefinition :: Static ( def) = defs. get ( "cpu_usage_pc" ) . unwrap ( ) {
342+ assert_eq ! ( def. 2 , None ) ;
343+ } else {
344+ panic ! ( "wrong type!" )
345+ }
346+ if let MetricDefinition :: Static ( def) = defs. get ( "deployment" ) . unwrap ( ) {
347+ assert_eq ! ( def. 2 , Some ( 60 ) ) ;
348+ } else {
349+ panic ! ( "wrong type!" )
350+ }
351+ }
352+
304353 #[ tokio:: test( flavor = "multi_thread" ) ]
305354 async fn test_consumer_loop ( ) {
306355 // Request a new server from the pool
@@ -309,7 +358,7 @@ mod tests {
309358 // Use one of these addresses to configure your client
310359 let host = server. host_with_port ( ) ;
311360 let url = server. url ( ) ;
312- let config = test_config ( url) ;
361+ let config = test_config ( url, None ) ;
313362 // Create a mock
314363 let mock = server
315364 . mock ( "POST" , "/" )
0 commit comments