Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up logs when using FIREBASE_DATACONNECT_POSTGRESQL_STRING #7882

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
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",
Expand All @@ -69,20 +70,20 @@

/**
* Exports emulator data on clean exit (SIGINT or process end)
* @param options

Check warning on line 73 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc @param "options" description
*/
export async function exportOnExit(options: any) {

Check warning on line 75 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing return type on function

Check warning on line 75 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const exportOnExitDir = options.exportOnExit;

Check warning on line 76 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 76 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .exportOnExit on an `any` value
if (exportOnExitDir) {
try {
utils.logBullet(
`Automatically exporting data using ${FLAG_EXPORT_ON_EXIT_NAME} "${exportOnExitDir}" ` +

Check warning on line 80 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
"please wait for the export to finish...",
);
await exportEmulatorData(exportOnExitDir, options, /* initiatedBy= */ "exit");

Check warning on line 83 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
} catch (e: any) {

Check warning on line 84 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
utils.logWarning(e);

Check warning on line 85 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
utils.logWarning(`Automatic export to "${exportOnExitDir}" failed, going to exit now...`);

Check warning on line 86 in src/emulator/controller.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "any" of template literal expression
}
}
}
Expand Down Expand Up @@ -419,7 +420,7 @@
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,
Expand Down
21 changes: 11 additions & 10 deletions src/emulator/dataconnectEmulator.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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",
);
}
Expand All @@ -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`,
"dataconnect",
`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");
Expand All @@ -111,16 +112,16 @@ export class DataConnectEmulator implements EmulatorInstance {
} else {
this.logger.logLabeled(
"ERROR",
"Data Connect",
"dataconnect",
`Postgres threw an unexpected error, shutting down the Data Connect emulator: ${err}`,
);
}
void cleanShutdown();
});
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);
Expand All @@ -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();
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/emulator/emulatorLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

@yuchenshi yuchenshi Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this in addition to BULLET?

break;
case "SUCCESS":
utils.logLabeledSuccess(label, text, "info", mergedData);
break;
Expand Down
Loading