@@ -19,7 +19,6 @@ package slos
19
19
import (
20
20
"bytes"
21
21
"encoding/json"
22
- "flag"
23
22
"fmt"
24
23
"strings"
25
24
"testing"
@@ -32,34 +31,12 @@ import (
32
31
"k8s.io/perf-tests/clusterloader2/pkg/measurement"
33
32
"k8s.io/perf-tests/clusterloader2/pkg/measurement/common/executors"
34
33
measurementutil "k8s.io/perf-tests/clusterloader2/pkg/measurement/util"
35
-
36
- _ "k8s.io/perf-tests/clusterloader2/pkg/flags" // init klog
37
- )
38
-
39
- var (
40
- // klogv1 allows users to turn on/off logging to stderr only through
41
- // the use of flag. This prevents us from having control over which
42
- // of the test functions have that mechanism turned off when we run
43
- // go test command.
44
- // TODO(#1286): refactor api_responsiveness_prometheus.go to make
45
- // testing of logging easier and remove this hack in the end.
46
- klogLogToStderr = true
47
34
)
48
35
49
- func turnOffLoggingToStderrInKlog (t * testing.T ) {
50
- if klogLogToStderr {
51
- err := flag .Set ("logtostderr" , "false" )
52
- if err != nil {
53
- t .Errorf ("Unable to set flag %v" , err )
54
- return
55
- }
56
- err = flag .Set ("v" , "2" )
57
- if err != nil {
58
- t .Errorf ("Unable to set flag %v" , err )
59
- return
60
- }
61
- flag .Parse ()
62
- klogLogToStderr = false
36
+ func changeLoggingVerbosity (t * testing.T , logLevel string ) {
37
+ var level klog.Level
38
+ if err := level .Set (logLevel ); err != nil {
39
+ t .Errorf ("Unable to set flag %v" , err )
63
40
}
64
41
}
65
42
@@ -574,10 +551,13 @@ func TestLogging(t *testing.T) {
574
551
},
575
552
}
576
553
577
- turnOffLoggingToStderrInKlog (t )
554
+ klog .LogToStderr (false )
555
+ defer klog .LogToStderr (true )
556
+ changeLoggingVerbosity (t , "2" )
578
557
579
558
for _ , tc := range cases {
580
559
t .Run (tc .name , func (t * testing.T ) {
560
+ // FIXME: Why this doesn't catch output?
581
561
buf := bytes .NewBuffer (nil )
582
562
klog .SetOutput (buf )
583
563
@@ -763,10 +743,13 @@ func TestAPIResponsivenessCustomThresholds(t *testing.T) {
763
743
},
764
744
}
765
745
766
- turnOffLoggingToStderrInKlog (t )
746
+ klog .LogToStderr (false )
747
+ defer klog .LogToStderr (true )
748
+ changeLoggingVerbosity (t , "2" )
767
749
768
750
for _ , tc := range cases {
769
751
t .Run (tc .name , func (t * testing.T ) {
752
+ // FIXME: Why this doesn't catch output?
770
753
buf := bytes .NewBuffer (nil )
771
754
klog .SetOutput (buf )
772
755
0 commit comments