Skip to content

Commit 6f34da5

Browse files
committed
Cleanup logrus imports
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 6020903 commit 6f34da5

54 files changed

Lines changed: 237 additions & 248 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/containerd-stress/cri_worker.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import (
2323
"sync"
2424
"time"
2525

26-
"github.com/sirupsen/logrus"
27-
2826
internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"
27+
"github.com/containerd/containerd/log"
2928
"github.com/containerd/containerd/pkg/cri/util"
3029
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
3130
)
@@ -63,7 +62,7 @@ func (w *criWorker) getFailures() int {
6362
func (w *criWorker) run(ctx, tctx context.Context) {
6463
defer func() {
6564
w.wg.Done()
66-
logrus.Infof("worker %d finished", w.id)
65+
log.L.Infof("worker %d finished", w.id)
6766
}()
6867
for {
6968
select {
@@ -74,13 +73,13 @@ func (w *criWorker) run(ctx, tctx context.Context) {
7473

7574
w.count++
7675
id := w.getID()
77-
logrus.Debugf("starting container %s", id)
76+
log.L.Debugf("starting container %s", id)
7877
start := time.Now()
7978
if err := w.runSandbox(tctx, ctx, id); err != nil {
8079
if err != context.DeadlineExceeded ||
8180
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
8281
w.failures++
83-
logrus.WithError(err).Errorf("running container %s", id)
82+
log.L.WithError(err).Errorf("running container %s", id)
8483
errCounter.WithValues(err.Error()).Inc()
8584

8685
}

cmd/containerd-stress/density.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131

3232
"github.com/containerd/containerd"
3333
"github.com/containerd/containerd/cio"
34+
"github.com/containerd/containerd/log"
3435
"github.com/containerd/containerd/namespaces"
3536
"github.com/containerd/containerd/oci"
36-
"github.com/sirupsen/logrus"
3737
"github.com/urfave/cli"
3838
)
3939

@@ -76,12 +76,12 @@ var densityCommand = cli.Command{
7676
if err := cleanup(ctx, client); err != nil {
7777
return err
7878
}
79-
logrus.Infof("pulling %s", config.Image)
79+
log.L.Infof("pulling %s", config.Image)
8080
image, err := client.Pull(ctx, config.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(config.Snapshotter))
8181
if err != nil {
8282
return err
8383
}
84-
logrus.Info("generating spec from image")
84+
log.L.Info("generating spec from image")
8585

8686
s := make(chan os.Signal, 1)
8787
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)

cmd/containerd-stress/exec_worker.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525

2626
"github.com/containerd/containerd"
2727
"github.com/containerd/containerd/cio"
28+
"github.com/containerd/containerd/log"
2829
"github.com/containerd/containerd/oci"
2930
specs "github.com/opencontainers/runtime-spec/specs-go"
30-
"github.com/sirupsen/logrus"
3131
)
3232

3333
type execWorker struct {
@@ -37,7 +37,7 @@ type execWorker struct {
3737
func (w *execWorker) exec(ctx, tctx context.Context) {
3838
defer func() {
3939
w.wg.Done()
40-
logrus.Infof("worker %d finished", w.id)
40+
log.L.Infof("worker %d finished", w.id)
4141
}()
4242
id := fmt.Sprintf("exec-container-%d", w.id)
4343
c, err := w.client.NewContainer(ctx, id,
@@ -46,32 +46,32 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
4646
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")),
4747
)
4848
if err != nil {
49-
logrus.WithError(err).Error("create exec container")
49+
log.L.WithError(err).Error("create exec container")
5050
return
5151
}
5252
defer c.Delete(ctx, containerd.WithSnapshotCleanup)
5353

5454
task, err := c.NewTask(ctx, cio.NullIO)
5555
if err != nil {
56-
logrus.WithError(err).Error("create exec container's task")
56+
log.L.WithError(err).Error("create exec container's task")
5757
return
5858
}
5959
defer task.Delete(ctx, containerd.WithProcessKill)
6060

6161
statusC, err := task.Wait(ctx)
6262
if err != nil {
63-
logrus.WithError(err).Error("wait exec container's task")
63+
log.L.WithError(err).Error("wait exec container's task")
6464
return
6565
}
6666

6767
if err := task.Start(ctx); err != nil {
68-
logrus.WithError(err).Error("exec container start failure")
68+
log.L.WithError(err).Error("exec container start failure")
6969
return
7070
}
7171

7272
spec, err := c.Spec(ctx)
7373
if err != nil {
74-
logrus.WithError(err).Error("failed to get spec")
74+
log.L.WithError(err).Error("failed to get spec")
7575
return
7676
}
7777

@@ -82,7 +82,7 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
8282
select {
8383
case <-tctx.Done():
8484
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
85-
logrus.WithError(err).Error("kill exec container's task")
85+
log.L.WithError(err).Error("kill exec container's task")
8686
}
8787
<-statusC
8888
return
@@ -91,14 +91,14 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
9191

9292
w.count++
9393
id := w.getID()
94-
logrus.Debugf("starting exec %s", id)
94+
log.L.Debugf("starting exec %s", id)
9595
start := time.Now()
9696

9797
if err := w.runExec(ctx, task, id, pspec); err != nil {
9898
if err != context.DeadlineExceeded ||
9999
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
100100
w.failures++
101-
logrus.WithError(err).Errorf("running exec %s", id)
101+
log.L.WithError(err).Errorf("running exec %s", id)
102102
errCounter.WithValues(err.Error()).Inc()
103103
}
104104
continue

cmd/containerd-stress/main.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import (
3030

3131
"github.com/containerd/containerd"
3232
"github.com/containerd/containerd/integration/remote"
33+
"github.com/containerd/containerd/log"
3334
"github.com/containerd/containerd/namespaces"
3435
"github.com/containerd/containerd/plugin"
3536
metrics "github.com/docker/go-metrics"
36-
"github.com/sirupsen/logrus"
3737
"github.com/urfave/cli"
3838
)
3939

@@ -177,10 +177,14 @@ func main() {
177177
}
178178
app.Before = func(context *cli.Context) error {
179179
if context.GlobalBool("json") {
180-
logrus.SetLevel(logrus.WarnLevel)
180+
if err := log.SetLevel("warn"); err != nil {
181+
return err
182+
}
181183
}
182184
if context.GlobalBool("debug") {
183-
logrus.SetLevel(logrus.DebugLevel)
185+
if err := log.SetLevel("debug"); err != nil {
186+
return err
187+
}
184188
}
185189
return nil
186190
}
@@ -241,7 +245,7 @@ func serve(c config) error {
241245
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
242246
}
243247
if err := srv.ListenAndServe(); err != nil {
244-
logrus.WithError(err).Error("listen and serve")
248+
log.L.WithError(err).Error("listen and serve")
245249
}
246250
}()
247251
checkBinarySizes()
@@ -287,7 +291,7 @@ func criTest(c config) error {
287291
workers []worker
288292
r = &run{}
289293
)
290-
logrus.Info("starting stress test run...")
294+
log.L.Info("starting stress test run...")
291295
// create the workers along with their spec
292296
for i := 0; i < c.Concurrency; i++ {
293297
wg.Add(1)
@@ -312,9 +316,9 @@ func criTest(c config) error {
312316
r.end()
313317

314318
results := r.gather(workers)
315-
logrus.Infof("ending test run in %0.3f seconds", results.Seconds)
319+
log.L.Infof("ending test run in %0.3f seconds", results.Seconds)
316320

317-
logrus.WithField("failures", r.failures).Infof(
321+
log.L.WithField("failures", r.failures).Infof(
318322
"create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)",
319323
results.Total,
320324
results.Seconds,
@@ -345,7 +349,7 @@ func test(c config) error {
345349
return err
346350
}
347351

348-
logrus.Infof("pulling %s", c.Image)
352+
log.L.Infof("pulling %s", c.Image)
349353
image, err := client.Pull(ctx, c.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(c.Snapshotter))
350354
if err != nil {
351355
return err
@@ -367,7 +371,7 @@ func test(c config) error {
367371
workers []worker
368372
r = &run{}
369373
)
370-
logrus.Info("starting stress test run...")
374+
log.L.Info("starting stress test run...")
371375
// create the workers along with their spec
372376
for i := 0; i < c.Concurrency; i++ {
373377
wg.Add(1)
@@ -414,9 +418,9 @@ func test(c config) error {
414418
results.ExecTotal = exec.count
415419
results.ExecFailures = exec.failures
416420
}
417-
logrus.Infof("ending test run in %0.3f seconds", results.Seconds)
421+
log.L.Infof("ending test run in %0.3f seconds", results.Seconds)
418422

419-
logrus.WithField("failures", r.failures).Infof(
423+
log.L.WithField("failures", r.failures).Infof(
420424
"create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)",
421425
results.Total,
422426
results.Seconds,

cmd/containerd-stress/size.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"os"
2121

22-
"github.com/sirupsen/logrus"
22+
"github.com/containerd/containerd/log"
2323
)
2424

2525
const defaultPath = "/usr/local/bin/"
@@ -37,12 +37,12 @@ func checkBinarySizes() {
3737
for _, name := range binaries {
3838
fi, err := os.Stat(name)
3939
if err != nil {
40-
logrus.WithError(err).Error("stat binary")
40+
log.L.WithError(err).Error("stat binary")
4141
continue
4242
}
4343

4444
if fi.IsDir() {
45-
logrus.Error(name, "is not a file")
45+
log.L.Error(name, "is not a file")
4646
continue
4747
}
4848

cmd/containerd-stress/worker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
"github.com/containerd/containerd"
2727
"github.com/containerd/containerd/cio"
28+
"github.com/containerd/containerd/log"
2829
"github.com/containerd/containerd/oci"
29-
"github.com/sirupsen/logrus"
3030
)
3131

3232
type ctrWorker struct {
@@ -44,7 +44,7 @@ type ctrWorker struct {
4444
func (w *ctrWorker) run(ctx, tctx context.Context) {
4545
defer func() {
4646
w.wg.Done()
47-
logrus.Infof("worker %d finished", w.id)
47+
log.L.Infof("worker %d finished", w.id)
4848
}()
4949
for {
5050
select {
@@ -55,13 +55,13 @@ func (w *ctrWorker) run(ctx, tctx context.Context) {
5555

5656
w.count++
5757
id := w.getID()
58-
logrus.Debugf("starting container %s", id)
58+
log.L.Debugf("starting container %s", id)
5959
start := time.Now()
6060
if err := w.runContainer(ctx, id); err != nil {
6161
if err != context.DeadlineExceeded ||
6262
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
6363
w.failures++
64-
logrus.WithError(err).Errorf("running container %s", id)
64+
log.L.WithError(err).Errorf("running container %s", id)
6565
errCounter.WithValues(err.Error()).Inc()
6666

6767
}

cmd/containerd/command/main_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func setupDumpStacks() {
7575
ev, _ := windows.UTF16PtrFromString(event)
7676
sd, err := windows.SecurityDescriptorFromString("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
7777
if err != nil {
78-
logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error())
78+
log.L.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error())
7979
return
8080
}
8181
var sa windows.SecurityAttributes
@@ -84,11 +84,11 @@ func setupDumpStacks() {
8484
sa.SecurityDescriptor = sd
8585
h, err := windows.CreateEvent(&sa, 0, 0, ev)
8686
if h == 0 || err != nil {
87-
logrus.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
87+
log.L.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
8888
return
8989
}
9090
go func() {
91-
logrus.Debugf("Stackdump - waiting signal at %s", event)
91+
log.L.Debugf("Stackdump - waiting signal at %s", event)
9292
for {
9393
windows.WaitForSingleObject(h, windows.INFINITE)
9494
dumpStacks(true)
@@ -109,7 +109,7 @@ func init() {
109109
// Microsoft/go-winio/tools/etw-provider-gen.
110110
provider, err := etw.NewProvider("ContainerD", etwCallback)
111111
if err != nil {
112-
logrus.Error(err)
112+
log.L.Error(err)
113113
} else {
114114
if hook, err := etwlogrus.NewHookFromProvider(provider); err == nil {
115115
logrus.AddHook(hook)

cmd/ctr/commands/containers/restore.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/containerd/containerd/cmd/ctr/commands"
2626
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
2727
"github.com/containerd/containerd/errdefs"
28-
"github.com/sirupsen/logrus"
28+
"github.com/containerd/containerd/log"
2929
"github.com/urfave/cli"
3030
)
3131

@@ -124,7 +124,7 @@ var restoreCommand = cli.Command{
124124
}
125125

126126
if err := tasks.HandleConsoleResize(ctx, task, con); err != nil {
127-
logrus.WithError(err).Error("console resize")
127+
log.G(ctx).WithError(err).Error("console resize")
128128
}
129129

130130
status := <-statusC

cmd/ctr/commands/run/run.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ import (
3030
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
3131
"github.com/containerd/containerd/containers"
3232
clabels "github.com/containerd/containerd/labels"
33+
"github.com/containerd/containerd/log"
3334
"github.com/containerd/containerd/oci"
3435
gocni "github.com/containerd/go-cni"
3536
specs "github.com/opencontainers/runtime-spec/specs-go"
36-
"github.com/sirupsen/logrus"
3737
"github.com/urfave/cli"
3838
)
3939

@@ -199,7 +199,7 @@ var Command = cli.Command{
199199
defer func() {
200200
if enableCNI {
201201
if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil {
202-
logrus.WithError(err).Error("network review")
202+
log.L.WithError(err).Error("network review")
203203
}
204204
}
205205
task.Delete(ctx)
@@ -232,7 +232,7 @@ var Command = cli.Command{
232232
}
233233
if tty {
234234
if err := tasks.HandleConsoleResize(ctx, task, con); err != nil {
235-
logrus.WithError(err).Error("console resize")
235+
log.L.WithError(err).Error("console resize")
236236
}
237237
} else {
238238
sigc := commands.ForwardAllSignals(ctx, task)
@@ -262,7 +262,7 @@ func buildLabels(cmdLabels, imageLabels map[string]string) map[string]string {
262262
} else {
263263
// In case the image label is invalid, we output a warning and skip adding it to the
264264
// container.
265-
logrus.WithError(err).Warnf("unable to add image label with key %s to the container", k)
265+
log.L.WithError(err).Warnf("unable to add image label with key %s to the container", k)
266266
}
267267
}
268268
// labels from the command line will override image and the initial image config labels

0 commit comments

Comments
 (0)