fix(emulator): stop repeating network access warnings for a URL already reported - #11083
Open
gauranshahuja wants to merge 1 commit into
Open
fix(emulator): stop repeating network access warnings for a URL already reported#11083gauranshahuja wants to merge 1 commit into
gauranshahuja wants to merge 1 commit into
Conversation
…dy reported The Functions emulator announces "External network resource requested!" (and the "Google API requested!" variant) again and again for the same URL, which buries everything else in a project that talks to external services. It is not per-request. initializeNetworkFiltering() in functionsEmulatorRuntime.ts already dedupes by href, but its `history` map is function-scoped and the function runs once per runtime process. The worker pool spawns a fresh runtime, the cache goes with the old one, and the same URL is announced again. So the dedup has to live in the parent. RuntimeWorker calls handleRuntimeLog in the emulator process and EmulatorLogger.warnOnceCache is static, so it spans every runtime for the whole session. Switching the two network-access cases to WARN_ONCE keys them on the rendered text, which contains the href: every distinct URL is still reported, once per session instead of once per runtime. It matches what this file already does for functions-config-missing-value. Adds src/emulator/emulatorLogger.spec.ts, which this file did not have. Fixes firebase#4939
Contributor
There was a problem hiding this comment.
Code Review
This pull request resolves an issue where the Functions emulator repeatedly logs warnings for the same external network or Google API requests across different runtime processes. By changing the log level from 'WARN' to 'WARN_ONCE' for these events, the emulator now deduplicates warnings by URL over the course of an emulator session. Unit tests have been added to verify this behavior, and the changelog has been updated. I have no feedback to provide as the changes are well-implemented and include appropriate test coverage.
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.
Description
Fixes #4939.
The Functions emulator repeats
External network resource requested!(and theGoogle API requested!variant) for the same URL over and over, which buries everything else in a project that talks to external
services. Two people asked for a way to turn it off; the only workaround in the thread is hand-editing
emulatorLogger.jsinsidenode_modules.The warning is not actually per-request.
initializeNetworkFiltering()infunctionsEmulatorRuntime.tsalready dedupes by href:
but
historyis function-scoped andinitializeNetworkFiltering()runs once per runtime process. Theworker pool spawns a fresh runtime, the cache goes with the old one, and the same URL is announced again.
So the dedup needs to live in the parent, which already has the mechanism:
RuntimeWorkercallshandleRuntimeLogin the emulator process, andEmulatorLogger.warnOnceCacheis static, so it spans everyruntime for the whole session. This changes the two network-access cases in
handleSystemLogfromWARNto
WARN_ONCE.WARN_ONCEkeys on the rendered text, which contains the href, so every distinct URL isstill reported - once per emulator session instead of once per runtime. Nothing is hidden, only repeated
lines are dropped. It also matches what this file already does for
functions-config-missing-value, theother advisory that can repeat.
Worth noting there is currently no way to silence just these:
--log-verbosity QUIETdoes not suppresswarnings at all (
WARNandQUIETare both verbosity 2, andshouldSupressis>), andSILENTtakesERRORwith it.The issue asks for "some parameter when starting emulators that would disable the output of certain types
of notifications". I have deliberately not added a
firebase.jsonkey or a flag - that is a design callthat belongs to you, and this fix removes the pain without one. If you would rather have an explicit
opt-out as well, say the shape you want and I will add it here.
Scenarios Tested
src/emulator/emulatorLogger.spec.tsis new - this file had no unit test before. It drives the real path(
handleRuntimeLogwith aSYSTEMlog, which is whatRuntimeWorkercalls):the worker pool, warns once
googleapis-network-accessbranchnon-default-admin-app-usedthree times still warns three times, so other warnings are untouchedAlso run locally:
npx tsc --project tsconfig.compile.json --noEmitclean; eslint on the touched filesreports no new warnings (the untouched file produces the same count); prettier clean; the
src/emulator/*.spec.tssuite.Sample Commands
No new commands or flags. Before, in a project that calls the same API from several runtimes:
After: that block appears once per URL per emulator session. A second, different URL still gets its own
warning.