From a141c51719ed541361f38efd5b35a3cadee7e778 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Mon, 28 Oct 2024 16:02:23 -0700 Subject: [PATCH 1/2] Clean up logs when using FIREBASE_DATACONNECT_POSTGRESQL_STRING --- CHANGELOG.md | 1 + src/emulator/controller.ts | 3 ++- src/emulator/dataconnectEmulator.ts | 19 ++++++++++--------- src/emulator/emulatorLogger.ts | 3 +++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e7058f86bc..f16eeee6996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ - Fixed Next.js issue with PPR routes not rendering correctly. (#7625) +- Fixed some misleading logs when using the Data Connect emulator with `FIREBASE_DATACONNECT_POSTGRESQL_STRING` set. diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index 5708097f97d..26b750ecfdb 100755 --- a/src/emulator/controller.ts +++ b/src/emulator/controller.ts @@ -60,6 +60,7 @@ import { readFirebaseJson } from "../dataconnect/fileUtils"; import { TasksEmulator } from "./tasksEmulator"; import { AppHostingEmulator } from "./apphosting"; import { sendVSCodeMessage, VSCODE_MESSAGE } from "../dataconnect/webhook"; +import { dataConnectLocalConnString } from "../api"; const START_LOGGING_EMULATOR = utils.envOverride( "START_LOGGING_EMULATOR", @@ -419,7 +420,7 @@ export async function startAll( portFixed: !!wsPortConfig, }; } - if (emulator === Emulators.DATACONNECT) { + if (emulator === Emulators.DATACONNECT && !dataConnectLocalConnString()) { const pglitePortConfig = options.config.src.emulators?.dataconnect?.postgresPort; listenConfig["dataconnect.postgres"] = { host: config.host, diff --git a/src/emulator/dataconnectEmulator.ts b/src/emulator/dataconnectEmulator.ts index c1acbfc66b1..44bb0a06bfe 100644 --- a/src/emulator/dataconnectEmulator.ts +++ b/src/emulator/dataconnectEmulator.ts @@ -1,5 +1,6 @@ import * as childProcess from "child_process"; import { EventEmitter } from "events"; +import * as clc from "colorette"; import { dataConnectLocalConnString } from "../api"; import { Constants } from "./constants"; @@ -64,13 +65,13 @@ export class DataConnectEmulator implements EmulatorInstance { if (Constants.isDemoProject(this.args.projectId)) { this.logger.logLabeled( "WARN", - "Data Connect", + "dataconnect", "Detected a 'demo-' project, but vector embeddings require a real project. Operations that use vector_embed will fail.", ); } else { this.logger.logLabeled( "WARN", - "Data Connect", + "dataconnect", "Operations that use vector_embed will make calls to production Vertex AI", ); } @@ -94,11 +95,11 @@ export class DataConnectEmulator implements EmulatorInstance { const pgPort = this.args.postgresListen?.[0].port; const pgHost = this.args.postgresListen?.[0].address; let connStr = dataConnectLocalConnString(); - if (dataConnectLocalConnString()) { + if (connStr) { this.logger.logLabeled( "INFO", "Data Connect", - `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${dataConnectLocalConnString()} - using that instead of starting a new database`, + `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`, ); } else if (pgHost && pgPort) { const pgServer = new PostgresServer(dbId, "postgres"); @@ -111,7 +112,7 @@ export class DataConnectEmulator implements EmulatorInstance { } else { this.logger.logLabeled( "ERROR", - "Data Connect", + "data onnect", `Postgres threw an unexpected error, shutting down the Data Connect emulator: ${err}`, ); } @@ -119,8 +120,8 @@ export class DataConnectEmulator implements EmulatorInstance { }); this.logger.logLabeled( "INFO", - "Data Connect", - `Started up Postgres server, listening on ${server.address()?.toString()}`, + "dataconnect", + `Started up Postgres server, listening on ${JSON.stringify(server.address())}`, ); } await this.connectToPostgres(new URL(connStr), dbId, serviceId); @@ -134,7 +135,7 @@ export class DataConnectEmulator implements EmulatorInstance { if (!emuInfo) { this.logger.logLabeled( "ERROR", - "Data Connect", + "dataconnect", "Could not connect to Data Connect emulator. Check dataconnect-debug.log for more details.", ); return Promise.reject(); @@ -146,7 +147,7 @@ export class DataConnectEmulator implements EmulatorInstance { if (this.usingExistingEmulator) { this.logger.logLabeled( "INFO", - "Data Connect", + "dataconnect", "Skipping cleanup of Data Connect emulator, as it was not started by this process.", ); return; diff --git a/src/emulator/emulatorLogger.ts b/src/emulator/emulatorLogger.ts index 65d48dd1726..8468d001fb0 100644 --- a/src/emulator/emulatorLogger.ts +++ b/src/emulator/emulatorLogger.ts @@ -310,6 +310,9 @@ You can probably fix this by running "npm install ${systemLog.data.name}@latest" case "BULLET": utils.logLabeledBullet(label, text, "info", mergedData); break; + case "INFO": + utils.logLabeledBullet(label, text, "info", mergedData); + break; case "SUCCESS": utils.logLabeledSuccess(label, text, "info", mergedData); break; From f96bed57c069313c9475a38af72d38f663d68548 Mon Sep 17 00:00:00 2001 From: Joe Hanley Date: Mon, 28 Oct 2024 16:06:45 -0700 Subject: [PATCH 2/2] typo --- src/emulator/dataconnectEmulator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emulator/dataconnectEmulator.ts b/src/emulator/dataconnectEmulator.ts index 44bb0a06bfe..3a125e3cf9d 100644 --- a/src/emulator/dataconnectEmulator.ts +++ b/src/emulator/dataconnectEmulator.ts @@ -98,7 +98,7 @@ export class DataConnectEmulator implements EmulatorInstance { if (connStr) { this.logger.logLabeled( "INFO", - "Data Connect", + "dataconnect", `FIREBASE_DATACONNECT_POSTGRESQL_STRING is set to ${clc.bold(connStr)} - using that instead of starting a new database`, ); } else if (pgHost && pgPort) { @@ -112,7 +112,7 @@ export class DataConnectEmulator implements EmulatorInstance { } else { this.logger.logLabeled( "ERROR", - "data onnect", + "dataconnect", `Postgres threw an unexpected error, shutting down the Data Connect emulator: ${err}`, ); }