@@ -181,13 +181,8 @@ func TestBenchSpyWithTwoLokiQueries(t *testing.T) {
181181 isComparableErrs := previousReport .IsComparable (& currentReport )
182182 require .Empty (t , isComparableErrs , "reports were not comparable" , isComparableErrs )
183183
184- currentAsStringSlice , castErr := benchspy .ResultsAs ([]string {}, currentReport .QueryExecutors , benchspy .StandardQueryExecutor_Loki )
185- require .NoError (t , castErr , "failed to cast results to string slice" )
186- require .NotEmpty (t , currentAsStringSlice , "results were empty" )
187-
188- previousAsStringSlice , castErr := benchspy .ResultsAs ([]string {}, previousReport .QueryExecutors , benchspy .StandardQueryExecutor_Loki )
189- require .NoError (t , castErr , "failed to cast results to string slice" )
190- require .NotEmpty (t , previousAsStringSlice , "results were empty" )
184+ currentAsStringSlice := benchspy .MustAllLokiResults (& currentReport )
185+ previousAsStringSlice := benchspy .MustAllLokiResults (& previousReport )
191186
192187 // vu over time
193188 require .NotEmpty (t , currentReport .QueryExecutors [0 ].Results ()["vu_over_time" ], "vu_over_time results were missing from current report" )
@@ -271,43 +266,21 @@ func TestBenchSpyWithStandardLokiMetrics(t *testing.T) {
271266
272267 gen .Run (true )
273268
274- currentReport , err := benchspy .NewStandardReport ("e7fc5826a572c09f8b93df3b9f674113372ce925" , benchspy .WithStandardQueryExecutorType (benchspy .StandardQueryExecutor_Loki ), benchspy .WithGenerators (gen ))
275- require .NoError (t , err )
276-
277269 fetchCtx , cancelFn := context .WithTimeout (context .Background (), 60 * time .Second )
278270 defer cancelFn ()
279271
280- fetchErr := currentReport .FetchData (fetchCtx )
281- require .NoError (t , fetchErr , "failed to fetch current report" )
282-
283- path , storeErr := currentReport .Store ()
284- require .NoError (t , storeErr , "failed to store current report" , path )
285-
286- // this is only needed, because we are using a non-standard directory
287- // otherwise, the Load method would be able to find the file
288- previousReport := benchspy.StandardReport {
289- LocalStorage : benchspy.LocalStorage {
290- Directory : "test_performance_reports" ,
291- },
292- }
293- loadErr := previousReport .Load (t .Name (), "e7fc5826a572c09f8b93df3b9f674113372ce924" )
294- require .NoError (t , loadErr , "failed to load previous report" )
295-
296- isComparableErrs := previousReport .IsComparable (currentReport )
297- require .Empty (t , isComparableErrs , "reports were not comparable" , isComparableErrs )
272+ currentReport , previousReport , err := benchspy .FetchNewReportAndLoadLatestPrevious (fetchCtx , "e7fc5826a572c09f8b93df3b9f674113372ce925" , benchspy .WithStandardQueryExecutorType (benchspy .StandardQueryExecutor_Loki ), benchspy .WithGenerators (gen ), benchspy .WithReportDirectory ("test_performance_reports" ))
273+ require .NoError (t , err , "failed to fetch current report or load the previous one" )
298274
299- currentAsStringSlice , castErr := benchspy .ResultsAs ([]string {}, currentReport .QueryExecutors , benchspy .StandardQueryExecutor_Loki )
300- require .NoError (t , castErr , "failed to cast results to string slice" )
301- require .NotEmpty (t , currentAsStringSlice , "results were empty" )
275+ // path, storeErr := currentReport.Store()
276+ // require.NoError(t, storeErr, "failed to store current report", path)
302277
303- previousAsStringSlice , castErr := benchspy .ResultsAs ([]string {}, previousReport .QueryExecutors , benchspy .StandardQueryExecutor_Loki )
304- require .NoError (t , castErr , "failed to cast results to string slice" )
305- require .NotEmpty (t , previousAsStringSlice , "results were empty" )
278+ currentAsStringSlice := benchspy .MustAllLokiResults (currentReport )
279+ previousAsStringSlice := benchspy .MustAllLokiResults (previousReport )
306280
307281 var compareMedian = func (metricName benchspy.StandardLoadMetric ) {
308282 require .NotEmpty (t , currentAsStringSlice [string (metricName )], "%s results were missing from current report" , string (metricName ))
309283 require .NotEmpty (t , previousAsStringSlice [string (metricName )], "%s results were missing from previous report" , string (metricName ))
310- require .Equal (t , len (currentAsStringSlice [string (metricName )]), len (previousAsStringSlice [string (metricName )]), "%s results are not the same length" , string (metricName ))
311284
312285 currentFloatSlice , err := benchspy .StringSliceToFloat64Slice (currentAsStringSlice [string (metricName )])
313286 require .NoError (t , err , "failed to convert %s results to float64 slice" , string (metricName ))
@@ -375,13 +348,8 @@ func TestBenchSpyWithStandardGeneratorMetrics(t *testing.T) {
375348 isComparableErrs := previousReport .IsComparable (currentReport )
376349 require .Empty (t , isComparableErrs , "reports were not comparable" , isComparableErrs )
377350
378- currentAsString , castErr := benchspy .ResultsAs ("" , currentReport .QueryExecutors , benchspy .StandardQueryExecutor_Generator )
379- require .NoError (t , castErr , "failed to cast results to string slice" )
380- require .NotEmpty (t , currentAsString , "results were empty" )
381-
382- previousAsString , castErr := benchspy .ResultsAs ("" , previousReport .QueryExecutors , benchspy .StandardQueryExecutor_Generator )
383- require .NoError (t , castErr , "failed to cast results to string slice" )
384- require .NotEmpty (t , previousAsString , "results were empty" )
351+ currentAsString := benchspy .MustAllGeneratorResults (currentReport )
352+ previousAsString := benchspy .MustAllGeneratorResults (& previousReport )
385353
386354 var compareValues = func (metricName benchspy.StandardLoadMetric ) {
387355 require .NotEmpty (t , currentAsString [string (metricName )], "%s results were missing from current report" , string (metricName ))
@@ -407,30 +375,6 @@ func TestBenchSpyWithStandardGeneratorMetrics(t *testing.T) {
407375 compareValues (benchspy .ErrorRate )
408376}
409377
410- // func TestBenchSpy_Prometheus(t *testing.T) {
411- // t.Skip("skipping test, since it requires a running CTFv2 node_set and observability stack [start it manually and run the test]")
412-
413- // before := time.Now().Add(-5 * time.Minute)
414- // // exclude bootstrap node
415- // prometheusNodeReporter, err := benchspy.NewStandardPrometheusQueryExecutor("http://localhost:9090", before, time.Now(), `node[^0]`)
416- // require.NoError(t, err)
417-
418- // fetchErr := prometheusNodeReporter.Execute(context.Background())
419- // require.NoError(t, fetchErr, "failed to fetch prometheus node resources")
420-
421- // resourcesAsValue := prometheusNodeReporter.MustResultsAsValue()
422- // medianCpuUsagePerNode := resourcesAsValue[string(benchspy.MedianCPUUsage)]
423- // require.Equal(t, medianCpuUsagePerNode.Type(), model.ValVector, "median cpu usage per node should be a vector")
424-
425- // medianCpuUsagePerNodeVector := medianCpuUsagePerNode.(model.Vector)
426- // require.NotEmpty(t, medianCpuUsagePerNodeVector, "median cpu usage per node vector should not be empty")
427- // require.Equal(t, 4, len(medianCpuUsagePerNodeVector), "median cpu usage per node vector should have 4 elements")
428-
429- // for _, sample := range medianCpuUsagePerNodeVector {
430- // require.NotZero(t, sample.Value, "median cpu usage per node should not be zero")
431- // }
432- // }
433-
434378func TestBenchSpy_Prometheus_And_Generator (t * testing.T ) {
435379 // this test requires CTFv2 node_set with observability stack to be running
436380 previousReport := benchspy.StandardReport {
@@ -473,8 +417,8 @@ func TestBenchSpy_Prometheus_And_Generator(t *testing.T) {
473417 isComparableErrs := previousReport .IsComparable (currentReport )
474418 require .Empty (t , isComparableErrs , "reports were not comparable" , isComparableErrs )
475419
476- currentAsValues := currentReport . QueryExecutors [ 1 ].( * benchspy.PrometheusQueryExecutor ). MustResultsAsValue ( )
477- previousAsValues := previousReport . QueryExecutors [ 1 ].( * benchspy.PrometheusQueryExecutor ). MustResultsAsValue ( )
420+ currentAsValues := benchspy .MustAllPrometheusResults ( currentReport )
421+ previousAsValues := benchspy .MustAllPrometheusResults ( & previousReport )
478422
479423 assert .Equal (t , len (currentAsValues ), len (previousAsValues ), "number of metrics in results should be the same" )
480424
0 commit comments