Skip to content

Commit abf58be

Browse files
committed
Fix clusterloader2 failures after flag registration changes
1 parent 2c1b670 commit abf58be

File tree

4 files changed

+16
-31
lines changed

4 files changed

+16
-31
lines changed

clusterloader2/cmd/clusterloader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func validateClusterFlags() *errors.ErrorList {
124124
}
125125

126126
func initFlags() {
127+
flags.InitFlagSet()
128+
127129
flags.StringVar(&clusterLoaderConfig.ReportDir, "report-dir", "", "Path to the directory where the reports should be saved. Default is empty, which cause reports being written to standard output.")
128130
// TODO(https://github.com/kubernetes/perf-tests/issues/641): Remove testconfig and testoverrides flags when test suite is fully supported.
129131
flags.StringArrayVar(&testConfigPaths, "testconfig", []string{}, "Paths to the test config files")

clusterloader2/pkg/flags/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"k8s.io/klog/v2"
2929
)
3030

31-
func init() {
31+
func InitFlagSet() {
3232
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
3333
klog.InitFlags(nil)
3434
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

clusterloader2/pkg/measurement/common/slos/api_responsiveness_prometheus_test.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package slos
1919
import (
2020
"bytes"
2121
"encoding/json"
22-
"flag"
2322
"fmt"
2423
"strings"
2524
"testing"
@@ -32,34 +31,12 @@ import (
3231
"k8s.io/perf-tests/clusterloader2/pkg/measurement"
3332
"k8s.io/perf-tests/clusterloader2/pkg/measurement/common/executors"
3433
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
4734
)
4835

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)
6340
}
6441
}
6542

@@ -574,10 +551,13 @@ func TestLogging(t *testing.T) {
574551
},
575552
}
576553

577-
turnOffLoggingToStderrInKlog(t)
554+
klog.LogToStderr(false)
555+
defer klog.LogToStderr(true)
556+
changeLoggingVerbosity(t, "2")
578557

579558
for _, tc := range cases {
580559
t.Run(tc.name, func(t *testing.T) {
560+
// FIXME: Why this doesn't catch output?
581561
buf := bytes.NewBuffer(nil)
582562
klog.SetOutput(buf)
583563

@@ -763,10 +743,13 @@ func TestAPIResponsivenessCustomThresholds(t *testing.T) {
763743
},
764744
}
765745

766-
turnOffLoggingToStderrInKlog(t)
746+
klog.LogToStderr(false)
747+
defer klog.LogToStderr(true)
748+
changeLoggingVerbosity(t, "2")
767749

768750
for _, tc := range cases {
769751
t.Run(tc.name, func(t *testing.T) {
752+
// FIXME: Why this doesn't catch output?
770753
buf := bytes.NewBuffer(nil)
771754
klog.SetOutput(buf)
772755

clusterloader2/run-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ users:
131131
export KUBECONFIG=${kubeconfig}
132132

133133
cd "${CLUSTERLOADER_ROOT}"/ && go build -o clusterloader './cmd/'
134-
./clusterloader --alsologtostderr --v="${CL2_VERBOSITY:-2}" "$@"
134+
./clusterloader --v="${CL2_VERBOSITY:-2}" "$@"

0 commit comments

Comments
 (0)