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: Verbose logging with flag #350

Merged
merged 4 commits into from
Jun 10, 2022
Merged

feat: Verbose logging with flag #350

merged 4 commits into from
Jun 10, 2022

Conversation

jkayani
Copy link
Member

@jkayani jkayani commented Jun 2, 2022

Description

Adds a verbose output flag so that users can troubleshoot AVP usage easier. Goal is to be able to trace:

  • The final configuration Viper sees
  • The processing being done for each placeholder
  • API calls and responses from backends for both authentication and getting secrets

Assuming this looks worthwhile, I think it'd be good for bug reports to include this info to help us debug what's happening. This PR amends the issue template to say that.

Fixes: #307

Checklist

Please make sure that your PR fulfills the following requirements:

  • Reviewed the guidelines for contributing to this repository
  • The commit message follows the Conventional Commits Guidelines.
  • Tests for the changes have been updated
  • Are you adding dependencies? If so, please run go mod tidy -compat=1.17 to ensure only the minimum is pulled in.
  • Docs have been added / updated
  • Optional. My organization is added to USERS.md.

Type of Change

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • New tests
  • Build/CI related changes
  • Documentation content changes
  • Other (please describe)

Other information

@jkayani jkayani requested a review from werne2j as a code owner June 2, 2022 04:52
@jkayani jkayani self-assigned this Jun 2, 2022
@jkayani
Copy link
Member Author

jkayani commented Jun 2, 2022

Sample output from stderr after running AVP on a template pulling secrets from IBM Cloud SM:

2022/06/02 00:42:42 reading configuration from config file /Users/jkayani/Documents/ops/argo/vault/ibm-sm-creds.yaml, overriding any previous settings
2022/06/02 00:42:42 reading configuration from environment, overriding any previous settings
2022/06/02 00:42:42 AVP configured with the following settings:
2022/06/02 00:42:42 avp_type: ibmsecretsmanager

2022/06/02 00:42:42 avp_ibm_api_key: REDACTED

2022/06/02 00:42:42 avp_ibm_instance_url: REDACTED

2022/06/02 00:42:42 avp_kv_version: 2

2022/06/02 00:42:42 IBM Cloud Secrets Manager enabling 3 API call retries with 20 seconds between tries
2022/06/02 00:42:42 IBM Cloud Secrets Manager listing secrets of from group default starting at offset 0
2022/06/02 00:42:44 IBM Cloud Secrets Manager list secrets in group HTTP response: {
    REDACTED
}

2022/06/02 00:42:44 IBM Cloud Secrets Manager get secret: getting secret beep of type arbitrary from group default
2022/06/02 00:42:44 IBM Cloud Secrets Manager get unversioned secret REDACTED HTTP response: {
    REDACTED
}

2022/06/02 00:42:44 calling GetSecrets to get all secrets from backend because avp.kubernetes.io/path is set to ibmcloud/arbitrary/secrets/groups/default
2022/06/02 00:42:44 found placeholder beep with modifiers []
2022/06/02 00:42:44 found placeholder path:ibmcloud/imported_cert/secrets/groups/default#certs with modifiers [ jsonPath {.certificate}]
2022/06/02 00:42:44 calling GetIndividualSecret for secret certs from path ibmcloud/imported_cert/secrets/groups/default at version 
2022/06/02 00:42:44 IBM Cloud Secrets Manager list secrets in group: cache hit group default
2022/06/02 00:42:44 IBM Cloud Secrets Manager get secret: getting secret certs of type imported_cert from group default
2022/06/02 00:42:45 IBM Cloud Secrets Manager get unversioned secret REDACTED HTTP response: {
    REDACTED
}

2022/06/02 00:42:45 processing modifier jsonPath with args ["jsonPath" "{.certificate}"]

Some of the output is out of order, probably b/c of the goroutines being used for this particular backend. It's still mostly traceable though especially with the original template.

@@ -59,6 +61,7 @@ func NewGenerateCommand() *cobra.Command {
}

v := viper.New()
viper.Set("verboseOutput", verboseOutput)
Copy link
Member Author

Choose a reason for hiding this comment

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

Using the global singleton Viper here since the verbose output setting isn't specific to any backend or even any part of the code (it's used when doing auth, replacements in the template, and when retrieving from backends)

@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2022

Codecov Report

Merging #350 (16624e9) into main (81b61bb) will increase coverage by 0.84%.
The diff coverage is 87.69%.

@@            Coverage Diff             @@
##             main     #350      +/-   ##
==========================================
+ Coverage   76.68%   77.53%   +0.84%     
==========================================
  Files          22       22              
  Lines         948     1006      +58     
==========================================
+ Hits          727      780      +53     
- Misses        137      142       +5     
  Partials       84       84              
Impacted Files Coverage Δ
pkg/kube/client.go 0.00% <0.00%> (ø)
pkg/utils/util.go 60.78% <0.00%> (-2.49%) ⬇️
pkg/auth/vault/approle.go 68.42% <66.66%> (+3.71%) ⬆️
pkg/auth/vault/github.go 64.70% <66.66%> (+4.70%) ⬆️
pkg/auth/vault/kubernetes.go 64.70% <66.66%> (+2.20%) ⬆️
pkg/backends/ibmsecretsmanager.go 78.85% <85.71%> (+0.28%) ⬆️
pkg/config/config.go 83.78% <91.66%> (+0.21%) ⬆️
cmd/generate.go 74.19% <100.00%> (+2.26%) ⬆️
pkg/backends/awssecretsmanager.go 70.83% <100.00%> (+2.65%) ⬆️
pkg/backends/azurekeyvault.go 78.57% <100.00%> (+5.04%) ⬆️
... and 7 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@werne2j
Copy link
Member

werne2j commented Jun 7, 2022

@jkayani does it make sense to add tests for the verbose logging?

@jkayani
Copy link
Member Author

jkayani commented Jun 9, 2022

@werne2j I don't know, what do you think? On one hand I don't like taking the hit on code coverage, but on the other, writing tests for this seems a bit silly, since it's really just supposed to be useful debug information.

I wonder if I can refactor so that the calls to the log function aren't wrapped in the conditional and instead the conditional is moved to the function definition - that'd probably reduce the code coverage hit (since the tests we have now would exercise those lines) and make the code a bit cleaner

@jkayani jkayani force-pushed the verbose branch 2 times, most recently from 2d3952e to f7fccdb Compare June 9, 2022 02:45
@werne2j
Copy link
Member

werne2j commented Jun 9, 2022

@jkayani I think moving the logic to the utility function makes sense.

Copy link
Member

@werne2j werne2j left a comment

Choose a reason for hiding this comment

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

Looks good!

@jkayani jkayani merged commit 45a4c25 into main Jun 10, 2022
@jkayani jkayani deleted the verbose branch June 10, 2022 21:14
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.

3 participants