diff options
author | Erin McNulty <erin.mcnulty@mongodb.com> | 2022-06-17 18:10:09 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-17 18:52:28 +0000 |
commit | 25450dbb0e50c4194c80cf8719771c58f871eefb (patch) | |
tree | 1cd1138250a0330b4412425cf89a7c56778e773a | |
parent | 866cb8fb5a50dd4b8bfe47824d90f6091a43a312 (diff) | |
download | mongo-25450dbb0e50c4194c80cf8719771c58f871eefb.tar.gz |
SERVER-62683: Client Metadata Information Should Show Pid In Testing Mode
-rw-r--r-- | jstests/noPassthrough/pid_testing_log.js | 51 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata.cpp | 4 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/client_metadata_test.cpp | 10 |
3 files changed, 60 insertions, 5 deletions
diff --git a/jstests/noPassthrough/pid_testing_log.js b/jstests/noPassthrough/pid_testing_log.js new file mode 100644 index 00000000000..91ff3d7612e --- /dev/null +++ b/jstests/noPassthrough/pid_testing_log.js @@ -0,0 +1,51 @@ +load("jstests/libs/parallelTester.js"); + +/** + * @tags: [requires_replication, requires_sharding] + * + * Test that servers set up in testing mode print the + * pid when they connect as a client to a mongod. + * + */ + +(function() { +"use strict"; + +const rsMin = 10; +const rsMax = 20; + +const baselineParameters = { + ShardingTaskExecutorPoolMinSize: rsMin, + ShardingTaskExecutorPoolMaxSize: rsMax, + ShardingTaskExecutorPoolMinSizeForConfigServers: 4, + ShardingTaskExecutorPoolMaxSizeForConfigServers: 6, +}; + +const mongosParameters = Object.assign( + {logComponentVerbosity: tojson({network: {connectionPool: 5}})}, baselineParameters); + +const st = new ShardingTest({ + config: {nodes: 1}, + shards: 1, + rs0: {nodes: 1}, + mongos: [{setParameter: mongosParameters}], +}); +const mongos = st.s0; + +const populateTestDb = () => { + const db = mongos.getDB('test'); + const coll = db.test; + assert.commandWorked(coll.insert({x: 1})); +}; + +populateTestDb(); + +let log = checkLog.getGlobalLog(mongos); +let hits = log.map(line => JSON.parse(line)) + .filter(o => o.msg == "client metadata") + .filter(o => o.attr.doc.application.pid !== null); + +assert(hits.length > 0); + +st.stop(); +})(); diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp index f66941d803f..626a340284e 100644 --- a/src/mongo/rpc/metadata/client_metadata.cpp +++ b/src/mongo/rpc/metadata/client_metadata.cpp @@ -307,7 +307,7 @@ void ClientMetadata::serialize(StringData driverName, ProcessInfo processInfo; std::string appName; - if (kDebugBuild) { + if (TestingProctor::instance().isEnabled()) { appName = processInfo.getProcessName(); if (appName.length() > kMaxApplicationNameByteLength) { static constexpr auto kEllipsis = "..."_sd; @@ -368,7 +368,7 @@ Status ClientMetadata::serializePrivate(StringData driverName, if (!appName.empty()) { BSONObjBuilder subObjBuilder(metaObjBuilder.subobjStart(kApplication)); subObjBuilder.append(kName, appName); - if (kDebugBuild) { + if (TestingProctor::instance().isEnabled()) { subObjBuilder.append(kPid, ProcessId::getCurrent().toString()); } } diff --git a/src/mongo/rpc/metadata/client_metadata_test.cpp b/src/mongo/rpc/metadata/client_metadata_test.cpp index 9d4c000abb9..994cdf489e8 100644 --- a/src/mongo/rpc/metadata/client_metadata_test.cpp +++ b/src/mongo/rpc/metadata/client_metadata_test.cpp @@ -47,6 +47,7 @@ #include "mongo/unittest/unittest.h" #include "mongo/util/processinfo.h" #include "mongo/util/scopeguard.h" +#include "mongo/util/testing_proctor.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kTest @@ -104,8 +105,9 @@ TEST(ClientMetadataTest, TestLoopbackTest) { .append(kApplication, BOB{} .append(kName, "g") - .appendElements(kDebugBuild ? BOB{}.append(kPid, pid).obj() - : BOB{}.obj()) + .appendElements(TestingProctor::instance().isEnabled() + ? BOB{}.append(kPid, pid).obj() + : BOB{}.obj()) .obj()) .append(kDriver, BOB{}.append(kName, "a").append(kVersion, "b").obj()) .append(kOperatingSystem, @@ -329,7 +331,9 @@ TEST(ClientMetadataTest, TestMongoSAppend) { .append(kApplication, BOB{} .append(kName, "g") - .appendElements(kDebugBuild ? BOB{}.append(kPid, pid).obj() : BOB{}.obj()) + .appendElements(TestingProctor::instance().isEnabled() + ? BOB{}.append(kPid, pid).obj() + : BOB{}.obj()) .obj()) .append(kDriver, BOB{}.append(kName, "a").append(kVersion, "b").obj()) .append(kOperatingSystem, |