summaryrefslogtreecommitdiff
path: root/src/mongo/client/sdam
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/client/sdam')
-rw-r--r--src/mongo/client/sdam/sdam_json_test_runner.cpp77
-rw-r--r--src/mongo/client/sdam/topology_description_test.cpp9
-rw-r--r--src/mongo/client/sdam/topology_manager.cpp11
-rw-r--r--src/mongo/client/sdam/topology_state_machine.cpp45
4 files changed, 104 insertions, 38 deletions
diff --git a/src/mongo/client/sdam/sdam_json_test_runner.cpp b/src/mongo/client/sdam/sdam_json_test_runner.cpp
index 10027290a17..ec4b8e453d2 100644
--- a/src/mongo/client/sdam/sdam_json_test_runner.cpp
+++ b/src/mongo/client/sdam/sdam_json_test_runner.cpp
@@ -43,6 +43,7 @@
#include "mongo/client/sdam/sdam_json_test_runner_cli_options_gen.h"
#include "mongo/client/sdam/topology_manager.h"
#include "mongo/logger/logger.h"
+#include "mongo/logv2/log.h"
#include "mongo/stdx/unordered_set.h"
#include "mongo/util/clock_source_mock.h"
#include "mongo/util/log.h"
@@ -126,10 +127,14 @@ public:
}
void LogParams() const {
- log() << "Verbosity: " << _verbose << std::endl;
- log() << "Source Directory: " << _sourceDirectory << std::endl;
+ LOGV2(20199, "Verbosity: {verbose}", "verbose"_attr = _verbose);
+ LOGV2(20200,
+ "Source Directory: {sourceDirectory}",
+ "sourceDirectory"_attr = _sourceDirectory);
if (_testFilters.size()) {
- log() << "Filters: " << boost::join(_testFilters, ", ");
+ LOGV2(20201,
+ "Filters: {boost_join_testFilters}",
+ "boost_join_testFilters"_attr = boost::join(_testFilters, ", "));
}
}
@@ -212,13 +217,18 @@ public:
for (auto response : _isMasterResponses) {
auto descriptionStr =
(response.getResponse()) ? response.getResponse()->toString() : "[ Network Error ]";
- log() << "Sending server description: " << response.getServer() << " : "
- << descriptionStr << std::endl;
+ LOGV2(20202,
+ "Sending server description: {response_getServer} : {descriptionStr}",
+ "response_getServer"_attr = response.getServer(),
+ "descriptionStr"_attr = descriptionStr);
topology.onServerDescription(response);
}
- log() << "TopologyDescription after Phase " << _phaseNum << ": "
- << topology.getTopologyDescription()->toString() << std::endl;
+ LOGV2(20203,
+ "TopologyDescription after Phase {phaseNum}: {topology_getTopologyDescription}",
+ "phaseNum"_attr = _phaseNum,
+ "topology_getTopologyDescription"_attr =
+ topology.getTopologyDescription()->toString());
validateServers(
&testResult, topology.getTopologyDescription(), _topologyOutcome["servers"].Obj());
@@ -553,11 +563,16 @@ public:
TestCaseResult result{{}, _testFilePath, _testName};
for (const auto& testPhase : _testPhases) {
- log() << emphasize("Phase " + std::to_string(testPhase.getPhaseNum()));
+ LOGV2(20204,
+ "{emphasize_Phase_std_to_string_testPhase_getPhaseNum}",
+ "emphasize_Phase_std_to_string_testPhase_getPhaseNum"_attr =
+ emphasize("Phase " + std::to_string(testPhase.getPhaseNum())));
auto phaseResult = testPhase.execute(topology);
result.phaseResults.push_back(phaseResult);
if (!result.Success()) {
- log() << "Phase " << phaseResult.phaseNumber << " failed.";
+ LOGV2(20205,
+ "Phase {phaseResult_phaseNumber} failed.",
+ "phaseResult_phaseNumber"_attr = phaseResult.phaseNumber);
break;
}
}
@@ -572,8 +587,11 @@ public:
private:
void parseTest(fs::path testFilePath) {
_testFilePath = testFilePath.string();
- log() << "";
- log() << emphasize("Parsing " + testFilePath.string());
+ LOGV2(20206, "");
+ LOGV2(20207,
+ "{emphasize_Parsing_testFilePath_string}",
+ "emphasize_Parsing_testFilePath_string"_attr =
+ emphasize("Parsing " + testFilePath.string()));
{
std::ifstream testFile(_testFilePath);
std::ostringstream json;
@@ -636,7 +654,10 @@ public:
for (auto jsonTest : testFiles) {
auto testCase = JsonTestCase(jsonTest);
try {
- log() << emphasize("Executing " + testCase.Name());
+ LOGV2(20208,
+ "{emphasize_Executing_testCase_Name}",
+ "emphasize_Executing_testCase_Name"_attr =
+ emphasize("Executing " + testCase.Name()));
results.push_back(testCase.execute());
} catch (const DBException& ex) {
std::stringstream error;
@@ -661,7 +682,9 @@ public:
results.begin(), results.end(), [](const JsonTestCase::TestCaseResult& result) {
return !result.Success();
})) {
- log() << emphasize("Failed Test Results");
+ LOGV2(20209,
+ "{emphasize_Failed_Test_Results}",
+ "emphasize_Failed_Test_Results"_attr = emphasize("Failed Test Results"));
}
for (const auto result : results) {
@@ -671,22 +694,31 @@ public:
if (result.Success()) {
++numSuccess;
} else {
- log() << emphasize(testName);
- log() << "error in file: " << file;
+ LOGV2(
+ 20210, "{emphasize_testName}", "emphasize_testName"_attr = emphasize(testName));
+ LOGV2(20211, "error in file: {file}", "file"_attr = file);
++numFailed;
for (auto phaseResult : phaseResults) {
- log() << "Phase " << phaseResult.phaseNumber << ": " << std::endl;
+ LOGV2(20212,
+ "Phase {phaseResult_phaseNumber}: ",
+ "phaseResult_phaseNumber"_attr = phaseResult.phaseNumber);
if (!phaseResult.Success()) {
for (auto error : phaseResult.errorDescriptions) {
- log() << "\t" << error.first << ": " << error.second << std::endl;
+ LOGV2(20213,
+ "\t{error_first}: {error_second}",
+ "error_first"_attr = error.first,
+ "error_second"_attr = error.second);
}
}
}
- log() << std::endl;
+ LOGV2(20214, "");
}
}
- log() << numTestCases << " test cases; " << numSuccess << " success; " << numFailed
- << " failed.";
+ LOGV2(20215,
+ "{numTestCases} test cases; {numSuccess} success; {numFailed} failed.",
+ "numTestCases"_attr = numTestCases,
+ "numSuccess"_attr = numSuccess,
+ "numFailed"_attr = numFailed);
return numFailed;
}
@@ -721,7 +753,10 @@ private:
if (filePath.string().find(filter) != std::string::npos) {
return true;
} else {
- LOG(2) << "'" << filePath.string() << "' skipped due to filter configuration.";
+ LOGV2_DEBUG(20216,
+ 2,
+ "'{filePath_string}' skipped due to filter configuration.",
+ "filePath_string"_attr = filePath.string());
}
}
diff --git a/src/mongo/client/sdam/topology_description_test.cpp b/src/mongo/client/sdam/topology_description_test.cpp
index 1b6181562ae..3f580a9d415 100644
--- a/src/mongo/client/sdam/topology_description_test.cpp
+++ b/src/mongo/client/sdam/topology_description_test.cpp
@@ -26,6 +26,8 @@
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/client/sdam/sdam_test_base.h"
#include "mongo/client/sdam/topology_description.h"
@@ -34,7 +36,9 @@
#include "mongo/client/sdam/server_description.h"
#include "mongo/client/sdam/server_description_builder.h"
#include "mongo/db/wire_version.h"
+#include "mongo/logv2/log.h"
#include "mongo/unittest/death_test.h"
+#include "mongo/util/log.h"
namespace mongo {
template std::ostream& operator<<(std::ostream& os,
@@ -143,8 +147,9 @@ TEST_F(TopologyDescriptionTestFixture, ShouldOnlyAllowSingleAndRsNoPrimaryWithSe
topologyTypes.end());
for (const auto topologyType : topologyTypes) {
- unittest::log() << "Check TopologyType " << toString(topologyType)
- << " with setName value.";
+ LOGV2(20217,
+ "Check TopologyType {topologyType} with setName value.",
+ "topologyType"_attr = toString(topologyType));
ASSERT_THROWS_CODE(
SdamConfiguration(kOneServer, topologyType, mongo::Seconds(10), kSetName),
DBException,
diff --git a/src/mongo/client/sdam/topology_manager.cpp b/src/mongo/client/sdam/topology_manager.cpp
index c2153ae667c..9cad8440f57 100644
--- a/src/mongo/client/sdam/topology_manager.cpp
+++ b/src/mongo/client/sdam/topology_manager.cpp
@@ -31,6 +31,7 @@
#include "mongo/client/sdam/topology_manager.h"
#include "mongo/client/sdam/topology_state_machine.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo::sdam {
@@ -76,10 +77,12 @@ void TopologyManager::onServerDescription(const IsMasterOutcome& isMasterOutcome
boost::optional<int> poolResetCounter = boost::none;
if (isMasterOutcome.isSuccess()) {
if (isStaleTopologyVersion(lastTopologyVersion, newTopologyVersion)) {
- log() << "Ignoring this isMaster response because our topologyVersion: "
- << lastTopologyVersion->toBSON()
- << "is fresher than the provided topologyVersion: "
- << newTopologyVersion->toBSON();
+ LOGV2(20218,
+ "Ignoring this isMaster response because our topologyVersion: "
+ "{lastTopologyVersion}is fresher than the provided topologyVersion: "
+ "{newTopologyVersion}",
+ "lastTopologyVersion"_attr = lastTopologyVersion->toBSON(),
+ "newTopologyVersion"_attr = newTopologyVersion->toBSON());
return;
}
diff --git a/src/mongo/client/sdam/topology_state_machine.cpp b/src/mongo/client/sdam/topology_state_machine.cpp
index dc793595b5c..c54053b2260 100644
--- a/src/mongo/client/sdam/topology_state_machine.cpp
+++ b/src/mongo/client/sdam/topology_state_machine.cpp
@@ -33,6 +33,7 @@
#include <ostream>
#include "mongo/client/sdam/sdam_test_base.h"
+#include "mongo/logv2/log.h"
#include "mongo/util/log.h"
namespace mongo::sdam {
@@ -149,8 +150,11 @@ void mongo::sdam::TopologyStateMachine::initTransitionTable() {
void TopologyStateMachine::onServerDescription(TopologyDescription& topologyDescription,
const ServerDescriptionPtr& serverDescription) {
if (!topologyDescription.containsServerAddress(serverDescription->getAddress())) {
- LOG(0) << kLogPrefix << "ignoring ismaster reply from server that is not in the topology: "
- << serverDescription->getAddress() << std::endl;
+ LOGV2(20219,
+ "{kLogPrefix}ignoring ismaster reply from server that is not in the topology: "
+ "{serverDescription_getAddress}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "serverDescription_getAddress"_attr = serverDescription->getAddress());
return;
}
@@ -364,40 +368,59 @@ void TopologyStateMachine::setTopologyTypeAndUpdateRSWithoutPrimary(
void TopologyStateMachine::removeServerDescription(TopologyDescription& topologyDescription,
const ServerAddress serverAddress) {
topologyDescription.removeServerDescription(serverAddress);
- LOG(0) << kLogPrefix << "server '" << serverAddress << "' was removed from the topology."
- << std::endl;
+ LOGV2(20220,
+ "{kLogPrefix}server '{serverAddress}' was removed from the topology.",
+ "kLogPrefix"_attr = kLogPrefix,
+ "serverAddress"_attr = serverAddress);
}
void TopologyStateMachine::modifyTopologyType(TopologyDescription& topologyDescription,
TopologyType topologyType) {
topologyDescription._type = topologyType;
- LOG(0) << kLogPrefix << "the topology type was set to " << toString(topologyType) << std::endl;
+ LOGV2(20221,
+ "{kLogPrefix}the topology type was set to {topologyType}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "topologyType"_attr = toString(topologyType));
}
void TopologyStateMachine::modifySetName(TopologyDescription& topologyDescription,
const boost::optional<std::string>& setName) {
topologyDescription._setName = setName;
- LOG(0) << kLogPrefix << "the topology setName was set to " << ((setName) ? *setName : "[null]")
- << std::endl;
+ LOGV2(20222,
+ "{kLogPrefix}the topology setName was set to {setName_setName_null}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "setName_setName_null"_attr = ((setName) ? *setName : "[null]"));
}
void TopologyStateMachine::installServerDescription(TopologyDescription& topologyDescription,
ServerDescriptionPtr newServerDescription,
bool newServer) {
topologyDescription.installServerDescription(newServerDescription);
- LOG(1) << kLogPrefix << ((newServer) ? "installed new" : "updated existing")
- << " server description: " << newServerDescription->toString() << std::endl;
+ LOGV2_DEBUG(20223,
+ 1,
+ "{kLogPrefix}{newServer_installed_new_updated_existing} server description: "
+ "{newServerDescription}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newServer_installed_new_updated_existing"_attr =
+ ((newServer) ? "installed new" : "updated existing"),
+ "newServerDescription"_attr = newServerDescription->toString());
}
void TopologyStateMachine::modifyMaxElectionId(TopologyDescription& topologyDescription,
const OID& newMaxElectionId) {
topologyDescription._maxElectionId = newMaxElectionId;
- LOG(0) << kLogPrefix << "topology max election id set to " << newMaxElectionId << std::endl;
+ LOGV2(20224,
+ "{kLogPrefix}topology max election id set to {newMaxElectionId}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newMaxElectionId"_attr = newMaxElectionId);
}
void TopologyStateMachine::modifyMaxSetVersion(TopologyDescription& topologyDescription,
int& newMaxSetVersion) {
topologyDescription._maxSetVersion = newMaxSetVersion;
- LOG(0) << kLogPrefix << "topology max set version set to " << newMaxSetVersion << std::endl;
+ LOGV2(20225,
+ "{kLogPrefix}topology max set version set to {newMaxSetVersion}",
+ "kLogPrefix"_attr = kLogPrefix,
+ "newMaxSetVersion"_attr = newMaxSetVersion);
}
} // namespace mongo::sdam