You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* add decodeRequestMiddleware & batch request decoding
* progress towards batch request processing
* hackily overriding headers fixes response
* refactor, headers still incorrect
* handle passing response headers
* handle empty batch requests
* rename & add docs to batchResponseWriter
* make batch requests concurrent
* cleanup & add doc comments to all funcs
* unit test the cache state header response
* fix default CORs header for cache misses
* fix cache hit counting
* reduce debug log noise
* add happy path testing for batch evm requests
* lol, don't fail b/c it is 4PM
* pass through error statuses!
* test more unhappy paths
* update missing .env vars, misc cleanup
* fix CI docker for e2e tests
* replace request logging mdw w/ decode request mdw
* update middleware sequence documentation
* add ProxyMaximumBatchSize configuration
proxy service responds 413 if it receives a request with >ProxyMaximumBatchSize sub-requests
* onErrStatus(status) -> onErrorHandler(status, body)
* update error handler to include current response headers
* refactor metrics tests to use require.Eventually
instead of arbitrarily sleeping and praying that the metric was created,
wait for the metrics to be created. if the expected metrics are not
created, the test will fail with a timeout.
Copy file name to clipboardexpand all lines: architecture/MIDDLEWARE.MD
+31-29
Original file line number
Diff line number
Diff line change
@@ -20,49 +20,51 @@ Any modifications that the middleware function makes to the request or response
20
20
21
21
The earlier the middleware is instantiated, the later it will run. For example the first middleware created by the proxy service is the middleware that will run after the request has been logged and proxied, thereby allowing it to access both the recorded request body and response body, and any context enrichment added by prior middleware.
1. Captures start time of request for latency metrics calculations
33
+
1. Attempts to decode the request:
34
+
* As a single EVM request. If successful, forwards to Single Request Middleware Sequence with the request in the context.
35
+
* As a batch EVM request. If successful, forwards to Batch Processing Middleware with batch in context.
36
+
* On failure to decode, the request is sent down the Single Request Middleware Sequence, but with nothing in the context.
41
37
42
-
// register middleware chain as the default handler for any request to the proxy service
43
-
mux.HandleFunc("/", requestLoggingMiddleware)
38
+
### Single Request Middleware Sequence
39
+
If a single request is decoded (as opposed to a batch list), or the request fails to decode, it is forwarded down this middleware sequence. Additionally, each individual sub-request of a batch is routed through this sequence in order to leverage caching and metrics collection.
44
40
45
-
// create an http server for the caller to start on demand with a call to ProxyService.Run()
This middleware sequence uses the decoded single request from the request context.
51
42
52
-
## Middleware
43
+
#### IsCached Middleware
44
+
The front part of the two-part caching middleware. Responsible for determining if an incoming request can be fielded from the cache. If it can, the cached response is put into the context.
53
45
54
-
### Request Logging Middleware
46
+
See [CACHING](./CACHING.md#iscachedmiddleware) for more details.
55
47
56
-
1. Logs the request body to stdout and stores a parsed version of the request body in the context key `X-KAVA-PROXY-DECODED-REQUEST-BODY` for use by other middleware.
57
-
58
-
### Proxy Middleware
48
+
#### Proxy Middleware
59
49
60
50
1. Proxies the request to the configured backend origin server.
51
+
2. Times the roundtrip latency for the response from the backend origin server and stores the latency in the context key `X-KAVA-PROXY-ORIGIN-ROUNDTRIP-LATENCY-MILLISECONDS` for use by other middleware.
61
52
62
-
1. Times the roundtrip latency for the response from the backend origin server and stores the latency in the context key `X-KAVA-PROXY-ORIGIN-ROUNDTRIP-LATENCY-MILLISECONDS` for use by other middleware.
53
+
The Proxy middleware is responsible for writing the response to the requestor. Subsequent middlewares are non-blocking to the response.
63
54
64
55
See [Proxy Routing](./PROXY_ROUTING.md) for details on configuration and how requests are routed.
65
56
66
-
### After Proxy Middleware
57
+
#### Caching Middleware
58
+
Handles determining if a response can be put in the cache if it isn't already.
59
+
60
+
See [CACHING](./CACHING.md#cachingmiddleware) for more details.
61
+
62
+
#### After Proxy Middleware
67
63
68
64
1. Parses the request body and latency from context key values and creates a request metric for the proxied request.
65
+
66
+
### Batch Processing Middleware
67
+
1. Pulls decoded batch out of the request context
68
+
2. Separates into individual sub-requests
69
+
3. Routes each sub-request through the Single Request Middleware Sequence in order to leverage caching and metrics creation.
70
+
4. Combines all sub-request responses into a single response to the client.
0 commit comments