فهرست منبع

libnet: resolver: remove direct use of logrus

This causes logs written through `r.log(ctx)` to not end in OTEL traces.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Albin Kerouanton 1 سال پیش
والد
کامیت
2c4551d86d
2فایلهای تغییر یافته به همراه5 افزوده شده و 6 حذف شده
  1. 3 4
      libnetwork/resolver.go
  2. 2 2
      libnetwork/resolver_test.go

+ 3 - 4
libnetwork/resolver.go

@@ -14,7 +14,6 @@ import (
 	"github.com/containerd/containerd/log"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/miekg/dns"
-	"github.com/sirupsen/logrus"
 	"go.opentelemetry.io/otel"
 	"go.opentelemetry.io/otel/attribute"
 	"go.opentelemetry.io/otel/codes"
@@ -78,7 +77,7 @@ type Resolver struct {
 	listenAddress string
 	proxyDNS      bool
 	startCh       chan struct{}
-	logger        *logrus.Logger
+	logger        *log.Entry
 
 	fwdSem      *semaphore.Weighted // Limit the number of concurrent external DNS requests in-flight
 	logInverval rate.Sometimes      // Rate-limit logging about hitting the fwdSem limit
@@ -97,9 +96,9 @@ func NewResolver(address string, proxyDNS bool, backend DNSBackend) *Resolver {
 	}
 }
 
-func (r *Resolver) log(ctx context.Context) *logrus.Logger {
+func (r *Resolver) log(ctx context.Context) *log.Entry {
 	if r.logger == nil {
-		return log.G(ctx).Logger
+		return log.G(ctx)
 	}
 	return r.logger
 }

+ 2 - 2
libnetwork/resolver_test.go

@@ -226,11 +226,11 @@ func TestOversizedDNSReply(t *testing.T) {
 	checkDNSRRType(t, resp.Answer[0].Header().Rrtype, dns.TypeA)
 }
 
-func testLogger(t *testing.T) *logrus.Logger {
+func testLogger(t *testing.T) *logrus.Entry {
 	logger := logrus.New()
 	logger.SetLevel(logrus.DebugLevel)
 	logger.SetOutput(tlogWriter{t})
-	return logger
+	return logrus.NewEntry(logger)
 }
 
 type tlogWriter struct{ t *testing.T }