@@ -337,6 +337,50 @@ var _ = g.Describe("[sig-cli] oc adm must-gather", func() {
337337 })
338338 })
339339 })
340+
341+ g .It ("runs successfully for metrics gathering" , func () {
342+ tempDir , err := os .MkdirTemp ("" , "test.oc-adm-must-gather." )
343+ o .Expect (err ).NotTo (o .HaveOccurred ())
344+ defer os .RemoveAll (tempDir )
345+
346+ args := []string {
347+ "--dest-dir" , tempDir ,
348+ "--" ,
349+ "/usr/bin/gather_metrics" ,
350+ fmt .Sprintf ("--min-time=%d" , time .Now ().Add (- 5 * time .Minute ).UnixMilli ()),
351+ fmt .Sprintf ("--max-time=%d" , time .Now ().UnixMilli ()),
352+ "--match=prometheus_ready" ,
353+ "--match=prometheus_build_info" ,
354+ }
355+ o .Expect (oc .Run ("adm" , "must-gather" ).Args (args ... ).Execute ()).To (o .Succeed ())
356+
357+ // wait for the contents to show up in the plugin output directory
358+ time .Sleep (5 * time .Second )
359+
360+ pluginOutputDir := GetPluginOutputDir (tempDir )
361+ metricsFile := path .Join (pluginOutputDir , "monitoring" , "metrics" , "metrics.openmetrics" )
362+ errorFile := path .Join (pluginOutputDir , "monitoring" , "metrics" , "metrics.stderr" )
363+
364+ // The error file should be empty
365+ o .Expect (errorFile ).To (o .BeAnExistingFile ())
366+ errorContent , err := os .ReadFile (errorFile )
367+ o .Expect (err ).NotTo (o .HaveOccurred ())
368+ o .Expect (errorContent ).To (o .BeEmpty ())
369+
370+ // The metrics file should contain some series with a given format
371+ o .Expect (metricsFile ).To (o .BeAnExistingFile ())
372+ metrics , err := os .ReadFile (metricsFile )
373+ o .Expect (err ).NotTo (o .HaveOccurred ())
374+
375+ lines := strings .Split (strings .TrimSpace (string (metrics )), "\n " )
376+ count := len (lines )
377+ o .Expect (count ).To (o .BeNumerically (">=" , 5 ))
378+ for _ , line := range lines [:count - 1 ] {
379+ o .Expect (line ).To (o .MatchRegexp (`^(prometheus_ready|prometheus_build_info)\{.*\} \d+ \d+` ))
380+ }
381+
382+ o .Expect (lines [count - 1 ]).To (o .Equal ("# EOF" ))
383+ })
340384})
341385
342386// GetPluginOutputDir returns the directory containing must-gather assets.
0 commit comments