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 7dafea27a5db..c70960761190 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 @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.common.annotations.VisibleForTesting; import com.mongodb.ConnectionString; +import com.mongodb.MongoCommandException; import com.mongodb.MongoConfigurationException; import com.mongodb.ReadConcern; import com.mongodb.client.MongoClient; @@ -134,9 +135,14 @@ public Stream read(final String collectionName, final List col } public Map getCollectionStats(final String collectionName) { - 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")); + 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(); + } } public String getServerType() { @@ -144,7 +150,12 @@ public String getServerType() { } public String getServerVersion() { - return getDatabase().runCommand(new BsonDocument("buildinfo", new BsonString(""))).get("version").toString(); + try { + return getDatabase().runCommand(new BsonDocument("buildinfo", new BsonString(""))).get("version").toString(); + } catch (final MongoCommandException e) { + LOGGER.warn("Unable to retrieve server version", e); + return null; + } } private Stream getStream(final MongoCursor cursor, final CheckedFunction mapper) { diff --git a/airbyte-db/db-lib/src/test/java/io/airbyte/db/mongodb/MongoDatabaseTest.java b/airbyte-db/db-lib/src/test/java/io/airbyte/db/mongodb/MongoDatabaseTest.java index 714c80316339..18c734721f23 100644 --- a/airbyte-db/db-lib/src/test/java/io/airbyte/db/mongodb/MongoDatabaseTest.java +++ b/airbyte-db/db-lib/src/test/java/io/airbyte/db/mongodb/MongoDatabaseTest.java @@ -8,11 +8,17 @@ import static io.airbyte.db.mongodb.MongoDatabase.COLLECTION_STORAGE_SIZE_KEY; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.JsonNode; +import com.mongodb.MongoCommandException; import com.mongodb.ReadConcern; +import com.mongodb.ServerAddress; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; import com.mongodb.client.MongoCollection; @@ -25,6 +31,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; +import org.bson.BsonDocument; +import org.bson.BsonString; import org.bson.Document; import org.bson.types.ObjectId; import org.junit.jupiter.api.AfterAll; @@ -155,6 +163,19 @@ void testGetCollectionStatistics() { assertEquals(4096, statistics.get(COLLECTION_STORAGE_SIZE_KEY)); } + @Test + void testGetCollectionStatisticsCommandError() { + final MongoDatabase mongoDatabase1 = mock(MongoDatabase.class); + final com.mongodb.client.MongoDatabase clientMongoDatabase = mock(com.mongodb.client.MongoDatabase.class); + final BsonDocument response = new BsonDocument("test", new BsonString("error")); + final MongoCommandException error = new MongoCommandException(response, mock(ServerAddress.class)); + when(clientMongoDatabase.runCommand(any())).thenThrow(error); + when(mongoDatabase1.getDatabase()).thenReturn(clientMongoDatabase); + + final Map statistics = mongoDatabase1.getCollectionStats(COLLECTION_NAME); + assertTrue(statistics.isEmpty()); + } + @Test void testGetServerType() { assertEquals(ClusterType.UNKNOWN.name(), mongoDatabase.getServerType()); @@ -165,4 +186,16 @@ void testGetServerVersion() { assertEquals(MONGO_DB_VERSION, mongoDatabase.getServerVersion()); } + @Test + void testGetServerVersionCommandError() { + final MongoDatabase mongoDatabase1 = mock(MongoDatabase.class); + final com.mongodb.client.MongoDatabase clientMongoDatabase = mock(com.mongodb.client.MongoDatabase.class); + final BsonDocument response = new BsonDocument("test", new BsonString("error")); + final MongoCommandException error = new MongoCommandException(response, mock(ServerAddress.class)); + when(clientMongoDatabase.runCommand(any())).thenThrow(error); + when(mongoDatabase1.getDatabase()).thenReturn(clientMongoDatabase); + + assertNull(mongoDatabase1.getServerVersion()); + } + } diff --git a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/Dockerfile index 0d642102d1e1..23bd454f9492 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.1 +LABEL io.airbyte.version=0.2.2 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 5572664514d5..97e8010f0ae0 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.1 + dockerImageTag: 0.2.2 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 6e13253af050..b411289c6b72 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.1 +LABEL io.airbyte.version=0.2.2 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 102023ed4086..3d7cad20ad47 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.1 + dockerImageTag: 0.2.2 dockerRepository: airbyte/source-mongodb-v2 githubIssueLabel: source-mongodb-v2 icon: mongodb.svg @@ -10,7 +10,7 @@ data: name: MongoDb registries: cloud: - dockerImageTag: 0.2.1 + dockerImageTag: 0.2.2 dockerRepository: airbyte/source-mongodb-strict-encrypt enabled: true oss: diff --git a/docs/integrations/sources/mongodb-v2.md b/docs/integrations/sources/mongodb-v2.md index cff6e011ce92..a219d783ae3d 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.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 | | 0.2.0 | 2023-06-26 | [27737](https://github.com/airbytehq/airbyte/pull/27737) | License Update: Elv2 | | 0.1.19 | 2022-10-07 | [17614](https://github.com/airbytehq/airbyte/pull/17614) | Increased discover performance |