Skip to content
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

feat: add trace for executables #744

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/notaryproject/notation-go v1.0.0-rc.6
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc4
github.com/oras-project/oras-credentials-go v0.2.0
github.com/oras-project/oras-credentials-go v0.3.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0=
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/oras-project/oras-credentials-go v0.2.0 h1:BvWAXo0e5unWR6Hfxyb0K04mHNHreQz/Zclw6IzCYJo=
github.com/oras-project/oras-credentials-go v0.2.0/go.mod h1:JVdg7a5k7hzTrEeeouwag0aCv7OLrS77r7/6w3gVirU=
github.com/oras-project/oras-credentials-go v0.2.1-0.20230714083315-2afb422fe225 h1:0T0CYijlSdn0ariTr48cRn6YDl445VZf3yqCqJKksqo=
github.com/oras-project/oras-credentials-go v0.2.1-0.20230714083315-2afb422fe225/go.mod h1:fFCebDQo0Do+gnM96uV9YUnRay0pwuRQupypvofsp4s=
Copy link
Contributor

@Wwwsylvia Wwwsylvia Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran go mod tidy.

github.com/oras-project/oras-credentials-go v0.3.0 h1:Bg1d9iAmgo50RlaIy2XI5MQs7qL00DB3R9Q4JRP1VWs=
github.com/oras-project/oras-credentials-go v0.3.0/go.mod h1:fFCebDQo0Do+gnM96uV9YUnRay0pwuRQupypvofsp4s=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
24 changes: 22 additions & 2 deletions internal/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cmd
import (
"context"

"github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation/internal/trace"
credentialstrace "github.com/oras-project/oras-credentials-go/trace"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -44,9 +46,27 @@ func (opts *LoggingFlagOpts) ApplyFlags(fs *pflag.FlagSet) {
// SetLoggerLevel sets up the logger based on common options.
func (opts *LoggingFlagOpts) SetLoggerLevel(ctx context.Context) context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question: Do we need to rename this function given that it now does more than setting logger level? 🤔 @JeyJeyGao

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the function to InitializaLogger.

if opts.Debug {
return trace.WithLoggerLevel(ctx, logrus.DebugLevel)
ctx = trace.WithLoggerLevel(ctx, logrus.DebugLevel)
} else if opts.Verbose {
return trace.WithLoggerLevel(ctx, logrus.InfoLevel)
ctx = trace.WithLoggerLevel(ctx, logrus.InfoLevel)
}
return withExecutableTrace(ctx)
JeyJeyGao marked this conversation as resolved.
Show resolved Hide resolved
}

// withExecutableTrace adds tracing for credential helper executables.
func withExecutableTrace(ctx context.Context) context.Context {
logger := log.GetLogger(ctx)
JeyJeyGao marked this conversation as resolved.
Show resolved Hide resolved
ctx = credentialstrace.WithExecutableTrace(ctx, &credentialstrace.ExecutableTrace{
ExecuteStart: func(executableName, action string) {
logger.Debugf("started executing credential helper program %s with action %s", executableName, action)
},
ExecuteDone: func(executableName, action string, err error) {
JeyJeyGao marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
logger.Errorf("finished executing credential helper program %s with action %s and got error %w", executableName, action, err)
} else {
logger.Debugf("finished executing credential helper program %s with action %s", executableName, action)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Debugf("finished executing credential helper program %s with action %s", executableName, action)
logger.Debugf("successfully finished executing credential helper program %s with action %s", executableName, action)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed accordingly

}
},
})
return ctx
}
Loading