Skip to content

Commit 0d9b7b4

Browse files
akashkulkoctavia-squidington-iiiairbyteio
authored
Better formatting/logging for pre-sync data (#25459)
* Log cursor alongside indexes * Better formatting for table estimates, indexes * Doc & dockerfile bump * Fix formatting * auto-bump connector version * Automated Commit - Formatting Changes * Fixing connector base issues * Fix failure * Fix changelog --------- Co-authored-by: Octavia Squidington III <[email protected]> Co-authored-by: airbyteio <[email protected]>
1 parent 9f20406 commit 0d9b7b4

File tree

10 files changed

+85
-40
lines changed

10 files changed

+85
-40
lines changed

airbyte-config-oss/init-oss/src/main/resources/seed/oss_catalog.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21220,7 +21220,7 @@
2122021220
"sourceDefinitionId": "decd338e-5647-4c0b-adf4-da0e75f5a750",
2122121221
"name": "Postgres",
2122221222
"dockerRepository": "airbyte/source-postgres",
21223-
"dockerImageTag": "2.0.24",
21223+
"dockerImageTag": "2.0.25",
2122421224
"documentationUrl": "https://docs.airbyte.com/integrations/sources/postgres",
2122521225
"icon": "postgresql.svg",
2122621226
"sourceType": "database",

airbyte-config-oss/init-oss/src/main/resources/seed/source_definitions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@
16191619
- name: Postgres
16201620
sourceDefinitionId: decd338e-5647-4c0b-adf4-da0e75f5a750
16211621
dockerRepository: airbyte/source-postgres
1622-
dockerImageTag: 2.0.24
1622+
dockerImageTag: 2.0.25
16231623
documentationUrl: https://docs.airbyte.com/integrations/sources/postgres
16241624
icon: postgresql.svg
16251625
sourceType: database

airbyte-config-oss/init-oss/src/main/resources/seed/source_specs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12152,7 +12152,7 @@
1215212152
supportsNormalization: false
1215312153
supportsDBT: false
1215412154
supported_destination_sync_modes: []
12155-
- dockerImage: "airbyte/source-postgres:2.0.24"
12155+
- dockerImage: "airbyte/source-postgres:2.0.25"
1215612156
spec:
1215712157
documentationUrl: "https://docs.airbyte.com/integrations/sources/postgres"
1215812158
connectionSpecification:

airbyte-db/db-lib/src/main/java/io/airbyte/db/jdbc/JdbcUtils.java

+39
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.fasterxml.jackson.databind.JsonNode;
2626
import com.google.common.collect.Maps;
2727
import java.sql.JDBCType;
28+
import java.text.CharacterIterator;
29+
import java.text.StringCharacterIterator;
2830
import java.util.HashMap;
2931
import java.util.List;
3032
import java.util.Map;
@@ -135,4 +137,41 @@ public static boolean useSsl(final JsonNode config) {
135137
return config.get(SSL_KEY).asBoolean();
136138
}
137139

140+
/**
141+
* Helper method for logging bytes in a human-readable format. This method logs in SI units
142+
* (B/kB/MB/GB)
143+
*/
144+
public static String humanReadableByteCountSI(final long bytes) {
145+
if (-1000 < bytes && bytes < 1000) {
146+
return bytes + " B";
147+
}
148+
final CharacterIterator ci = new StringCharacterIterator("kMGTPE");
149+
long formattedBytes = bytes;
150+
while (bytes <= -999_950 || bytes >= 999_950) {
151+
formattedBytes /= 1000;
152+
ci.next();
153+
}
154+
return String.format("%.1f %cB", formattedBytes / 1000.0, ci.current());
155+
}
156+
157+
/**
158+
* Helper method for logging bytes in a human-readable format. This method logs in Binary units
159+
* (B/KiB/MiB/GiB)
160+
*/
161+
public static String humanReadableByteCountBin(final long bytes) {
162+
final long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes);
163+
final int bytePrefixCount = 1024;
164+
if (absB < bytePrefixCount) {
165+
return bytes + " B";
166+
}
167+
long value = absB;
168+
final CharacterIterator ci = new StringCharacterIterator("KMGTPE");
169+
for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) {
170+
value >>= 10;
171+
ci.next();
172+
}
173+
value *= Long.signum(bytes);
174+
return String.format("%.1f %ciB", value / 1024.0, ci.current());
175+
}
176+
138177
}

airbyte-integrations/connectors/source-jdbc/src/main/java/io/airbyte/integrations/source/jdbc/AbstractJdbcSource.java

+17-14
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,24 @@ protected void logPreSyncDebugData(final JdbcDatabase database, final Configured
442442
database.getMetaData().getDatabaseProductVersion());
443443

