SERVER-126186: Add serverStatus section for search stats (#53372)
GitOrigin-RevId: 6553e3e0c70ca18c7e4a7be4cd11b2765842879e
This commit is contained in:
parent
6bdbe5c9d6
commit
5c14ec8028
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Tests that the searchTaskExecutorMetrics section appears in connPoolStats on both mongod and
|
||||
* Tests that the searchTaskExecutorMetrics section appears in serverStatus on both mongod and
|
||||
* mongos, and has the expected structure with diagnosticInfo, networkInterface, and connectionPool
|
||||
* sub-sections for both the mongot and searchIndexMgmt executors.
|
||||
* sub-sections for both the mongot and searchIndex executors.
|
||||
*
|
||||
* @tags: [requires_sharding]
|
||||
*/
|
||||
@ -17,12 +17,12 @@ if (_isWindows()) {
|
||||
// Callers must set this.conn before these tests run (e.g. in a before/beforeEach hook).
|
||||
function searchTaskExecutorMetricsTests() {
|
||||
beforeEach(function () {
|
||||
const stats = assert.commandWorked(this.conn.adminCommand({connPoolStats: 1}));
|
||||
this.metrics = stats.searchTaskExecutorMetrics;
|
||||
const status = assert.commandWorked(this.conn.adminCommand({serverStatus: 1}));
|
||||
this.metrics = status.searchTaskExecutorMetrics;
|
||||
});
|
||||
|
||||
it("has searchTaskExecutorMetrics section", function () {
|
||||
assert(this.metrics !== undefined, "searchTaskExecutorMetrics missing from connPoolStats");
|
||||
assert(this.metrics !== undefined, "searchTaskExecutorMetrics missing from serverStatus");
|
||||
});
|
||||
|
||||
for (const executorName of ["mongot", "searchIndex"]) {
|
||||
@ -51,7 +51,7 @@ function searchTaskExecutorMetricsTests() {
|
||||
}
|
||||
}
|
||||
|
||||
describe("searchTaskExecutorMetrics in connPoolStats", function () {
|
||||
describe("searchTaskExecutorMetrics in serverStatus", function () {
|
||||
describe("standalone", function () {
|
||||
before(function () {
|
||||
this.mongotmock = new MongotMock();
|
||||
@ -57,29 +57,6 @@
|
||||
namespace mongo {
|
||||
namespace {
|
||||
|
||||
void appendExecutorStats(StringData key,
|
||||
const StatusWith<std::shared_ptr<executor::TaskExecutor>>& sw,
|
||||
BSONObjBuilder& bob) {
|
||||
if (!sw.isOK())
|
||||
return;
|
||||
auto& exec = sw.getValue();
|
||||
BSONObjBuilder sub = bob.subobjStart(key);
|
||||
{
|
||||
BSONObjBuilder diagnosticInfo = sub.subobjStart("diagnosticInfo");
|
||||
exec->appendDiagnosticBSON(&diagnosticInfo);
|
||||
}
|
||||
{
|
||||
BSONObjBuilder networkInterface = sub.subobjStart("networkInterface");
|
||||
exec->appendNetworkInterfaceStats(networkInterface);
|
||||
}
|
||||
{
|
||||
BSONObjBuilder connectionPool = sub.subobjStart("connectionPool");
|
||||
executor::ConnectionPoolStats poolStats{};
|
||||
exec->appendConnectionStats(&poolStats);
|
||||
poolStats.appendToBSON(connectionPool);
|
||||
}
|
||||
}
|
||||
|
||||
class PoolStats final : public BasicCommand {
|
||||
public:
|
||||
PoolStats() : BasicCommand("connPoolStats") {}
|
||||
@ -153,17 +130,6 @@ public:
|
||||
// Always report all replica sets being tracked.
|
||||
ReplicaSetMonitorManager::get()->report(&result);
|
||||
|
||||
// Search executors
|
||||
{
|
||||
BSONObjBuilder searchStats = result.subobjStart("searchTaskExecutorMetrics");
|
||||
appendExecutorStats(
|
||||
"mongot", executor::getMongotTaskExecutor(opCtx->getServiceContext()), searchStats);
|
||||
appendExecutorStats(
|
||||
"searchIndex",
|
||||
executor::getSearchIndexManagementTaskExecutor(opCtx->getServiceContext()),
|
||||
searchStats);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -109,7 +109,9 @@ mongo_cc_library(
|
||||
deps = [
|
||||
":mongot_options",
|
||||
":search_index_options",
|
||||
"//src/mongo/db/commands/server_status:server_status_core",
|
||||
"//src/mongo/executor:connection_pool_controllers",
|
||||
"//src/mongo/executor:connection_pool_stats",
|
||||
"//src/mongo/executor:network_interface_factory",
|
||||
"//src/mongo/executor:network_interface_thread_pool",
|
||||
"//src/mongo/executor:pinned_connection_task_executor_registry",
|
||||
|
||||
@ -30,9 +30,15 @@
|
||||
|
||||
#include "mongo/db/query/search/search_task_executors.h"
|
||||
|
||||
#include "mongo/bson/bsonelement.h"
|
||||
#include "mongo/bson/bsonobj.h"
|
||||
#include "mongo/bson/bsonobjbuilder.h"
|
||||
#include "mongo/db/commands/server_status/server_status.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/db/query/search/mongot_options.h"
|
||||
#include "mongo/db/query/search/search_index_options.h"
|
||||
#include "mongo/executor/connection_pool_controllers.h"
|
||||
#include "mongo/executor/connection_pool_stats.h"
|
||||
#include "mongo/executor/network_interface_factory.h"
|
||||
#include "mongo/executor/network_interface_thread_pool.h"
|
||||
#include "mongo/executor/pinned_connection_task_executor_registry.h"
|
||||
@ -151,6 +157,50 @@ void shutdownTaskExecutor(ServiceContext* svc,
|
||||
destroyTaskExecutor(executor);
|
||||
}
|
||||
|
||||
// TODO (SERVER-126178): Remove this server status section and add to connPoolStats.
|
||||
class SearchTaskExecutorServerStatusSection : public ServerStatusSection {
|
||||
public:
|
||||
using ServerStatusSection::ServerStatusSection;
|
||||
|
||||
bool includeByDefault() const override {
|
||||
return true;
|
||||
}
|
||||
|
||||
BSONObj generateSection(OperationContext* opCtx, const BSONElement&) const override {
|
||||
BSONObjBuilder bob;
|
||||
auto* svc = opCtx->getServiceContext();
|
||||
|
||||
auto appendStats = [&](StringData key,
|
||||
const StatusWith<std::shared_ptr<TaskExecutor>>& sw) {
|
||||
if (!sw.isOK())
|
||||
return;
|
||||
auto& exec = sw.getValue();
|
||||
BSONObjBuilder sub = bob.subobjStart(key);
|
||||
{
|
||||
BSONObjBuilder diagnosticInfo = sub.subobjStart("diagnosticInfo");
|
||||
exec->appendDiagnosticBSON(&diagnosticInfo);
|
||||
}
|
||||
{
|
||||
BSONObjBuilder networkInterface = sub.subobjStart("networkInterface");
|
||||
exec->appendNetworkInterfaceStats(networkInterface, true /*forServerStatus*/);
|
||||
}
|
||||
{
|
||||
BSONObjBuilder connectionPool = sub.subobjStart("connectionPool");
|
||||
executor::ConnectionPoolStats poolStats{};
|
||||
exec->appendConnectionStats(&poolStats);
|
||||
poolStats.appendToBSON(connectionPool);
|
||||
}
|
||||
};
|
||||
|
||||
appendStats("mongot", getMongotTaskExecutor(svc));
|
||||
appendStats("searchIndex", getSearchIndexManagementTaskExecutor(svc));
|
||||
return bob.obj();
|
||||
}
|
||||
};
|
||||
|
||||
const auto& searchTaskExecutorSection =
|
||||
*ServerStatusSectionBuilder<SearchTaskExecutorServerStatusSection>("searchTaskExecutorMetrics");
|
||||
|
||||
} // namespace
|
||||
|
||||
StatusWith<std::shared_ptr<TaskExecutor>> getMongotTaskExecutor(ServiceContext* svc) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user