Repository navigation
Gateway Node proxies user requests to Vault Node - #18420
Conversation
…way-vault-flow-with-mocks
| cfg.RequestTimeoutSec = 30 | ||
| } | ||
|
|
||
| userRateLimiter, _ := ratelimit.NewRateLimiter(cfg.UserRateLimiterConfig) |
There was a problem hiding this comment.
What's the second value that is being omitted here? (Not an error I hope 😬 ?)
There was a problem hiding this comment.
It is error. we should handle it
| ErrNotAllowlisted = errors.New("sender not allowlisted") | ||
| ErrRateLimited = errors.New("rate-limited") | ||
|
|
||
| promRequestInternalError = promauto.NewCounterVec(prometheus.CounterOpts{ |
There was a problem hiding this comment.
We should use beholder rather than prometheus :)
|
|
||
| userRateLimiter *ratelimit.RateLimiter | ||
| nodeRateLimiter *ratelimit.RateLimiter | ||
| requestTimeoutSec int |
There was a problem hiding this comment.
Why not use a time.Duration here directly?
There was a problem hiding this comment.
I don't see the timeout being used or enforced in our logic.
The gateway has a separate timeout for user request anyway.
If we want to use this timeout to just keep our pendingRequests queue bounded, we will need to implement a cleanup on timeout.
Currently the timeout is just used on a context when calling the don.SendToNode() method, but that doesn't affect our queue here.
There was a problem hiding this comment.
Updated the timeout to affect the queue instead of just the don.SendToNode. This also effectively prunes the queue.
|
|
||
| func NewHandler(methodConfig json.RawMessage, donConfig *config.DONConfig, don gw_handlers.DON, lggr logger.Logger) *handler { | ||
| var cfg Config | ||
| if err := json.Unmarshal(methodConfig, &cfg); err != nil { |
There was a problem hiding this comment.
@DeividasK A JSON unmarshal error should be a critical failure IMO; that way we catch it as soon as we deploy the job to the node.
There was a problem hiding this comment.
Yes, just fail and propagate the error back.
| requestTimeoutSec: cfg.RequestTimeoutSec, | ||
| userRateLimiter: userRateLimiter, | ||
| nodeRateLimiter: nodeRateLimiter, | ||
| pendingRequests: make(map[string]*pendingRequest), |
There was a problem hiding this comment.
Are we doing anything to ensure that this won't grow in an unbounded way? eg. expiring requests that haven't received a response in a long time
| ConnectorMethod = "vault" | ||
| HandlerName = "VaultHandler" | ||
|
|
||
| promRequestInternalError = promauto.NewCounterVec(prometheus.CounterOpts{ |
|
|
||
| func NewHandler(methodConfig json.RawMessage, donConfig *config.DONConfig, don gw_handlers.DON, lggr logger.Logger) *handler { | ||
| var cfg Config | ||
| if err := json.Unmarshal(methodConfig, &cfg); err != nil { |
There was a problem hiding this comment.
Yes, just fail and propagate the error back.
| cfg.RequestTimeoutSec = 30 | ||
| } | ||
|
|
||
| userRateLimiter, _ := ratelimit.NewRateLimiter(cfg.UserRateLimiterConfig) |
There was a problem hiding this comment.
It is error. we should handle it
| return errors.New("vault service does not support legacy messages") | ||
| } | ||
|
|
||
| func (h *handler) HandleJSONRPCUserMessage(ctx context.Context, jsonRequest jsonrpc.Request[json.RawMessage], callbackCh chan<- gw_handlers.UserCallbackPayload) error { |
There was a problem hiding this comment.
nit optional:
you can define a type for this generic
type JsonRawMessageRequest = jsonrpc.Request[json.RawMessage]
And then use this type everywhere for readability.
Just helps readability in case you use it in a lot of places.
|
|
||
| rawResponse, err := jsonrpc.EncodeResponse(resp) | ||
| if err != nil { | ||
| return h.sendResponse(ctx, h.errorResponse(pendingRequest.req, api.NodeReponseEncodingError, fmt.Errorf("failed to marshal response: %w", err)), pendingRequest.callbackCh) |
There was a problem hiding this comment.
instead of fmt.Errorf, use:
errors.New("failed to marshal response: " + err.Error()))
I think linter would already be complaining about it.
There was a problem hiding this comment.
Linter seems to be fine with it 🤷♂️
| } | ||
| defer delete(h.pendingRequests, resp.ID) | ||
|
|
||
| rawResponse, err := jsonrpc.EncodeResponse(resp) |
There was a problem hiding this comment.
The resp object could still contain an error inside right?
We have to propagate that error in that case, instead of sending api.NoError.
| h.lggr.Infof("Processed response for request %s from node %s", resp.ID, nodeAddr) | ||
| return nil | ||
| case <-ctx.Done(): | ||
| promRequestInternalError.WithLabelValues(h.donConfig.DonId, api.RequestTimeoutError.String()).Inc() |
There was a problem hiding this comment.
This failure necessarily may not be a timeout error.
|
|
||
| userRateLimiter *ratelimit.RateLimiter | ||
| nodeRateLimiter *ratelimit.RateLimiter | ||
| requestTimeoutSec int |
There was a problem hiding this comment.
I don't see the timeout being used or enforced in our logic.
The gateway has a separate timeout for user request anyway.
If we want to use this timeout to just keep our pendingRequests queue bounded, we will need to implement a cleanup on timeout.
Currently the timeout is just used on a context when calling the don.SendToNode() method, but that doesn't affect our queue here.
Flakeguard SummaryRan new or updated tests between View Flaky Detector Details | Compare Changes Found Flaky Tests ❌4 Results
ArtifactsFor detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json. |
Flakeguard SummaryRan new or updated tests between View Flaky Detector Details | Compare Changes Found Flaky Tests ❌2 Results
ArtifactsFor detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json. |
|
| func (h *handler) Start(ctx context.Context) error { | ||
| return h.StartOnce("VaultHandler", func() error { | ||
| h.lggr.Info("starting vault handler") | ||
| ctx, _ := h.stopCh.NewCtx() |
There was a problem hiding this comment.
You should call the cancel func by deferring it inside the go func on line 145
There was a problem hiding this comment.
(And maybe calling <-ctx.Done() on line 151 for consistency
There was a problem hiding this comment.
I'll address this in a follow up PR




This PR introduces a new
VaultHandlerimplementation and updates to error handling.TODOs