444444
for (final ConfiguredAirbyteStream stream : catalog.getStreams()) {
445-
final String streamName = stream.getStream().getName();
446-
final String schemaName = stream.getStream().getNamespace();
447-
final ResultSet indexInfo = database.getMetaData().getIndexInfo(null,
448-
schemaName,
449-
streamName,
450-
false,
451-
false);
452-
LOGGER.info("Discovering indexes for schema \"{}\", table \"{}\"", schemaName, streamName);
453-
while (indexInfo.next()) {
454-
LOGGER.info("Index name: {}, Column: {}, Unique: {}",
455-
indexInfo.getString(JDBC_INDEX_NAME),
456-
indexInfo.getString(JDBC_COLUMN_COLUMN_NAME),
457-
!indexInfo.getBoolean(JDBC_INDEX_NON_UNIQUE));
445+
if (stream.getSyncMode().equals(SyncMode.INCREMENTAL)) {
446+
final String streamName = stream.getStream().getName();
447+
final String schemaName = stream.getStream().getNamespace();
448+
final String cursorFieldName = stream.getCursorField() != null && stream.getCursorField().size() != 0 ? stream.getCursorField().get(0) : "";
449+
final ResultSet indexInfo = database.getMetaData().getIndexInfo(null,
450+
schemaName,
451+
streamName,
452+
false,
453+
false);
454+
LOGGER.info("Discovering indexes for schema \"{}\", table \"{}\", with cursor field \"{}\"", schemaName, streamName, cursorFieldName);
455+
while (indexInfo.next()) {
456+
LOGGER.info("Index name: {}, Column: {}, Unique: {}",
457+
indexInfo.getString(JDBC_INDEX_NAME),
458+
indexInfo.getString(JDBC_COLUMN_COLUMN_NAME),
459+
!indexInfo.getBoolean(JDBC_INDEX_NON_UNIQUE));
460+
}
461+
indexInfo.close();
458462
}
459-
indexInfo.close();
460463
}
461464
}
462465

airbyte-integrations/connectors/source-postgres-strict-encrypt/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ ENV APPLICATION source-postgres-strict-encrypt
1616

1717
COPY --from=build /airbyte /airbyte
1818

19-
LABEL io.airbyte.version=2.0.24
19+
LABEL io.airbyte.version=2.0.25
2020
LABEL io.airbyte.name=airbyte/source-postgres-strict-encrypt

airbyte-integrations/connectors/source-postgres/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ ENV APPLICATION source-postgres
1616

1717
COPY --from=build /airbyte /airbyte
1818

19-
LABEL io.airbyte.version=2.0.24
19+
LABEL io.airbyte.version=2.0.25
2020
LABEL io.airbyte.name=airbyte/source-postgres

