-
Notifications
You must be signed in to change notification settings - Fork 53
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
new(cmd,pkg,docs,docgen,validate): switched from slog
go library to rich-text falcoctl log library
#333
Conversation
@@ -46,12 +47,12 @@ func validateArgs() cobra.PositionalArgs { | |||
if len(args) == 0 { | |||
return nil | |||
} | |||
return cobra.ExactValidArgs(1)(c, args) | |||
return cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs)(c, args) |
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 avoids using a deprecated method.
} | ||
} | ||
|
||
// NewCompletionCmd ... | ||
func NewCompletionCmd() *cobra.Command { | ||
func NewCompletionCmd(_ *ConfigOptions, _ *RootOptions, _ *pflag.FlagSet) *cobra.Command { |
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.
Same signature as other commands.
errArr := []error{} | ||
for _, e := range errors { | ||
var errs validator.ValidationErrors | ||
errors.As(err, &errs) |
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.
Use errors.As
as suggested by ide.
This kind of cleanup is done multiple times.
} | ||
|
||
// NewConfigOptions creates an instance of ConfigOptions. | ||
func NewConfigOptions() *ConfigOptions { | ||
o := &ConfigOptions{} | ||
func NewConfigOptions() (*ConfigOptions, error) { |
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.
When creating a configoptions, default to a INFO level logger.
@@ -212,7 +211,6 @@ func buildMirror(a amazonBuilder, r string, kv kernelrelease.KernelRelease) (str | |||
} | |||
|
|||
mirror := fmt.Sprintf("%s/%s", baseURL, "mirror.list") | |||
slog.With("url", mirror, "version", r).Debug("looking for repo...") |
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.
I don't think we actually needed these ones; passing a printer
down there would be a nightmare :)
Also, i think distro builders should not log anything.
@@ -415,7 +421,6 @@ func GetResolvingURLs(urls []string) ([]string, error) { | |||
} | |||
if res.StatusCode == http.StatusOK { | |||
results = append(results, u) | |||
slog.With("url", u).Debug("kernel header url found") |
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.
Again, passing the printer down here would be a bit troublesome.
I preferred to just kill this debug log (and adding a log in KernelDownloadScript
: https://github.com/falcosecurity/driverkit/pull/333/files#diff-16a66a3bc20a8ec693f64ed821148f71efa386a7e942444444eb591512bf129bR173)
} | ||
base, err := url.Parse(uu.Host) | ||
if err != nil { | ||
slog.Error(err.Error()) | ||
os.Exit(1) | ||
panic(err) |
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.
Panic instead of erroring out. Again, this was done to avoid passing the printer down here.
@@ -63,26 +63,27 @@ func (bp *DockerBuildProcessor) String() string { | |||
return DockerBuildProcessorName | |||
} | |||
|
|||
func mustCheckArchUseQemu(ctx context.Context, b *builder.Build, cli *client.Client) { | |||
func (bp *DockerBuildProcessor) mustCheckArchUseQemu(ctx context.Context, b *builder.Build, cli *client.Client) { |
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.
Added the receiver since we need to access bp.Printer
. I could've just used b.Printer
instead, it would be the same, but i preferred this way since this method is tied to docker build processor anyway.
slog.With("processor", c.Name()).Info("driver building, it will take a few seconds") | ||
if !configOptions.DryRun { | ||
b := rootOpts.ToBuild() | ||
RunE: func(c *cobra.Command, args []string) error { |
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.
Another small change: return an error from executors instead of dealing with os.Exit(1)
ourselves.
cmd/docker.go
Outdated
// Since we use a spinner, cache log data to a bytesbuffer; | ||
// we will later print it once we stop the spinner. | ||
var buf bytes.Buffer | ||
b := rootOpts.ToBuild(configOpts.Printer.WithWriter(&buf)) |
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 is a small trick: since when using a Spinner
we cannot print anything to screen (otherwise that would cause a spinner refresh that changes its title and looks ugly), we store to Build
a printer that prints to a bytes buffer; then we defer a function that prints everything after the spinner was stopped.
c1d2c62
to
40efc36
Compare
slog
go library to rich-text falcoctl log libraryslog
go library to rich-text falcoctl log library
Needs a rebase! Going to rebase asap! |
… use rich-text falcoctl log library. Signed-off-by: Federico Di Pierro <[email protected]>
Signed-off-by: Federico Di Pierro <[email protected]>
Signed-off-by: Federico Di Pierro <[email protected]>
Moreover, moved cmd output to more strictly follow `falcoctl` one, with regards to printing usage/helper messages. Signed-off-by: Federico Di Pierro <[email protected]>
Signed-off-by: Federico Di Pierro <[email protected]>
40efc36
to
66e37f7
Compare
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: EXONER4TED, FedeDP The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
Any specific area of the project related to this PR?
/area cmd
/area pkg
/area docs
What this PR does / why we need it:
To better integrate falcoctl and driverkit, we needed to:
slog
instance)Since falcoctl log library is much richer and better, i ported driverkit to use it; now each executor takes a logger parameter, that makes much easier and seamless the ingreation with falcoctl.
The result is wonderful:
driverkit.webm
While i was at it, i also:
local
builderhelp/usage
message printing to follow same conventions as falcoctl (ie: print them less often basically :D)TODO:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: