summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorPavi Vetriselvan <pavithra.vetriselvan@mongodb.com>2021-04-21 10:42:44 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-07 05:07:15 +0000
commitd8a0fa7c0dd64e01a83fd45b63a2616164f2c019 (patch)
tree027c53326ea5e357854ed96603b2766f898a6ed0 /src/mongo/rpc
parent58817e04308cbea4aa7627005cb5aaadd32c89fe (diff)
downloadmongo-d8a0fa7c0dd64e01a83fd45b63a2616164f2c019.tar.gz
SERVER-55788 Deprecate legacy wire protocol opcodes
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/SConscript10
-rw-r--r--src/mongo/rpc/deprecated_wire_ops.idl44
-rw-r--r--src/mongo/rpc/warn_deprecated_wire_ops.cpp77
-rw-r--r--src/mongo/rpc/warn_deprecated_wire_ops.h54
4 files changed, 181 insertions, 4 deletions
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 22125593a9b..c16d1e116c4 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -51,14 +51,16 @@ protoEnv.Library(
env.Library(
target='rpc',
source=[
+ 'deprecated_wire_ops.idl',
'factory.cpp',
- 'object_check.cpp',
- 'legacy_request.cpp',
- 'legacy_request_builder.cpp',
'legacy_reply.cpp',
'legacy_reply_builder.cpp',
- 'reply_builder_interface.cpp',
+ 'legacy_request.cpp',
+ 'legacy_request_builder.cpp',
+ 'object_check.cpp',
'object_check.idl',
+ 'reply_builder_interface.cpp',
+ 'warn_deprecated_wire_ops.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
diff --git a/src/mongo/rpc/deprecated_wire_ops.idl b/src/mongo/rpc/deprecated_wire_ops.idl
new file mode 100644
index 00000000000..c36ba1e9577
--- /dev/null
+++ b/src/mongo/rpc/deprecated_wire_ops.idl
@@ -0,0 +1,44 @@
+# Copyright (C) 2021-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.
+
+global:
+ cpp_namespace: mongo
+
+server_parameters:
+ deprecatedWireOpsWarningPeriodInSeconds:
+ description: "The period in which the server logs a warning message for deprecated op codes
+ and getLastError command. The server logs a warning message only once per each
+ client in this period irrespective of how many such requests have been
+ received.
+ Such requests include OP_QUERY, OP_GET_MORE, OP_KILL_CURSORS, OP_INSERT,
+ OP_UPDATE, OP_DELETE op codes and getLastError command."
+ set_at: [ startup ]
+ cpp_vartype: AtomicWord<int>
+ cpp_varname: deprecatedWireOpsWarningPeriodInSeconds
+ default: 3600
+ validator:
+ gte: 0
diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.cpp b/src/mongo/rpc/warn_deprecated_wire_ops.cpp
new file mode 100644
index 00000000000..c1d199d4b0b
--- /dev/null
+++ b/src/mongo/rpc/warn_deprecated_wire_ops.cpp
@@ -0,0 +1,77 @@
+/**
+ * Copyright (C) 2021-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.
+ */
+
+#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/rpc/warn_deprecated_wire_ops.h"
+
+#include <fmt/format.h>
+#include <string>
+
+#include "mongo/db/client.h"
+#include "mongo/logv2/log.h"
+#include "mongo/logv2/log_severity_suppressor.h"
+#include "mongo/rpc/deprecated_wire_ops_gen.h"
+#include "mongo/rpc/metadata/client_metadata.h"
+#include "mongo/util/duration.h"
+#include "mongo/util/static_immortal.h"
+
+namespace mongo {
+
+using namespace fmt::literals;
+
+void warnDeprecation(Client& client, StringData op) {
+ static StaticImmortal<logv2::KeyedSeveritySuppressor<std::string>> bumpedSeverity{
+ Seconds{deprecatedWireOpsWarningPeriodInSeconds.load()},
+ logv2::LogSeverity::Warning(),
+ logv2::LogSeverity::Debug(2)};
+
+ std::string clientKey;
+ BSONObj clientInfo;
+ if (auto clientMetadata = ClientMetadata::get(&client); clientMetadata) {
+ auto clientMetadataDoc = clientMetadata->getDocument();
+ clientKey = "{}{}{}"_format(clientMetadata->getApplicationName(),
+ clientMetadataDoc["driver"]["name"].toString(),
+ clientMetadataDoc["driver"]["version"].toString());
+ clientInfo = clientMetadataDoc;
+ } else {
+ clientKey = "{}"_format(client.clientAddress());
+ clientInfo = BSON("address" << client.clientAddress(/*includePort*/ true));
+ }
+
+ LOGV2_DEBUG(5578800,
+ (*bumpedSeverity)(clientKey).toInt(),
+ "Deprecated operation requested",
+ "op"_attr = op,
+ "clientInfo"_attr = clientInfo);
+}
+
+} // namespace mongo
diff --git a/src/mongo/rpc/warn_deprecated_wire_ops.h b/src/mongo/rpc/warn_deprecated_wire_ops.h
new file mode 100644
index 00000000000..ac70c41a930
--- /dev/null
+++ b/src/mongo/rpc/warn_deprecated_wire_ops.h
@@ -0,0 +1,54 @@
+/**
+ * Copyright (C) 2021-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 "mongo/db/client.h"
+#include "mongo/rpc/message.h"
+
+namespace mongo {
+
+/**
+ * Logs a warning message for use of a legacy opcode or getLastError command once per each unique
+ * client in 60 minutes-period by default.
+ * - The specific deprecated op code or command is given by 'op' parameter.
+ * - Each client is identified by remote IP if client metadata is not available. If client metadata
+ * is available, a client is identified by client metadata’s application name + driver name +
+ * driver version.
+ * - The log message includes the following information.
+ * - Either client IP and port if client metadata is not available,
+ * - Or client metadata if client metadata is available.
+ * - The warning period is defined by 'deprecatedWireOpsWarningPeriodInSeconds' setParameter.
+ * - The default value is 3600 seconds.
+ * - If this value is 0, every legacy op code or getLastError request is logged with a warning
+ * message.
+ */
+void warnDeprecation(Client& client, StringData op);
+
+} // namespace mongo