-
Notifications
You must be signed in to change notification settings - Fork 628
fix: make rpc_timeout and max_bundle_workers configurable on the agent #7093
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -29,15 +29,16 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| rpcTimeout = 30 * time.Second | ||
|
|
||
| // maxBundleWorkers is the maximum number of worker goroutines to use when fetching bundles. | ||
| rpcTimeout = 30 * time.Second | ||
| maxBundleWorkers = 10 | ||
|
Comment on lines
+32
to
33
Member
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. Could you rename these to |
||
| ) | ||
|
|
||
| var ( | ||
| ErrUnableToGetStream = errors.New("unable to get a stream") | ||
|
|
||
| RPCTimeout = rpcTimeout | ||
| MaxBundleWorkers = maxBundleWorkers | ||
|
Comment on lines
+39
to
+40
Member
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. These do not need to be exported, maybe after renaming the consts, these can become |
||
|
|
||
| entryOutputMask = &types.EntryMask{ | ||
| SpiffeId: true, | ||
| Selectors: true, | ||
|
|
@@ -57,6 +58,14 @@ var ( | |
| RPCTimeoutWithCacheHit = rpcTimeout | ||
| ) | ||
|
|
||
| func SetRPCTimeout(d time.Duration) { | ||
| RPCTimeout = d | ||
| } | ||
|
|
||
| func SetMaxBundleWorkers(n int) { | ||
| MaxBundleWorkers = n | ||
| } | ||
|
|
||
| func SetJWTSVIDCacheHitTimeout(d time.Duration) { | ||
| RPCTimeoutWithCacheHit = d | ||
| } | ||
|
|
@@ -146,7 +155,7 @@ func (c *client) FetchUpdates(ctx context.Context) (*Update, error) { | |
| c.c.RotMtx.RLock() | ||
| defer c.c.RotMtx.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| ctx, cancel := context.WithTimeout(ctx, RPCTimeout) | ||
| defer cancel() | ||
|
|
||
| protoEntries, err := c.fetchEntries(ctx) | ||
|
|
@@ -212,7 +221,7 @@ func (c *client) SyncUpdates(ctx context.Context, cachedEntries map[string]*comm | |
| c.c.RotMtx.RLock() | ||
| defer c.c.RotMtx.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| ctx, cancel := context.WithTimeout(ctx, RPCTimeout) | ||
| defer cancel() | ||
|
|
||
| entriesStats, err := c.syncEntries(ctx, cachedEntries) | ||
|
|
@@ -254,7 +263,7 @@ func (c *client) SyncUpdates(ctx context.Context, cachedEntries map[string]*comm | |
| } | ||
|
|
||
| func (c *client) RenewSVID(ctx context.Context, csr []byte) (*X509SVID, error) { | ||
| ctx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| ctx, cancel := context.WithTimeout(ctx, RPCTimeout) | ||
| defer cancel() | ||
|
|
||
| agentClient, connection, err := c.newAgentClient() | ||
|
|
@@ -288,7 +297,7 @@ func (c *client) PostStatus(ctx context.Context, agentVersion string) error { | |
| c.c.RotMtx.RLock() | ||
| defer c.c.RotMtx.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| ctx, cancel := context.WithTimeout(ctx, RPCTimeout) | ||
| defer cancel() | ||
|
|
||
| agentClient, connection, err := c.newAgentClient() | ||
|
|
@@ -313,7 +322,7 @@ func (c *client) NewX509SVIDs(ctx context.Context, csrs map[string][]byte) (map[ | |
| c.c.RotMtx.RLock() | ||
| defer c.c.RotMtx.RUnlock() | ||
|
|
||
| ctx, cancel := context.WithTimeout(ctx, rpcTimeout) | ||
| ctx, cancel := context.WithTimeout(ctx, RPCTimeout) | ||
| defer cancel() | ||
|
|
||
| svids := make(map[string]*X509SVID) | ||
|
|
@@ -354,7 +363,7 @@ func (c *client) NewJWTSVID(ctx context.Context, entryID string, audience []stri | |
| c.c.RotMtx.RLock() | ||
| defer c.c.RotMtx.RUnlock() | ||
|
|
||
| timeout := rpcTimeout | ||
| timeout := RPCTimeout | ||
| if hasCacheHit { | ||
| timeout = RPCTimeoutWithCacheHit | ||
| } | ||
|
|
@@ -679,13 +688,13 @@ func (c *client) fetchBundles(ctx context.Context, federatedBundles []string) ([ | |
|
|
||
| // fetchFederatedBundlesConcurrently fetches federated bundles concurrently. | ||
| // This is done to improve sync times when there are many federations. This should ensure that the | ||
| // sync does not exceed rpcTimeout. | ||
| // sync does not exceed RPCTimeout. | ||
| func (c *client) fetchFederatedBundlesConcurrently(ctx context.Context, bundleClient bundlev1.BundleClient, trustDomains []string, bundles []*types.Bundle) ([]*types.Bundle, error) { | ||
|
salimeid marked this conversation as resolved.
|
||
| jobCh := make(chan string) | ||
| resultCh := make(chan fetchBundleResult, len(trustDomains)) | ||
| // Start a set of worker goroutines. | ||
| wg := sync.WaitGroup{} | ||
| for range min(maxBundleWorkers, len(trustDomains)) { | ||
| for range min(MaxBundleWorkers, len(trustDomains)) { | ||
| wg.Go(func() { | ||
| for trustDomain := range jobCh { | ||
| bundle, err := c.fetchFederatedBundle(ctx, bundleClient, trustDomain) | ||
|
|
||
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.
We should keep this comment.