From 37705dfbbbbd9cb88bd7a4a1cd20ca25aa0f0a53 Mon Sep 17 00:00:00 2001 From: Bingyi Sun Date: Fri, 17 Dec 2021 19:07:39 +0800 Subject: [PATCH] Add module name to logger in proxy (#13580) Signed-off-by: sunby Co-authored-by: sunby --- cmd/roles/roles.go | 3 ++- internal/proxy/impl.go | 13 +++++++++---- internal/proxy/proxy.go | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/roles/roles.go b/cmd/roles/roles.go index 19aa4a18a2..a301db36d2 100644 --- a/cmd/roles/roles.go +++ b/cmd/roles/roles.go @@ -351,7 +351,8 @@ func (mr *MilvusRoles) Run(localMsg bool, alias string) { var pn *components.Proxy if mr.EnableProxy { - pn = mr.runProxy(ctx, localMsg, alias) + pctx := logutil.WithModule(ctx, "Proxy") + pn = mr.runProxy(pctx, localMsg, alias) if pn != nil { defer pn.Stop() } diff --git a/internal/proxy/impl.go b/internal/proxy/impl.go index d1e3ee19e6..253fd7b4c5 100644 --- a/internal/proxy/impl.go +++ b/internal/proxy/impl.go @@ -24,6 +24,7 @@ import ( "strconv" "github.com/milvus-io/milvus/internal/common" + "github.com/milvus-io/milvus/internal/logutil" "github.com/milvus-io/milvus/internal/util/funcutil" @@ -46,6 +47,8 @@ import ( "github.com/milvus-io/milvus/internal/util/typeutil" ) +const moduleName = "Proxy" + // UpdateStateCode updates the state code of Proxy. func (node *Proxy) UpdateStateCode(code internalpb.StateCode) { node.stateCode.Store(code) @@ -94,7 +97,8 @@ func (node *Proxy) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringRe // InvalidateCollectionMetaCache invalidate the meta cache of specific collection. func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *proxypb.InvalidateCollMetaCacheRequest) (*commonpb.Status, error) { - log.Debug("InvalidateCollectionMetaCache", + ctx = logutil.WithModule(ctx, moduleName) + logutil.Logger(ctx).Debug("received request to invalidate collection meta cache", zap.String("role", typeutil.ProxyRole), zap.String("db", request.DbName), zap.String("collection", request.CollectionName)) @@ -103,7 +107,7 @@ func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *p if globalMetaCache != nil { globalMetaCache.RemoveCollection(ctx, collectionName) // no need to return error, though collection may be not cached } - log.Debug("InvalidateCollectionMetaCache Done", + logutil.Logger(ctx).Debug("complete to invalidate collection meta cache", zap.String("role", typeutil.ProxyRole), zap.String("db", request.DbName), zap.String("collection", request.CollectionName)) @@ -116,7 +120,8 @@ func (node *Proxy) InvalidateCollectionMetaCache(ctx context.Context, request *p // ReleaseDQLMessageStream release the query message stream of specific collection. func (node *Proxy) ReleaseDQLMessageStream(ctx context.Context, request *proxypb.ReleaseDQLMessageStreamRequest) (*commonpb.Status, error) { - log.Debug("ReleaseDQLMessageStream", + ctx = logutil.WithModule(ctx, moduleName) + logutil.Logger(ctx).Debug("received request to release DQL message strem", zap.Any("role", typeutil.ProxyRole), zap.Any("db", request.DbID), zap.Any("collection", request.CollectionID)) @@ -127,7 +132,7 @@ func (node *Proxy) ReleaseDQLMessageStream(ctx context.Context, request *proxypb _ = node.chMgr.removeDQLStream(request.CollectionID) - log.Debug("ReleaseDQLMessageStream Done", + logutil.Logger(ctx).Debug("complete to release DQL message stream", zap.Any("role", typeutil.ProxyRole), zap.Any("db", request.DbID), zap.Any("collection", request.CollectionID)) diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index bbc6aca1a4..ca5c85616c 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -25,6 +25,7 @@ import ( "syscall" "time" + "github.com/milvus-io/milvus/internal/logutil" "github.com/milvus-io/milvus/internal/util/metricsinfo" "github.com/milvus-io/milvus/internal/metrics" @@ -103,7 +104,7 @@ func NewProxy(ctx context.Context, factory msgstream.Factory) (*Proxy, error) { msFactory: factory, } node.UpdateStateCode(internalpb.StateCode_Abnormal) - log.Debug("Proxy", zap.Any("State", node.stateCode.Load())) + logutil.Logger(ctx).Debug("create a new Proxy instance", zap.Any("state", node.stateCode.Load())) return node, nil }