Skip to content

Commit

Permalink
add some kv, raft related counters
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince committed Dec 21, 2021
1 parent 8053d5f commit aa3f927
Show file tree
Hide file tree
Showing 68 changed files with 375 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/clients/meta/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ nebula_add_library(
FileBasedClusterIdMan.cpp
)

nebula_add_subdirectory(stats)
nebula_add_subdirectory(test)
3 changes: 3 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <thrift/lib/cpp/util/EnumUtils.h>

#include "clients/meta/FileBasedClusterIdMan.h"
#include "clients/meta/stats/MetaClientStats.h"
#include "common/base/Base.h"
#include "common/base/MurmurHash2.h"
#include "common/conf/Configuration.h"
Expand Down Expand Up @@ -626,6 +627,7 @@ void MetaClient::getResponse(Request req,
bool toLeader,
int32_t retry,
int32_t retryLimit) {
stats::StatsManager::addValue(kNumRpcSentToMetad);
auto* evb = ioThreadPool_->getEventBase();
HostAddr host;
{
Expand Down Expand Up @@ -660,6 +662,7 @@ void MetaClient::getResponse(Request req,
this](folly::Try<RpcResponse>&& t) mutable {
// exception occurred during RPC
if (t.hasException()) {
stats::StatsManager::addValue(kNumRpcSentToMetadFailed);
if (toLeader) {
updateLeader();
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/clients/meta/stats/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.

nebula_add_library(
meta_client_stats_obj
OBJECT
MetaClientStats.cpp
)
19 changes: 19 additions & 0 deletions src/clients/meta/stats/MetaClientStats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include "clients/meta/stats/MetaClientStats.h"

namespace nebula {

stats::CounterId kNumRpcSentToMetad;
stats::CounterId kNumRpcSentToMetadFailed;

void initMetaClientStats() {
kNumRpcSentToMetad = stats::StatsManager::registerStats("num_rpc_sent_to_metad", "rate, sum");
kNumRpcSentToMetadFailed =
stats::StatsManager::registerStats("num_rpc_sent_to_metad_failed", "rate, sum");
}

} // namespace nebula
17 changes: 17 additions & 0 deletions src/clients/meta/stats/MetaClientStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#pragma once

#include "common/stats/StatsManager.h"

namespace nebula {

extern stats::CounterId kNumRpcSentToMetad;
extern stats::CounterId kNumRpcSentToMetadFailed;

void initMetaClientStats();

} // namespace nebula
2 changes: 2 additions & 0 deletions src/clients/storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ nebula_add_library(
InternalStorageClient.cpp
)

nebula_add_subdirectory(stats)

5 changes: 5 additions & 0 deletions src/clients/storage/StorageClientBase-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include <folly/Try.h>

#include "clients/storage/stats/StorageClientStats.h"
#include "common/ssl/SSLConfig.h"
#include "common/stats/StatsManager.h"
#include "common/time/WallClock.h"

namespace nebula {
Expand Down Expand Up @@ -230,6 +232,7 @@ void StorageClientBase<ClientType>::getResponseImpl(
std::pair<HostAddr, Request> request,
RemoteFunc remoteFunc,
std::shared_ptr<folly::Promise<StatusOr<Response>>> pro) {
stats::StatsManager::addValue(kNumRpcSentToStoraged);
using TransportException = apache::thrift::transport::TTransportException;
if (evb == nullptr) {
DCHECK(!!ioThreadPool_);
Expand Down Expand Up @@ -266,6 +269,7 @@ void StorageClientBase<ClientType>::getResponseImpl(
.thenError(folly::tag_t<TransportException>{},
[spaceId, partsId = std::move(partsId), host, pro, this](
TransportException&& ex) mutable {
stats::StatsManager::addValue(kNumRpcSentToStoragedFailed);
if (ex.getType() == TransportException::TIMED_OUT) {
LOG(ERROR) << "Request to " << host << " time out: " << ex.what();
} else {
Expand All @@ -278,6 +282,7 @@ void StorageClientBase<ClientType>::getResponseImpl(
.thenError(folly::tag_t<std::exception>{},
[spaceId, partsId = std::move(partsId), host, pro, this](
std::exception&& ex) mutable {
stats::StatsManager::addValue(kNumRpcSentToStoragedFailed);
// exception occurred during RPC
pro->setValue(Status::Error(
folly::stringPrintf("RPC failure in StorageClient: %s", ex.what())));
Expand Down
9 changes: 9 additions & 0 deletions src/clients/storage/stats/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.

nebula_add_library(
storage_client_stats_obj
OBJECT
StorageClientStats.cpp
)
20 changes: 20 additions & 0 deletions src/clients/storage/stats/StorageClientStats.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include "clients/meta/stats/MetaClientStats.h"

namespace nebula {

stats::CounterId kNumRpcSentToStoraged;
stats::CounterId kNumRpcSentToStoragedFailed;

void initStorageClientStats() {
kNumRpcSentToStoraged =
stats::StatsManager::registerStats("num_rpc_sent_to_storaged", "rate, sum");
kNumRpcSentToStoragedFailed =
stats::StatsManager::registerStats("num_rpc_sent_to_storaged_failed", "rate, sum");
}

} // namespace nebula
17 changes: 17 additions & 0 deletions src/clients/storage/stats/StorageClientStats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#pragma once

#include "common/stats/StatsManager.h"

namespace nebula {

extern stats::CounterId kNumRpcSentToStoraged;
extern stats::CounterId kNumRpcSentToStoragedFailed;

void initStorageClientStats();

} // namespace nebula
3 changes: 3 additions & 0 deletions src/codec/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ set(CODEC_TEST_LIBS
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
$<TARGET_OBJECTS:kv_stats_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:conf_obj>
$<TARGET_OBJECTS:meta_obj>
Expand Down
4 changes: 3 additions & 1 deletion src/common/expression/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ set(expression_test_common_libs
$<TARGET_OBJECTS:network_obj>
$<TARGET_OBJECTS:fs_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
$<TARGET_OBJECTS:datatypes_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:datetime_parser_obj>
Expand Down
9 changes: 8 additions & 1 deletion src/daemons/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ set(common_deps

set(storage_meta_deps
$<TARGET_OBJECTS:kvstore_obj>
$<TARGET_OBJECTS:storage_stats_obj>
$<TARGET_OBJECTS:meta_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
$<TARGET_OBJECTS:kv_stats_obj>
$<TARGET_OBJECTS:raftex_obj>
$<TARGET_OBJECTS:wal_obj>
$<TARGET_OBJECTS:disk_man_obj>
Expand Down Expand Up @@ -109,7 +114,9 @@ nebula_add_executable(
SetupLogging.cpp
SetupBreakpad.cpp
OBJECTS
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
$<TARGET_OBJECTS:util_obj>
$<TARGET_OBJECTS:service_obj>
$<TARGET_OBJECTS:graph_session_obj>
Expand Down
4 changes: 2 additions & 2 deletions src/daemons/GraphDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "common/time/TimezoneInfo.h"
#include "graph/service/GraphFlags.h"
#include "graph/service/GraphService.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"
#include "version/Version.h"
#include "webservice/WebService.h"

Expand Down Expand Up @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) {
if (FLAGS_enable_ssl || FLAGS_enable_graph_ssl || FLAGS_enable_meta_ssl) {
folly::ssl::init();
}
nebula::initCounters();
nebula::initGraphStats();

if (FLAGS_flagfile.empty()) {
printHelp(argv[0]);
Expand Down
4 changes: 4 additions & 0 deletions src/daemons/MetaDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "meta/http/MetaHttpIngestHandler.h"
#include "meta/http/MetaHttpReplaceHostHandler.h"
#include "meta/processors/job/JobManager.h"
#include "meta/stats/MetaStats.h"
#include "version/Version.h"
#include "webservice/Router.h"
#include "webservice/WebService.h"
Expand Down Expand Up @@ -218,6 +219,9 @@ int main(int argc, char* argv[]) {
return EXIT_FAILURE;
}

// Init stats
nebula::initMetaStats();

folly::init(&argc, &argv, true);
if (FLAGS_enable_ssl || FLAGS_enable_meta_ssl) {
folly::ssl::init();
Expand Down
4 changes: 4 additions & 0 deletions src/daemons/StorageDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "common/process/ProcessUtils.h"
#include "common/time/TimezoneInfo.h"
#include "storage/StorageServer.h"
#include "storage/stats/StorageStats.h"
#include "version/Version.h"

DEFINE_string(local_ip, "", "IP address which is used to identify this server");
Expand Down Expand Up @@ -80,6 +81,9 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

// Init stats
nebula::initStorageStats();

folly::init(&argc, &argv, true);
if (FLAGS_enable_ssl || FLAGS_enable_meta_ssl) {
folly::ssl::init();
Expand Down
4 changes: 3 additions & 1 deletion src/graph/context/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ SET(CONTEXT_TEST_LIBS
$<TARGET_OBJECTS:ssl_obj>
$<TARGET_OBJECTS:memory_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
)

nebula_add_test(
Expand Down
2 changes: 1 addition & 1 deletion src/graph/executor/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#include "graph/planner/plan/PlanNode.h"
#include "graph/planner/plan/Query.h"
#include "graph/service/GraphFlags.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"
#include "interface/gen-cpp2/graph_types.h"

using folly::stringPrintf;
Expand Down
4 changes: 3 additions & 1 deletion src/graph/executor/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ SET(EXEC_QUERY_TEST_OBJS
$<TARGET_OBJECTS:graph_obj>
$<TARGET_OBJECTS:ssl_obj>
$<TARGET_OBJECTS:version_obj>
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
)

SET(EXEC_QUERY_TEST_LIBS
Expand Down
4 changes: 3 additions & 1 deletion src/graph/optimizer/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ set(OPTIMIZER_TEST_LIB
$<TARGET_OBJECTS:memory_obj>
$<TARGET_OBJECTS:geo_index_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:meta_client_stats_obj>
$<TARGET_OBJECTS:storage_client_stats_obj>
)

nebula_add_test(
Expand Down
2 changes: 1 addition & 1 deletion src/graph/planner/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nebula_add_test(
$<TARGET_OBJECTS:storage_thrift_obj>
$<TARGET_OBJECTS:meta_client_obj>
$<TARGET_OBJECTS:stats_obj>
$<TARGET_OBJECTS:stats_def_obj>
$<TARGET_OBJECTS:graph_stats_obj>
$<TARGET_OBJECTS:time_obj>
$<TARGET_OBJECTS:meta_thrift_obj>
$<TARGET_OBJECTS:common_thrift_obj>
Expand Down
2 changes: 1 addition & 1 deletion src/graph/service/GraphService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "graph/service/GraphFlags.h"
#include "graph/service/PasswordAuthenticator.h"
#include "graph/service/RequestContext.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"
#include "version/Version.h"

namespace nebula {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/service/QueryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "graph/planner/plan/PlanNode.h"
#include "graph/scheduler/AsyncMsgNotifyBasedScheduler.h"
#include "graph/scheduler/Scheduler.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"
#include "graph/util/AstUtils.h"
#include "graph/validator/Validator.h"
#include "parser/ExplainSentence.h"
Expand Down
2 changes: 1 addition & 1 deletion src/graph/session/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "common/stats/StatsManager.h"
#include "common/time/WallClock.h"
#include "graph/context/QueryContext.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"

namespace nebula {
namespace graph {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/session/GraphSessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "common/stats/StatsManager.h"
#include "common/time/WallClock.h"
#include "graph/service/GraphFlags.h"
#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"

namespace nebula {
namespace graph {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/stats/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under Apache 2.0 License.

nebula_add_library(
stats_def_obj
graph_stats_obj
OBJECT
StatsDef.cpp
GraphStats.cpp
)
10 changes: 7 additions & 3 deletions src/graph/stats/StatsDef.cpp → src/graph/stats/GraphStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* This source code is licensed under Apache 2.0 License.
*/

#include "graph/stats/StatsDef.h"
#include "graph/stats/GraphStats.h"

#include "clients/meta/stats/MetaClientStats.h"
#include "clients/storage/stats/StorageClientStats.h"
#include "common/base/Base.h"
#include "common/stats/StatsManager.h"

DEFINE_int32(slow_query_threshold_us,
200000,
Expand Down Expand Up @@ -40,7 +41,7 @@ stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed;
stats::CounterId kNumActiveSessions;
stats::CounterId kNumReclaimedExpiredSessions;

void initCounters() {
void initGraphStats() {
kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum");
kNumActiveQueries = stats::StatsManager::registerStats("num_active_queries", "sum");
kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum");
Expand Down Expand Up @@ -74,6 +75,9 @@ void initCounters() {
kNumActiveSessions = stats::StatsManager::registerStats("num_active_sessions", "sum");
kNumReclaimedExpiredSessions =
stats::StatsManager::registerStats("num_reclaimed_expired_sessions", "rate, sum");

initMetaClientStats();
initStorageClientStats();
}

} // namespace nebula
Loading

0 comments on commit aa3f927

Please sign in to comment.