Cleanup logrus imports

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2023-05-05 11:54:14 -07:00
parent 6020903f2c
commit 6f34da5f80
54 changed files with 237 additions and 248 deletions

View File

@@ -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"
)
@@ -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 {
@@ -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()
}

View File

@@ -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"
)
@@ -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)

View File

@@ -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 {
@@ -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,
@@ -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
}
@@ -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
@@ -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

View File

@@ -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"
)
@@ -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
}
@@ -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()
@@ -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)
@@ -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,
@@ -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
@@ -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)
@@ -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,

View File

@@ -19,7 +19,7 @@ package main
import (
"os"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
)
const defaultPath = "/usr/local/bin/"
@@ -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
}

View File

@@ -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 {
@@ -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 {
@@ -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()
}

View File

@@ -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
@@ -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)
@@ -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)

View File

@@ -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"
)
@@ -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

View File

@@ -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"
)
@@ -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)
@@ -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)
@@ -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

View File

@@ -25,11 +25,11 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/pkg/netns"
"github.com/containerd/containerd/snapshots"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -122,7 +122,7 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
con := console.Current()
size, err := con.Size()
if err != nil {
logrus.WithError(err).Error("console size")
log.L.WithError(err).Error("console size")
}
opts = append(opts, oci.WithTTYSize(int(size.Width), int(size.Height)))
}

View File

@@ -30,13 +30,13 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
ptypes "github.com/containerd/containerd/protobuf/types"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/containerd/ttrpc"
"github.com/containerd/typeurl/v2"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -204,7 +204,7 @@ var execCommand = cli.Command{
}
fmt.Printf("exec running with pid %d\n", r.Pid)
if context.Bool("attach") {
logrus.Info("attaching")
log.L.Info("attaching")
if tty {
current := console.Current()
defer current.Reset()

View File

@@ -24,7 +24,7 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
)
type killer interface {
@@ -38,16 +38,16 @@ func ForwardAllSignals(ctx gocontext.Context, task killer) chan os.Signal {
go func() {
for s := range sigc {
if canIgnoreSignal(s) {
logrus.Debugf("Ignoring signal %s", s)
log.L.Debugf("Ignoring signal %s", s)
continue
}
logrus.Debug("forwarding signal ", s)
log.L.Debug("forwarding signal ", s)
if err := task.Kill(ctx, s.(syscall.Signal)); err != nil {
if errdefs.IsNotFound(err) {
logrus.WithError(err).Debugf("Not forwarding signal %s", s)
log.L.WithError(err).Debugf("Not forwarding signal %s", s)
return
}
logrus.WithError(err).Errorf("forward signal %s", s)
log.L.WithError(err).Errorf("forward signal %s", s)
}
}
}()

View File

@@ -20,7 +20,7 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
"github.com/urfave/cli"
)
@@ -66,7 +66,7 @@ var attachCommand = cli.Command{
if tty {
if err := 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)

View File

@@ -26,8 +26,8 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -174,7 +174,7 @@ var execCommand = cli.Command{
}
if tty {
if err := HandleConsoleResize(ctx, process, con); err != nil {
logrus.WithError(err).Error("console resize")
log.L.WithError(err).Error("console resize")
}
} else {
sigc := commands.ForwardAllSignals(ctx, process)

View File

@@ -23,10 +23,10 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/log"
gocni "github.com/containerd/go-cni"
"github.com/containerd/typeurl/v2"
"github.com/moby/sys/signal"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
@@ -54,7 +54,7 @@ func RemoveCniNetworkIfExist(ctx context.Context, container containerd.Container
return err
}
if err := network.Remove(ctx, commands.FullID(ctx, container), ""); err != nil {
logrus.WithError(err).Error("network remove error")
log.L.WithError(err).Error("network remove error")
return err
}
}

View File

@@ -23,7 +23,7 @@ import (
"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/log"
"github.com/urfave/cli"
)
@@ -115,7 +115,7 @@ var startCommand = cli.Command{
}
if tty {
if err := 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)