mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
perf(core): drop per-request lookups and allocations on the shared request path (#7323)
* perf(core): drop per-request lookups on the shared request path Every request resolved the EmulatorConfig and ResolvedServiceCatalog CDI beans again in the claim, account and signature filters, fetched the RequestContext through Instance.get() on each storage operation, built a URI for the Host even when the header was present, formatted the Date header from scratch, and let CloudTrail copy its key set to find no trails. The filters resolve config and catalog once. AccountAwareStorageBackend and RegionResolver keep the RequestContext client proxy. RequestHost reads the Host header before it touches the URI. The Date header is cached per second as one immutable pair. StorageBackend gets isEmpty(), which every in-memory map implements directly, and emitS3DataEvent returns at once when no trail exists. * perf(core): read the query map once and mint request ids without SecureRandom AccountContextFilter asked UriInfo for the query parameters up to six times per request, and each call builds a new map wrapper. It now reads them once and hands the map to its helpers. AwsRequestIdFilter drew its UUID from SecureRandom. A request id is not a secret, so it is now a version 4 UUID built from ThreadLocalRandom, with the same format and the same single id in all three headers. * perf(core): scope AccountAwareStorageBackend.isEmpty to the current account keys() and scan() only see the current account, so isEmpty() now answers for that account too. A delegate with no entries at all still answers without copying its key set. * chore(cognito): give the sign-up scope test one request context that follows the calling thread AccountAwareStorageBackend keeps the RequestContext it gets from the Instance, as the request scoped client proxy forwards to the current request. The test handed out a different context per get() call from a ThreadLocal, so the kept one pinned both threads to the first account. It now hands out one context whose account id follows the thread.
This commit is contained in:
1 parent
6abdb4cc44
commit
055036508e
17 files changed
+183
-28
No files matched your search
+17
@@ -35,6 +35,23 @@ class AccountAwareStorageBackendTest {
|
||||
assertEquals("111111111111", storage.accountId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void isEmptyLooksOnlyAtTheCurrentAccount() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
AccountAwareStorageBackend<String> first =
|
||||
new AccountAwareStorageBackend<>(raw, null, "111111111111");
|
||||
AccountAwareStorageBackend<String> second =
|
||||
new AccountAwareStorageBackend<>(raw, null, "222222222222");
|
||||
|
||||
assertTrue(first.isEmpty());
|
||||
assertTrue(second.isEmpty());
|
||||
|
||||
first.put("resource", "value");
|
||||
|
||||
assertFalse(first.isEmpty());
|
||||
assertTrue(second.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void putAllPrefixesEveryEntryWithTheRequestScope() {
|
||||
InMemoryStorage<String, String> raw = new InMemoryStorage<>();
|
||||
|
||||
+7
-1
@@ -58,7 +58,13 @@ class CognitoSignUpCreationScopeTest {
|
||||
void overlappingSignUpReservesOnlyTheSameAccountAndUsername(
|
||||
boolean firstRequestIsAdmin, boolean differentAccount) throws Exception {
|
||||
Instance<RequestContext> contexts = mock(Instance.class);
|
||||
when(contexts.get()).thenAnswer(invocation -> requestContext.get());
|
||||
// One context that forwards to the calling thread's, as the request scoped client proxy does.
|
||||
when(contexts.get()).thenReturn(new RequestContext() {
|
||||
@Override
|
||||
public String getAccountId() {
|
||||
return requestContext.get().getAccountId();
|
||||
}
|
||||
});
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", FIRST_ACCOUNT) {
|
||||
@Override
|
||||
public String getAccountId() {
|
||||
|
||||
Reference in new issue
Block a user