diff options
author | Jonathan Reams <jbreams@mongodb.com> | 2015-04-30 09:47:35 -0400 |
---|---|---|
committer | Jonathan Reams <jbreams@mongodb.com> | 2015-04-30 09:47:35 -0400 |
commit | c269033226874638626b6c028bf0f81fa0af2006 (patch) | |
tree | eda7eaf89b4389b245940fe5af3eac67e0807ba6 /src/mongo/util | |
parent | 88882960587d58c83f42ffaee6b3ab39b43be66c (diff) | |
download | mongo-c269033226874638626b6c028bf0f81fa0af2006.tar.gz |
SERVER-18099 Refactor buildinfo/version reporting
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/net/ssl_manager.cpp | 12 | ||||
-rw-r--r-- | src/mongo/util/stacktrace_posix.cpp | 1 | ||||
-rw-r--r-- | src/mongo/util/version.cpp.in | 99 | ||||
-rw-r--r-- | src/mongo/util/version.h | 25 | ||||
-rw-r--r-- | src/mongo/util/version_reporting.cpp | 132 | ||||
-rw-r--r-- | src/mongo/util/version_reporting.h | 60 |
6 files changed, 118 insertions, 211 deletions
diff --git a/src/mongo/util/net/ssl_manager.cpp b/src/mongo/util/net/ssl_manager.cpp index 3e4bbe62142..6f9be1a1c03 100644 --- a/src/mongo/util/net/ssl_manager.cpp +++ b/src/mongo/util/net/ssl_manager.cpp @@ -65,12 +65,7 @@ namespace mongo { SSLParams sslGlobalParams; -#ifndef MONGO_CONFIG_SSL - const std::string getSSLVersion(const std::string &prefix, const std::string &suffix) { - return ""; - } -#else - +#ifdef MONGO_CONFIG_SSL // Old copies of OpenSSL will not have constants to disable protocols they don't support. // Define them to values we can OR together safely to generically disable these protocols across // all versions of OpenSSL. @@ -81,11 +76,6 @@ namespace mongo { #define SSL_OP_NO_TLSv1_2 0 #endif - - const std::string getSSLVersion(const std::string &prefix, const std::string &suffix) { - return prefix + SSLeay_version(SSLEAY_VERSION) + suffix; - } - namespace { /** diff --git a/src/mongo/util/stacktrace_posix.cpp b/src/mongo/util/stacktrace_posix.cpp index 95c43f84fce..79b680625ac 100644 --- a/src/mongo/util/stacktrace_posix.cpp +++ b/src/mongo/util/stacktrace_posix.cpp @@ -187,6 +187,7 @@ namespace { BSONObjBuilder soMap; soMap << "mongodbVersion" << versionString; soMap << "gitVersion" << gitVersion(); + soMap << "compiledModules" << compiledModules(); struct utsname unameData; if (!uname(&unameData)) { BSONObjBuilder unameBuilder(soMap.subobjStart("uname")); diff --git a/src/mongo/util/version.cpp.in b/src/mongo/util/version.cpp.in index 3724d12594d..205e119c6d5 100644 --- a/src/mongo/util/version.cpp.in +++ b/src/mongo/util/version.cpp.in @@ -27,13 +27,27 @@ * then also delete it in the license file. */ +#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kControl + #include "mongo/platform/basic.h" -#include "mongo/util/version.h" +#include <initializer_list> +#include <boost/version.hpp> +#include <sstream> +#include <string> #include "mongo/base/parse_number.h" +#include "mongo/bson/bsonobjbuilder.h" +#include "mongo/config.h" #include "mongo/db/jsobj.h" +#include "mongo/util/debug_util.h" +#include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/version.h" + +#ifdef MONGO_CONFIG_SSL +#include <openssl/crypto.h> +#endif namespace mongo { @@ -41,6 +55,14 @@ namespace mongo { using std::stringstream; const char versionString[] = "@mongo_code_version@"; + const char * gitVersion() { return "@buildinfo_git_version@"; } + const char * compiledJSEngine() { return "@buildinfo_js_engine@"; } + const char * allocator() { return "@buildinfo_allocator@"; } + + std::vector<std::string> compiledModules() { + const std::vector<string> modules_list = @buildinfo_modules@; + return modules_list; + } // See unit test for example outputs BSONArray toVersionArray(const char* version){ @@ -116,4 +138,77 @@ namespace mongo { return ss.str(); } -} // namespace mongo + void printGitVersion() { log() << "git version: " << gitVersion(); } + + const std::string openSSLVersion(const std::string &prefix, const std::string &suffix) { +#ifndef MONGO_CONFIG_SSL + return ""; +#else + return prefix + SSLeay_version(SSLEAY_VERSION) + suffix; +#endif + } + + void printOpenSSLVersion() { +#ifdef MONGO_CONFIG_SSL + log() << openSSLVersion("OpenSSL version: "); +#endif + } + +#if defined(_WIN32) + const char * targetMinOS() { +#if (NTDDI_VERSION >= NTDDI_WIN7) + return "Windows 7/Windows Server 2008 R2"; +#elif (NTDDI_VERSION >= NTDDI_VISTA) + return "Windows Vista/Windows Server 2008"; +#else +#error This targeted Windows version is not supported +#endif // NTDDI_VERSION + } + + void printTargetMinOS() { + log() << "targetMinOS: " << targetMinOS(); + } +#endif // _WIN32 + + void printAllocator() { + log() << "allocator: " << allocator(); + } + + void appendBuildInfo(BSONObjBuilder& result) { + result << "version" << versionString + << "gitVersion" << gitVersion() +#if defined(_WIN32) + << "targetMinOS" << targetMinOS() +#endif + << "allocator" << allocator() + << "versionArray" << versionArray + << "javascriptEngine" << compiledJSEngine(); + + BSONObjBuilder opensslInfo(result.subobjStart("openssl")); +#ifdef MONGO_CONFIG_SSL + opensslInfo << "running" << openSSLVersion() + << "compiled" << OPENSSL_VERSION_TEXT; +#else + opensslInfo << "running" << "disabled" + << "compiled" << "disabled"; +#endif + opensslInfo.done(); + + BSONObjBuilder buildvarsInfo(result.subobjStart("buildEnvironment")); + buildvarsInfo << "build_command" << "@buildinfo_cmdline@" + << "cc" << "@buildinfo_cc_version@" + << "ccflags" << "@buildinfo_ccflags@" + << "cflags" << "@buildinfo_cflags@" + << "cxx" << "@buildinfo_cxx_version@" + << "cxxflags" << "@buildinfo_cxxflags@" + << "linkflags" << "@buildinfo_linkflags@" + << "modules" << compiledModules() + << "target_arch" << "@buildinfo_target_arch@" + << "target_os" << "@buildinfo_target_os@"; + buildvarsInfo.done(); + + result << "pointerSizeBits" << (int)sizeof(void*) * 8; + result.appendBool( "debug" , kDebugBuild ); + result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); + } +} diff --git a/src/mongo/util/version.h b/src/mongo/util/version.h index 1de46d666e6..2289c4216e4 100644 --- a/src/mongo/util/version.h +++ b/src/mongo/util/version.h @@ -35,24 +35,37 @@ namespace mongo { struct BSONArray; + class BSONObjBuilder; // mongo version extern const char versionString[]; extern const BSONArray versionArray; std::string mongodVersion(); + // mongo git version + const char* gitVersion(); + const char* distName(); + void printGitVersion(); + std::vector<std::string> compiledModules(); + // Convert a version std::string into a numeric array BSONArray toVersionArray(const char* version); // Checks whether another version is the same major version as us bool isSameMajorVersion(const char* version); - const char * gitVersion(); - const char * compiledJSEngine(); - const char * allocator(); - const char * loaderFlags(); - const char * compilerFlags(); - std::string sysInfo(); + // Get/print the version of OpenSSL that's used at runtime + const std::string openSSLVersion( + const std::string& prefix = "", + const std::string& suffix = ""); + void printOpenSSLVersion(); + + // Append build info data to a BSONObjBuilder + void appendBuildInfo(BSONObjBuilder& result); + + void printTargetMinOS(); + void printAllocator(); + void show_warnings(); } // namespace mongo diff --git a/src/mongo/util/version_reporting.cpp b/src/mongo/util/version_reporting.cpp deleted file mode 100644 index 263aaabbc90..00000000000 --- a/src/mongo/util/version_reporting.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// @file version.cpp - -/* Copyright 2009 10gen Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects - * for all of the code used other than as permitted herein. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you do not - * wish to do so, delete this exception statement from your version. If you - * delete this 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::kControl - -#include "mongo/platform/basic.h" - -#include "mongo/util/version_reporting.h" - -#include <boost/version.hpp> -#include <sstream> -#include <string> - -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/config.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/service_context.h" -#include "mongo/util/debug_util.h" -#include "mongo/util/log.h" -#include "mongo/util/net/ssl_manager.h" -#include "mongo/util/version.h" - -namespace mongo { - - using std::endl; - using std::string; - using std::stringstream; - - void printGitVersion() { log() << "git version: " << gitVersion() << endl; } - - const std::string openSSLVersion(const std::string &prefix, const std::string &suffix) { - return getSSLVersion(prefix, suffix); - } - - void printOpenSSLVersion() { -#ifdef MONGO_CONFIG_SSL - log() << openSSLVersion("OpenSSL version: ") << endl; -#endif - } - - BSONArray storageEngineList() { - if (!hasGlobalServiceContext()) - return BSONArray(); - - boost::scoped_ptr<StorageFactoriesIterator> sfi( - getGlobalServiceContext()->makeStorageFactoriesIterator()); - - if (!sfi) - return BSONArray(); - - BSONArrayBuilder engineArrayBuilder; - - while (sfi->more()) { - engineArrayBuilder.append(sfi->next()->getCanonicalName()); - } - - return engineArrayBuilder.arr(); - } - -#if defined(_WIN32) - std::string targetMinOS() { - stringstream ss; -#if (NTDDI_VERSION >= NTDDI_WIN7) - ss << "Windows 7/Windows Server 2008 R2"; -#elif (NTDDI_VERSION >= NTDDI_VISTA) - ss << "Windows Vista/Windows Server 2008"; -#else -#error This targetted Windows version is not supported -#endif // NTDDI_VERSION - return ss.str(); - } - - void printTargetMinOS() { - log() << "targetMinOS: " << targetMinOS(); - } -#endif // _WIN32 - - void printSysInfo() { - log() << "build info: " << sysInfo() << endl; - } - - void printAllocator() { - log() << "allocator: " << allocator() << endl; - } - - void appendBuildInfo(BSONObjBuilder& result) { - result << "version" << versionString - << "gitVersion" << gitVersion() -#if defined(_WIN32) - << "targetMinOS" << targetMinOS() -#endif - << "OpenSSLVersion" << openSSLVersion() - << "sysInfo" << sysInfo() - << "loaderFlags" << loaderFlags() - << "compilerFlags" << compilerFlags() - << "allocator" << allocator() - << "storageEngines" << storageEngineList() - << "versionArray" << versionArray - << "javascriptEngine" << compiledJSEngine() -/*TODO: add this back once the module system is in place -- maybe once we do something like serverstatus with callbacks*/ -// << "interpreterVersion" << globalScriptEngine->getInterpreterVersionString() - << "bits" << ( sizeof( int* ) == 4 ? 32 : 64 ); - result.appendBool( "debug" , kDebugBuild ); - result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize); - } -} diff --git a/src/mongo/util/version_reporting.h b/src/mongo/util/version_reporting.h deleted file mode 100644 index 5714d580678..00000000000 --- a/src/mongo/util/version_reporting.h +++ /dev/null @@ -1,60 +0,0 @@ -/** -* Copyright (C) 2012 10gen Inc. -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU Affero General Public License, version 3, -* as published by the Free Software Foundation. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Affero General Public License for more details. -* -* You should have received a copy of the GNU Affero General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* As a special exception, the copyright holders give permission to link the -* code of portions of this program with the OpenSSL library under certain -* conditions as described in each individual source file and distribute -* linked combinations including the program with the OpenSSL library. You -* must comply with the GNU Affero General Public License in all respects -* for all of the code used other than as permitted herein. If you modify -* file(s) with this exception, you may extend this exception to your -* version of the file(s), but you are not obligated to do so. If you do not -* wish to do so, delete this exception statement from your version. If you -* delete this exception statement from all source files in the program, -* then also delete it in the license file. -*/ - -#pragma once - -#include <string> - -#include "mongo/bson/bsonobj.h" - -namespace mongo { - class BSONObjBuilder; - - void appendBuildInfo(BSONObjBuilder& result); - - const char * gitVersion(); - const char * compiledJSEngine(); - const char * allocator(); - const char * loaderFlags(); - const char * compilerFlags(); - - void printGitVersion(); - - const std::string openSSLVersion(const std::string &prefix = "", const std::string &suffix = ""); - void printOpenSSLVersion(); - - BSONArray storageEngineList(); - - std::string sysInfo(); - void printSysInfo(); - void printTargetMinOS(); - void printAllocator(); - - void show_warnings(); - -} // namespace mongo |