Cleanup logrus imports
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
@@ -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()
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user