Skip to content

Commit

Permalink
Merge pull request containerd#8481 from mxpv/logrus
Browse files Browse the repository at this point in the history
Cleanup logrus imports
  • Loading branch information
mxpv committed May 6, 2023
2 parents 5dda3d8 + 6f34da5 commit 98f48d4
Show file tree
Hide file tree
Showing 54 changed files with 237 additions and 248 deletions.
9 changes: 4 additions & 5 deletions cmd/containerd-stress/cri_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
"sync"
"time"

"github.com/sirupsen/logrus"

internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/pkg/cri/util"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
Expand Down Expand Up @@ -63,7 +62,7 @@ func (w *criWorker) getFailures() int {
func (w *criWorker) run(ctx, tctx context.Context) {
defer func() {
w.wg.Done()
logrus.Infof("worker %d finished", w.id)
log.L.Infof("worker %d finished", w.id)
}()
for {
select {
Expand All @@ -74,13 +73,13 @@ func (w *criWorker) run(ctx, tctx context.Context) {

w.count++
id := w.getID()
logrus.Debugf("starting container %s", id)
log.L.Debugf("starting container %s", id)
start := time.Now()
if err := w.runSandbox(tctx, ctx, id); err != nil {
if err != context.DeadlineExceeded ||
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
w.failures++
logrus.WithError(err).Errorf("running container %s", id)
log.L.WithError(err).Errorf("running container %s", id)
errCounter.WithValues(err.Error()).Inc()

}
Expand Down
6 changes: 3 additions & 3 deletions cmd/containerd-stress/density.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -76,12 +76,12 @@ var densityCommand = cli.Command{
if err := cleanup(ctx, client); err != nil {
return err
}
logrus.Infof("pulling %s", config.Image)
log.L.Infof("pulling %s", config.Image)
image, err := client.Pull(ctx, config.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(config.Snapshotter))
if err != nil {
return err
}
logrus.Info("generating spec from image")
log.L.Info("generating spec from image")

s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
Expand Down
20 changes: 10 additions & 10 deletions cmd/containerd-stress/exec_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/oci"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
)

type execWorker struct {
Expand All @@ -37,7 +37,7 @@ type execWorker struct {
func (w *execWorker) exec(ctx, tctx context.Context) {
defer func() {
w.wg.Done()
logrus.Infof("worker %d finished", w.id)
log.L.Infof("worker %d finished", w.id)
}()
id := fmt.Sprintf("exec-container-%d", w.id)
c, err := w.client.NewContainer(ctx, id,
Expand All @@ -46,32 +46,32 @@ func (w *execWorker) exec(ctx, tctx context.Context) {
containerd.WithNewSpec(oci.WithImageConfig(w.image), oci.WithUsername("games"), oci.WithProcessArgs("sleep", "30d")),
)
if err != nil {
logrus.WithError(err).Error("create exec container")
log.L.WithError(err).Error("create exec container")
return
}
defer c.Delete(ctx, containerd.WithSnapshotCleanup)

task, err := c.NewTask(ctx, cio.NullIO)
if err != nil {
logrus.WithError(err).Error("create exec container's task")
log.L.WithError(err).Error("create exec container's task")
return
}
defer task.Delete(ctx, containerd.WithProcessKill)

statusC, err := task.Wait(ctx)
if err != nil {
logrus.WithError(err).Error("wait exec container's task")
log.L.WithError(err).Error("wait exec container's task")
return
}

if err := task.Start(ctx); err != nil {
logrus.WithError(err).Error("exec container start failure")
log.L.WithError(err).Error("exec container start failure")
return
}

spec, err := c.Spec(ctx)
if err != nil {
logrus.WithError(err).Error("failed to get spec")
log.L.WithError(err).Error("failed to get spec")
return
}

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

w.count++
id := w.getID()
logrus.Debugf("starting exec %s", id)
log.L.Debugf("starting exec %s", id)
start := time.Now()

if err := w.runExec(ctx, task, id, pspec); err != nil {
if err != context.DeadlineExceeded ||
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
w.failures++
logrus.WithError(err).Errorf("running exec %s", id)
log.L.WithError(err).Errorf("running exec %s", id)
errCounter.WithValues(err.Error()).Inc()
}
continue
Expand Down
26 changes: 15 additions & 11 deletions cmd/containerd-stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/integration/remote"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/plugin"
metrics "github.com/docker/go-metrics"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -177,10 +177,14 @@ func main() {
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("json") {
logrus.SetLevel(logrus.WarnLevel)
if err := log.SetLevel("warn"); err != nil {
return err
}
}
if context.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
if err := log.SetLevel("debug"); err != nil {
return err
}
}
return nil
}
Expand Down Expand Up @@ -241,7 +245,7 @@ func serve(c config) error {
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
}
if err := srv.ListenAndServe(); err != nil {
logrus.WithError(err).Error("listen and serve")
log.L.WithError(err).Error("listen and serve")
}
}()
checkBinarySizes()
Expand Down Expand Up @@ -287,7 +291,7 @@ func criTest(c config) error {
workers []worker
r = &run{}
)
logrus.Info("starting stress test run...")
log.L.Info("starting stress test run...")
// create the workers along with their spec
for i := 0; i < c.Concurrency; i++ {
wg.Add(1)
Expand All @@ -312,9 +316,9 @@ func criTest(c config) error {
r.end()

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

logrus.WithField("failures", r.failures).Infof(
log.L.WithField("failures", r.failures).Infof(
"create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)",
results.Total,
results.Seconds,
Expand Down Expand Up @@ -345,7 +349,7 @@ func test(c config) error {
return err
}

logrus.Infof("pulling %s", c.Image)
log.L.Infof("pulling %s", c.Image)
image, err := client.Pull(ctx, c.Image, containerd.WithPullUnpack, containerd.WithPullSnapshotter(c.Snapshotter))
if err != nil {
return err
Expand All @@ -367,7 +371,7 @@ func test(c config) error {
workers []worker
r = &run{}
)
logrus.Info("starting stress test run...")
log.L.Info("starting stress test run...")
// create the workers along with their spec
for i := 0; i < c.Concurrency; i++ {
wg.Add(1)
Expand Down Expand Up @@ -414,9 +418,9 @@ func test(c config) error {
results.ExecTotal = exec.count
results.ExecFailures = exec.failures
}
logrus.Infof("ending test run in %0.3f seconds", results.Seconds)
log.L.Infof("ending test run in %0.3f seconds", results.Seconds)

logrus.WithField("failures", r.failures).Infof(
log.L.WithField("failures", r.failures).Infof(
"create/start/delete %d containers in %0.3f seconds (%0.3f c/sec) or (%0.3f sec/c)",
results.Total,
results.Seconds,
Expand Down
6 changes: 3 additions & 3 deletions cmd/containerd-stress/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package main
import (
"os"

"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
)

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

if fi.IsDir() {
logrus.Error(name, "is not a file")
log.L.Error(name, "is not a file")
continue
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/containerd-stress/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/oci"
"github.com/sirupsen/logrus"
)

type ctrWorker struct {
Expand All @@ -44,7 +44,7 @@ type ctrWorker struct {
func (w *ctrWorker) run(ctx, tctx context.Context) {
defer func() {
w.wg.Done()
logrus.Infof("worker %d finished", w.id)
log.L.Infof("worker %d finished", w.id)
}()
for {
select {
Expand All @@ -55,13 +55,13 @@ func (w *ctrWorker) run(ctx, tctx context.Context) {

w.count++
id := w.getID()
logrus.Debugf("starting container %s", id)
log.L.Debugf("starting container %s", id)
start := time.Now()
if err := w.runContainer(ctx, id); err != nil {
if err != context.DeadlineExceeded ||
!strings.Contains(err.Error(), context.DeadlineExceeded.Error()) {
w.failures++
logrus.WithError(err).Errorf("running container %s", id)
log.L.WithError(err).Errorf("running container %s", id)
errCounter.WithValues(err.Error()).Inc()

}
Expand Down
8 changes: 4 additions & 4 deletions cmd/containerd/command/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func setupDumpStacks() {
ev, _ := windows.UTF16PtrFromString(event)
sd, err := windows.SecurityDescriptorFromString("D:P(A;;GA;;;BA)(A;;GA;;;SY)")
if err != nil {
logrus.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error())
log.L.Errorf("failed to get security descriptor for debug stackdump event %s: %s", event, err.Error())
return
}
var sa windows.SecurityAttributes
Expand All @@ -84,11 +84,11 @@ func setupDumpStacks() {
sa.SecurityDescriptor = sd
h, err := windows.CreateEvent(&sa, 0, 0, ev)
if h == 0 || err != nil {
logrus.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
log.L.Errorf("failed to create debug stackdump event %s: %s", event, err.Error())
return
}
go func() {
logrus.Debugf("Stackdump - waiting signal at %s", event)
log.L.Debugf("Stackdump - waiting signal at %s", event)
for {
windows.WaitForSingleObject(h, windows.INFINITE)
dumpStacks(true)
Expand All @@ -109,7 +109,7 @@ func init() {
// Microsoft/go-winio/tools/etw-provider-gen.
provider, err := etw.NewProvider("ContainerD", etwCallback)
if err != nil {
logrus.Error(err)
log.L.Error(err)
} else {
if hook, err := etwlogrus.NewHookFromProvider(provider); err == nil {
logrus.AddHook(hook)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ctr/commands/containers/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
"github.com/containerd/containerd/errdefs"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -124,7 +124,7 @@ var restoreCommand = cli.Command{
}

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

status := <-statusC
Expand Down
8 changes: 4 additions & 4 deletions cmd/ctr/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import (
"github.com/containerd/containerd/cmd/ctr/commands/tasks"
"github.com/containerd/containerd/containers"
clabels "github.com/containerd/containerd/labels"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/oci"
gocni "github.com/containerd/go-cni"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -199,7 +199,7 @@ var Command = cli.Command{
defer func() {
if enableCNI {
if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil {
logrus.WithError(err).Error("network review")
log.L.WithError(err).Error("network review")
}
}
task.Delete(ctx)
Expand Down Expand Up @@ -232,7 +232,7 @@ var Command = cli.Command{
}
if tty {
if err := tasks.HandleConsoleResize(ctx, task, con); err != nil {
logrus.WithError(err).Error("console resize")
log.L.WithError(err).Error("console resize")
}
} else {
sigc := commands.ForwardAllSignals(ctx, task)
Expand Down Expand Up @@ -262,7 +262,7 @@ func buildLabels(cmdLabels, imageLabels map[string]string) map[string]string {
} else {
// In case the image label is invalid, we output a warning and skip adding it to the
// container.
logrus.WithError(err).Warnf("unable to add image label with key %s to the container", k)
log.L.WithError(err).Warnf("unable to add image label with key %s to the container", k)
}
}
// labels from the command line will override image and the initial image config labels
Expand Down
Loading

0 comments on commit 98f48d4

Please sign in to comment.