summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorIrina Yatsenko <irina.yatsenko@mongodb.com>2021-07-08 16:37:15 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-07-09 18:06:09 +0000
commit95b18771c85283900f7a992b7eda350b8a3d6067 (patch)
treea4c5e154c3b88e837de0506ab06fba3e4ec4b218 /src/mongo/rpc
parentdc0b308cfc2014e4f3b655aca7d296263c0592c9 (diff)
downloadmongo-95b18771c85283900f7a992b7eda350b8a3d6067.tar.gz
SERVER-58337 Log and count as deprecated commands issued via OP_QUERY
All commands, except isMaster and hello, that use OP_QUERY with $cmd namespace are now flagged as deprecated.
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/op_legacy_integration_test.cpp83
1 files changed, 81 insertions, 2 deletions
diff --git a/src/mongo/rpc/op_legacy_integration_test.cpp b/src/mongo/rpc/op_legacy_integration_test.cpp
index 00240748e8c..8eb7776c3de 100644
--- a/src/mongo/rpc/op_legacy_integration_test.cpp
+++ b/src/mongo/rpc/op_legacy_integration_test.cpp
@@ -29,6 +29,7 @@
#include "mongo/client/dbclient_connection.h"
#include "mongo/db/dbmessage.h"
+#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/unittest/integration_test.h"
#include "mongo/unittest/unittest.h"
@@ -159,7 +160,7 @@ TEST(OpLegacy, DeprecatedReadOpsCounters) {
}
// Check whether the most recent "deprecation" entry in the log matches the given opName and
-// severity. Return 'false' if no deprecation entries found.
+// severity (if the 'severity' string isn't empty). Return 'false' if no deprecation entries found.
bool wasLogged(DBClientBase* conn, const std::string& opName, const std::string& severity) {
BSONObj getLogResponse;
ASSERT(conn->runCommand("admin", fromjson("{getLog: 'global'}"), getLogResponse));
@@ -168,7 +169,7 @@ bool wasLogged(DBClientBase* conn, const std::string& opName, const std::string&
for (auto it = logEntries.rbegin(); it != logEntries.rend(); ++it) {
auto entry = it->String();
if (entry.find("\"id\":5578800") != std::string::npos) {
- const bool severityMatches =
+ const bool severityMatches = severity.empty() ||
(entry.find(std::string("\"s\":\"") + severity + "\"") != std::string::npos);
const bool opNameMatches =
(entry.find(std::string("\"op\":\"") + opName + "\"") != std::string::npos);
@@ -306,5 +307,83 @@ TEST(OpLegacy, DeprecatedOpsLogging) {
exerciseDeprecatedOps(conn.get(), "D2" /*expectedSeverity*/);
}
+TEST(OpLegacy, GenericCommandViaOpQuery) {
+ auto conn = getIntegrationTestConnection();
+
+ auto serverStatusCmd = fromjson("{serverStatus: 1}");
+ BSONObj serverStatusReplyPrior;
+ ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReplyPrior));
+
+ // Because we cannot link the log entries to the issued commands, limit the search window for
+ // the query-related entry in the log by first running a different command (e.g. getLastError).
+ ASSERT_EQ("", getLastError(conn.get())); // will start failing soon but will still log
+ ASSERT(wasLogged(conn.get(), "getLastError", ""));
+
+ // The actual command doesn't matter, as long as it's not 'hello' or 'isMaster'.
+ auto opQuery = makeQueryMessage("test.$cmd",
+ serverStatusCmd,
+ 1 /*nToReturn*/,
+ 0 /*nToSkip*/,
+ nullptr /*fieldsToReturn*/,
+ 0 /*queryOptions*/);
+ Message replyQuery;
+ ASSERT(conn->call(opQuery, replyQuery));
+ QueryResult::ConstView qr = replyQuery.singleData().view2ptr();
+ BufReader data(qr.data(), qr.dataLen());
+ BSONObj obj = data.read<BSONObj>();
+ ASSERT_OK(getStatusFromCommandResult(obj)); // will fail after we remove the support for $cmd
+
+ // The logic around log severity for the deprecation logging is tested elsewhere. Here we check
+ // that it gets logged at all.
+ ASSERT(wasLogged(conn.get(), "query", ""));
+
+ BSONObj serverStatusReply;
+ ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply));
+ ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "query") + 1,
+ getDeprecatedOpCount(serverStatusReply, "query"));
+}
+
+// 'hello' and 'isMaster' commands, issued via OP_QUERY protocol, are still fully supported.
+void testAllowedCommand(const char* command) {
+ auto conn = getIntegrationTestConnection();
+
+ auto serverStatusCmd = fromjson("{serverStatus: 1}");
+ BSONObj serverStatusReplyPrior;
+ ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReplyPrior));
+
+ // Because we cannot link the log entries to the issued commands, limit the search window for
+ // the query-related entry in the log by first running a different command (e.g. getLastError).
+ ASSERT_EQ("", getLastError(conn.get())); // will start failing soon but will still log
+ ASSERT(wasLogged(conn.get(), "getLastError", ""));
+
+ auto opQuery = makeQueryMessage("test.$cmd",
+ fromjson(command),
+ 1 /*nToReturn*/,
+ 0 /*nToSkip*/,
+ nullptr /*fieldsToReturn*/,
+ 0 /*queryOptions*/);
+ Message replyQuery;
+ ASSERT(conn->call(opQuery, replyQuery));
+ QueryResult::ConstView qr = replyQuery.singleData().view2ptr();
+ BufReader data(qr.data(), qr.dataLen());
+ BSONObj obj = data.read<BSONObj>();
+ ASSERT_OK(getStatusFromCommandResult(obj));
+
+ ASSERT_FALSE(wasLogged(conn.get(), "query", ""));
+
+ BSONObj serverStatusReply;
+ ASSERT(conn->runCommand("admin", serverStatusCmd, serverStatusReply));
+ ASSERT_EQ(getDeprecatedOpCount(serverStatusReplyPrior, "query"),
+ getDeprecatedOpCount(serverStatusReply, "query"));
+}
+
+TEST(OpLegacy, HelloCommandViaOpQuery) {
+ testAllowedCommand("{hello: 1}");
+}
+
+TEST(OpLegacy, IsMasterCommandViaOpQuery) {
+ testAllowedCommand("{isMaster: 1}");
+}
+
} // namespace
} // namespace mongo