Skip to content

Commit c453242

Browse files
author
Sara Wei
committed
add klog
1 parent e3e183f commit c453242

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

cmd/kperf/commands/runner/runner.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package runner
22

33
import (
44
"context"
5+
"flag"
56
"fmt"
67
"os"
78
"path/filepath"
9+
"strconv"
810

911
"github.com/Azure/kperf/api/types"
1012
"github.com/Azure/kperf/request"
1113

1214
"github.com/urfave/cli"
1315
"gopkg.in/yaml.v2"
16+
"k8s.io/klog/v2"
1417
)
1518

1619
// Command represents runner subcommand.
@@ -67,8 +70,19 @@ var runCommand = cli.Command{
6770
Name: "result",
6871
Usage: "Path to the file which stores results",
6972
},
73+
cli.IntFlag{
74+
Name: "v",
75+
Usage: "log level for V logs",
76+
Value: 0,
77+
},
7078
},
7179
Action: func(cliCtx *cli.Context) error {
80+
// initialize klog
81+
klog.InitFlags(nil)
82+
flag.Set("v", strconv.Itoa(cliCtx.Int("v")))
83+
defer klog.Flush()
84+
flag.Parse()
85+
7286
profileCfg, err := loadConfig(cliCtx)
7387
if err != nil {
7488
return err

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
k8s.io/apimachinery v0.28.4
1212
k8s.io/cli-runtime v0.28.4
1313
k8s.io/client-go v0.28.4
14+
k8s.io/klog/v2 v2.100.1
1415
k8s.io/kubectl v0.28.4
1516
)
1617

@@ -135,7 +136,6 @@ require (
135136
k8s.io/apiextensions-apiserver v0.28.4 // indirect
136137
k8s.io/apiserver v0.28.4 // indirect
137138
k8s.io/component-base v0.28.4 // indirect
138-
k8s.io/klog/v2 v2.100.1 // indirect
139139
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
140140
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
141141
oras.land/oras-go v1.2.4 // indirect

request/schedule.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"golang.org/x/time/rate"
1414
"k8s.io/client-go/rest"
15+
"k8s.io/klog/v2"
1516
)
1617

1718
const defaultTimeout = 60 * time.Second
@@ -55,7 +56,10 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
5556
for builder := range reqBuilderCh {
5657
_, req := builder.Build(cli)
5758

59+
klog.V(9).Infof("Request URL: %s", req.URL())
60+
5861
if err := limiter.Wait(ctx); err != nil {
62+
klog.V(9).Infof("Rate limiter wait failed: %v", err)
5963
cancel()
6064
return
6165
}
@@ -77,6 +81,7 @@ func Schedule(ctx context.Context, spec *types.LoadProfileSpec, restCli []rest.I
7781

7882
if err != nil {
7983
respMetric.ObserveFailure(err)
84+
klog.V(9).Infof("Request stream failed: %v", err)
8085
}
8186
}()
8287
}

0 commit comments

Comments
 (0)