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

update(output): complete rework of the output system #335

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

alacuku
Copy link
Member

@alacuku alacuku commented Oct 25, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

/kind flaky-test

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area library

/area cli

/area tests

/area examples

What this PR does / why we need it:

It's a complete rework of the output system. The scope is to introduce a consistent logging and formatting across all falcoctl commands. It is done by using structured logging, but at the same time objects as spinners and progress bars are rendered during the operations but removed once done. Furthermore the new logging prints also the timestamps which is handy for the faloctl artifact follow command. It allows to know when a specific actions has been performed and easies the troubleshooting problems when they occurs.

The old flags --verbose and --disable-styling have been deprecated and substituted with --log-level and --log-format flags. It will be completely removed in one of the next releases of falcoctl.

The new log levels supported in falcoctl are:

  • Info;
  • Debug;
  • Warn;
  • Trace.
    The default value is Info.

The new formats are color, text and json.

By setting the --verbose flag is equivalent to using --log-level debug and the --disable-styling is equivalent to --log-format json

Here are some examples of the new output in falcoctl:

Default logging:

❯ falcoctl artifact install k8saudit
2023-10-25 12:07:12 INFO  Resolving dependencies ... 
2023-10-25 12:07:13 INFO  Installing artifacts refs: [ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest]
2023-10-25 12:07:13 INFO  Preparing to pull artifact ref: ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest
2023-10-25 12:07:14 INFO  Pulling layer 75ff683c3b71 
2023-10-25 12:07:14 INFO  Pulling layer e2908ebf2c03                                                                  
2023-10-25 12:07:15 INFO  Pulling layer bebd560a926b                                                                  
2023-10-25 12:07:15 INFO  Verifying signature for artifact                                                            
                      └ digest: ghcr.io/falcosecurity/plugins/plugin/k8saudit@sha256:230dfdc0e1d331c5085f3f4c860838dcfc27f9aca8d615ce7d771ace4b621dc6
2023-10-25 12:07:17 INFO  Signature successfully verified! 
2023-10-25 12:07:17 INFO  Extracting and installing artifact type: plugin file: k8saudit-0.6.1-linux-x86_64.tar.gz
2023-10-25 12:07:17 INFO  Artifact successfully installed                                                             
                      ├ name: ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest
                      ├ type: plugin
                      ├ digest: sha256:bebd560a926b9f6234561363ae082daa740abb68b9d6da19bdaf16c13e795a34
                      └ directory: /usr/share/falco/plugins

Same as above but in json format:

❯ falcoctl artifact install k8saudit --log-format json
{"level":"INFO","msg":"Resolving dependencies ...","timestamp":"2023-10-25 12:09:10"}
{"level":"INFO","msg":"Installing artifacts","refs":["ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest"],"timestamp":"2023-10-25 12:09:11"}
{"level":"INFO","msg":"Preparing to pull artifact","ref":"ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest","timestamp":"2023-10-25 12:09:11"}
{"level":"INFO","msg":"Pulling layer 75ff683c3b71","timestamp":"2023-10-25 12:09:11"}
{"level":"INFO","msg":"Pulling layer e2908ebf2c03","timestamp":"2023-10-25 12:09:12"}
{"level":"INFO","msg":"Pulling layer bebd560a926b","timestamp":"2023-10-25 12:09:13"}
{"digest":"ghcr.io/falcosecurity/plugins/plugin/k8saudit@sha256:230dfdc0e1d331c5085f3f4c860838dcfc27f9aca8d615ce7d771ace4b621dc6","level":"INFO","msg":"Verifying signature for artifact","timestamp":"2023-10-25 12:09:13"}
{"level":"INFO","msg":"Signature successfully verified!","timestamp":"2023-10-25 12:09:14"}
{"file":"k8saudit-0.6.1-linux-x86_64.tar.gz","level":"INFO","msg":"Extracting and installing artifact","timestamp":"2023-10-25 12:09:14","type":"plugin"}                                                                                          
{"digest":"sha256:bebd560a926b9f6234561363ae082daa740abb68b9d6da19bdaf16c13e795a34","directory":"/usr/share/falco/plugins","level":"INFO","msg":"Artifact successfully installed","name":"ghcr.io/falcosecurity/plugins/plugin/k8saudit:latest","timestamp":"2023-10-25 12:09:14","type":"plugin"}

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

Huge job, thank you very much! Left some minor comments, but this LGTM!

cmd/version/version.go Outdated Show resolved Hide resolved
internal/follower/follower.go Show resolved Hide resolved
Old flags "--verbose" and "--disable-styling" have been deprecated.

Two new flags configure the output system:

* --log-level can be one of info, warn debug or trace.
* --log-format can be one of color, text, json.

The output is done using a logger that is used across all commands.
Having a unique logger guarantees a consistent format of the output.

Signed-off-by: Aldo Lacuku <[email protected]>
@alacuku alacuku force-pushed the kcl/refactor-output-subsystem branch from 248e093 to 054f187 Compare October 25, 2023 12:13
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

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

/approve

@poiana
Copy link
Contributor

poiana commented Oct 25, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alacuku, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana
Copy link
Contributor

poiana commented Oct 25, 2023

LGTM label has been added.

Git tree hash: bb9a9c692640a32db52a63023d9218a68a452837

@poiana poiana merged commit b6678c2 into falcosecurity:main Oct 25, 2023
14 checks passed
@alacuku alacuku deleted the kcl/refactor-output-subsystem branch November 3, 2023 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants