Skip to content

Commit

Permalink
bugfix mongodb collect extra metrics npe (#1257)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Sep 23, 2023
1 parent dd974e5 commit 52d8be5
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public void collect(CollectRep.MetricsData.Builder builder, long appId, String a
document = (Document) document.get(metricsParts[i]);
}
}
if (document == null) {
throw new RuntimeException("the document get from command " + metrics.getMongodb().getCommand() + " is null.");
}
fillBuilder(metrics, valueRowBuilder, document);
builder.addValues(valueRowBuilder.build());
} catch (MongoServerUnavailableException | MongoTimeoutException unavailableException) {
Expand All @@ -137,7 +140,7 @@ public String supportProtocol() {
private void fillBuilder(Metrics metrics, CollectRep.ValueRow.Builder valueRowBuilder, Document document) {
metrics.getAliasFields().forEach(it -> {
if (document.containsKey(it)) {
Object fieldValue =document.get(it);
Object fieldValue = document.get(it);
if (fieldValue == null) {
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
} else {
Expand Down

0 comments on commit 52d8be5

Please sign in to comment.