diff options
author | Spencer Jackson <spencer.jackson@mongodb.com> | 2019-02-21 17:14:34 -0500 |
---|---|---|
committer | Spencer Jackson <spencer.jackson@mongodb.com> | 2019-02-25 13:16:17 -0500 |
commit | 7b6c745329dd48ee1ad7c128aeb5ea2ce31e72e3 (patch) | |
tree | 0aaf7e85be60be1b1cb522632b49947aa2c3e536 /src | |
parent | 582ae15f89f2cac5e89d9b670f8f80efb6d90db0 (diff) | |
download | mongo-7b6c745329dd48ee1ad7c128aeb5ea2ce31e72e3.tar.gz |
SERVER-39731 Migrate server parameters in src/mongo/db/traffic_recorder.cpp to IDL
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/db/traffic_recorder.cpp | 41 | ||||
-rw-r--r-- | src/mongo/db/traffic_recorder.idl | 17 | ||||
-rw-r--r-- | src/mongo/db/traffic_recorder_validators.cpp | 48 | ||||
-rw-r--r-- | src/mongo/db/traffic_recorder_validators.h | 41 |
5 files changed, 118 insertions, 33 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 87b4129382c..3dbc0c8e8a5 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -2139,15 +2139,17 @@ env.Library( target='traffic_recorder', source=[ 'traffic_recorder.cpp', + 'traffic_recorder_validators.cpp', env.Idlc('traffic_recorder.idl')[0], ], LIBDEPS=[ '$BUILD_DIR/mongo/base', ], LIBDEPS_PRIVATE=[ + "$BUILD_DIR/mongo/db/commands/server_status", '$BUILD_DIR/mongo/db/service_context', + '$BUILD_DIR/mongo/idl/server_parameter', "$BUILD_DIR/mongo/rpc/rpc", - "$BUILD_DIR/mongo/db/commands/server_status", ], ) diff --git a/src/mongo/db/traffic_recorder.cpp b/src/mongo/db/traffic_recorder.cpp index 6ba88708b78..8e73b91d37a 100644 --- a/src/mongo/db/traffic_recorder.cpp +++ b/src/mongo/db/traffic_recorder.cpp @@ -30,6 +30,7 @@ #include "mongo/platform/basic.h" #include "mongo/db/traffic_recorder.h" +#include "mongo/db/traffic_recorder_gen.h" #include <boost/filesystem/operations.hpp> #include <fstream> @@ -39,8 +40,6 @@ #include "mongo/base/init.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/commands/server_status.h" -#include "mongo/db/commands/test_commands_enabled.h" -#include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/rpc/factory.h" #include "mongo/stdx/thread.h" @@ -51,42 +50,20 @@ namespace mongo { namespace { -constexpr auto kDefaultTrafficRecordingDirectory = ""_sd; - -MONGO_EXPORT_STARTUP_SERVER_PARAMETER(trafficRecordingDirectory, - std::string, - kDefaultTrafficRecordingDirectory.toString()) - ->withValidator([](const std::string& newValue) { - if (!boost::filesystem::is_directory(newValue)) { - return Status(ErrorCodes::FileNotOpen, - str::stream() << "traffic recording directory \"" << newValue - << "\" is not a directory."); - } - - return Status::OK(); - }); - -MONGO_EXPORT_STARTUP_SERVER_PARAMETER(AlwaysRecordTraffic, std::string, ""); - bool shouldAlwaysRecordTraffic = false; MONGO_INITIALIZER(ShouldAlwaysRecordTraffic)(InitializerContext*) { - if (!AlwaysRecordTraffic.size()) { + if (!gAlwaysRecordTraffic.size()) { return Status::OK(); } - if (!getTestCommandsEnabled()) { - return Status(ErrorCodes::BadValue, - "invalid to set AlwaysRecordTraffic if test commands are not enabled"); - } - - if (trafficRecordingDirectory.empty()) { + if (gTrafficRecordingDirectory.empty()) { if (serverGlobalParams.logpath.empty()) { return Status(ErrorCodes::BadValue, "invalid to set AlwaysRecordTraffic without a logpath or " "trafficRecordingDirectory"); } else { - trafficRecordingDirectory = serverGlobalParams.logpath; + gTrafficRecordingDirectory = serverGlobalParams.logpath; } } @@ -255,10 +232,10 @@ private: "Traffic recording filename must not be empty", !filename.empty()); - if (trafficRecordingDirectory.back() == '/') { - trafficRecordingDirectory.pop_back(); + if (gTrafficRecordingDirectory.back() == '/') { + gTrafficRecordingDirectory.pop_back(); } - auto parentPath = boost::filesystem::path(trafficRecordingDirectory); + auto parentPath = boost::filesystem::path(gTrafficRecordingDirectory); auto path = parentPath / filename; uassert(ErrorCodes::BadValue, @@ -302,7 +279,7 @@ void TrafficRecorder::start(const StartRecordingTraffic& options) { uassert(ErrorCodes::BadValue, "Traffic recording directory not set", - !trafficRecordingDirectory.empty()); + !gTrafficRecordingDirectory.empty()); { stdx::lock_guard<stdx::mutex> lk(_mutex); @@ -341,7 +318,7 @@ void TrafficRecorder::observe(const transport::SessionHandle& ts, if (!_recording) { StartRecordingTraffic options; - options.setFilename(AlwaysRecordTraffic); + options.setFilename(gAlwaysRecordTraffic); options.setMaxFileSize(std::numeric_limits<int64_t>::max()); _recording = std::make_shared<Recording>(options); diff --git a/src/mongo/db/traffic_recorder.idl b/src/mongo/db/traffic_recorder.idl index fa9cd232c14..3516f461d61 100644 --- a/src/mongo/db/traffic_recorder.idl +++ b/src/mongo/db/traffic_recorder.idl @@ -31,6 +31,7 @@ global: cpp_namespace: "mongo" + cpp_includes: "mongo/db/traffic_recorder_validators.h" imports: - "mongo/idl/basic_types.idl" @@ -75,3 +76,19 @@ commands: stopRecordingTraffic: description: "stop recording Command" namespace: ignored + +server_parameters: + trafficRecordingDirectory: + description: 'Path to directory where traffic recordings will be saved' + set_at: startup + cpp_vartype: std::string + cpp_varname: gTrafficRecordingDirectory + validator: + callback: 'validateTrafficRecordDestination' + + AlwaysRecordTraffic: + description: 'Start server with traffic recording enabled, and ensure all records are flushed. Test only.' + test_only: true + set_at: startup + cpp_vartype: std::string + cpp_varname: gAlwaysRecordTraffic diff --git a/src/mongo/db/traffic_recorder_validators.cpp b/src/mongo/db/traffic_recorder_validators.cpp new file mode 100644 index 00000000000..a96e489f45c --- /dev/null +++ b/src/mongo/db/traffic_recorder_validators.cpp @@ -0,0 +1,48 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * 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 + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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 Server Side 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. + */ + +#include "mongo/db/traffic_recorder_validators.h" + +#include <boost/filesystem/operations.hpp> + +#include "mongo/util/mongoutils/str.h" + +namespace mongo { + +Status validateTrafficRecordDestination(const std::string& path) { + if (!path.empty() && !boost::filesystem::is_directory(path)) { + return Status(ErrorCodes::FileNotOpen, + str::stream() << "traffic recording directory \"" << path + << "\" is not a directory."); + } + + return Status::OK(); +} + +} // namespace mongo diff --git a/src/mongo/db/traffic_recorder_validators.h b/src/mongo/db/traffic_recorder_validators.h new file mode 100644 index 00000000000..94e2c10bff6 --- /dev/null +++ b/src/mongo/db/traffic_recorder_validators.h @@ -0,0 +1,41 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * 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 + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * <http://www.mongodb.com/licensing/server-side-public-license>. + * + * 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 Server Side 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/base/status.h" + +namespace mongo { + +Status validateTrafficRecordDestination(const std::string& path); + + +} // namespace mongo |