From 0622860baf2aae4e6441ff60326bceb6f8a44f01 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Thu, 27 Jul 2023 06:18:58 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Source=20Mongo:=20fix=20potentia?= =?UTF-8?q?l=20npe=20when=20collecting=20stats=20(#28760)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * avoid NPE in getCollectionStats * remove accidental whitespace * update mongo changelog --- .../io/airbyte/db/mongodb/MongoDatabase.java | 16 +++++++++++----- .../source-mongodb-strict-encrypt/Dockerfile | 2 +- .../source-mongodb-strict-encrypt/metadata.yaml | 2 +- .../connectors/source-mongodb-v2/Dockerfile | 2 +- .../connectors/source-mongodb-v2/metadata.yaml | 4 ++-- .../MongoDbSource.java | 3 +-- docs/integrations/sources/mongodb-v2.md | 3 ++- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java index c70960761190..fd81b3914ce6 100644 --- a/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java +++ b/airbyte-db/db-lib/src/main/java/io/airbyte/db/mongodb/MongoDatabase.java @@ -137,12 +137,18 @@ public Stream read(final String collectionName, final List col public Map getCollectionStats(final String collectionName) { try { final Document collectionStats = getDatabase().runCommand(new BsonDocument("collStats", new BsonString(collectionName))); - return Map.of(COLLECTION_COUNT_KEY, collectionStats.get("count"), - COLLECTION_STORAGE_SIZE_KEY, collectionStats.get("storageSize")); - } catch (final MongoCommandException e) { - LOGGER.warn("Unable to retrieve collection statistics", e); - return Map.of(); + final var count = collectionStats.get("count"); + final var storageSize = collectionStats.get("storageSize"); + + if (count != null && storageSize != null) { + return Map.of(COLLECTION_COUNT_KEY, collectionStats.get("count"), + COLLECTION_STORAGE_SIZE_KEY, collectionStats.get("storageSize")); + } + } catch (final Exception e) { + LOGGER.warn("Unable to retrieve collection statistics - {}", e.getMessage(), e); } + + return Map.of(); } public String getServerType() { diff --git a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile index 87a298b317b4..75f2d9d9b4d9 100644 --- a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile +++ b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile @@ -24,5 +24,5 @@ ENV APPLICATION source-mongodb-strict-encrypt COPY --from=build /airbyte /airbyte -LABEL io.airbyte.version=0.2.3 +LABEL io.airbyte.version=0.2.4 LABEL io.airbyte.name=airbyte/source-mongodb-strict-encrypt diff --git a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/metadata.yaml b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/metadata.yaml index 00fb4d70eab9..720e6cbf9ff8 100644 --- a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/metadata.yaml +++ b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/metadata.yaml @@ -7,7 +7,7 @@ data: connectorSubtype: database connectorType: source definitionId: b2e713cd-cc36-4c0a-b5bd-b47cb8a0561e - dockerImageTag: 0.2.3 + dockerImageTag: 0.2.4 dockerRepository: airbyte/source-mongodb-strict-encrypt githubIssueLabel: source-mongodb-v2 icon: mongodb.svg diff --git a/airbyte-integrations/connectors/source-mongodb-v2/Dockerfile b/airbyte-integrations/connectors/source-mongodb-v2/Dockerfile index b411289c6b72..748e81a32313 100644 --- a/airbyte-integrations/connectors/source-mongodb-v2/Dockerfile +++ b/airbyte-integrations/connectors/source-mongodb-v2/Dockerfile @@ -24,5 +24,5 @@ ENV APPLICATION source-mongodb-v2 COPY --from=build /airbyte /airbyte -LABEL io.airbyte.version=0.2.2 +LABEL io.airbyte.version=0.2.4 LABEL io.airbyte.name=airbyte/source-mongodb-v2 diff --git a/airbyte-integrations/connectors/source-mongodb-v2/metadata.yaml b/airbyte-integrations/connectors/source-mongodb-v2/metadata.yaml index c7149c2847c9..9b5dddd73aa8 100644 --- a/airbyte-integrations/connectors/source-mongodb-v2/metadata.yaml +++ b/airbyte-integrations/connectors/source-mongodb-v2/metadata.yaml @@ -2,7 +2,7 @@ data: connectorSubtype: database connectorType: source definitionId: b2e713cd-cc36-4c0a-b5bd-b47cb8a0561e - dockerImageTag: 0.2.3 + dockerImageTag: 0.2.4 dockerRepository: airbyte/source-mongodb-v2 githubIssueLabel: source-mongodb-v2 icon: mongodb.svg @@ -10,7 +10,7 @@ data: name: MongoDb registries: cloud: - dockerImageTag: 0.2.3 + dockerImageTag: 0.2.4 dockerRepository: airbyte/source-mongodb-strict-encrypt enabled: true oss: diff --git a/airbyte-integrations/connectors/source-mongodb-v2/src/main/java/io.airbyte.integrations.source.mongodb/MongoDbSource.java b/airbyte-integrations/connectors/source-mongodb-v2/src/main/java/io.airbyte.integrations.source.mongodb/MongoDbSource.java index 9f4d556c4229..8eb48ed7b148 100644 --- a/airbyte-integrations/connectors/source-mongodb-v2/src/main/java/io.airbyte.integrations.source.mongodb/MongoDbSource.java +++ b/airbyte-integrations/connectors/source-mongodb-v2/src/main/java/io.airbyte.integrations.source.mongodb/MongoDbSource.java @@ -265,8 +265,7 @@ private Optional generateFilter(final CursorInfo cursorInfo, final BsonTyp public void close() {} private void recordStatistics(final MongoDatabase database, final String collectionName) { - final Map data = new HashMap<>(); - data.putAll(database.getCollectionStats(collectionName)); + final Map data = new HashMap<>(database.getCollectionStats(collectionName)); data.put("version", database.getServerVersion()); data.put("type", database.getServerType()); LOGGER.info(Jsons.serialize(data)); diff --git a/docs/integrations/sources/mongodb-v2.md b/docs/integrations/sources/mongodb-v2.md index d0ba7e9efc50..1b082f18e940 100644 --- a/docs/integrations/sources/mongodb-v2.md +++ b/docs/integrations/sources/mongodb-v2.md @@ -101,7 +101,8 @@ For more information regarding configuration parameters, please see [MongoDb Doc ## Changelog | Version | Date | Pull Request | Subject | -|:--------|:-----------| :------------------------------------------------------- |:----------------------------------------------------------------------------------------------------------| +|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------| +| 0.2.4 | 2023-07-26 | [28760](https://github.com/airbytehq/airbyte/pull/28760) | Fix bug preventing some syncs from succeeding when collecting stats | | 0.2.3 | 2023-07-26 | [28733](https://github.com/airbytehq/airbyte/pull/28733) | Fix bug preventing syncs from discovering field types | | 0.2.2 | 2023-07-25 | [28692](https://github.com/airbytehq/airbyte/pull/28692) | Fix bug preventing statistics retrieval from views | | 0.2.1 | 2023-07-21 | [28527](https://github.com/airbytehq/airbyte/pull/28527) | Log server information |