Repository navigation
Conversation
Author
|
Note 🤖 Gemini 4 Neon responding on behalf of @thehamsti Follow-up from running this build live in production for an hour: this fixes both silent metric loss and significant AWS cost overhead, not just Lambda timeouts.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In AWS accounts with thousands of Lambda functions in a region,
firehose_metrics_tag_enrichmentpaginateslambda:ListFunctionsacross every function in the region on every cold start and everyCACHE_TTL_MINUTESrefresh per concurrent Firehose container.When functions use customer-managed KMS keys for environment variables, AWS Lambda internally triggers
kms:Decryptfor every function returned byListFunctions. In an account with ~16,000 Lambda functions (~400 actively emitting metrics), concurrent Firehose containers hitTooManyRequestsExceptionthrottling, causing 120s Lambda timeouts (~5,800/day, ~23% Firehose processing failures), container evictions, Firehose retries, and a sustained retry storm generating significant CloudTrail/GuardDuty/KMS overhead.What changed
ListFunctionspagination with an on-demand per-function cache (FunctionCache) backed byGetFunction, fetching only functions that actually appear inAWS/Lambdametrics (which already matches the existinglambda:GetFunctionIAM grant and drastically reduceskms:Decryptvolume in large accounts).FUNCTION_LOOKUP_BUDGET) so a cold or throttled batch returns records with their tags (and any stale properties) well before the 120s Lambda timeout, warming remaining functions on subsequent invocations.ResourceNotFoundExceptiontoOk(None)so deleted or unresolvable function names clear stale properties and cache empty forcache_ttl(10 min), while transient errors preserve stale properties forERROR_TTL(60s).lambda:ListFunctionson the shared account-wideTagEnrichmentLambdaRoleso multi-region rolling upgrades do not disrupt older regional binaries; removing it (and optionally moving toGetFunctionConfiguration) can follow in a separate PR.Verification
cargo test --locked(50 passed, 0 failed),cargo clippy --all-targets --locked -- -D warnings(clean),cargo fmt --check(clean).provided.al2023arm64 built vialambda/build.sh, deployed to a production account with ~16,000 Lambdas / ~400 active):AWS/Lambdarecords receive fulltagsandproperties(Runtime,MemorySize,Timeout,Architecture,PackageType), and missing functions (ResourceNotFoundException) succeed cleanly without an emptypropertieskey.ExecuteProcessing.Success, sustainedListFunctions+kms:Decryptstorm.0errors/timeouts,1.0000FirehoseExecuteProcessing.Success,0.5–5.2scold-cache batches,1–3 mswarm batches,25–31 MBmax memory, and0ListFunctionscalls.Council review
Rounds: 2
Created with Gemini 4 Neon in T3 Code.