airbyte-integrations/connectors/source-postgres/src/main/java/io/airbyte/integrations/source/postgres/PostgresSource.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import java.sql.Connection;
7575
import java.sql.PreparedStatement;
7676
import java.sql.SQLException;
77+
import java.text.NumberFormat;
7778
import java.time.Duration;
7879
import java.time.Instant;
7980
import java.util.ArrayList;
@@ -572,8 +573,8 @@ protected void estimateFullRefreshSyncSize(final JdbcDatabase database,
572573
// read a row and Stringify it to better understand the accurate volume of data sent over the wire.
573574
// However, this approach doesn't account for different row sizes.
574575
AirbyteTraceMessageUtility.emitEstimateTrace(PLATFORM_DATA_INCREASE_FACTOR * syncByteCount, Type.STREAM, syncRowCount, tableName, schemaName);
575-
LOGGER.info(String.format("Estimate for table: %s : {sync_row_count: %s, sync_bytes: %s, total_table_row_count: %s, total_table_bytes: %s}",
576-
fullTableName, syncRowCount, syncByteCount, syncRowCount, syncByteCount));
576+
LOGGER.info(String.format("Estimate for table in full refresh mode: %s : {rows_to_sync: %s, data_to_sync: %s}",
577+
fullTableName, NumberFormat.getInstance().format(syncRowCount), JdbcUtils.humanReadableByteCountSI(syncByteCount)));
577578
}
578579
} catch (final SQLException e) {
579580
LOGGER.warn("Error occurred while attempting to estimate sync size", e);
@@ -614,8 +615,9 @@ protected void estimateIncrementalSyncSize(final JdbcDatabase database,
614615
// read a row and Stringify it to better understand the accurate volume of data sent over the wire.
615616
// However, this approach doesn't account for different row sizes
616617
AirbyteTraceMessageUtility.emitEstimateTrace(PLATFORM_DATA_INCREASE_FACTOR * syncByteCount, Type.STREAM, syncRowCount, tableName, schemaName);
617-
LOGGER.info(String.format("Estimate for table: %s : {sync_row_count: %s, sync_bytes: %s, total_table_row_count: %s, total_table_bytes: %s}",
618-
fullTableName, syncRowCount, syncByteCount, tableRowCount, tableRowCount));
618+
LOGGER.info(String.format("Estimate for table in incremental mode: %s : {rows_to_sync: %s, data_to_sync: %s, table_row_count: %s, table_size: %s}",
619+
fullTableName, NumberFormat.getInstance().format(syncRowCount), JdbcUtils.humanReadableByteCountSI(syncByteCount), NumberFormat.getInstance().format(tableRowCount),
620+
JdbcUtils.humanReadableByteCountSI(tableByteCount)));
619621
} catch (final SQLException e) {
620622
LOGGER.warn("Error occurred while attempting to estimate sync size", e);
621623
}

connectors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
| **PokeAPI** | <img alt="PokeAPI icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/pokeapi.svg" height="30" height="30"/> | Source | airbyte/source-pokeapi:0.1.5 | alpha | [docs](https://docs.airbyte.com/integrations/sources/pokeapi) | [connectors/source/pokeapi](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/pokeapi) | [source-pokeapi](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-pokeapi) | <small>`6371b14b-bc68-4236-bfbd-468e8df8e968`</small> |
184184
| **Polygon Stock API** | <img alt="Polygon Stock API icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/polygon.svg" height="30" height="30"/> | Source | airbyte/source-polygon-stock-api:0.1.1 | alpha | [docs](https://docs.airbyte.com/integrations/sources/polygon-stock-api) | [connectors/source/polygon-stock-api](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/polygon-stock-api) | [source-polygon-stock-api](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-polygon-stock-api) | <small>`5807d72f-0abc-49f9-8fa5-ae820007032b`</small> |
185185
| **PostHog** | <img alt="PostHog icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/posthog.svg" height="30" height="30"/> | Source | airbyte/source-posthog:0.1.9 | beta | [docs](https://docs.airbyte.com/integrations/sources/posthog) | [connectors/source/posthog](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/posthog) | [source-posthog](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-posthog) | <small>`af6d50ee-dddf-4126-a8ee-7faee990774f`</small> |
186-
| **Postgres** | <img alt="Postgres icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/postgresql.svg" height="30" height="30"/> | Source | airbyte/source-postgres:2.0.24 | generally_available | [docs](https://docs.airbyte.com/integrations/sources/postgres) | [connectors/source/postgres](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/postgres) | [source-postgres](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-postgres) | <small>`decd338e-5647-4c0b-adf4-da0e75f5a750`</small> |
186+
| **Postgres** | <img alt="Postgres icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/postgresql.svg" height="30" height="30"/> | Source | airbyte/source-postgres:2.0.25 | generally_available | [docs](https://docs.airbyte.com/integrations/sources/postgres) | [connectors/source/postgres](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/postgres) | [source-postgres](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-postgres) | <small>`decd338e-5647-4c0b-adf4-da0e75f5a750`</small> |
187187
| **Postmark App** | <img alt="Postmark App icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/postmark.svg" height="30" height="30"/> | Source | airbyte/source-postmarkapp:0.1.0 | alpha | [docs](https://docs.airbyte.com/integrations/sources/postmarkapp) | [connectors/source/postmarkapp](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/postmarkapp) | [source-postmarkapp](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-postmarkapp) | <small>`cde75ca1-1e28-4a0f-85bb-90c546de9f1f`</small> |
188188
| **PrestaShop** | <img alt="PrestaShop icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/prestashop.svg" height="30" height="30"/> | Source | airbyte/source-prestashop:0.3.1 | beta | [docs](https://docs.airbyte.com/integrations/sources/prestashop) | [connectors/source/prestashop](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/prestashop) | [source-prestashop](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-prestashop) | <small>`d60a46d4-709f-4092-a6b7-2457f7d455f5`</small> |
189189
| **Primetric** | <img alt="Primetric icon" src="https://raw.githubusercontent.com/airbytehq/airbyte /master/airbyte-config-oss/init-oss/src/main/resources/icons/primetric.svg" height="30" height="30"/> | Source | airbyte/source-primetric:0.1.0 | alpha | [docs](https://docs.airbyte.com/integrations/sources/primetric) | [connectors/source/primetric](https://github.com/airbytehq/airbyte/issues?q=is:open+is:issue+label:connectors/source/primetric) | [source-primetric](https://github.com/airbytehq/airbyte/tree/master/airbyte-integrations/connectors/source-primetric) | <small>`f636c3c6-4077-45ac-b109-19fc62a283c1`</small> |

0 commit comments

Comments
 (0)