summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2018-07-11 04:15:52 +0000
committerKevin Pulo <kevin.pulo@mongodb.com>2018-07-26 11:32:12 +0000
commit72058227a20ffded4ead6dc396db0d486b1f1753 (patch)
tree2e6d9f13fca46a097b70cf90b6706b793a2f0542
parent6e30589695a5f1837decdb1010590e4c92f77343 (diff)
downloadmongo-72058227a20ffded4ead6dc396db0d486b1f1753.tar.gz
SERVER-35854 naively log received client metadata
-rw-r--r--src/mongo/db/repl/replication_info.cpp3
-rw-r--r--src/mongo/rpc/SConscript2
-rw-r--r--src/mongo/rpc/metadata/client_metadata_naive.cpp47
-rw-r--r--src/mongo/rpc/metadata/client_metadata_naive.h43
-rw-r--r--src/mongo/s/commands/cluster_is_master_cmd.cpp4
5 files changed, 99 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index 50e84803c6f..4f0e8595546 100644
--- a/src/mongo/db/repl/replication_info.cpp
+++ b/src/mongo/db/repl/replication_info.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/repl/replication_coordinator_global.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/wire_version.h"
+#include "mongo/rpc/metadata/client_metadata_naive.h"
#include "mongo/s/write_ops/batched_command_request.h"
namespace mongo {
@@ -225,6 +226,8 @@ public:
if (cmdObj["forShell"].trueValue())
LastError::get(txn->getClient()).disable();
+ logClientMetadata(txn->getClient(), cmdObj);
+
appendReplicationInfo(txn, result, 0);
if (serverGlobalParams.configsvrMode == CatalogManager::ConfigServerMode::CSRS) {
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index cba4e0dfba9..17afc9c365a 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -139,6 +139,7 @@ env.Library(
source=[
'metadata.cpp',
'metadata/audit_metadata.cpp',
+ 'metadata/client_metadata_naive.cpp',
'metadata/config_server_metadata.cpp',
'metadata/server_selection_metadata.cpp',
'metadata/sharding_metadata.cpp',
@@ -150,6 +151,7 @@ env.Library(
'$BUILD_DIR/mongo/client/read_preference',
'$BUILD_DIR/mongo/db/repl/optime',
'$BUILD_DIR/mongo/util/decorable',
+ '$BUILD_DIR/mongo/util/net/hostandport',
],
)
diff --git a/src/mongo/rpc/metadata/client_metadata_naive.cpp b/src/mongo/rpc/metadata/client_metadata_naive.cpp
new file mode 100644
index 00000000000..9d5abd78782
--- /dev/null
+++ b/src/mongo/rpc/metadata/client_metadata_naive.cpp
@@ -0,0 +1,47 @@
+/**
+ * Copyright (C) 2018 MongoDB 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::kNetwork
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/rpc/metadata/client_metadata_naive.h"
+
+#include "mongo/util/log.h"
+
+namespace mongo {
+
+void logClientMetadata(const Client* const client, const BSONObj& isMasterCmdObj) {
+ BSONElement elem = isMasterCmdObj[kMetadataDocumentName];
+ if (!elem.eoo()) {
+ log() << "client supplied metadata " << client->getRemote().toString() << " "
+ << client->desc() << ": " << elem.jsonString(Strict);
+ }
+}
+
+} // namespace mongo
diff --git a/src/mongo/rpc/metadata/client_metadata_naive.h b/src/mongo/rpc/metadata/client_metadata_naive.h
new file mode 100644
index 00000000000..64b4411edce
--- /dev/null
+++ b/src/mongo/rpc/metadata/client_metadata_naive.h
@@ -0,0 +1,43 @@
+/**
+ * Copyright (C) 2018 MongoDB 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 "mongo/bson/bsonobj.h"
+#include "mongo/db/client.h"
+
+namespace mongo {
+
+const char kMetadataDocumentName[] = "client";
+
+/**
+ * Log client and client metadata information to disk.
+ */
+void logClientMetadata(const Client*, const BSONObj& isMasterCmdObj);
+
+} // namespace mongo
diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp
index 14a697808be..38dd399ac78 100644
--- a/src/mongo/s/commands/cluster_is_master_cmd.cpp
+++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp
@@ -29,7 +29,9 @@
#include "mongo/platform/basic.h"
#include "mongo/db/commands.h"
+#include "mongo/db/operation_context.h"
#include "mongo/db/wire_version.h"
+#include "mongo/rpc/metadata/client_metadata_naive.h"
#include "mongo/s/catalog/forwarding_catalog_manager.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/batched_command_request.h"
@@ -65,6 +67,8 @@ public:
int options,
std::string& errmsg,
BSONObjBuilder& result) {
+ logClientMetadata(txn->getClient(), cmdObj);
+
result.appendBool("ismaster", true);
result.append("msg", "isdbgrid");
result.appendNumber("maxBsonObjectSize", BSONObjMaxUserSize);