diff options
author | Andrii Dobroshynskyi <andrii.dobroshynskyi@mongodb.com> | 2020-06-25 16:56:58 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-06-30 20:53:40 +0000 |
commit | 7917051ba59a15fddf70493ffe50ec28289523ae (patch) | |
tree | 422ce2cd320ed318ff9efae02ff60156e0257ffe /src/mongo/db/commands | |
parent | 5c9db8373b31516386625d02540d6492bf5be5c3 (diff) | |
download | mongo-7917051ba59a15fddf70493ffe50ec28289523ae.tar.gz |
SERVER-48742 Log changes to profiler settings
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r-- | src/mongo/db/commands/profile_common.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/mongo/db/commands/profile_common.cpp b/src/mongo/db/commands/profile_common.cpp index bfb095630eb..5b41f6a2fa8 100644 --- a/src/mongo/db/commands/profile_common.cpp +++ b/src/mongo/db/commands/profile_common.cpp @@ -26,13 +26,16 @@ * exception statement from all source files in the program, then also delete * it in the license file. */ +#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand #include "mongo/platform/basic.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands/profile_common.h" #include "mongo/db/commands/profile_gen.h" +#include "mongo/db/jsobj.h" #include "mongo/idl/idl_parser.h" +#include "mongo/logv2/log.h" namespace mongo { @@ -69,10 +72,12 @@ bool ProfileCmdBase::run(OperationContext* opCtx, // Delegate to _applyProfilingLevel to set the profiling level appropriately whether we are on // mongoD or mongoS. int oldLevel = _applyProfilingLevel(opCtx, dbName, profilingLevel); + auto oldSlowMS = serverGlobalParams.slowMS; + auto oldSampleRate = serverGlobalParams.sampleRate; result.append("was", oldLevel); - result.append("slowms", serverGlobalParams.slowMS); - result.append("sampleRate", serverGlobalParams.sampleRate); + result.append("slowms", oldSlowMS); + result.append("sampleRate", oldSampleRate); if (auto slowms = request.getSlowms()) { serverGlobalParams.slowMS = *slowms; @@ -84,6 +89,27 @@ bool ProfileCmdBase::run(OperationContext* opCtx, serverGlobalParams.sampleRate = *sampleRate; } + // Log the change made to server's profiling settings, unless the request was to get the current + // value. + if (profilingLevel != -1) { + logv2::DynamicAttributes attrs; + + BSONObjBuilder oldState; + BSONObjBuilder newState; + + oldState.append("level"_sd, oldLevel); + oldState.append("slowms"_sd, oldSlowMS); + oldState.append("sampleRate"_sd, oldSampleRate); + attrs.add("from", oldState.obj()); + + newState.append("level"_sd, profilingLevel); + newState.append("slowms"_sd, serverGlobalParams.slowMS); + newState.append("sampleRate"_sd, serverGlobalParams.sampleRate); + attrs.add("to", newState.obj()); + + LOGV2(48742, "Profiler settings changed", attrs); + } + return true; } } // namespace mongo |