diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/db.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/log_process_details.cpp | 34 | ||||
-rw-r--r-- | src/mongo/db/log_process_details.h | 7 | ||||
-rw-r--r-- | src/mongo/db/mongod_options.cpp | 35 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.h | 7 | ||||
-rw-r--r-- | src/mongo/s/mongos_options.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/version_mongos.cpp | 19 | ||||
-rw-r--r-- | src/mongo/s/version_mongos.h | 11 | ||||
-rw-r--r-- | src/mongo/shell/shell_options.cpp | 16 | ||||
-rw-r--r-- | src/mongo/util/version.cpp | 107 | ||||
-rw-r--r-- | src/mongo/util/version.h | 13 |
13 files changed, 145 insertions, 123 deletions
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index b5588f4bbfe..2742b0666b0 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -326,7 +326,7 @@ ExitCode _initAndListen(ServiceContext* serviceContext, int listenPort) { VersionInfoInterface::instance().logTargetMinOS(); #endif - logProcessDetails(); + logProcessDetails(nullptr); serviceContext->setServiceEntryPoint(std::make_unique<ServiceEntryPointMongod>(serviceContext)); diff --git a/src/mongo/db/log_process_details.cpp b/src/mongo/db/log_process_details.cpp index 9d43247991a..f63401df6fd 100644 --- a/src/mongo/db/log_process_details.cpp +++ b/src/mongo/db/log_process_details.cpp @@ -33,6 +33,11 @@ #include "mongo/db/log_process_details.h" +#include <ostream> + +#include "mongo/bson/bsonobj.h" +#include "mongo/bson/bsonobjbuilder.h" +#include "mongo/bson/json.h" #include "mongo/db/repl/repl_set_config.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/server_options.h" @@ -44,26 +49,35 @@ namespace mongo { +namespace { + bool is32bit() { return (sizeof(int*) == 4); } -void logProcessDetails() { - auto&& vii = VersionInfoInterface::instance(); - vii.logBuildInfo(); - - ProcessInfo p; - LOGV2( - 51765, "Operating system", "name"_attr = p.getOsName(), "version"_attr = p.getOsVersion()); +} // namespace +void logProcessDetails(std::ostream* os) { + auto&& vii = VersionInfoInterface::instance(); if (ProcessInfo::getMemSizeMB() < ProcessInfo::getSystemMemSizeMB()) { LOGV2_WARNING(20720, "Available memory is less than system memory", "availableMemSizeMB"_attr = ProcessInfo::getMemSizeMB(), "systemMemSizeMB"_attr = ProcessInfo::getSystemMemSizeMB()); } - - printCommandLineOpts(); + auto osInfo = BSONObjBuilder() + .append("name", ProcessInfo::getOsName()) + .append("version", ProcessInfo::getOsVersion()) + .obj(); + vii.logBuildInfo(os); + if (os) { + *os << format(FMT_STRING("Operating System: {}"), + tojson(osInfo, ExtendedRelaxedV2_0_0, true)) + << std::endl; + } else { + LOGV2(51765, "Operating System", "os"_attr = osInfo); + } + printCommandLineOpts(os); } void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { @@ -89,7 +103,7 @@ void logProcessDetailsForLogRotate(ServiceContext* serviceContext) { } } - logProcessDetails(); + logProcessDetails(nullptr); } } // namespace mongo diff --git a/src/mongo/db/log_process_details.h b/src/mongo/db/log_process_details.h index d74fcc5fe52..677fea672bb 100644 --- a/src/mongo/db/log_process_details.h +++ b/src/mongo/db/log_process_details.h @@ -29,14 +29,17 @@ #pragma once +#include <iosfwd> + namespace mongo { class ServiceContext; /** - * Writes useful information about the running process to the diagnostic log on startup. + * Writes useful information about the running process. + * If `os` is nonnull, print to it, else to LOGV2. */ -void logProcessDetails(); +void logProcessDetails(std::ostream* os); /** * Writes useful information about the running process to diagnostic log diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp index c1926b20762..78a8befe022 100644 --- a/src/mongo/db/mongod_options.cpp +++ b/src/mongo/db/mongod_options.cpp @@ -101,23 +101,20 @@ void printMongodHelp(const moe::OptionSection& options) { }; namespace { -void sysRuntimeInfo() { + +void appendSysInfo(BSONObjBuilder* obj) { + auto o = BSONObjBuilder(obj->subobjStart("sysinfo")); #if defined(_SC_PAGE_SIZE) - LOGV2(20873, - " page size: {int_sysconf_SC_PAGE_SIZE}", - "int_sysconf_SC_PAGE_SIZE"_attr = (int)sysconf(_SC_PAGE_SIZE)); + o.append("_SC_PAGE_SIZE", (long long)sysconf(_SC_PAGE_SIZE)); #endif #if defined(_SC_PHYS_PAGES) - LOGV2(20874, - " _SC_PHYS_PAGES: {sysconf_SC_PHYS_PAGES}", - "sysconf_SC_PHYS_PAGES"_attr = sysconf(_SC_PHYS_PAGES)); + o.append("_SC_PHYS_PAGES", (long long)sysconf(_SC_PHYS_PAGES)); #endif #if defined(_SC_AVPHYS_PAGES) - LOGV2(20875, - " _SC_AVPHYS_PAGES: {sysconf_SC_AVPHYS_PAGES}", - "sysconf_SC_AVPHYS_PAGES"_attr = sysconf(_SC_AVPHYS_PAGES)); + o.append("_SC_AVPHYS_PAGES", (long long)sysconf(_SC_AVPHYS_PAGES)); #endif } + } // namespace bool handlePreValidationMongodOptions(const moe::Environment& params, @@ -126,24 +123,16 @@ bool handlePreValidationMongodOptions(const moe::Environment& params, printMongodHelp(moe::startupOptions); return false; } - - auto setPlainLogFormat = []() { - auto& globalDomain = logv2::LogManager::global().getGlobalDomainInternal(); - logv2::LogDomainGlobal::ConfigurationOptions config = globalDomain.config(); - config.format = logv2::LogFormat::kPlain; - invariant(globalDomain.configure(config).isOK()); - }; - if (params.count("version") && params["version"].as<bool>() == true) { - setPlainLogFormat(); auto&& vii = VersionInfoInterface::instance(); - LOGV2(20876, "{mongodVersion_vii}", "mongodVersion_vii"_attr = mongodVersion(vii)); - vii.logBuildInfo(); + std::cout << mongodVersion(vii) << std::endl; + vii.logBuildInfo(&std::cout); return false; } if (params.count("sysinfo") && params["sysinfo"].as<bool>() == true) { - setPlainLogFormat(); - sysRuntimeInfo(); + BSONObjBuilder obj; + appendSysInfo(&obj); + std::cout << tojson(obj.done(), ExtendedRelaxedV2_0_0, true) << std::endl; return false; } diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index 878fa85a40f..0d237dfe7bd 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -37,10 +37,12 @@ #include <boost/algorithm/string/trim.hpp> #include <boost/filesystem.hpp> #include <boost/filesystem/operations.hpp> +#include <fmt/format.h> #include <ios> #include <iostream> #include "mongo/base/status.h" +#include "mongo/bson/json.h" #include "mongo/bson/util/builder.h" #include "mongo/config.h" #include "mongo/db/server_options.h" @@ -113,8 +115,14 @@ Status setParsedOpts(const moe::Environment& params) { } } // namespace -void printCommandLineOpts() { - LOGV2(21951, "Options set by command line", "options"_attr = serverGlobalParams.parsedOpts); +void printCommandLineOpts(std::ostream* os) { + if (os) { + *os << format(FMT_STRING("Options set by command line: {}"), + tojson(serverGlobalParams.parsedOpts, ExtendedRelaxedV2_0_0, true)) + << std::endl; + } else { + LOGV2(21951, "Options set by command line", "options"_attr = serverGlobalParams.parsedOpts); + } } Status validateServerOptions(const moe::Environment& params) { diff --git a/src/mongo/db/server_options_server_helpers.h b/src/mongo/db/server_options_server_helpers.h index 51a59315554..5a243ab5dee 100644 --- a/src/mongo/db/server_options_server_helpers.h +++ b/src/mongo/db/server_options_server_helpers.h @@ -29,6 +29,8 @@ #pragma once +#include <iosfwd> + #include "mongo/base/status.h" #include "mongo/util/options_parser/environment.h" #include "mongo/util/options_parser/option_section.h" @@ -66,6 +68,9 @@ Status setupServerOptions(const std::vector<std::string>& args); */ Status storeServerOptions(const optionenvironment::Environment& params); -void printCommandLineOpts(); +/** + * Write to `os`, or to LOGV2 if null. + */ +void printCommandLineOpts(std::ostream* os); } // namespace mongo diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp index f77696af1fe..e706a0c2af0 100644 --- a/src/mongo/s/mongos_options.cpp +++ b/src/mongo/s/mongos_options.cpp @@ -64,7 +64,7 @@ bool handlePreValidationMongosOptions(const moe::Environment& params, return false; } if (params.count("version") && params["version"].as<bool>() == true) { - printShardingVersionInfo(true); + logShardingVersionInfo(&std::cout); return false; } if (params.count("test") && params["test"].as<bool>() == true) { diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 7a017eaabd8..04600263475 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -540,7 +540,8 @@ private: ExitCode runMongosServer(ServiceContext* serviceContext) { ThreadClient tc("mongosMain", serviceContext); - printShardingVersionInfo(false); + + logShardingVersionInfo(nullptr); initWireSpec(); diff --git a/src/mongo/s/version_mongos.cpp b/src/mongo/s/version_mongos.cpp index e5c268554d5..ff2cc60946e 100644 --- a/src/mongo/s/version_mongos.cpp +++ b/src/mongo/s/version_mongos.cpp @@ -44,18 +44,15 @@ namespace mongo { -void printShardingVersionInfo(bool isForVersionReportingOnly) { - auto&& vii = VersionInfoInterface::instance(); - - if (isForVersionReportingOnly) { - auto& globalDomain = logv2::LogManager::global().getGlobalDomainInternal(); - logv2::LogDomainGlobal::ConfigurationOptions config = globalDomain.config(); - config.format = logv2::LogFormat::kPlain; - invariant(globalDomain.configure(config).isOK()); - LOGV2(22900, "{mongosVersion_vii}", "mongosVersion_vii"_attr = mongosVersion(vii)); - vii.logBuildInfo(); +void logShardingVersionInfo(std::ostream* os) { + if (os) { + auto&& vii = VersionInfoInterface::instance(); + *os << mongosVersion(vii) << std::endl; + vii.logBuildInfo(os); + *os << std::endl; } else { - logProcessDetails(); + logProcessDetails(nullptr); } } + } // namespace mongo diff --git a/src/mongo/s/version_mongos.h b/src/mongo/s/version_mongos.h index c688b075abb..5a9bde68623 100644 --- a/src/mongo/s/version_mongos.h +++ b/src/mongo/s/version_mongos.h @@ -27,12 +27,17 @@ * it in the license file. */ +#include <iosfwd> + namespace mongo { /** - * Outputs the version of MongoS either to the standard output (as part of the --version option, - * which case isForVersionReportingOnly = true) or to the log file as part of server startup. + * Outputs the version of MongoS as part of server startup. + * Goes to `os` if nonnull, else to LOGV2. + * + * NOTE: Outputs the version of MongoS to `os` (as part of the --version option), + * which reports different data than if `os` is null! */ -void printShardingVersionInfo(bool isForVersionReportingOnly); +void logShardingVersionInfo(std::ostream* os); } // namespace mongo diff --git a/src/mongo/shell/shell_options.cpp b/src/mongo/shell/shell_options.cpp index b6eef266cf9..f060b25e5fa 100644 --- a/src/mongo/shell/shell_options.cpp +++ b/src/mongo/shell/shell_options.cpp @@ -86,14 +86,16 @@ std::string getMongoShellHelp(StringData name, const moe::OptionSection& options bool handlePreValidationMongoShellOptions(const moe::Environment& params, const std::vector<std::string>& args) { - auto&& vii = VersionInfoInterface::instance(); - if (params.count("version") || params.count("help")) { + if (params.count("help")) { + auto&& vii = VersionInfoInterface::instance(); std::cout << mongoShellVersion(vii) << std::endl; - if (params.count("help")) { - std::cout << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; - } else { - vii.logBuildInfo(); - } + std::cout << getMongoShellHelp(args[0], moe::startupOptions) << std::endl; + return false; + } + if (params.count("version")) { + auto&& vii = VersionInfoInterface::instance(); + std::cout << mongoShellVersion(vii) << std::endl; + vii.logBuildInfo(&std::cout); return false; } return true; diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp index 04de18b76b3..79b6fb3432f 100644 --- a/src/mongo/util/version.cpp +++ b/src/mongo/util/version.cpp @@ -41,14 +41,12 @@ #endif #endif -#include <boost/iterator/filter_iterator.hpp> -#include <boost/iterator/transform_iterator.hpp> -#include <pcrecpp.h> - #include <fmt/format.h> #include <sstream> #include "mongo/base/string_data.h" +#include "mongo/bson/bsonobj.h" +#include "mongo/bson/json.h" #include "mongo/db/jsobj.h" #include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" @@ -135,49 +133,51 @@ std::string VersionInfoInterface::makeVersionString(StringData binaryName) const } void VersionInfoInterface::appendBuildInfo(BSONObjBuilder* result) const { - *result << "version" << version() << "gitVersion" << gitVersion() + BSONObjBuilder& o = *result; + o.append("version", version()); + o.append("gitVersion", gitVersion()); #if defined(_WIN32) - << "targetMinOS" << targetMinOS() + o.append("targetMinOS", targetMinOS()); #endif - << "modules" << modules() << "allocator" << allocator() << "javascriptEngine" - << jsEngine() << "sysInfo" - << "deprecated"; - - BSONArrayBuilder versionArray(result->subarrayStart("versionArray")); - versionArray << majorVersion() << minorVersion() << patchVersion() << extraVersion(); - versionArray.done(); - - BSONObjBuilder opensslInfo(result->subobjStart("openssl")); + o.append("modules", modules()); + o.append("allocator", allocator()); + o.append("javascriptEngine", jsEngine()); + o.append("sysInfo", "deprecated"); + + BSONArrayBuilder(o.subarrayStart("versionArray")) + .append(majorVersion()) + .append(minorVersion()) + .append(patchVersion()) + .append(extraVersion()); + + BSONObjBuilder(o.subobjStart("openssl")) #ifdef MONGO_CONFIG_SSL #if MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_OPENSSL - opensslInfo << "running" << openSSLVersion() << "compiled" << OPENSSL_VERSION_TEXT; + .append("running", openSSLVersion()) + .append("compiled", OPENSSL_VERSION_TEXT) #elif MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_WINDOWS - opensslInfo << "running" - << "Windows SChannel"; + .append("running", "Windows SChannel") #elif MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_APPLE - opensslInfo << "running" - << "Apple Secure Transport"; + .append("running", "Apple Secure Transport") #else #error "Unknown SSL Provider" #endif // MONGO_CONFIG_SSL_PROVIDER #else - opensslInfo << "running" - << "disabled" - << "compiled" - << "disabled"; + .append("running", "disabled") + .append("compiled", "disabled") #endif - opensslInfo.done(); + ; { - BSONObjBuilder env(result->subobjStart("buildEnvironment")); + auto env = BSONObjBuilder(o.subobjStart("buildEnvironment")); for (auto&& e : buildInfo()) if (e.inBuildInfo) env.append(e.key, e.value); } - *result << "bits" << (int)sizeof(void*) * 8; - result->appendBool("debug", kDebugBuild); - result->appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); + o.append("bits", (int)sizeof(void*) * CHAR_BIT); + o.appendBool("debug", kDebugBuild); + o.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); } std::string VersionInfoInterface::openSSLVersion(StringData prefix, StringData suffix) const { @@ -192,37 +192,28 @@ void VersionInfoInterface::logTargetMinOS() const { LOGV2(23398, "Target operating system minimum version", "targetMinOS"_attr = targetMinOS()); } -void VersionInfoInterface::logBuildInfo() const { - logv2::DynamicAttributes attrs; - attrs.add("version", version()); - attrs.add("gitVersion", gitVersion()); - +void VersionInfoInterface::logBuildInfo(std::ostream* os) const { + BSONObjBuilder bob; + bob.append("version", version()); + bob.append("gitVersion", gitVersion()); #if defined(MONGO_CONFIG_SSL) && MONGO_CONFIG_SSL_PROVIDER == MONGO_CONFIG_SSL_PROVIDER_OPENSSL - std::string opensslVersion = openSSLVersion(); - attrs.add("openSSLVersion", opensslVersion); + bob.append("openSSLVersion", openSSLVersion()); #endif - - attrs.add("allocator", allocator()); - - auto modules_list = modules(); - auto modules_sequence = logv2::seqLog(modules_list.begin(), modules_list.end()); - attrs.add("modules", modules_sequence); - - auto build = buildInfo(); - - auto envFilter = [](auto&& bi) { return bi.inBuildInfo && !bi.value.empty(); }; - - auto filtered_begin = boost::make_filter_iterator(envFilter, build.begin(), build.end()); - auto filtered_end = boost::make_filter_iterator(envFilter, build.end(), build.end()); - - auto envFormatter = [](auto&& bi) { return BSONObjBuilder{}.append(bi.key, bi.value).obj(); }; - - auto begin = boost::make_transform_iterator(filtered_begin, envFormatter); - auto end = boost::make_transform_iterator(filtered_end, envFormatter); - auto buildEnv = logv2::seqLog(begin, end); - attrs.add("environment", buildEnv); - - LOGV2(23403, "Build Info", attrs); + bob.append("modules", modules()); + bob.append("allocator", allocator()); + { + auto envObj = BSONObjBuilder(bob.subobjStart("environment")); + for (auto&& bi : buildInfo()) + if (bi.inVersion && !bi.value.empty()) + envObj.append(bi.key, bi.value); + } + BSONObj obj = bob.done(); + if (os) { + // If printing to ostream, print a json object with a single "buildInfo" element. + *os << "Build Info:" << tojson(obj, ExtendedRelaxedV2_0_0, true) << std::endl; + } else { + LOGV2(23403, "Build Info", "buildInfo"_attr = obj); + } } std::string mongoShellVersion(const VersionInfoInterface& provider) { diff --git a/src/mongo/util/version.h b/src/mongo/util/version.h index 0492afeb5bc..04ed69e4275 100644 --- a/src/mongo/util/version.h +++ b/src/mongo/util/version.h @@ -34,6 +34,7 @@ #include <vector> #include "mongo/base/string_data.h" +#include "mongo/bson/bsonobj.h" namespace mongo { @@ -144,7 +145,10 @@ public: std::string makeVersionString(StringData binaryName) const; /** - * Appends the information associated with 'buildInfo', above, to the given builder. + * Appends several fields of build information to the `result`. One of them is + * "buildEnvironment", mapped to a subobject containing most of the information associated + * with 'buildInfo', above, but with the elements for which inBuildInfo == false + * removed. */ void appendBuildInfo(BSONObjBuilder* result) const; @@ -154,9 +158,12 @@ public: void logTargetMinOS() const; /** - * Logs the result of 'buildInfo', above. + * Logs similar info to `appendBuildInfo`, suitable for the --version flag or for a + * startup log message (trimmed for user-friendliness). The `buildInfo` data appear + * in a subobject mapped to the "environment" key, but with the elements for which + * inVersion == false removed. Puts to `os` if nonnull, else to LOGV2. */ - void logBuildInfo() const; + void logBuildInfo(std::ostream* os) const; protected: constexpr VersionInfoInterface() = default; |