Skip to content

Commit

Permalink
fix PMD UndefineMagicConstantRule Failure
Browse files Browse the repository at this point in the history
  • Loading branch information
liudonghua123 committed Jan 1, 2023
1 parent 9e17d10 commit 864dfb5
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public void collect(Builder builder, long appId, String app, Metrics metrics) {
MongoClient mongoClient = getClient(metrics);
MongoDatabase mongoDatabase = mongoClient.getDatabase(metrics.getMongodb().getDatabase());
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
if (metrics.getName().startsWith("serverStatus")) {
String serverStatusKsy = "serverStatus";
String buildInfoKey = "buildInfo";
if (metrics.getName().startsWith(serverStatusKsy)) {
// https://www.mongodb.com/docs/manual/reference/command/serverStatus/#metrics
Document serverStatus = mongoDatabase.runCommand(new Document("serverStatus", 1));
Document serverStatus = mongoDatabase.runCommand(new Document(serverStatusKsy, 1));
// the name of metrics is like serverStatus.metrics.document, split it and get the related sub document
String[] metricsParts = metrics.getName().split("\\.");
Document metricsDocument = serverStatus;
Expand All @@ -85,9 +87,9 @@ public void collect(Builder builder, long appId, String app, Metrics metrics) {
}
fillBuilder(metrics, valueRowBuilder, metricsDocument);
}
else if(metrics.getName().equals("buildInfo")) {
else if(metrics.getName().equals(buildInfoKey)) {
// https://www.mongodb.com/docs/manual/reference/command/buildInfo/#usage
Document buildInfo = mongoDatabase.runCommand(new Document("buildInfo", 1));
Document buildInfo = mongoDatabase.runCommand(new Document(buildInfoKey, 1));
fillBuilder(metrics, valueRowBuilder, buildInfo);
}
builder.addValues(valueRowBuilder.build());
Expand Down

0 comments on commit 864dfb5

Please sign in to comment.