fix(functions): normalize migrated extension memory to valid MemoryOption - #11056
fix(functions): normalize migrated extension memory to valid MemoryOption#11056wandamora wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds memory resolution logic for migrated Extension instances, ensuring that the highest memory value is selected when both V1 and V2 parameters are present, and normalizes memory strings for global options. The reviewer provided valuable feedback pointing out critical bugs in the parseMemory implementation regarding decimal values and standard units, as well as suggesting a more robust regex in memoryToMb to handle optional whitespace.
b41ea15 to
2b94934
Compare
2b94934 to
239517c
Compare
ajperel
left a comment
There was a problem hiding this comment.
Please get Victor to review, he's the expert, but the overall approach seems good (I'm trusting you on what formats come out of extensions and are accepted by setGlobalOptions). Leaving some feedback from Joe's skill that seem ok.
Description
When exporting Firebase Extensions for migration to Cloud Functions kits (
ext:export --mode functions), memory settings are mapped to theEXT_MIGRATED_SYSTEM_MEMORYenvironment variable. However:B(e.g."256Mi","512Mi","1Gi"), and v1 parameters are integers representing megabytes (e.g."256","1024"). Directly assigning these values produces invalidMemoryOptionvalues forfirebase-functions/v2'ssetGlobalOptions, which expects"MiB"/"GiB"suffixes (e.g."256MiB","1GiB").functionsEnvFromInstance.Changes:
memoryToMbandresolveMigratedMemoryinsrc/extensions/export.tsto convert memory values to MB and safely resolve multiple memory parameters by selecting the higher memory allocation (preventing runtime OOMs when migrating multi-function extensions to a shared global kit configuration).parseMemoryinsrc/extensions/export.tsto normalize raw memory values into valid Cloud Functions v2MemoryOptionstrings ("256MiB","512MiB","1GiB").functionsEnvFromInstanceto normalizeEXT_MIGRATED_SYSTEM_MEMORYupon export, ensuring the generated.env.<projectId>file contains standard, unambiguous units and keeping user-facing kit migration templates free of parsing boilerplate.src/extensions/export.spec.tscovering memory conversion, normalization permutations, conflict resolution, and environment generation.Scenarios Tested
npx mocha src/extensions/export.spec.ts(all 62 tests passing):memoryToMbcorrectly parses plain megabytes ("256","1024"),Mi/MiB("256Mi","512MiB"),Gi/GiB("1Gi","2GiB"), decimals ("0.5Gi"), negative numbers, and invalid inputs.parseMemorycorrectly maps all standard memory options from128MiBto32GiB, normalizes1024Mi->1GiBand2048Mi->2GiB, accurately parses1GB,1G, and0.5Gi, and returnsundefinedfor non-standard/invalid inputs.resolveMigratedMemoryhandles missing params, single v1/v2 params, selects the higher memory allocation when both are present, and falls back to spec defaults.functionsEnvFromInstancenormalizesEXT_MIGRATED_SYSTEM_MEMORYto validMemoryOptionvalues for v1-only, v2-only, equal memory, v1-higher, and spec-default fallback cases.ext:export->kits:installflow to ensure parameters apply cleanly within.envandfunctions.yaml.Sample Flow