-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[AGENTCFG-13] Adding a scatter mechanism in the secrets component #34744
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"encoding/json" | ||
"fmt" | ||
"io" | ||
"math/rand" | ||
"net/http" | ||
"path/filepath" | ||
"regexp" | ||
|
@@ -88,8 +89,9 @@ type secretResolver struct { | |
// responseMaxSize defines max size of the JSON output from a secrets reader backend | ||
responseMaxSize int | ||
// refresh secrets at a regular interval | ||
refreshInterval time.Duration | ||
ticker *time.Ticker | ||
refreshInterval time.Duration | ||
refreshIntervalScatter time.Duration | ||
ticker *time.Ticker | ||
// filename to write audit records to | ||
auditFilename string | ||
auditFileMaxSize int | ||
|
@@ -216,6 +218,7 @@ func (r *secretResolver) Configure(params secrets.ConfigParams) { | |
r.responseMaxSize = SecretBackendOutputMaxSizeDefault | ||
} | ||
r.refreshInterval = time.Duration(params.RefreshInterval) * time.Second | ||
r.refreshIntervalScatter = time.Duration(params.RefreshIntervalScatter) * time.Second | ||
r.commandAllowGroupExec = params.GroupExecPerm | ||
r.removeTrailingLinebreak = params.RemoveLinebreak | ||
if r.commandAllowGroupExec { | ||
|
@@ -241,7 +244,9 @@ func (r *secretResolver) startRefreshRoutine() { | |
if r.ticker != nil || r.refreshInterval == 0 { | ||
return | ||
} | ||
r.ticker = time.NewTicker(r.refreshInterval) | ||
// Generate a random value within the range [-r.refreshIntervalScatter, r.refreshIntervalScatter] | ||
randDuration := time.Duration(rand.Int63n(2*int64(r.refreshIntervalScatter))) - r.refreshIntervalScatter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using a new duration That way, if I configure a We could enable this behavior by default with a setting to disable it (maybe |
||
r.ticker = time.NewTicker(r.refreshInterval + randDuration) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this works since we only want to change the first tick of the ticker. Here, if we configure a interval of 1 hour but the What we actually want is for the first tick to happens between startTime and startTime+ |
||
go func() { | ||
for { | ||
<-r.ticker.C | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add info around the refresh configuration/behavior to the information returned by the API (see the endpoint register here).