Skip to content

Commit

Permalink
🐛 Source Mongo: fix potential npe when collecting stats (#28760)
Browse files Browse the repository at this point in the history
* avoid NPE in getCollectionStats

* remove accidental whitespace

* update mongo changelog
  • Loading branch information
colesnodgrass authored Jul 27, 2023
1 parent eab3f34 commit 0622860
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,18 @@ public Stream<JsonNode> read(final String collectionName, final List<String> col
public Map<String, Object> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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
license: ELv2
name: MongoDb
registries:
cloud:
dockerImageTag: 0.2.3
dockerImageTag: 0.2.4
dockerRepository: airbyte/source-mongodb-strict-encrypt
enabled: true
oss:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ private Optional<Bson> generateFilter(final CursorInfo cursorInfo, final BsonTyp
public void close() {}

private void recordStatistics(final MongoDatabase database, final String collectionName) {
final Map<String, Object> data = new HashMap<>();
data.putAll(database.getCollectionStats(collectionName));
final Map<String, Object> data = new HashMap<>(database.getCollectionStats(collectionName));
data.put("version", database.getServerVersion());
data.put("type", database.getServerType());
LOGGER.info(Jsons.serialize(data));
Expand Down
3 changes: 2 additions & 1 deletion docs/integrations/sources/mongodb-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit 0622860

Please sign in to comment.