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: structured logging #368

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

feat: structured logging #368

wants to merge 3 commits into from

Conversation

ekristen
Copy link
Owner

@ekristen ekristen commented Oct 6, 2024

Overview

Note: this is still a work in progress.

This implements structured logging.

Example

> aws-nuke - 3.0.0-dev - dirty
Do you really want to nuke the account with the ID 637423565883 and the alias 'no-alias-637423565883'?
Waiting 3s before continuing.
{"level":"info","msg":"filtered: cannot delete AWS managed key","owner":"us-east-1","prop:ID":"4960b196-e3e1-4f46-b82e-764ae098bada","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"4960b196-e3e1-4f46-b82e-764ae098bada","state":7,"time":"2024-10-05T23:45:00-06:00","type":"KMSKey"}
{"level":"info","msg":"filtered: cannot delete AWS managed key","owner":"us-east-1","prop:ID":"49faf6ef-ae89-4203-bb29-1bc32be20228","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"49faf6ef-ae89-4203-bb29-1bc32be20228","state":7,"time":"2024-10-05T23:45:00-06:00","type":"KMSKey"}
{"level":"info","msg":"filtered: cannot delete AWS managed key","owner":"us-east-1","prop:ID":"bfec52f0-a84c-4c78-a305-368918386251","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"bfec52f0-a84c-4c78-a305-368918386251","state":7,"time":"2024-10-05T23:45:00-06:00","type":"KMSKey"}
Scan complete: 3 total, 0 nukeable, 3 filtered.

No resource to delete.

Running It

Note: this omits standard required options like configs.

aws-nuke --log-format=json

Questions

  1. Should everything be handled by the logging (i.e. version and wait for 3 seconds, etc)
  2. Should properties be prefixed by prop: or should it be stripped

Builds

You can clone and run the following command:

goreleaser build --snapshot --clean --single-target

Resolves #154

@ekristen ekristen marked this pull request as draft October 6, 2024 05:43
@kieran-lowe
Copy link

Thanks a bunch for working on this! 👊

@ekristen
Copy link
Owner Author

ekristen commented Oct 6, 2024

@kieran-lowe my pleasure. feedback would be appreciated.

@cland
Copy link

cland commented Oct 21, 2024

Thanks for working on this @ekristen .

Question on the logging format:
How would it look after nuke has run and some resources have been removed, others failed or filtered etc? Will there be a 'Status' with possible values 'removed' | 'filtered' | 'failed' etc that one can then filter on when they process the json output? A useful outcome is a logfile that will enable users of the logfile to put together a summary almost like your https://ekristen.github.io/aws-nuke/cli-usage/#aws-nuke-explain-config summary but more reporting on that the nuke module has managed to do.

To tweak your example a bit, I am picturing something like this:

{"level":"info",nuke-status:"removed","msg":"remove successfully","owner":"us-east-1","prop:ID":"4960b196-e3e1-4f46-b82e-764ae098bada","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"4960b196-e3e1-4f46-b82e-764ae098bada","state":7,"time":"2024-10-05T23:45:00-06:00","type":"KMSKey"}
{"level":"info",nuke-status:"filtered","msg":"filtered: cannot delete AWS managed key","owner":"us-east-1","prop:ID":"49faf6ef-ae89-4203-bb29-1bc32be20228","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"49faf6ef-ae89-4203-bb29-1bc32be20228","state":7,"time":"2024-10-05T23:45:00-06:00","type":"KMSKey"}
{"level":"info",nuke-status:"failed","msg":"Failed: Cannot delete the directory because it still has authorized applications","owner":"us-east-1","prop:ID":"bfec52f0-a84c-4c78-a305-368918386251","prop:Manager":"AWS","prop:State":"Enabled","prop:_tagPrefix":"tag","resource":"bfec52f0-a84c-4c78-a305-368918386251","state":7,"time":"2024-10-05T23:45:00-06:00","type":"DirectoryServiceDirectory"}
{"level":"info","nuke-summary":{"total":3,"filtered":1,"removed":1,"failed":1}}

Apologies if this is already the case and I have missed it somehow but that's just my thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[idea] structured logs/report
3 participants