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

api/client: provide the ability to set a logger on retryablehttp.Client #11696

Merged
merged 4 commits into from May 27, 2021

Conversation

calvn
Copy link
Member

@calvn calvn commented May 24, 2021

This PR adds the ability to set a logger on api.Client which is used on its underlying retryablehttp.Client instance when making requests. This value is nil by default and is only non-empty if set explicitly to maintain backwards compatibility and to avoid any unexpected output or noise that might result from it otherwise. Note that even though retryablehttp.Client accepts an interface{} as a logger to allow for either non-leveled or leveled loggers to be provided, I'm enforcing a leveled logger (e.g. hclog) to be provided to our api/client package.

As a concrete example, setting an hclog.Logger, which satisfies the retryablehttp.LevelLogger interface, on agent's proxy layer allows us to output the number of retry attempts that the client makes.

Without a logger:

2021-05-21T17:51:36.867-0700 [INFO]  auth.handler: authenticating
2021-05-21T17:51:37.209-0700 [INFO]  cache: received request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:51:37.209-0700 [DEBUG] cache.leasecache: forwarding request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:51:37.209-0700 [INFO]  cache.apiproxy: forwarding request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:51:40.106-0700 [ERROR] auth.handler: error authenticating: error="Put "http://localhost:8200/v1/auth/approle/login": dial tcp [::1]:8200: connect: connection refused" backoff=1.98s
==> Vault agent shutdown triggered

With a logger:

2021-05-21T17:42:34.456-0700 [INFO]  auth.handler: authenticating
2021-05-21T17:42:35.032-0700 [INFO]  cache: received request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:42:35.032-0700 [DEBUG] cache.leasecache: forwarding request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:42:35.032-0700 [INFO]  cache.apiproxy: forwarding request: method=PUT path=/v1/auth/approle/login
2021-05-21T17:42:35.032-0700 [DEBUG] cache.apiproxy.client: performing request: method=PUT url=http://localhost:8200/v1/auth/approle/login
2021-05-21T17:42:35.033-0700 [ERROR] cache.apiproxy.client: request failed: error="Put "http://localhost:8200/v1/auth/approle/login": dial tcp [::1]:8200: connect: connection refused" method=PUT url=http://localhost:8200/v1/auth/approle/login
2021-05-21T17:42:35.033-0700 [DEBUG] cache.apiproxy.client: retrying request: request="PUT http://localhost:8200/v1/auth/approle/login" timeout=1.481137504s remaining=2
2021-05-21T17:42:36.517-0700 [ERROR] cache.apiproxy.client: request failed: error="Put "http://localhost:8200/v1/auth/approle/login": dial tcp [::1]:8200: connect: connection refused" method=PUT url=http://localhost:8200/v1/auth/approle/login
2021-05-21T17:42:36.517-0700 [DEBUG] cache.apiproxy.client: retrying request: request="PUT http://localhost:8200/v1/auth/approle/login" timeout=2.803235972s remaining=1
2021-05-21T17:42:37.757-0700 [ERROR] auth.handler: error authenticating: error="Put "http://localhost:8200/v1/auth/approle/login": dial tcp [::1]:8200: connect: connection refused" backoff=1.99s
2021-05-21T17:42:39.324-0700 [ERROR] cache.apiproxy.client: request failed: error="Put "http://localhost:8200/v1/auth/approle/login": dial tcp [::1]:8200: connect: connection refused" method=PUT url=http://localhost:8200/v1/auth/approle/login
==> Vault agent shutdown triggered

@calvn calvn added the core/api label May 24, 2021
@calvn calvn added this to the 1.8 milestone May 24, 2021
@vercel vercel bot temporarily deployed to Preview – vault May 24, 2021 23:33 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 24, 2021 23:33 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook May 27, 2021 00:36 Inactive
@vercel vercel bot temporarily deployed to Preview – vault May 27, 2021 00:36 Inactive
@calvn calvn merged commit f6a945b into master May 27, 2021
@calvn calvn deleted the api-client-logger branch May 27, 2021 17:25
calvn added a commit that referenced this pull request May 27, 2021
calvn added a commit that referenced this pull request May 27, 2021
* changelog: add entry for #11696

* Update 11696.txt

* Update 11696.txt
AndreyZamyslov pushed a commit to yandex-cloud/vault that referenced this pull request Jun 10, 2021
…nt (hashicorp#11696)

* api/client: provide the ability to set a logger on retryablehttp.Client

* go mod tidy; fix import ordering

* go mod vendor
AndreyZamyslov pushed a commit to yandex-cloud/vault that referenced this pull request Jun 10, 2021
* changelog: add entry for hashicorp#11696

* Update 11696.txt

* Update 11696.txt
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
…nt (hashicorp#11696)

* api/client: provide the ability to set a logger on retryablehttp.Client

* go mod tidy; fix import ordering

* go mod vendor
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
* changelog: add entry for hashicorp#11696

* Update 11696.txt

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

Successfully merging this pull request may close these issues.

None yet

2 participants