diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-05-16 14:48:19 -0400 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-05-21 16:35:25 -0400 |
commit | f30e70b5d1ebae87f373de108314993e58309739 (patch) | |
tree | 97b5f921d9329cd573fc76d536105c50196d04d2 /src/mongo/client | |
parent | db55694f289d99db4f808a44643130818f3048a4 (diff) | |
download | mongo-f30e70b5d1ebae87f373de108314993e58309739.tar.gz |
SERVER-36099 Trim FTDC connection pool stats
Diffstat (limited to 'src/mongo/client')
-rw-r--r-- | src/mongo/client/replica_set_monitor.cpp | 35 | ||||
-rw-r--r-- | src/mongo/client/replica_set_monitor.h | 5 | ||||
-rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 9 | ||||
-rw-r--r-- | src/mongo/client/replica_set_monitor_manager.h | 5 |
4 files changed, 34 insertions, 20 deletions
diff --git a/src/mongo/client/replica_set_monitor.cpp b/src/mongo/client/replica_set_monitor.cpp index 21b2e42b4ad..25927212728 100644 --- a/src/mongo/client/replica_set_monitor.cpp +++ b/src/mongo/client/replica_set_monitor.cpp @@ -157,6 +157,15 @@ struct HostNotIn { const std::set<HostAndPort>& _hosts; }; +int32_t pingTimeMillis(const Node& node) { + auto latencyMillis = node.latencyMicros / 1000; + if (latencyMillis > numeric_limits<int32_t>::max()) { + // In particular, Node::unknownLatency does not fit in an int32. + return numeric_limits<int32_t>::max(); + } + return latencyMillis; +} + /** * Replica set refresh period on the task executor. */ @@ -397,12 +406,21 @@ ReplicaSetChangeNotifier& ReplicaSetMonitor::getNotifier() { } // TODO move to correct order with non-statics before pushing -void ReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder) const { +void ReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder, bool forFTDC) const { stdx::lock_guard<stdx::mutex> lk(_state->mutex); + BSONObjBuilder monitorInfo(bsonObjBuilder.subobjStart(getName())); + if (forFTDC) { + for (size_t i = 0; i < _state->nodes.size(); i++) { + const Node& node = _state->nodes[i]; + monitorInfo.appendNumber(node.host.toString(), pingTimeMillis(node)); + } + return; + } + // NOTE: the format here must be consistent for backwards compatibility - BSONArrayBuilder hosts(bsonObjBuilder.subarrayStart("hosts")); - for (unsigned i = 0; i < _state->nodes.size(); i++) { + BSONArrayBuilder hosts(monitorInfo.subarrayStart("hosts")); + for (size_t i = 0; i < _state->nodes.size(); i++) { const Node& node = _state->nodes[i]; BSONObjBuilder builder; @@ -411,15 +429,7 @@ void ReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder) const { builder.append("ismaster", node.isMaster); // intentionally not camelCase builder.append("hidden", false); // we don't keep hidden nodes in the set builder.append("secondary", node.isUp && !node.isMaster); - - int32_t pingTimeMillis = 0; - if (node.latencyMicros / 1000 > numeric_limits<int32_t>::max()) { - // In particular, Node::unknownLatency does not fit in an int32. - pingTimeMillis = numeric_limits<int32_t>::max(); - } else { - pingTimeMillis = node.latencyMicros / 1000; - } - builder.append("pingTimeMillis", pingTimeMillis); + builder.append("pingTimeMillis", pingTimeMillis(node)); if (!node.tags.isEmpty()) { builder.append("tags", node.tags); @@ -427,7 +437,6 @@ void ReplicaSetMonitor::appendInfo(BSONObjBuilder& bsonObjBuilder) const { hosts.append(builder.obj()); } - hosts.done(); } void ReplicaSetMonitor::shutdown() { diff --git a/src/mongo/client/replica_set_monitor.h b/src/mongo/client/replica_set_monitor.h index a306b1b9547..b28364c6a25 100644 --- a/src/mongo/client/replica_set_monitor.h +++ b/src/mongo/client/replica_set_monitor.h @@ -155,9 +155,10 @@ public: bool contains(const HostAndPort& server) const; /** - * Writes information about our cached view of the set to a BSONObjBuilder. + * Writes information about our cached view of the set to a BSONObjBuilder. If + * forFTDC, trim to minimize its size for full-time diagnostic data capture. */ - void appendInfo(BSONObjBuilder& b) const; + void appendInfo(BSONObjBuilder& b, bool forFTDC = false) const; /** * Returns true if the monitor knows a usable primary from it's interal view. diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index f8f6078b23a..dff3d8a16c4 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -203,19 +203,22 @@ void ReplicaSetMonitorManager::removeAllMonitors() { } } -void ReplicaSetMonitorManager::report(BSONObjBuilder* builder) { +void ReplicaSetMonitorManager::report(BSONObjBuilder* builder, bool forFTDC) { // Don't hold _mutex the whole time to avoid ever taking a monitor's mutex while holding the // manager's mutex. Otherwise we could get a deadlock between the manager's, monitor's, and // ShardRegistry's mutex due to the ReplicaSetMonitor's AsynchronousConfigChangeHook potentially // calling ShardRegistry::updateConfigServerConnectionString. auto setNames = getAllSetNames(); + + BSONObjBuilder setStats( + builder->subobjStart(forFTDC ? "replicaSetPingTimesMillis" : "replicaSets")); + for (const auto& setName : setNames) { auto monitor = getMonitor(setName); if (!monitor) { continue; } - BSONObjBuilder monitorInfo(builder->subobjStart(setName)); - monitor->appendInfo(monitorInfo); + monitor->appendInfo(setStats, forFTDC); } } diff --git a/src/mongo/client/replica_set_monitor_manager.h b/src/mongo/client/replica_set_monitor_manager.h index 1adf42fb16d..b0a08f8f4e5 100644 --- a/src/mongo/client/replica_set_monitor_manager.h +++ b/src/mongo/client/replica_set_monitor_manager.h @@ -86,9 +86,10 @@ public: void shutdown(); /** - * Reports information about the replica sets tracked by us, for diagnostic purposes. + * Reports information about the replica sets tracked by us, for diagnostic purposes. If + * forFTDC, trim to minimize its size for full-time diagnostic data capture. */ - void report(BSONObjBuilder* builder); + void report(BSONObjBuilder* builder, bool forFTDC = false); /** * Returns an executor for running RSM tasks. |