-
Notifications
You must be signed in to change notification settings - Fork 9
ING-1308: Add configurable timeout for Data API KV operations #339
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: master
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 |
|---|---|---|
| @@ -1,16 +1,22 @@ | ||
| package server_v1 | ||
|
|
||
| import ( | ||
| "context" | ||
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/couchbase/stellar-gateway/dataapiv1" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| const defaultDapiKvTimeout = 120 * time.Second | ||
|
Contributor
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. nit: is it worth renaming this to maxDapiKvTimeout, since we do not allow the timeout to be set above this? |
||
|
|
||
| type DataApiServer struct { | ||
| logger *zap.Logger | ||
| errorHandler *ErrorHandler | ||
| authHandler *AuthHandler | ||
|
|
||
| kvTimeout time.Duration | ||
| } | ||
|
|
||
| var _ dataapiv1.StrictServerInterface = &DataApiServer{} | ||
|
|
@@ -24,6 +30,7 @@ func NewDataApiServer( | |
| logger: logger, | ||
| errorHandler: errorHandler, | ||
| authHandler: authHandler, | ||
| kvTimeout: defaultDapiKvTimeout, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -35,6 +42,31 @@ func (s *DataApiServer) parseKey(key string) ([]byte, *Status) { | |
| return []byte(key), nil | ||
| } | ||
|
|
||
| func (s *DataApiServer) withKvTimeout(ctx context.Context) (context.Context, context.CancelFunc) { | ||
| return context.WithTimeout(ctx, s.kvTimeout) | ||
| } | ||
|
|
||
| func (s *DataApiServer) ReconfigureKvTimeout(timeout time.Duration) { | ||
| if timeout <= 0 { | ||
| // Ignore non-positive values; keep existing timeout. | ||
| s.logger.Warn("ignoring non-positive data api kv timeout", zap.Duration("timeout", timeout)) | ||
| return | ||
| } | ||
|
|
||
| if timeout < time.Second { | ||
| s.logger.Warn("data api kv timeout too low; coercing to 1s", zap.Duration("requested_timeout", timeout)) | ||
| timeout = time.Second | ||
| } | ||
|
Comment on lines
+56
to
+59
|
||
|
|
||
| if timeout > defaultDapiKvTimeout { | ||
| s.logger.Warn("data api kv timeout too high; coercing to 120s", zap.Duration("requested_timeout", timeout)) | ||
| timeout = defaultDapiKvTimeout | ||
| } | ||
|
|
||
| s.logger.Info("reconfiguring data api kv timeout", zap.Duration("timeout", timeout)) | ||
| s.kvTimeout = timeout | ||
| } | ||
|
|
||
| func (s *DataApiServer) parseCAS(etag *string) (uint64, *Status) { | ||
| if etag != nil { | ||
| casUint, err := strconv.ParseUint(*etag, 16, 64) | ||
|
|
||
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.
Should we remove this if since we perform validation on the DapiKvTimeout being > 0 inside ReconfigureKvTimeout?