Skip to content

Added config params & retry logic for getting secrets. See #2542 - #2717

Merged
vito merged 1 commit into
concourse:masterfrom
romankartgh:master
Nov 29, 2018
Merged

vito merged 1 commit into
concourse:masterfrom
romankartgh:master

Conversation

@romankartgh

Copy link
Copy Markdown
Contributor
  • every manager has SecretRetry with retry params (attempts + interval)
  • SecretRetry gets passed down to Get() into each cred manager
  • Get() now performs a configured number of retries instead of a single
    lookup and fail
  • couple of unit tests added for retries (just for ssm, but they are
    all the same)

@romankartgh

romankartgh commented Oct 23, 2018 •

Copy link
Copy Markdown
Contributor Author

@vito we tried adding retries to https://github.com/concourse/atc/blob/master/creds/eval.go#L10:6 as you recommended in #2542, but revealed a number of issues:

  1. it'd be global retry for a given template. e.g. if a template has 20 vars and failure rate for var lookup is 1/20, then these retries wouldn't be very helpful
  2. a bigger problem is that evaluate() operates with interfaces and a very limited set of data, so passing ATC params or cred manager params (like # of retries and interval between retries) seems nearly impossible in this piece of code. hardcoding these values would be pretty bad and might cause issues for some environments.

so we decided not to go down that path and settled on:

  1. introducing a simple struct with retry params
  2. adding it to every cred manager
  3. passing it down to Get()
  4. doing retries in Get() on a per-variable basis, using a common method

adding this to every cred manager is not ideal, but we couldn't any common base that cred managers currently share. and even cred manager parameter parsing is done separately using cred manager name as a prefix. in the end it turned out ok, I think (not that many changes). but you'll have to configure retry attempts/timeout for every cred manager separately

in order for this to work, we also need to:

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Having the retry logic in Get makes total sense, though I wonder if we could do it outside of each credential manager instead? I agree with the flaws with adding it to evaluate, but I think there's one more place we could try.

For example, everywhere we call NewVariables returns a creds.Variables interface - could we have a creds.Variables implementation that wraps the real implementation with retry logic? If I understand your changes correctly, that would accomplish the same goals, and only require one implementation (and one set of tests). I'm just worried about adding more behavior to the credential managers as the unit tests for some are slim to nonexistant (we cover them in TopGun instead, but that's also where testing things like retry logic can feel very cumbersome).

In fact, we might even be able to inject the retry logic all the way up top when we first construct a creds.VariablesFactory - by having a RetryableVariablesFactory that wraps the original, and having it return a RetryableVariables which wraps the original creds.Variables in turn.

What do ya think? 🙂

@romankartgh

Copy link
Copy Markdown
Contributor Author

@vito that makes a lot of sense, I should have done this this way from the very beginning.
pushed a new commit to address this:

  • introduced RetryableVariablesFactory and RetryableVariables
  • added unit tests for RetryableVariablesFactory
  • retry config (attempts + interval) left on per-credmgr basis in case people want to configure different parameters for different credmgrs (if you feel global params would be better, it not a big deal to switch)
  • bumped up the version of retryhttps

@vito vito left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sweet! I think we can even skip the changes to the different managers by wrapping it once, way up in ATCCommand:

return variablesFactory, nil

You could also embed the creds.SecretRetryConfig here, which is currently empty - that way we don't have a bunch of different flags for the different credential managers:

CredentialManagement struct{} `group:"Credential Management"`

@romankartgh

Copy link
Copy Markdown
Contributor Author

@vito if we embed SecretRetryConfig into RunCommand/CredentialManagement, I assume retry parameters would become global.

right now it's done on cred mgr basis, i.e.:

--vault-secret-retry-attempts
--vault-secret-retry-interval
--credhub-secret-retry-attempts
--credhub-secret-retry-interval
...

are you asking to switch to global?

@vito

vito commented Nov 27, 2018

Copy link
Copy Markdown
Contributor

@ralekseenkov Yeah, I think it's fine to just have it global, since you can only configure one credential manager anyway. I don't think there's a need to configure it separately for each backend.

@romankartgh

Copy link
Copy Markdown
Contributor Author

ok, I switched it to global

    Credential Management:
          --secret-retry-attempts
          --secret-retry-interval


type SecretRetryConfig struct {
Attempts int `long:"secret-retry-attempts" default:"5" description:"The number of attempts secret will be retried to be fetched, in case a retryable error happens."`
Interval time.Duration `long:"secret-retry-interval" default:"1s" description:"The interval between secret retry retrieval attempts."`

This comment was marked as spam.

@vito

vito commented Nov 29, 2018

Copy link
Copy Markdown
Contributor

This is good to go so I'll just merge this in so you can try it out more easily. If the retry logic proves problematic it should be easy enough to switch to exponential backoff in a followup PR. This is still better than no retry at all. Thanks a bunch! 🎊

@vito
vito merged commit 53263f0 into concourse:master Nov 29, 2018
@vito vito added this to the v5.0.0 milestone Jan 10, 2019
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.

2 participants