Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11541: Reduce logQueryExplain to only happen if Trace logs are enabled #2134

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ private Bson withIncludeExcludes(@NotNull Set<String> includes, @NotNull Set<Str
}

/**
* Logs an explain of a mongo query. If log level is INFO it does it one-lined,
* if log level is DEBUG it does it pretty print multi-lined.
* Logs an explain of a mongo query if trace is enabled
*
* This is done once every 24h of livetime of this particular object.
* This is done once every 24h of lifetime of this particular object.
*
* @param logMsg the log message to use - should contain two "{}" for the hint
* and the explain json
Expand All @@ -218,14 +217,7 @@ private void logQueryExplain(String logMsg, @NotNull Bson query, Bson hint) {
getNodeCollection(), query, hint);
final BasicDBObject winningPlan = MongoUtils.getWinningPlan(explainResult);
final BasicDBObject result = winningPlan == null ? explainResult : winningPlan;
if (LOG.isDebugEnabled()) {
// if log level is DEBUG, let's do a pretty print
String prettyPrinted = JsopBuilder.prettyPrint(result.toJson());
LOG.debug(logMsg, hint, prettyPrinted);
} else {
// otherwise let's just do a compact print
LOG.info(logMsg, hint, result);
}
LOG.trace(logMsg, hint, result);
lastExplainLogMs = System.currentTimeMillis();
}

Expand Down Expand Up @@ -271,7 +263,10 @@ public Iterable<NodeDocument> getModifiedDocs(final long fromModified, final lon
// first sort by _modified and then by _id
final Bson sort = ascending(MODIFIED_IN_SECS, ID);

logQueryExplain("fullGC query explain details, hint : {} - explain : {}", query, modifiedIdHint);
if (LOG.isTraceEnabled()) {
logQueryExplain("fullGC query explain details, hint : {} - explain : {}", query, modifiedIdHint);
}

if (LOG.isDebugEnabled()) {
BsonDocument bson = query.toBsonDocument(BsonDocument.class, MongoClient.getDefaultCodecRegistry());
LOG.debug("getModifiedDocs : query is {}", bson);
Expand Down
Loading