From 6cfd1be4d2b70d041a4c508e1ab1423d6c619ed3 Mon Sep 17 00:00:00 2001 From: Stephane Geneix Date: Wed, 21 Feb 2024 12:07:08 -0800 Subject: [PATCH] improve logging in MsSQLTestDatabase --- .../source/mssql/MsSQLTestDatabase.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java b/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java index 98f8c2c2c8f6..c7a4b25e1d47 100644 --- a/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java +++ b/airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java @@ -69,6 +69,7 @@ static public MsSQLTestDatabase in(final BaseImage imageName, final ContainerMod public MsSQLTestDatabase(final MSSQLServerContainer container) { super(container); + LOGGER.info("SGX creating new database. databaseId=" + this.databaseId + ", databaseName=" + getDatabaseName()); } public MsSQLTestDatabase withCdc() { @@ -104,17 +105,17 @@ public MsSQLTestDatabase withShortenedCapturePollingInterval() { private void waitForAgentState(final boolean running) { final String expectedValue = running ? "Running." : "Stopped."; - LOGGER.debug("Waiting for SQLServerAgent state to change to '{}'.", expectedValue); + LOGGER.info(formatLogLine("Waiting for SQLServerAgent state to change to '{}'."), expectedValue); for (int i = 0; i < MAX_RETRIES; i++) { try { final var r = query(ctx -> ctx.fetch("EXEC master.dbo.xp_servicecontrol 'QueryState', N'SQLServerAGENT';").get(0)); if (expectedValue.equalsIgnoreCase(r.getValue(0).toString())) { - LOGGER.debug("SQLServerAgent state is '{}', as expected.", expectedValue); + LOGGER.info(formatLogLine("SQLServerAgent state is '{}', as expected."), expectedValue); return; } - LOGGER.debug("Retrying, SQLServerAgent state {} does not match expected '{}'.", r, expectedValue); + LOGGER.info(formatLogLine("Retrying, SQLServerAgent state {} does not match expected '{}'."), r, expectedValue); } catch (final SQLException e) { - LOGGER.debug("Retrying agent state query after catching exception {}.", e.getMessage()); + LOGGER.info(formatLogLine("Retrying agent state query after catching exception {}."), e.getMessage()); } try { Thread.sleep(1_000); // Wait one second between retries. @@ -122,21 +123,21 @@ private void waitForAgentState(final boolean running) { throw new RuntimeException(e); } } - throw new RuntimeException("Exhausted retry attempts while polling for agent state"); + throw new RuntimeException(formatLogLine("Exhausted retry attempts while polling for agent state")); } public MsSQLTestDatabase withWaitUntilMaxLsnAvailable() { - LOGGER.debug("Waiting for max LSN to become available for database {}.", getDatabaseName()); + LOGGER.info(formatLogLine("Waiting for max LSN to become available for database {}."), getDatabaseName()); for (int i = 0; i < MAX_RETRIES; i++) { try { final var maxLSN = query(ctx -> ctx.fetch("SELECT sys.fn_cdc_get_max_lsn();").get(0).get(0, byte[].class)); if (maxLSN != null) { - LOGGER.debug("Max LSN available for database {}: {}", getDatabaseName(), Lsn.valueOf(maxLSN)); + LOGGER.info(formatLogLine("Max LSN available for database {}: {}"), getDatabaseName(), Lsn.valueOf(maxLSN)); return self(); } - LOGGER.debug("Retrying, max LSN still not available for database {}.", getDatabaseName()); + LOGGER.info(formatLogLine("Retrying, max LSN still not available for database {}."), getDatabaseName()); } catch (final SQLException e) { - LOGGER.warn("Retrying max LSN query after catching exception {}", e.getMessage()); + LOGGER.info(formatLogLine("Retrying max LSN query after catching exception {}"), e.getMessage()); } try { Thread.sleep(1_000); // Wait one second between retries.