-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify NSM logging system #1308
Open
anastasia-malysheva
wants to merge
6
commits into
networkservicemesh:main
Choose a base branch
from
anastasia-malysheva:1272-simplify-log-tracing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ebf273b
Remove EnableTracing and udpate condition to enable tracing by Log level
anastasia-malysheva 5e6914a
Lint fix
anastasia-malysheva 897fa47
Add check for registry trace
anastasia-malysheva 067d2a0
fix lint error
anastasia-malysheva 510ee8f
simplify registry traceInfo
anastasia-malysheva a4f482f
lint fixes
anastasia-malysheva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,16 +21,30 @@ package trace | |||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/sirupsen/logrus" | ||||||
"google.golang.org/protobuf/proto" | ||||||
|
||||||
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils" | ||||||
"github.com/networkservicemesh/sdk/pkg/tools/log" | ||||||
"github.com/networkservicemesh/sdk/pkg/tools/log/logruslogger" | ||||||
"github.com/networkservicemesh/sdk/pkg/tools/log/spanlogger" | ||||||
) | ||||||
|
||||||
type contextKeyType string | ||||||
|
||||||
const ( | ||||||
loggedType = "registry" | ||||||
traceInfoKey contextKeyType = "RegistryInfo" | ||||||
loggedType string = "registry" | ||||||
) | ||||||
|
||||||
// traceInfo - struct, containing string representations of request and response, used for tracing. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
type traceInfo struct { | ||||||
// Request is last Registry action of NetworkService{Client, Server} | ||||||
Request proto.Message | ||||||
// Response is last Registry action-response of NetworkService{Client, Server} | ||||||
Response proto.Message | ||||||
} | ||||||
|
||||||
// withLog - provides corresponding logger in context | ||||||
func withLog(parent context.Context, operation string) (c context.Context, f func()) { | ||||||
if parent == nil { | ||||||
|
@@ -41,13 +55,31 @@ func withLog(parent context.Context, operation string) (c context.Context, f fun | |||||
parent = grpcutils.PassTraceToOutgoing(parent) | ||||||
|
||||||
if grpcTraceState := grpcutils.TraceFromContext(parent); (grpcTraceState == grpcutils.TraceOn) || | ||||||
(grpcTraceState == grpcutils.TraceUndefined && log.IsTracingEnabled()) { | ||||||
(grpcTraceState == grpcutils.TraceUndefined && logrus.GetLevel() == logrus.TraceLevel) { | ||||||
ctx, sLogger, span, sFinish := spanlogger.FromContext(parent, operation, map[string]interface{}{"type": loggedType}) | ||||||
ctx, lLogger, lFinish := logruslogger.FromSpan(ctx, span, operation, map[string]interface{}{"type": loggedType}) | ||||||
return log.WithLog(ctx, sLogger, lLogger), func() { | ||||||
return withTrace(log.WithLog(ctx, sLogger, lLogger)), func() { | ||||||
sFinish() | ||||||
lFinish() | ||||||
} | ||||||
} | ||||||
return log.WithLog(parent), func() {} | ||||||
} | ||||||
|
||||||
// withTrace - Provides a traceInfo in context | ||||||
func withTrace(parent context.Context) context.Context { | ||||||
if parent == nil { | ||||||
panic("cannot create context from nil parent") | ||||||
} | ||||||
if _, ok := trace(parent); ok { | ||||||
// We already had registry info | ||||||
return parent | ||||||
} | ||||||
|
||||||
return context.WithValue(parent, traceInfoKey, &traceInfo{}) | ||||||
} | ||||||
|
||||||
func trace(ctx context.Context) (*traceInfo, bool) { | ||||||
val, ok := ctx.Value(traceInfoKey).(*traceInfo) | ||||||
return val, ok | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is always
false
We don't need to check Request and Response, because these fields are used only for
networkservice
(not forregistry
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glazychev-art , fixes for both comments were made