From d27132fe88f262aa5c55595c2ec15f44fae5bcba Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Fri, 10 Dec 2021 11:48:44 +0800 Subject: [PATCH 01/10] add more metrics --- src/common/stats/StatsManager.cpp | 3 +++ src/common/stats/StatsManager.h | 1 + src/graph/service/GraphService.cpp | 8 ++++++++ src/graph/service/QueryInstance.cpp | 12 +++++++++++- src/graph/stats/StatsDef.cpp | 20 ++++++++++++++++++++ src/graph/stats/StatsDef.h | 10 ++++++++++ src/parser/SequentialSentences.h | 2 ++ 7 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/common/stats/StatsManager.cpp b/src/common/stats/StatsManager.cpp index 083b7c890db..4b92cbbf271 100644 --- a/src/common/stats/StatsManager.cpp +++ b/src/common/stats/StatsManager.cpp @@ -161,6 +161,9 @@ void StatsManager::addValue(const CounterId& id, VT value) { } } +// static +void StatsManager::decValue(const CounterId& id, VT value) { addValue(id, -value); } + // static bool StatsManager::strToPct(folly::StringPiece part, double& pct) { static const int32_t divisors[] = {1, 1, 10, 100, 1000, 10000}; diff --git a/src/common/stats/StatsManager.h b/src/common/stats/StatsManager.h index 3a1524c088a..cc2dfe75f75 100644 --- a/src/common/stats/StatsManager.h +++ b/src/common/stats/StatsManager.h @@ -114,6 +114,7 @@ class StatsManager final { folly::StringPiece counterName, VT bucketSize, VT min, VT max, std::string stats); static void addValue(const CounterId& id, VT value = 1); + static void decValue(const CounterId& id, VT value = 1); // The parameter counter here must be a qualified counter name, which includes // all three parts (counter name, method/percentile, and time range). Here are diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 6854aaa6411..7fcdf14bddf 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -8,6 +8,7 @@ #include "clients/storage/StorageClient.h" #include "common/base/Base.h" #include "common/encryption/MD5Utils.h" +#include "common/stats/StatsManager.h" #include "common/time/Duration.h" #include "common/time/TimezoneInfo.h" #include "graph/service/CloudAuthenticator.h" @@ -69,6 +70,8 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorCode = ErrorCode::E_BAD_USERNAME_PASSWORD; ctx->resp().errorMsg.reset(new std::string("Bad username/password")); ctx->finish(); + stats::StatsManager::addValue(kNumAuthFailedSessions); + stats::StatsManager::addValue(kNumAuthFailedSessionsBadUserNamePassword); return future; } @@ -76,6 +79,8 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorCode = ErrorCode::E_TOO_MANY_CONNECTIONS; ctx->resp().errorMsg.reset(new std::string("Too many connections in the cluster")); ctx->finish(); + stats::StatsManager::addValue(kNumAuthFailedSessions); + stats::StatsManager::addValue(kNumAuthFailedSessionsOutOfMaxAllowed); return future; } @@ -96,6 +101,7 @@ folly::Future GraphService::future_authenticate(const std::string& ctx->resp().errorMsg.reset(new std::string("Get session for sessionId is nullptr")); return ctx->finish(); } + stats::StatsManager::addValue(kNumOpenedSessions); ctx->setSession(sessionPtr); ctx->resp().sessionId.reset(new int64_t(ctx->session()->id())); ctx->resp().timeZoneOffsetSeconds.reset( @@ -124,6 +130,7 @@ folly::Future GraphService::future_executeWithParameter( ctx->setSessionMgr(sessionManager_.get()); auto future = ctx->future(); stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue(kNumActiveQueries); // When the sessionId is 0, it means the clients to ping the connection is ok if (sessionId == 0) { ctx->resp().errorCode = ErrorCode::E_SESSION_INVALID; @@ -190,6 +197,7 @@ folly::Future GraphService::future_execute(int64_t sessionId, } ctx->setSession(std::move(sessionPtr)); queryEngine_->execute(std::move(ctx)); + stats::StatsManager::decValue(kNumActiveQueries); }; sessionManager_->findSession(sessionId, getThreadManager()).thenValue(std::move(cb)); return future; diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index 8fad33c67e4..358d357033a 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -6,6 +6,7 @@ #include "graph/service/QueryInstance.h" #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/executor/ExecutionError.h" #include "graph/executor/Executor.h" @@ -18,6 +19,8 @@ #include "graph/util/AstUtils.h" #include "graph/validator/Validator.h" #include "parser/ExplainSentence.h" +#include "parser/Sentence.h" +#include "parser/SequentialSentences.h" using nebula::opt::Optimizer; using nebula::opt::OptRule; @@ -65,6 +68,12 @@ Status QueryInstance::validateAndOptimize() { auto result = GQLParser(qctx()).parse(rctx->query()); NG_RETURN_IF_ERROR(result); sentence_ = std::move(result).value(); + if (sentence_->kind() == Sentence::Kind::kSequential) { + size_t num = static_cast(sentence_.get())->numSentences(); + stats::StatsManager::addValue(kNumSentences, num); + } else { + stats::StatsManager::addValue(kNumSentences); + } NG_RETURN_IF_ERROR(Validator::validate(sentence_.get(), qctx())); NG_RETURN_IF_ERROR(findBestPlan()); @@ -123,6 +132,8 @@ void QueryInstance::onError(Status status) { case Status::Code::kPermissionError: rctx->resp().errorCode = ErrorCode::E_BAD_PERMISSION; break; + case Status::Code::kLeaderChanged: + stats::StatsManager::addValue(kNumQueryErrosLeaderChanges); case Status::Code::kBalanced: case Status::Code::kEdgeNotFound: case Status::Code::kError: @@ -131,7 +142,6 @@ void QueryInstance::onError(Status status) { case Status::Code::kInserted: case Status::Code::kKeyNotFound: case Status::Code::kPartialSuccess: - case Status::Code::kLeaderChanged: case Status::Code::kNoSuchFile: case Status::Code::kNotSupported: case Status::Code::kPartNotFound: diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index 762f07c8585..3143194bdc2 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -16,19 +16,39 @@ DEFINE_int32(slow_query_threshold_us, namespace nebula { stats::CounterId kNumQueries; +stats::CounterId kNumActiveQueries; stats::CounterId kNumSlowQueries; stats::CounterId kNumQueryErrors; +stats::CounterId kNumQueryErrosLeaderChanges; +stats::CounterId kNumSentences; stats::CounterId kQueryLatencyUs; stats::CounterId kSlowQueryLatencyUs; +stats::CounterId kNumOpenedSessions; +stats::CounterId kNumAuthFailedSessions; +stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; +stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; + void initCounters() { kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum"); + kNumActiveQueries = stats::StatsManager::registerStats("num_active_queries", "rate, sum"); kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum"); + kNumSentences = stats::StatsManager::registerStats("num_sentences", "rate, sum"); kNumQueryErrors = stats::StatsManager::registerStats("num_query_errors", "rate, sum"); + kNumQueryErrosLeaderChanges = + stats::StatsManager::registerStats("num_query_errors_leader_changes", "rate, sum"); kQueryLatencyUs = stats::StatsManager::registerHisto( "query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); kSlowQueryLatencyUs = stats::StatsManager::registerHisto( "slow_query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + + kNumOpenedSessions = stats::StatsManager::registerStats("num_opened_sessions", "rate, sum"); + kNumAuthFailedSessions = + stats::StatsManager::registerStats("num_auth_failed_sessions", "rate, sum"); + kNumAuthFailedSessionsBadUserNamePassword = stats::StatsManager::registerStats( + "num_auth_failed_sessions_bad_username_password", "rate, sum"); + kNumAuthFailedSessionsOutOfMaxAllowed = stats::StatsManager::registerStats( + "num_auth_failed_sessions_out_of_max_allowed", "rate, sum"); } } // namespace nebula diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h index 0ac0a878e45..32848ae24ef 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/StatsDef.h @@ -13,12 +13,22 @@ DECLARE_int32(slow_query_threshold_us); namespace nebula { +// query related extern stats::CounterId kNumQueries; +extern stats::CounterId kNumActiveQueries; extern stats::CounterId kNumSlowQueries; extern stats::CounterId kNumQueryErrors; +extern stats::CounterId kNumQueryErrosLeaderChanges; +extern stats::CounterId kNumSentences; extern stats::CounterId kQueryLatencyUs; extern stats::CounterId kSlowQueryLatencyUs; +// session related +extern stats::CounterId kNumOpenedSessions; +extern stats::CounterId kNumAuthFailedSessions; +extern stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; +extern stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; + void initCounters(); } // namespace nebula diff --git a/src/parser/SequentialSentences.h b/src/parser/SequentialSentences.h index 5cf192b26a5..6c99d39599d 100644 --- a/src/parser/SequentialSentences.h +++ b/src/parser/SequentialSentences.h @@ -34,6 +34,8 @@ class SequentialSentences final : public Sentence { return result; } + size_t numSentences() const { return sentences_.size(); } + std::string toString() const override; private: From 3192a41e4e45606b754818886861383dd1cfcab8 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Mon, 20 Dec 2021 23:04:45 +0800 Subject: [PATCH 02/10] support to dynamic register metrics --- conf/nebula-graphd.conf.default | 2 + conf/nebula-graphd.conf.production | 2 + src/common/stats/StatsManager.cpp | 204 ++++++++++++++++----- src/common/stats/StatsManager.h | 57 ++++-- src/graph/executor/admin/SpaceExecutor.cpp | 13 ++ src/graph/executor/admin/SpaceExecutor.h | 2 + src/graph/executor/test/CMakeLists.txt | 1 + src/graph/planner/test/CMakeLists.txt | 1 + src/graph/service/GraphService.cpp | 3 + src/graph/service/QueryInstance.cpp | 19 +- src/graph/service/QueryInstance.h | 2 +- src/graph/stats/StatsDef.cpp | 1 + src/graph/stats/StatsDef.h | 1 + 13 files changed, 248 insertions(+), 60 deletions(-) diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index 69eee083941..da2efa27c98 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -86,3 +86,5 @@ ########## experimental feature ########## # if use experimental features --enable_experimental_feature=false + +--enable_space_level_metrics=false diff --git a/conf/nebula-graphd.conf.production b/conf/nebula-graphd.conf.production index 3c1518f90cd..67798fa6942 100644 --- a/conf/nebula-graphd.conf.production +++ b/conf/nebula-graphd.conf.production @@ -84,3 +84,5 @@ ########## experimental feature ########## # if use experimental features --enable_experimental_feature=false + +--enable_space_level_metrics=false diff --git a/src/common/stats/StatsManager.cpp b/src/common/stats/StatsManager.cpp index 4b92cbbf271..6db76f83be7 100644 --- a/src/common/stats/StatsManager.cpp +++ b/src/common/stats/StatsManager.cpp @@ -5,7 +5,9 @@ #include "common/stats/StatsManager.h" +#include #include +#include #include "common/base/Base.h" @@ -51,7 +53,7 @@ void StatsManager::parseStats(const folly::StringPiece stats, // Percentile double pct; if (strToPct(trimmedPart, pct)) { - percentiles.push_back(std::make_pair(trimmedPart, pct)); + percentiles.emplace_back(trimmedPart, pct); } else { LOG(ERROR) << "\"" << trimmedPart << "\" is not a valid percentile form"; } @@ -63,38 +65,45 @@ void StatsManager::parseStats(const folly::StringPiece stats, // static CounterId StatsManager::registerStats(folly::StringPiece counterName, std::string stats) { - using std::chrono::seconds; - - auto& sm = get(); std::vector methods; std::vector> percentiles; parseStats(stats, methods, percentiles); + return registerStats(counterName, methods); +} + +CounterId StatsManager::registerStats(folly::StringPiece counterName, + std::vector methods) { + using std::chrono::seconds; + + auto& sm = get(); std::string name = counterName.toString(); folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); auto it = sm.nameMap_.find(name); if (it != sm.nameMap_.end()) { - DCHECK_GT(it->second.id_.index(), 0); + DCHECK(!it->second.id_.isHisto()); VLOG(2) << "The counter \"" << name << "\" already exists"; it->second.methods_ = methods; - return it->second.id_.index(); + return it->second.id_; } // Insert the Stats - sm.stats_.emplace_back(std::make_pair( - std::make_unique(), - std::make_unique(60, - std::initializer_list( - {seconds(5), seconds(60), seconds(600), seconds(3600)})))); - int32_t index = sm.stats_.size(); - sm.nameMap_.emplace( + sm.stats_.emplace( + counterName, + std::make_pair(std::make_unique(), + std::make_unique( + 60, + std::initializer_list( + {seconds(5), seconds(60), seconds(600), seconds(3600)})))); + std::string index(counterName); + auto it2 = sm.nameMap_.emplace( std::piecewise_construct, std::forward_as_tuple(std::move(name)), std::forward_as_tuple( - index, std::move(methods), std::vector>())); + index, std::move(methods), std::vector>(), false)); VLOG(1) << "Registered stats " << counterName.toString(); - return index; + return it2.first->second.id_; } // static @@ -103,39 +112,147 @@ CounterId StatsManager::registerHisto(folly::StringPiece counterName, StatsManager::VT min, StatsManager::VT max, std::string stats) { - using std::chrono::seconds; std::vector methods; std::vector> percentiles; parseStats(stats, methods, percentiles); + return registerHisto(counterName, bucketSize, min, max, methods, percentiles); +} +// static +CounterId StatsManager::registerHisto(folly::StringPiece counterName, + StatsManager::VT bucketSize, + StatsManager::VT min, + StatsManager::VT max, + std::vector methods, + std::vector> percentiles) { + using std::chrono::seconds; auto& sm = get(); std::string name = counterName.toString(); folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); auto it = sm.nameMap_.find(name); if (it != sm.nameMap_.end()) { - DCHECK_LT(it->second.id_.index(), 0); + DCHECK(it->second.id_.isHisto()); VLOG(2) << "The counter \"" << name << "\" already exists"; it->second.methods_ = methods; it->second.percentiles_ = percentiles; - return it->second.id_.index(); + return it->second.id_; } // Insert the Histogram - sm.histograms_.emplace_back( + sm.histograms_.emplace( + counterName, std::make_pair(std::make_unique(), std::make_unique( bucketSize, min, max, StatsType(60, {seconds(5), seconds(60), seconds(600), seconds(3600)})))); - int32_t index = -sm.histograms_.size(); - sm.nameMap_.emplace(std::piecewise_construct, - std::forward_as_tuple(std::move(name)), - std::forward_as_tuple(index, std::move(methods), std::move(percentiles))); + std::string index(counterName); + auto it2 = sm.nameMap_.emplace( + std::piecewise_construct, + std::forward_as_tuple(std::move(name)), + std::forward_as_tuple( + index, std::move(methods), std::move(percentiles), true, bucketSize, min, max)); VLOG(1) << "Registered histogram " << counterName.toString() << " [bucketSize: " << bucketSize << ", min value: " << min << ", max value: " << max << "]"; - return index; + return it2.first->second.id_; +} + +// static +CounterId StatsManager::counterWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + auto it = sm.nameMap_.find(newIndex); + // Get the counter if it already exists + if (it != sm.nameMap_.end()) { + return it->second.id_; + } + + // Register a new counter if it doesn't exist + auto it2 = sm.nameMap_.find(index); + DCHECK(it2 != sm.nameMap_.end()); + auto& methods = it2->second.methods_; + + return registerStats(newIndex, methods); +} + +// static +CounterId StatsManager::histoWithLabels(const CounterId& id, const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + auto it = sm.nameMap_.find(newIndex); + // Get the counter if it already exists + if (it != sm.nameMap_.end()) { + return it->second.id_; + } + + auto it2 = sm.nameMap_.find(index); + DCHECK(it2 != sm.nameMap_.end()); + auto& methods = it2->second.methods_; + auto& percentiles = it2->second.percentiles_; + + return registerHisto( + newIndex, it2->second.bucketSize_, it2->second.min_, it2->second.max_, methods, percentiles); +} + +// static +void StatsManager::removeCounterWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); + auto it = sm.nameMap_.find(newIndex); + if (it != sm.nameMap_.end()) { + sm.nameMap_.erase(it); + } + sm.stats_.erase(newIndex); +} + +// static +void StatsManager::removeHistoWithLabels(const CounterId& id, + const std::vector& labels) { + using std::chrono::seconds; + + auto& sm = get(); + auto index = id.index(); + CHECK(!labels.empty()); + std::string newIndex; + for (auto& [k, v] : labels) { + newIndex.append(k).append("_").append(v).append("_"); + } + newIndex.append(index); + folly::RWSpinLock::WriteHolder wh(sm.nameMapLock_); + auto it = sm.nameMap_.find(newIndex); + if (it != sm.nameMap_.end()) { + sm.nameMap_.erase(it); + } + sm.histograms_.erase(newIndex); } // static @@ -143,21 +260,21 @@ void StatsManager::addValue(const CounterId& id, VT value) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); - if (index > 0) { + if (!id.valid()) { + LOG(FATAL) << "Invalid counter id"; + } + std::string index = id.index(); + bool isHisto = id.isHisto(); + if (!isHisto) { // Stats - --index; - DCHECK_LT(index, sm.stats_.size()); + DCHECK(sm.stats_.find(index) != sm.stats_.end()); std::lock_guard g(*(sm.stats_[index].first)); sm.stats_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value); - } else if (index < 0) { + } else { // Histogram - index = -(index + 1); - DCHECK_LT(index, sm.histograms_.size()); + DCHECK(sm.histograms_.find(index) != sm.histograms_.end()); std::lock_guard g(*(sm.histograms_[index].first)); sm.histograms_[index].second->addValue(seconds(time::WallClock::fastNowInSec()), value); - } else { - LOG(FATAL) << "Invalid counter id"; } } @@ -325,23 +442,21 @@ StatusOr StatsManager::readStats(const CounterId& id, StatsManager::StatsMethod method) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); + std::string index = id.index(); - if (index == 0) { + if (index == "") { return Status::Error("Invalid stats"); } - if (index > 0) { + if (!id.isHisto()) { // stats - --index; - DCHECK_LT(index, sm.stats_.size()); + DCHECK(sm.stats_.find(index) != sm.stats_.end()); std::lock_guard g(*(sm.stats_[index].first)); sm.stats_[index].second->update(seconds(time::WallClock::fastNowInSec())); return readValue(*(sm.stats_[index].second), range, method); } else { // histograms_ - index = -(index + 1); - DCHECK_LT(index, sm.histograms_.size()); + DCHECK(sm.histograms_.find(index) != sm.histograms_.end()); std::lock_guard g(*(sm.histograms_[index].first)); sm.histograms_[index].second->update(seconds(time::WallClock::fastNowInSec())); return readValue(*(sm.histograms_[index].second), range, method); @@ -376,13 +491,14 @@ StatusOr StatsManager::readHisto(const CounterId& id, double pct) { using std::chrono::seconds; auto& sm = get(); - int32_t index = id.index(); + std::string index = id.index(); - if (index >= 0) { + if (!id.isHisto()) { return Status::Error("Invalid stats"); } - index = -(index + 1); - if (static_cast(index) >= sm.histograms_.size()) { + + auto it = sm.histograms_.find(index); + if (it == sm.histograms_.end()) { return Status::Error("Invalid stats"); } diff --git a/src/common/stats/StatsManager.h b/src/common/stats/StatsManager.h index cc2dfe75f75..52dac86a60c 100644 --- a/src/common/stats/StatsManager.h +++ b/src/common/stats/StatsManager.h @@ -21,8 +21,9 @@ namespace stats { // A wrapper class of counter index. Each instance can only be writtern once. class CounterId final { public: - CounterId() : index_{0} {} - CounterId(int32_t index) : index_{index} {} // NOLINT + CounterId() = default; + CounterId(const std::string& index, bool isHisto = false) // NOLINT + : index_{index}, isHisto_(isHisto) {} CounterId(const CounterId&) = default; CounterId& operator=(const CounterId& right) { @@ -34,11 +35,12 @@ class CounterId final { LOG(FATAL) << "CounterId cannot be assigned twice"; } index_ = right.index_; + isHisto_ = right.isHisto_; return *this; } - CounterId& operator=(int32_t right) { - if (right == 0) { + CounterId& operator=(const std::string& right) { + if (right == "") { LOG(FATAL) << "Invalid counter id"; } if (valid()) { @@ -49,12 +51,15 @@ class CounterId final { return *this; } - bool valid() const { return index_ != 0; } + bool valid() const { return index_ != ""; } - int32_t index() const { return index_; } + bool isHisto() const { return isHisto_; } + + std::string index() const { return index_; } private: - int32_t index_; + std::string index_; + bool isHisto_{false}; }; /** @@ -84,6 +89,7 @@ class StatsManager final { using VT = int64_t; using StatsType = folly::MultiLevelTimeSeries; using HistogramType = folly::TimeseriesHistogram; + using LabelPair = std::pair; public: enum class StatsMethod { SUM = 1, COUNT, AVG, RATE }; @@ -110,8 +116,21 @@ class StatsManager final { // those specified in the parameter **stats**. If **stats** is empty, nothing // will return from readAllValue() static CounterId registerStats(folly::StringPiece counterName, std::string stats); + static CounterId registerStats(folly::StringPiece counterName, std::vector methods); static CounterId registerHisto( folly::StringPiece counterName, VT bucketSize, VT min, VT max, std::string stats); + static CounterId registerHisto(folly::StringPiece counterName, + VT bucketSize, + VT min, + VT max, + std::vector methods, + std::vector> percentiles); + + static CounterId counterWithLabels(const CounterId& id, const std::vector& labels); + static CounterId histoWithLabels(const CounterId& id, const std::vector& labels); + + static void removeCounterWithLabels(const CounterId& id, const std::vector& labels); + static void removeHistoWithLabels(const CounterId& id, const std::vector& labels); static void addValue(const CounterId& id, VT value = 1); static void decValue(const CounterId& id, VT value = 1); @@ -153,11 +172,21 @@ class StatsManager final { CounterId id_; std::vector methods_; std::vector> percentiles_; + VT bucketSize_, min_, max_; - CounterInfo(int32_t index, + CounterInfo(const std::string& index, std::vector&& methods, - std::vector>&& percentiles) - : id_(index), methods_(std::move(methods)), percentiles_(std::move(percentiles)) {} + std::vector>&& percentiles, + bool isHisto = false, + VT bucketSize = VT(), + VT min = VT(), + VT max = VT()) + : id_(index, isHisto), + methods_(std::move(methods)), + percentiles_(std::move(percentiles)), + bucketSize_(bucketSize), + min_(min), + max_(max) {} }; std::string domain_; @@ -171,10 +200,14 @@ class StatsManager final { std::unordered_map nameMap_; // All time series stats - std::vector, std::unique_ptr>> stats_; + std::unordered_map, std::unique_ptr>> + stats_; // All histogram stats - std::vector, std::unique_ptr>> histograms_; + std::unordered_map, std::unique_ptr>> + histograms_; }; } // namespace stats diff --git a/src/graph/executor/admin/SpaceExecutor.cpp b/src/graph/executor/admin/SpaceExecutor.cpp index f2a452482fc..cb18bdfd6c7 100644 --- a/src/graph/executor/admin/SpaceExecutor.cpp +++ b/src/graph/executor/admin/SpaceExecutor.cpp @@ -5,10 +5,12 @@ #include "graph/executor/admin/SpaceExecutor.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/context/QueryContext.h" #include "graph/planner/plan/Admin.h" #include "graph/service/PermissionManager.h" +#include "graph/stats/StatsDef.h" #include "graph/util/FTIndexUtils.h" #include "graph/util/SchemaUtil.h" @@ -140,6 +142,7 @@ folly::Future DropSpaceExecutor::execute() { LOG(ERROR) << "Drop space `" << dsNode->getSpaceName() << "' failed: " << resp.status(); return resp.status(); } + unRegisterSpaceLevelMetrics(dsNode->getSpaceName()); if (dsNode->getSpaceName() == qctx()->rctx()->session()->space().name) { SpaceInfo spaceInfo; spaceInfo.name = ""; @@ -163,6 +166,16 @@ folly::Future DropSpaceExecutor::execute() { }); } +void DropSpaceExecutor::unRegisterSpaceLevelMetrics(const std::string &spaceName) { + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::removeCounterWithLabels(kNumQueries, {{"space", spaceName}}); + stats::StatsManager::removeCounterWithLabels(kNumSlowQueries, {{"space", spaceName}}); + stats::StatsManager::removeCounterWithLabels(kNumQueryErrors, {{"space", spaceName}}); + stats::StatsManager::removeHistoWithLabels(kQueryLatencyUs, {{"space", spaceName}}); + stats::StatsManager::removeHistoWithLabels(kSlowQueryLatencyUs, {{"space", spaceName}}); + } +} + folly::Future ShowSpacesExecutor::execute() { SCOPED_TIMER(&execTime_); diff --git a/src/graph/executor/admin/SpaceExecutor.h b/src/graph/executor/admin/SpaceExecutor.h index e0c917d93f0..f61e5e3e95a 100644 --- a/src/graph/executor/admin/SpaceExecutor.h +++ b/src/graph/executor/admin/SpaceExecutor.h @@ -40,6 +40,8 @@ class DropSpaceExecutor final : public Executor { DropSpaceExecutor(const PlanNode *node, QueryContext *qctx) : Executor("DropSpaceExecutor", node, qctx) {} + void unRegisterSpaceLevelMetrics(const std::string &spaceName); + folly::Future execute() override; }; diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index 2dc394bfeb0..137117153ff 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -12,6 +12,7 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ + $ $ $ $ diff --git a/src/graph/planner/test/CMakeLists.txt b/src/graph/planner/test/CMakeLists.txt index bb45ebd9201..02aa6b5edb0 100644 --- a/src/graph/planner/test/CMakeLists.txt +++ b/src/graph/planner/test/CMakeLists.txt @@ -18,6 +18,7 @@ nebula_add_test( $ $ $ + $ $ $ $ diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 7fcdf14bddf..65789d0deba 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -195,6 +195,9 @@ folly::Future GraphService::future_execute(int64_t sessionId, new std::string(folly::stringPrintf("SessionId[%ld] does not exist", sessionId))); return ctx->finish(); } + stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumQueries, {{"space", sessionPtr->space().name}})); ctx->setSession(std::move(sessionPtr)); queryEngine_->execute(std::move(ctx)); stats::StatsManager::decValue(kNumActiveQueries); diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index 358d357033a..be2d6b709aa 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -101,7 +101,7 @@ void QueryInstance::onFinish() { auto latency = rctx->duration().elapsedInUSec(); rctx->resp().latencyInUs = latency; - addSlowQueryStats(latency); + addSlowQueryStats(latency, spaceName); rctx->finish(); rctx->session()->deleteQuery(qctx_.get()); @@ -161,17 +161,30 @@ void QueryInstance::onError(Status status) { auto latency = rctx->duration().elapsedInUSec(); rctx->resp().latencyInUs = latency; stats::StatsManager::addValue(kNumQueryErrors); - addSlowQueryStats(latency); + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumQueryErrors, {{"space", spaceName}})); + addSlowQueryStats(latency, spaceName); rctx->session()->deleteQuery(qctx_.get()); rctx->finish(); delete this; } -void QueryInstance::addSlowQueryStats(uint64_t latency) const { +void QueryInstance::addSlowQueryStats(uint64_t latency, const std::string &spaceName) const { stats::StatsManager::addValue(kQueryLatencyUs, latency); + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::addValue( + stats::StatsManager::histoWithLabels(kQueryLatencyUs, {{"space", spaceName}}), latency); + } if (latency > static_cast(FLAGS_slow_query_threshold_us)) { stats::StatsManager::addValue(kNumSlowQueries); stats::StatsManager::addValue(kSlowQueryLatencyUs, latency); + if (FLAGS_enable_space_level_metrics) { + stats::StatsManager::addValue( + stats::StatsManager::counterWithLabels(kNumSlowQueries, {{"space", spaceName}})); + stats::StatsManager::addValue( + stats::StatsManager::histoWithLabels(kSlowQueryLatencyUs, {{"space", spaceName}}), + latency); + } } } diff --git a/src/graph/service/QueryInstance.h b/src/graph/service/QueryInstance.h index c8c51bb46cf..d9d9c144146 100644 --- a/src/graph/service/QueryInstance.h +++ b/src/graph/service/QueryInstance.h @@ -49,7 +49,7 @@ class QueryInstance final : public cpp::NonCopyable, public cpp::NonMovable { Status validateAndOptimize(); // return true if continue to execute bool explainOrContinue(); - void addSlowQueryStats(uint64_t latency) const; + void addSlowQueryStats(uint64_t latency, const std::string& spaceName) const; void fillRespData(ExecutionResponse* resp); Status findBestPlan(); diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index 3143194bdc2..7fa32041934 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -12,6 +12,7 @@ DEFINE_int32(slow_query_threshold_us, 200000, "Any query slower than this threshold value will be considered" " as a slow query"); +DEFINE_bool(enable_space_level_metrics, false, "Whether to enable space level metrircs"); namespace nebula { diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h index 32848ae24ef..58ea244156d 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/StatsDef.h @@ -10,6 +10,7 @@ #include "common/stats/StatsManager.h" DECLARE_int32(slow_query_threshold_us); +DECLARE_bool(enable_space_level_metrics); namespace nebula { From df15a18e092ba5bac0294ddb463f7e338f68d49a Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Mon, 13 Dec 2021 16:07:43 +0800 Subject: [PATCH 03/10] add more metrics --- src/common/expression/test/CMakeLists.txt | 1 + src/graph/executor/Executor.cpp | 6 +++++ src/graph/executor/test/CMakeLists.txt | 1 + src/graph/service/GraphService.cpp | 3 +++ src/graph/service/QueryInstance.cpp | 2 ++ src/graph/session/ClientSession.cpp | 4 +++ src/graph/session/GraphSessionManager.cpp | 4 +++ src/graph/stats/StatsDef.cpp | 32 +++++++++++++++++++++++ src/graph/stats/StatsDef.h | 19 ++++++++++++-- 9 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index 4457d468103..700a4da5f30 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(expression_test_common_libs $ $ $ + $ $ $ $ diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index d52e9bd60ca..f33b14bd24c 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -12,6 +12,7 @@ #include "common/base/ObjectPool.h" #include "common/memory/MemoryUtils.h" +#include "common/stats/StatsManager.h" #include "common/time/ScopedTimer.h" #include "graph/context/ExecutionContext.h" #include "graph/context/QueryContext.h" @@ -98,6 +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 "interface/gen-cpp2/graph_types.h" using folly::stringPrintf; @@ -157,9 +159,11 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { return pool->add(new PassThroughExecutor(node, qctx)); } case PlanNode::Kind::kAggregate: { + stats::StatsManager::addValue(kNumAggregateExecutors); return pool->add(new AggregateExecutor(node, qctx)); } case PlanNode::Kind::kSort: { + stats::StatsManager::addValue(kNumSortExecutors); return pool->add(new SortExecutor(node, qctx)); } case PlanNode::Kind::kTopN: { @@ -202,6 +206,7 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { case PlanNode::Kind::kTagIndexFullScan: case PlanNode::Kind::kTagIndexPrefixScan: case PlanNode::Kind::kTagIndexRangeScan: { + stats::StatsManager::addValue(kNumIndexScanExecutors); return pool->add(new IndexScanExecutor(node, qctx)); } case PlanNode::Kind::kStart: { @@ -573,6 +578,7 @@ Status Executor::close() { Status Executor::checkMemoryWatermark() { if (node_->isQueryNode() && MemoryUtils::kHitMemoryHighWatermark.load()) { + stats::StatsManager::addValue(kNumOomExecutors); return Status::Error("Used memory hits the high watermark(%lf) of total system memory.", FLAGS_system_memory_high_watermark_ratio); } diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index 137117153ff..081c935649b 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -54,6 +54,7 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ + $ ) SET(EXEC_QUERY_TEST_LIBS diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 65789d0deba..6a360e6704d 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -102,6 +102,7 @@ folly::Future GraphService::future_authenticate(const std::string& return ctx->finish(); } stats::StatsManager::addValue(kNumOpenedSessions); + stats::StatsManager::addValue(kNumActiveSessions); ctx->setSession(sessionPtr); ctx->resp().sessionId.reset(new int64_t(ctx->session()->id())); ctx->resp().timeZoneOffsetSeconds.reset( @@ -118,6 +119,7 @@ folly::Future GraphService::future_authenticate(const std::string& void GraphService::signout(int64_t sessionId) { VLOG(2) << "Sign out session " << sessionId; sessionManager_->removeSession(sessionId); + stats::StatsManager::decValue(kNumActiveSessions); } folly::Future GraphService::future_executeWithParameter( @@ -171,6 +173,7 @@ folly::Future GraphService::future_execute(int64_t sessionId, ctx->setSessionMgr(sessionManager_.get()); auto future = ctx->future(); stats::StatsManager::addValue(kNumQueries); + stats::StatsManager::addValue(kNumActiveQueries); // When the sessionId is 0, it means the clients to ping the connection is ok if (sessionId == 0) { ctx->resp().errorCode = ErrorCode::E_SESSION_INVALID; diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index be2d6b709aa..f89d10d3f30 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -77,6 +77,7 @@ Status QueryInstance::validateAndOptimize() { NG_RETURN_IF_ERROR(Validator::validate(sentence_.get(), qctx())); NG_RETURN_IF_ERROR(findBestPlan()); + stats::StatsManager::addValue(kOptimizerLatencyUs, *(qctx_->plan()->optimizeTimeInUs())); return Status::OK(); } @@ -103,6 +104,7 @@ void QueryInstance::onFinish() { rctx->resp().latencyInUs = latency; addSlowQueryStats(latency, spaceName); rctx->finish(); + stats::StatsManager::addValue(kSentBytes, rctx->resp().data->size()); rctx->session()->deleteQuery(qctx_.get()); // The `QueryInstance' is the root node holding all resources during the diff --git a/src/graph/session/ClientSession.cpp b/src/graph/session/ClientSession.cpp index c27e60166f3..0a3b44c690a 100644 --- a/src/graph/session/ClientSession.cpp +++ b/src/graph/session/ClientSession.cpp @@ -5,8 +5,10 @@ #include "graph/session/ClientSession.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "graph/context/QueryContext.h" +#include "graph/stats/StatsDef.h" namespace nebula { namespace graph { @@ -75,6 +77,7 @@ void ClientSession::markQueryKilled(nebula::ExecutionPlanID epId) { return; } context->second->markKilled(); + // stats::StatsManager::addValue(kNumKilledQueries); VLOG(1) << "Mark query killed in local cache, epId: " << epId; auto query = session_.queries_ref()->find(epId); @@ -91,6 +94,7 @@ void ClientSession::markAllQueryKilled() { context.second->markKilled(); session_.queries_ref()->clear(); } + // stats::StatsManager::addValue(kNumKilledQueries, contexts_.size()); } } // namespace graph } // namespace nebula diff --git a/src/graph/session/GraphSessionManager.cpp b/src/graph/session/GraphSessionManager.cpp index c11003d9eb1..894545cad61 100644 --- a/src/graph/session/GraphSessionManager.cpp +++ b/src/graph/session/GraphSessionManager.cpp @@ -6,8 +6,10 @@ #include "graph/session/GraphSessionManager.h" #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "graph/service/GraphFlags.h" +#include "graph/stats/StatsDef.h" namespace nebula { namespace graph { @@ -181,6 +183,8 @@ void GraphSessionManager::reclaimExpiredSessions() { LOG(ERROR) << "Remove session `" << iter->first << "' failed: " << resp.status(); } iter = activeSessions_.erase(iter); + // stats::StatsManager::decValue(kNumActiveSessions); + // stats::StatsManager::addValue(kNumReclaimedExpiredSessions); // TODO: Disconnect the connection of the session } } diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index 7fa32041934..f2db000e495 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -24,11 +24,24 @@ stats::CounterId kNumQueryErrosLeaderChanges; stats::CounterId kNumSentences; stats::CounterId kQueryLatencyUs; stats::CounterId kSlowQueryLatencyUs; +stats::CounterId kNumKilledQueries; + +stats::CounterId kOptimizerLatencyUs; + +stats::CounterId kNumAggregateExecutors; +stats::CounterId kNumSortExecutors; +stats::CounterId kNumIndexScanExecutors; +stats::CounterId kNumOomExecutors; + +stats::CounterId kReceivedBytes; +stats::CounterId kSentBytes; stats::CounterId kNumOpenedSessions; stats::CounterId kNumAuthFailedSessions; stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; +stats::CounterId kNumActiveSessions; +stats::CounterId kNumReclaimedExpiredSessions; void initCounters() { kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum"); @@ -42,6 +55,22 @@ void initCounters() { "query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); kSlowQueryLatencyUs = stats::StatsManager::registerHisto( "slow_query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kNumKilledQueries = stats::StatsManager::registerStats("num_killed_queries", "rate, sum"); + + kOptimizerLatencyUs = stats::StatsManager::registerHisto( + "optimizer_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + + kReceivedBytes = stats::StatsManager::registerHisto( + "received_bytes", 1000, 1, 4194304, "avg, p75, p95, p99, p999"); // 1 Byte ~ 4194304 Bytes + kSentBytes = stats::StatsManager::registerHisto( + "sent_bytes", 1000, 1, 4294967296, "avg, p75, p95, p99, p999"); // 1 Byte ~ 4 GiB + + kNumAggregateExecutors = + stats::StatsManager::registerStats("num_aggregate_executors", "rate, sum"); + kNumSortExecutors = stats::StatsManager::registerStats("num_sort_executors", "rate, sum"); + kNumIndexScanExecutors = + stats::StatsManager::registerStats("num_indexscan_executors", "rate, sum"); + kNumOomExecutors = stats::StatsManager::registerStats("num_oom_executors", "rate, sum"); kNumOpenedSessions = stats::StatsManager::registerStats("num_opened_sessions", "rate, sum"); kNumAuthFailedSessions = @@ -50,6 +79,9 @@ void initCounters() { "num_auth_failed_sessions_bad_username_password", "rate, sum"); kNumAuthFailedSessionsOutOfMaxAllowed = stats::StatsManager::registerStats( "num_auth_failed_sessions_out_of_max_allowed", "rate, sum"); + kNumActiveSessions = stats::StatsManager::registerStats("num_active_sessions", "rate, sum"); + kNumReclaimedExpiredSessions = + stats::StatsManager::registerStats("num_reclaimed_expired_sessions", "rate, sum"); } } // namespace nebula diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h index 58ea244156d..cfbca29677b 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/StatsDef.h @@ -14,7 +14,7 @@ DECLARE_bool(enable_space_level_metrics); namespace nebula { -// query related +// Query extern stats::CounterId kNumQueries; extern stats::CounterId kNumActiveQueries; extern stats::CounterId kNumSlowQueries; @@ -23,12 +23,27 @@ extern stats::CounterId kNumQueryErrosLeaderChanges; extern stats::CounterId kNumSentences; extern stats::CounterId kQueryLatencyUs; extern stats::CounterId kSlowQueryLatencyUs; +extern stats::CounterId kNumKilledQueries; -// session related +extern stats::CounterId kOptimizerLatencyUs; + +// Executor +extern stats::CounterId kNumAggregateExecutors; +extern stats::CounterId kNumSortExecutors; +extern stats::CounterId kNumIndexScanExecutors; +extern stats::CounterId kNumOomExecutors; + +// Server client traffic +extern stats::CounterId kReceivedBytes; +extern stats::CounterId kSentBytes; + +// Session extern stats::CounterId kNumOpenedSessions; extern stats::CounterId kNumAuthFailedSessions; extern stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; extern stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; +extern stats::CounterId kNumActiveSessions; +extern stats::CounterId kNumReclaimedExpiredSessions; void initCounters(); From 7df18588039ef50f707ae8210eef8d55bceb1341 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Mon, 13 Dec 2021 17:48:47 +0800 Subject: [PATCH 04/10] compile pass --- src/common/expression/test/CMakeLists.txt | 2 +- src/graph/context/test/CMakeLists.txt | 2 ++ src/graph/optimizer/test/CMakeLists.txt | 2 ++ src/graph/session/ClientSession.cpp | 4 ++-- src/graph/session/GraphSessionManager.cpp | 4 ++-- src/graph/stats/StatsDef.cpp | 4 ++-- src/graph/util/test/CMakeLists.txt | 2 ++ src/graph/validator/test/CMakeLists.txt | 1 + src/graph/visitor/test/CMakeLists.txt | 1 + src/meta/processors/job/JobManager.cpp | 2 ++ src/meta/processors/job/JobManager.h | 2 ++ src/parser/test/CMakeLists.txt | 1 + 12 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index 700a4da5f30..09c9e139b58 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -9,7 +9,7 @@ set(expression_test_common_libs $ $ $ - $ + $ $ $ $ diff --git a/src/graph/context/test/CMakeLists.txt b/src/graph/context/test/CMakeLists.txt index 4fd9cdcef5c..6b8286bfec0 100644 --- a/src/graph/context/test/CMakeLists.txt +++ b/src/graph/context/test/CMakeLists.txt @@ -42,6 +42,8 @@ SET(CONTEXT_TEST_LIBS $ $ $ + $ + $ ) nebula_add_test( diff --git a/src/graph/optimizer/test/CMakeLists.txt b/src/graph/optimizer/test/CMakeLists.txt index 0f3c0fc72ad..e29af4031e2 100644 --- a/src/graph/optimizer/test/CMakeLists.txt +++ b/src/graph/optimizer/test/CMakeLists.txt @@ -48,6 +48,8 @@ set(OPTIMIZER_TEST_LIB $ $ $ + $ + $ ) nebula_add_test( diff --git a/src/graph/session/ClientSession.cpp b/src/graph/session/ClientSession.cpp index 0a3b44c690a..74fa1f6cfbc 100644 --- a/src/graph/session/ClientSession.cpp +++ b/src/graph/session/ClientSession.cpp @@ -77,7 +77,7 @@ void ClientSession::markQueryKilled(nebula::ExecutionPlanID epId) { return; } context->second->markKilled(); - // stats::StatsManager::addValue(kNumKilledQueries); + stats::StatsManager::addValue(kNumKilledQueries); VLOG(1) << "Mark query killed in local cache, epId: " << epId; auto query = session_.queries_ref()->find(epId); @@ -94,7 +94,7 @@ void ClientSession::markAllQueryKilled() { context.second->markKilled(); session_.queries_ref()->clear(); } - // stats::StatsManager::addValue(kNumKilledQueries, contexts_.size()); + stats::StatsManager::addValue(kNumKilledQueries, contexts_.size()); } } // namespace graph } // namespace nebula diff --git a/src/graph/session/GraphSessionManager.cpp b/src/graph/session/GraphSessionManager.cpp index 894545cad61..3d256bac75d 100644 --- a/src/graph/session/GraphSessionManager.cpp +++ b/src/graph/session/GraphSessionManager.cpp @@ -183,8 +183,8 @@ void GraphSessionManager::reclaimExpiredSessions() { LOG(ERROR) << "Remove session `" << iter->first << "' failed: " << resp.status(); } iter = activeSessions_.erase(iter); - // stats::StatsManager::decValue(kNumActiveSessions); - // stats::StatsManager::addValue(kNumReclaimedExpiredSessions); + stats::StatsManager::decValue(kNumActiveSessions); + stats::StatsManager::addValue(kNumReclaimedExpiredSessions); // TODO: Disconnect the connection of the session } } diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index f2db000e495..6a1a84fc535 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -45,7 +45,7 @@ stats::CounterId kNumReclaimedExpiredSessions; void initCounters() { kNumQueries = stats::StatsManager::registerStats("num_queries", "rate, sum"); - kNumActiveQueries = stats::StatsManager::registerStats("num_active_queries", "rate, sum"); + kNumActiveQueries = stats::StatsManager::registerStats("num_active_queries", "sum"); kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum"); kNumSentences = stats::StatsManager::registerStats("num_sentences", "rate, sum"); kNumQueryErrors = stats::StatsManager::registerStats("num_query_errors", "rate, sum"); @@ -79,7 +79,7 @@ void initCounters() { "num_auth_failed_sessions_bad_username_password", "rate, sum"); kNumAuthFailedSessionsOutOfMaxAllowed = stats::StatsManager::registerStats( "num_auth_failed_sessions_out_of_max_allowed", "rate, sum"); - kNumActiveSessions = stats::StatsManager::registerStats("num_active_sessions", "rate, sum"); + kNumActiveSessions = stats::StatsManager::registerStats("num_active_sessions", "sum"); kNumReclaimedExpiredSessions = stats::StatsManager::registerStats("num_reclaimed_expired_sessions", "rate, sum"); } diff --git a/src/graph/util/test/CMakeLists.txt b/src/graph/util/test/CMakeLists.txt index 4e0b0235e0e..7d3031a5b19 100644 --- a/src/graph/util/test/CMakeLists.txt +++ b/src/graph/util/test/CMakeLists.txt @@ -45,6 +45,8 @@ nebula_add_test( $ $ $ + $ + $ LIBRARIES gtest gtest_main diff --git a/src/graph/validator/test/CMakeLists.txt b/src/graph/validator/test/CMakeLists.txt index 0363a74afc5..ab6a41e7fbb 100644 --- a/src/graph/validator/test/CMakeLists.txt +++ b/src/graph/validator/test/CMakeLists.txt @@ -26,6 +26,7 @@ set(VALIDATOR_TEST_LIBS $ $ $ + $ $ $ $ diff --git a/src/graph/visitor/test/CMakeLists.txt b/src/graph/visitor/test/CMakeLists.txt index bbf2e21b564..d84f3d7144a 100644 --- a/src/graph/visitor/test/CMakeLists.txt +++ b/src/graph/visitor/test/CMakeLists.txt @@ -31,6 +31,7 @@ nebula_add_test( $ $ $ + $ $ $ $ diff --git a/src/meta/processors/job/JobManager.cpp b/src/meta/processors/job/JobManager.cpp index ca2c116e719..38f2bff019a 100644 --- a/src/meta/processors/job/JobManager.cpp +++ b/src/meta/processors/job/JobManager.cpp @@ -12,6 +12,7 @@ #include #include "common/http/HttpClient.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/MetaKeyUtils.h" #include "interface/gen-cpp2/common_types.h" @@ -33,6 +34,7 @@ using nebula::kvstore::KVIterator; namespace nebula { namespace meta { +stats::CounterId kNumRunningJobs = stats::StatsManager::registerStats("num_running_jobs", "sum"); JobManager* JobManager::getInstance() { static JobManager inst; diff --git a/src/meta/processors/job/JobManager.h b/src/meta/processors/job/JobManager.h index 8d9a2e8d188..59eac5d2dff 100644 --- a/src/meta/processors/job/JobManager.h +++ b/src/meta/processors/job/JobManager.h @@ -14,6 +14,7 @@ #include "common/base/Base.h" #include "common/base/ErrorOr.h" +#include "common/stats/StatsManager.h" #include "interface/gen-cpp2/meta_types.h" #include "kvstore/NebulaStore.h" #include "meta/processors/job/JobDescription.h" @@ -23,6 +24,7 @@ namespace nebula { namespace meta { +extern stats::CounterId kNumRunningJobs; class JobManager : public nebula::cpp::NonCopyable, public nebula::cpp::NonMovable { friend class JobManagerTest; diff --git a/src/parser/test/CMakeLists.txt b/src/parser/test/CMakeLists.txt index 8a08473f042..c6fc74dfbf6 100644 --- a/src/parser/test/CMakeLists.txt +++ b/src/parser/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(PARSER_TEST_LIBS $ $ $ + $ $ $ $ From c80710dd2813e8b2522214f0b3fb59511a0716b2 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Wed, 15 Dec 2021 11:07:40 +0800 Subject: [PATCH 05/10] add some data related counters --- src/graph/service/QueryInstance.cpp | 3 ++- src/graph/stats/StatsDef.cpp | 4 ++-- src/graph/stats/StatsDef.h | 2 +- src/meta/MetaServiceHandler.h | 4 ++++ src/meta/processors/job/AdminJobProcessor.cpp | 4 ++++ src/meta/processors/job/AdminJobProcessor.h | 2 ++ src/meta/processors/job/JobManager.cpp | 2 +- src/storage/GraphStorageServiceHandler.cpp | 6 ++++++ src/storage/mutate/AddEdgesProcessor.cpp | 4 ++++ src/storage/mutate/AddEdgesProcessor.h | 2 ++ src/storage/mutate/AddVerticesProcessor.cpp | 4 ++++ src/storage/mutate/AddVerticesProcessor.h | 1 + src/storage/mutate/DeleteEdgesProcessor.cpp | 4 ++++ src/storage/mutate/DeleteEdgesProcessor.h | 1 + src/storage/mutate/DeleteTagsProcessor.cpp | 4 ++++ src/storage/mutate/DeleteTagsProcessor.h | 1 + src/storage/mutate/DeleteVerticesProcessor.cpp | 3 +++ src/storage/mutate/DeleteVerticesProcessor.h | 1 + 18 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index f89d10d3f30..3a24e6e4cdc 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -135,7 +135,8 @@ void QueryInstance::onError(Status status) { rctx->resp().errorCode = ErrorCode::E_BAD_PERMISSION; break; case Status::Code::kLeaderChanged: - stats::StatsManager::addValue(kNumQueryErrosLeaderChanges); + stats::StatsManager::addValue(kNumQueryErrorsLeaderChanges); + [[fallthrough]]; case Status::Code::kBalanced: case Status::Code::kEdgeNotFound: case Status::Code::kError: diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index 6a1a84fc535..9dd3769df86 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -20,7 +20,7 @@ stats::CounterId kNumQueries; stats::CounterId kNumActiveQueries; stats::CounterId kNumSlowQueries; stats::CounterId kNumQueryErrors; -stats::CounterId kNumQueryErrosLeaderChanges; +stats::CounterId kNumQueryErrorsLeaderChanges; stats::CounterId kNumSentences; stats::CounterId kQueryLatencyUs; stats::CounterId kSlowQueryLatencyUs; @@ -49,7 +49,7 @@ void initCounters() { kNumSlowQueries = stats::StatsManager::registerStats("num_slow_queries", "rate, sum"); kNumSentences = stats::StatsManager::registerStats("num_sentences", "rate, sum"); kNumQueryErrors = stats::StatsManager::registerStats("num_query_errors", "rate, sum"); - kNumQueryErrosLeaderChanges = + kNumQueryErrorsLeaderChanges = stats::StatsManager::registerStats("num_query_errors_leader_changes", "rate, sum"); kQueryLatencyUs = stats::StatsManager::registerHisto( "query_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h index cfbca29677b..47a48dfa3e3 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/StatsDef.h @@ -19,7 +19,7 @@ extern stats::CounterId kNumQueries; extern stats::CounterId kNumActiveQueries; extern stats::CounterId kNumSlowQueries; extern stats::CounterId kNumQueryErrors; -extern stats::CounterId kNumQueryErrosLeaderChanges; +extern stats::CounterId kNumQueryErrorsLeaderChanges; extern stats::CounterId kNumSentences; extern stats::CounterId kQueryLatencyUs; extern stats::CounterId kSlowQueryLatencyUs; diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index a1d7332fbf8..9be896c2ac7 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -11,6 +11,8 @@ #include "kvstore/KVStore.h" #include "meta/processors/admin/AdminClient.h" #include "meta/processors/admin/HBProcessor.h" +#include "meta/processors/job/AdminJobProcessor.h" +#include "meta/processors/job/JobManager.h" namespace nebula { namespace meta { @@ -23,6 +25,8 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { // Initialize counters kHBCounters.init(); + kNumActiveJobs = stats::StatsManager::registerStats("num_active_jobs", "sum"); + kNumRunningJobs = stats::StatsManager::registerStats("num_running_jobs", "sum"); } /** diff --git a/src/meta/processors/job/AdminJobProcessor.cpp b/src/meta/processors/job/AdminJobProcessor.cpp index 950a34d18dc..dfbdf9af4f0 100644 --- a/src/meta/processors/job/AdminJobProcessor.cpp +++ b/src/meta/processors/job/AdminJobProcessor.cpp @@ -6,11 +6,13 @@ #include "meta/processors/job/AdminJobProcessor.h" #include "common/base/StatusOr.h" +#include "common/stats/StatsManager.h" #include "meta/processors/job/JobDescription.h" #include "meta/processors/job/JobManager.h" namespace nebula { namespace meta { +stats::CounterId kNumActiveJobs; void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { cpp2::AdminJobResult result; @@ -59,6 +61,7 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { errorCode = jobMgr->addJob(jobDesc, adminClient_); if (errorCode == nebula::cpp2::ErrorCode::SUCCEEDED) { result.set_job_id(nebula::value(jobId)); + stats::StatsManager::addValue(kNumActiveJobs); } break; } @@ -121,6 +124,7 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { auto ret = jobMgr->recoverJob(spaceName, adminClient_, jobIds); if (nebula::ok(ret)) { result.set_recovered_job_num(nebula::value(ret)); + stats::StatsManager::addValue(kNumActiveJobs); } else { errorCode = nebula::error(ret); } diff --git a/src/meta/processors/job/AdminJobProcessor.h b/src/meta/processors/job/AdminJobProcessor.h index 589e81a7fa4..3a920f01358 100644 --- a/src/meta/processors/job/AdminJobProcessor.h +++ b/src/meta/processors/job/AdminJobProcessor.h @@ -6,11 +6,13 @@ #ifndef META_ADMINJOBPROCESSOR_H_ #define META_ADMINJOBPROCESSOR_H_ +#include "common/stats/StatsManager.h" #include "meta/processors/BaseProcessor.h" #include "meta/processors/admin/AdminClient.h" namespace nebula { namespace meta { +extern stats::CounterId kNumActiveJobs; class AdminJobProcessor : public BaseProcessor { public: diff --git a/src/meta/processors/job/JobManager.cpp b/src/meta/processors/job/JobManager.cpp index 38f2bff019a..5a6ad9296ca 100644 --- a/src/meta/processors/job/JobManager.cpp +++ b/src/meta/processors/job/JobManager.cpp @@ -34,7 +34,7 @@ using nebula::kvstore::KVIterator; namespace nebula { namespace meta { -stats::CounterId kNumRunningJobs = stats::StatsManager::registerStats("num_running_jobs", "sum"); +stats::CounterId kNumRunningJobs; JobManager* JobManager::getInstance() { static JobManager inst; diff --git a/src/storage/GraphStorageServiceHandler.cpp b/src/storage/GraphStorageServiceHandler.cpp index 7f7f027af5e..8fa037a65eb 100644 --- a/src/storage/GraphStorageServiceHandler.cpp +++ b/src/storage/GraphStorageServiceHandler.cpp @@ -63,6 +63,12 @@ GraphStorageServiceHandler::GraphStorageServiceHandler(StorageEnv* env) : env_(e kPutCounters.init("kv_put"); kGetCounters.init("kv_get"); kRemoveCounters.init("kv_remove"); + + kNumVerticesInserted = stats::StatsManager::registerStats("num_vertices_inserted", "rate, sum"); + kNumEdgesInserted = stats::StatsManager::registerStats("num_edges_inserted", "rate, sum"); + kNumEdgesDeleted = stats::StatsManager::registerStats("num_edges_deleted", "rate, sum"); + kNumTagsDeleted = stats::StatsManager::registerStats("num_tags_deleted", "rate, sum"); + kNumVerticesDeleted = stats::StatsManager::registerStats("num_vertices_deleted", "rate, sum"); } // Vertice section diff --git a/src/storage/mutate/AddEdgesProcessor.cpp b/src/storage/mutate/AddEdgesProcessor.cpp index ad28cdc76bb..640e3fb0516 100644 --- a/src/storage/mutate/AddEdgesProcessor.cpp +++ b/src/storage/mutate/AddEdgesProcessor.cpp @@ -8,6 +8,7 @@ #include #include "codec/RowWriterV2.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" @@ -17,6 +18,7 @@ namespace nebula { namespace storage { ProcessorCounters kAddEdgesCounters; +stats::CounterId kNumEdgesInserted; void AddEdgesProcessor::process(const cpp2::AddEdgesRequest& req) { spaceId_ = req.get_space_id(); @@ -141,6 +143,7 @@ void AddEdgesProcessor::doProcess(const cpp2::AddEdgesRequest& req) { }); } else { doPut(spaceId_, partId, std::move(data)); + stats::StatsManager::addValue(kNumEdgesInserted, data.size()); } } } @@ -302,6 +305,7 @@ void AddEdgesProcessor::doProcessWithIndex(const cpp2::AddEdgesRequest& req) { break; } batchHolder->put(std::move(key), std::move(retEnc.value())); + stats::StatsManager::addValue(kNumEdgesInserted); } if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { env_->edgesML_->unlockBatch(dummyLock); diff --git a/src/storage/mutate/AddEdgesProcessor.h b/src/storage/mutate/AddEdgesProcessor.h index d34f5718218..9495bb0377a 100644 --- a/src/storage/mutate/AddEdgesProcessor.h +++ b/src/storage/mutate/AddEdgesProcessor.h @@ -7,6 +7,7 @@ #define STORAGE_MUTATE_ADDEDGESPROCESSOR_H_ #include "common/base/Base.h" +#include "common/stats/StatsManager.h" #include "kvstore/LogEncoder.h" #include "storage/BaseProcessor.h" #include "storage/StorageFlags.h" @@ -15,6 +16,7 @@ namespace nebula { namespace storage { extern ProcessorCounters kAddEdgesCounters; +extern stats::CounterId kNumEdgesInserted; class AddEdgesProcessor : public BaseProcessor { friend class TransactionManager; diff --git a/src/storage/mutate/AddVerticesProcessor.cpp b/src/storage/mutate/AddVerticesProcessor.cpp index a3a5fe810d5..a7a80f64c20 100644 --- a/src/storage/mutate/AddVerticesProcessor.cpp +++ b/src/storage/mutate/AddVerticesProcessor.cpp @@ -8,6 +8,7 @@ #include #include "codec/RowWriterV2.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" @@ -18,6 +19,7 @@ namespace nebula { namespace storage { ProcessorCounters kAddVerticesCounters; +stats::CounterId kNumVerticesInserted; void AddVerticesProcessor::process(const cpp2::AddVerticesRequest& req) { spaceId_ = req.get_space_id(); @@ -127,6 +129,7 @@ void AddVerticesProcessor::doProcess(const cpp2::AddVerticesRequest& req) { handleAsync(spaceId_, partId, code); } else { doPut(spaceId_, partId, std::move(data)); + stats::StatsManager::addValue(kNumVerticesInserted, data.size()); } } } @@ -285,6 +288,7 @@ void AddVerticesProcessor::doProcessWithIndex(const cpp2::AddVerticesRequest& re * step 3 , Insert new vertex data */ batchHolder->put(std::move(key), std::move(retEnc.value())); + stats::StatsManager::addValue(kNumVerticesInserted); } if (code != nebula::cpp2::ErrorCode::SUCCEEDED) { break; diff --git a/src/storage/mutate/AddVerticesProcessor.h b/src/storage/mutate/AddVerticesProcessor.h index ea8e34b56e4..295bea0374f 100644 --- a/src/storage/mutate/AddVerticesProcessor.h +++ b/src/storage/mutate/AddVerticesProcessor.h @@ -16,6 +16,7 @@ namespace nebula { namespace storage { extern ProcessorCounters kAddVerticesCounters; +extern stats::CounterId kNumVerticesInserted; class AddVerticesProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteEdgesProcessor.cpp b/src/storage/mutate/DeleteEdgesProcessor.cpp index 47d63d24db3..def7c9aceaf 100644 --- a/src/storage/mutate/DeleteEdgesProcessor.cpp +++ b/src/storage/mutate/DeleteEdgesProcessor.cpp @@ -7,6 +7,7 @@ #include +#include "common/stats/StatsManager.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" @@ -15,6 +16,7 @@ namespace nebula { namespace storage { ProcessorCounters kDelEdgesCounters; +stats::CounterId kNumEdgesDeleted; void DeleteEdgesProcessor::process(const cpp2::DeleteEdgesRequest& req) { spaceId_ = req.get_space_id(); @@ -76,6 +78,7 @@ void DeleteEdgesProcessor::process(const cpp2::DeleteEdgesRequest& req) { continue; } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumEdgesDeleted, keys.size()); } } else { for (auto& part : partEdges) { @@ -185,6 +188,7 @@ ErrorOr DeleteEdgesProcessor::deleteEdges( } } batchHolder->remove(std::move(key)); + stats::StatsManager::addValue(kNumEdgesDeleted); } else if (ret == nebula::cpp2::ErrorCode::E_KEY_NOT_FOUND) { continue; } else { diff --git a/src/storage/mutate/DeleteEdgesProcessor.h b/src/storage/mutate/DeleteEdgesProcessor.h index 9e240b624f9..8bcd7553409 100644 --- a/src/storage/mutate/DeleteEdgesProcessor.h +++ b/src/storage/mutate/DeleteEdgesProcessor.h @@ -14,6 +14,7 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelEdgesCounters; +extern stats::CounterId kNumEdgesDeleted; class DeleteEdgesProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteTagsProcessor.cpp b/src/storage/mutate/DeleteTagsProcessor.cpp index 3e48ae7e542..5285223160e 100644 --- a/src/storage/mutate/DeleteTagsProcessor.cpp +++ b/src/storage/mutate/DeleteTagsProcessor.cpp @@ -5,6 +5,7 @@ #include "storage/mutate/DeleteTagsProcessor.h" +#include "common/stats/StatsManager.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" @@ -14,6 +15,7 @@ namespace nebula { namespace storage { ProcessorCounters kDelTagsCounters; +stats::CounterId kNumTagsDeleted; void DeleteTagsProcessor::process(const cpp2::DeleteTagsRequest& req) { spaceId_ = req.get_space_id(); @@ -60,6 +62,7 @@ void DeleteTagsProcessor::process(const cpp2::DeleteTagsRequest& req) { } } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumTagsDeleted, keys.size()); } } else { for (const auto& part : parts) { @@ -146,6 +149,7 @@ ErrorOr DeleteTagsProcessor::deleteTags( } } batchHolder->remove(std::move(key)); + stats::StatsManager::addValue(kNumTagsDeleted); } } return encodeBatchValue(batchHolder->getBatch()); diff --git a/src/storage/mutate/DeleteTagsProcessor.h b/src/storage/mutate/DeleteTagsProcessor.h index 5c473f16b66..37128a3cea8 100644 --- a/src/storage/mutate/DeleteTagsProcessor.h +++ b/src/storage/mutate/DeleteTagsProcessor.h @@ -15,6 +15,7 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelTagsCounters; +extern stats::CounterId kNumTagsDeleted; class DeleteTagsProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteVerticesProcessor.cpp b/src/storage/mutate/DeleteVerticesProcessor.cpp index 8e3ffc91a24..4b637005db2 100644 --- a/src/storage/mutate/DeleteVerticesProcessor.cpp +++ b/src/storage/mutate/DeleteVerticesProcessor.cpp @@ -14,6 +14,7 @@ namespace nebula { namespace storage { ProcessorCounters kDelVerticesCounters; +stats::CounterId kNumVerticesDeleted; void DeleteVerticesProcessor::process(const cpp2::DeleteVerticesRequest& req) { spaceId_ = req.get_space_id(); @@ -80,6 +81,7 @@ void DeleteVerticesProcessor::process(const cpp2::DeleteVerticesRequest& req) { continue; } doRemove(spaceId_, partId, std::move(keys)); + stats::StatsManager::addValue(kNumVerticesDeleted, keys.size()); } } else { for (auto& pv : partVertices) { @@ -170,6 +172,7 @@ ErrorOr DeleteVerticesProcessor::deleteVer } } batchHolder->remove(key.str()); + stats::StatsManager::addValue(kNumVerticesDeleted); iter->next(); } } diff --git a/src/storage/mutate/DeleteVerticesProcessor.h b/src/storage/mutate/DeleteVerticesProcessor.h index a5ec2f0b678..be326819fa9 100644 --- a/src/storage/mutate/DeleteVerticesProcessor.h +++ b/src/storage/mutate/DeleteVerticesProcessor.h @@ -15,6 +15,7 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelVerticesCounters; +extern stats::CounterId kNumVerticesDeleted; class DeleteVerticesProcessor : public BaseProcessor { public: From 6e1be3d20babd8dce6e02b06d5a56efb37879861 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Wed, 15 Dec 2021 16:24:28 +0800 Subject: [PATCH 06/10] remove kSentbytes, kReceivedBytes --- src/graph/service/QueryInstance.cpp | 1 - src/graph/stats/StatsDef.cpp | 8 -------- src/graph/stats/StatsDef.h | 4 ++-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index 3a24e6e4cdc..aede766d5ee 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -104,7 +104,6 @@ void QueryInstance::onFinish() { rctx->resp().latencyInUs = latency; addSlowQueryStats(latency, spaceName); rctx->finish(); - stats::StatsManager::addValue(kSentBytes, rctx->resp().data->size()); rctx->session()->deleteQuery(qctx_.get()); // The `QueryInstance' is the root node holding all resources during the diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/StatsDef.cpp index 9dd3769df86..4292d7c3075 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/StatsDef.cpp @@ -33,9 +33,6 @@ stats::CounterId kNumSortExecutors; stats::CounterId kNumIndexScanExecutors; stats::CounterId kNumOomExecutors; -stats::CounterId kReceivedBytes; -stats::CounterId kSentBytes; - stats::CounterId kNumOpenedSessions; stats::CounterId kNumAuthFailedSessions; stats::CounterId kNumAuthFailedSessionsBadUserNamePassword; @@ -60,11 +57,6 @@ void initCounters() { kOptimizerLatencyUs = stats::StatsManager::registerHisto( "optimizer_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); - kReceivedBytes = stats::StatsManager::registerHisto( - "received_bytes", 1000, 1, 4194304, "avg, p75, p95, p99, p999"); // 1 Byte ~ 4194304 Bytes - kSentBytes = stats::StatsManager::registerHisto( - "sent_bytes", 1000, 1, 4294967296, "avg, p75, p95, p99, p999"); // 1 Byte ~ 4 GiB - kNumAggregateExecutors = stats::StatsManager::registerStats("num_aggregate_executors", "rate, sum"); kNumSortExecutors = stats::StatsManager::registerStats("num_sort_executors", "rate, sum"); diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/StatsDef.h index 47a48dfa3e3..7c796e834ea 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/StatsDef.h @@ -34,8 +34,8 @@ extern stats::CounterId kNumIndexScanExecutors; extern stats::CounterId kNumOomExecutors; // Server client traffic -extern stats::CounterId kReceivedBytes; -extern stats::CounterId kSentBytes; +// extern stats::CounterId kReceivedBytes; +// extern stats::CounterId kSentBytes; // Session extern stats::CounterId kNumOpenedSessions; From 4e4b67433df590d25d9191a0d042d26af66cec3e Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Thu, 16 Dec 2021 15:44:48 +0800 Subject: [PATCH 07/10] add some kv, raft related counters --- src/clients/meta/CMakeLists.txt | 1 + src/clients/meta/MetaClient.cpp | 3 ++ src/clients/meta/stats/CMakeLists.txt | 9 ++++++ src/clients/meta/stats/MetaClientStats.cpp | 19 +++++++++++++ src/clients/meta/stats/MetaClientStats.h | 17 +++++++++++ src/clients/storage/CMakeLists.txt | 2 ++ src/clients/storage/StorageClientBase-inl.h | 5 ++++ src/clients/storage/stats/CMakeLists.txt | 9 ++++++ .../storage/stats/StorageClientStats.cpp | 20 +++++++++++++ .../storage/stats/StorageClientStats.h | 17 +++++++++++ src/codec/test/CMakeLists.txt | 3 ++ src/common/expression/test/CMakeLists.txt | 4 ++- src/daemons/CMakeLists.txt | 9 +++++- src/daemons/GraphDaemon.cpp | 4 +-- src/daemons/MetaDaemon.cpp | 4 +++ src/daemons/StorageDaemon.cpp | 4 +++ src/graph/context/test/CMakeLists.txt | 4 ++- src/graph/executor/Executor.cpp | 2 +- src/graph/executor/test/CMakeLists.txt | 4 ++- src/graph/optimizer/test/CMakeLists.txt | 4 ++- src/graph/planner/test/CMakeLists.txt | 2 +- src/graph/service/GraphService.cpp | 2 +- src/graph/service/QueryInstance.cpp | 2 +- src/graph/session/ClientSession.cpp | 2 +- src/graph/session/GraphSessionManager.cpp | 2 +- src/graph/stats/CMakeLists.txt | 4 +-- .../stats/{StatsDef.cpp => GraphStats.cpp} | 10 +++++-- src/graph/stats/{StatsDef.h => GraphStats.h} | 6 ++-- src/graph/util/test/CMakeLists.txt | 4 ++- src/graph/validator/test/CMakeLists.txt | 4 ++- src/graph/visitor/test/CMakeLists.txt | 4 ++- src/kvstore/CMakeLists.txt | 1 + src/kvstore/Part.cpp | 3 ++ src/kvstore/raftex/RaftPart.cpp | 6 ++++ src/kvstore/raftex/RaftPart.h | 5 ++++ src/kvstore/raftex/RaftexService.cpp | 1 + src/kvstore/raftex/test/CMakeLists.txt | 4 +++ src/kvstore/stats/CMakeLists.txt | 9 ++++++ src/kvstore/stats/KVStats.cpp | 28 +++++++++++++++++++ src/kvstore/stats/KVStats.h | 20 +++++++++++++ src/kvstore/test/CMakeLists.txt | 4 +++ src/meta/CMakeLists.txt | 6 ++++ src/meta/stats/CMakeLists.txt | 9 ++++++ src/meta/stats/MetaStats.cpp | 12 ++++++++ src/meta/stats/MetaStats.h | 14 ++++++++++ src/parser/test/CMakeLists.txt | 4 ++- src/storage/CMakeLists.txt | 1 + src/storage/GraphStorageServiceHandler.cpp | 6 ---- src/storage/admin/AdminProcessor.h | 2 ++ src/storage/mutate/AddEdgesProcessor.cpp | 2 +- src/storage/mutate/AddEdgesProcessor.h | 1 - src/storage/mutate/AddVerticesProcessor.cpp | 2 +- src/storage/mutate/AddVerticesProcessor.h | 1 - src/storage/mutate/DeleteEdgesProcessor.cpp | 2 +- src/storage/mutate/DeleteEdgesProcessor.h | 1 - src/storage/mutate/DeleteTagsProcessor.cpp | 2 +- src/storage/mutate/DeleteTagsProcessor.h | 1 - .../mutate/DeleteVerticesProcessor.cpp | 2 +- src/storage/mutate/DeleteVerticesProcessor.h | 1 - src/storage/stats/CMakeLists.txt | 9 ++++++ src/storage/stats/StorageStats.cpp | 28 +++++++++++++++++++ src/storage/stats/StorageStats.h | 20 +++++++++++++ src/storage/test/CMakeLists.txt | 4 +++ src/tools/db-dump/CMakeLists.txt | 4 +++ src/tools/db-upgrade/CMakeLists.txt | 4 +++ src/tools/meta-dump/CMakeLists.txt | 4 +++ src/tools/simple-kv-verify/CMakeLists.txt | 4 +++ src/tools/storage-perf/CMakeLists.txt | 4 +++ 68 files changed, 375 insertions(+), 42 deletions(-) create mode 100644 src/clients/meta/stats/CMakeLists.txt create mode 100644 src/clients/meta/stats/MetaClientStats.cpp create mode 100644 src/clients/meta/stats/MetaClientStats.h create mode 100644 src/clients/storage/stats/CMakeLists.txt create mode 100644 src/clients/storage/stats/StorageClientStats.cpp create mode 100644 src/clients/storage/stats/StorageClientStats.h rename src/graph/stats/{StatsDef.cpp => GraphStats.cpp} (94%) rename src/graph/stats/{StatsDef.h => GraphStats.h} (92%) create mode 100644 src/kvstore/stats/CMakeLists.txt create mode 100644 src/kvstore/stats/KVStats.cpp create mode 100644 src/kvstore/stats/KVStats.h create mode 100644 src/meta/stats/CMakeLists.txt create mode 100644 src/meta/stats/MetaStats.cpp create mode 100644 src/meta/stats/MetaStats.h create mode 100644 src/storage/stats/CMakeLists.txt create mode 100644 src/storage/stats/StorageStats.cpp create mode 100644 src/storage/stats/StorageStats.h diff --git a/src/clients/meta/CMakeLists.txt b/src/clients/meta/CMakeLists.txt index 113b88245c6..c5175f58ff6 100644 --- a/src/clients/meta/CMakeLists.txt +++ b/src/clients/meta/CMakeLists.txt @@ -12,4 +12,5 @@ nebula_add_library( FileBasedClusterIdMan.cpp ) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) diff --git a/src/clients/meta/MetaClient.cpp b/src/clients/meta/MetaClient.cpp index 851791b0f67..6658299dfe9 100644 --- a/src/clients/meta/MetaClient.cpp +++ b/src/clients/meta/MetaClient.cpp @@ -12,6 +12,7 @@ #include #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" @@ -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; { @@ -660,6 +662,7 @@ void MetaClient::getResponse(Request req, this](folly::Try&& t) mutable { // exception occurred during RPC if (t.hasException()) { + stats::StatsManager::addValue(kNumRpcSentToMetadFailed); if (toLeader) { updateLeader(); } else { diff --git a/src/clients/meta/stats/CMakeLists.txt b/src/clients/meta/stats/CMakeLists.txt new file mode 100644 index 00000000000..68a18484869 --- /dev/null +++ b/src/clients/meta/stats/CMakeLists.txt @@ -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 + ) diff --git a/src/clients/meta/stats/MetaClientStats.cpp b/src/clients/meta/stats/MetaClientStats.cpp new file mode 100644 index 00000000000..3f73f4f76fe --- /dev/null +++ b/src/clients/meta/stats/MetaClientStats.cpp @@ -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 diff --git a/src/clients/meta/stats/MetaClientStats.h b/src/clients/meta/stats/MetaClientStats.h new file mode 100644 index 00000000000..46fa1497931 --- /dev/null +++ b/src/clients/meta/stats/MetaClientStats.h @@ -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 diff --git a/src/clients/storage/CMakeLists.txt b/src/clients/storage/CMakeLists.txt index c6df1f8dda6..34293727a3a 100644 --- a/src/clients/storage/CMakeLists.txt +++ b/src/clients/storage/CMakeLists.txt @@ -19,3 +19,5 @@ nebula_add_library( InternalStorageClient.cpp ) +nebula_add_subdirectory(stats) + diff --git a/src/clients/storage/StorageClientBase-inl.h b/src/clients/storage/StorageClientBase-inl.h index a402bc71a88..abeb3ed130c 100644 --- a/src/clients/storage/StorageClientBase-inl.h +++ b/src/clients/storage/StorageClientBase-inl.h @@ -7,7 +7,9 @@ #include +#include "clients/storage/stats/StorageClientStats.h" #include "common/ssl/SSLConfig.h" +#include "common/stats/StatsManager.h" #include "common/time/WallClock.h" namespace nebula { @@ -230,6 +232,7 @@ void StorageClientBase::getResponseImpl( std::pair request, RemoteFunc remoteFunc, std::shared_ptr>> pro) { + stats::StatsManager::addValue(kNumRpcSentToStoraged); using TransportException = apache::thrift::transport::TTransportException; if (evb == nullptr) { DCHECK(!!ioThreadPool_); @@ -266,6 +269,7 @@ void StorageClientBase::getResponseImpl( .thenError(folly::tag_t{}, [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 { @@ -278,6 +282,7 @@ void StorageClientBase::getResponseImpl( .thenError(folly::tag_t{}, [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()))); diff --git a/src/clients/storage/stats/CMakeLists.txt b/src/clients/storage/stats/CMakeLists.txt new file mode 100644 index 00000000000..a1acb23dcea --- /dev/null +++ b/src/clients/storage/stats/CMakeLists.txt @@ -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 + ) diff --git a/src/clients/storage/stats/StorageClientStats.cpp b/src/clients/storage/stats/StorageClientStats.cpp new file mode 100644 index 00000000000..097f4cf3e8c --- /dev/null +++ b/src/clients/storage/stats/StorageClientStats.cpp @@ -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 diff --git a/src/clients/storage/stats/StorageClientStats.h b/src/clients/storage/stats/StorageClientStats.h new file mode 100644 index 00000000000..9c2e3567e4d --- /dev/null +++ b/src/clients/storage/stats/StorageClientStats.h @@ -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 diff --git a/src/codec/test/CMakeLists.txt b/src/codec/test/CMakeLists.txt index f529f16431e..1bf4e06fe07 100644 --- a/src/codec/test/CMakeLists.txt +++ b/src/codec/test/CMakeLists.txt @@ -22,6 +22,9 @@ set(CODEC_TEST_LIBS $ $ $ + $ + $ + $ $ $ $ diff --git a/src/common/expression/test/CMakeLists.txt b/src/common/expression/test/CMakeLists.txt index 09c9e139b58..b71eb7aac88 100644 --- a/src/common/expression/test/CMakeLists.txt +++ b/src/common/expression/test/CMakeLists.txt @@ -9,7 +9,9 @@ set(expression_test_common_libs $ $ $ - $ + $ + $ + $ $ $ $ diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index 292c3936d78..cc0530863f7 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -38,6 +38,11 @@ set(common_deps set(storage_meta_deps $ + $ + $ + $ + $ + $ $ $ $ @@ -109,7 +114,9 @@ nebula_add_executable( SetupLogging.cpp SetupBreakpad.cpp OBJECTS - $ + $ + $ + $ $ $ $ diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp index 78cfdd36370..7a32be6c1ac 100644 --- a/src/daemons/GraphDaemon.cpp +++ b/src/daemons/GraphDaemon.cpp @@ -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" @@ -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]); diff --git a/src/daemons/MetaDaemon.cpp b/src/daemons/MetaDaemon.cpp index 5aa7521107b..4059f1d3076 100644 --- a/src/daemons/MetaDaemon.cpp +++ b/src/daemons/MetaDaemon.cpp @@ -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" @@ -219,6 +220,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(); diff --git a/src/daemons/StorageDaemon.cpp b/src/daemons/StorageDaemon.cpp index 37e5957c4f8..124a2cc7c20 100644 --- a/src/daemons/StorageDaemon.cpp +++ b/src/daemons/StorageDaemon.cpp @@ -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"); @@ -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(); diff --git a/src/graph/context/test/CMakeLists.txt b/src/graph/context/test/CMakeLists.txt index 6b8286bfec0..779335bc5a0 100644 --- a/src/graph/context/test/CMakeLists.txt +++ b/src/graph/context/test/CMakeLists.txt @@ -43,7 +43,9 @@ SET(CONTEXT_TEST_LIBS $ $ $ - $ + $ + $ + $ ) nebula_add_test( diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index f33b14bd24c..4e753d4b013 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -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; diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index 081c935649b..50030fc2053 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -54,7 +54,9 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ - $ + $ + $ + $ ) SET(EXEC_QUERY_TEST_LIBS diff --git a/src/graph/optimizer/test/CMakeLists.txt b/src/graph/optimizer/test/CMakeLists.txt index e29af4031e2..ae0f1357bb3 100644 --- a/src/graph/optimizer/test/CMakeLists.txt +++ b/src/graph/optimizer/test/CMakeLists.txt @@ -49,7 +49,9 @@ set(OPTIMIZER_TEST_LIB $ $ $ - $ + $ + $ + $ ) nebula_add_test( diff --git a/src/graph/planner/test/CMakeLists.txt b/src/graph/planner/test/CMakeLists.txt index 02aa6b5edb0..ac07fbb708f 100644 --- a/src/graph/planner/test/CMakeLists.txt +++ b/src/graph/planner/test/CMakeLists.txt @@ -18,7 +18,7 @@ nebula_add_test( $ $ $ - $ + $ $ $ $ diff --git a/src/graph/service/GraphService.cpp b/src/graph/service/GraphService.cpp index 6a360e6704d..e63550e4b6e 100644 --- a/src/graph/service/GraphService.cpp +++ b/src/graph/service/GraphService.cpp @@ -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 { diff --git a/src/graph/service/QueryInstance.cpp b/src/graph/service/QueryInstance.cpp index aede766d5ee..4b42a5c9a7f 100644 --- a/src/graph/service/QueryInstance.cpp +++ b/src/graph/service/QueryInstance.cpp @@ -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" diff --git a/src/graph/session/ClientSession.cpp b/src/graph/session/ClientSession.cpp index 74fa1f6cfbc..7451eb5d312 100644 --- a/src/graph/session/ClientSession.cpp +++ b/src/graph/session/ClientSession.cpp @@ -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 { diff --git a/src/graph/session/GraphSessionManager.cpp b/src/graph/session/GraphSessionManager.cpp index 3d256bac75d..d4a9851a859 100644 --- a/src/graph/session/GraphSessionManager.cpp +++ b/src/graph/session/GraphSessionManager.cpp @@ -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 { diff --git a/src/graph/stats/CMakeLists.txt b/src/graph/stats/CMakeLists.txt index a1cd2878085..e837ad66cf8 100644 --- a/src/graph/stats/CMakeLists.txt +++ b/src/graph/stats/CMakeLists.txt @@ -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 ) diff --git a/src/graph/stats/StatsDef.cpp b/src/graph/stats/GraphStats.cpp similarity index 94% rename from src/graph/stats/StatsDef.cpp rename to src/graph/stats/GraphStats.cpp index 4292d7c3075..adab4a84352 100644 --- a/src/graph/stats/StatsDef.cpp +++ b/src/graph/stats/GraphStats.cpp @@ -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, @@ -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"); @@ -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 diff --git a/src/graph/stats/StatsDef.h b/src/graph/stats/GraphStats.h similarity index 92% rename from src/graph/stats/StatsDef.h rename to src/graph/stats/GraphStats.h index 7c796e834ea..70bb6a1efd1 100644 --- a/src/graph/stats/StatsDef.h +++ b/src/graph/stats/GraphStats.h @@ -3,8 +3,7 @@ * This source code is licensed under Apache 2.0 License. */ -#ifndef GRAPH_STATS_STATSDEF_H_ -#define GRAPH_STATS_STATSDEF_H_ +#pragma once #include "common/base/Base.h" #include "common/stats/StatsManager.h" @@ -45,7 +44,6 @@ extern stats::CounterId kNumAuthFailedSessionsOutOfMaxAllowed; extern stats::CounterId kNumActiveSessions; extern stats::CounterId kNumReclaimedExpiredSessions; -void initCounters(); +void initGraphStats(); } // namespace nebula -#endif // GRAPH_STATS_STATSDEF_H_ diff --git a/src/graph/util/test/CMakeLists.txt b/src/graph/util/test/CMakeLists.txt index 7d3031a5b19..05d1b74119b 100644 --- a/src/graph/util/test/CMakeLists.txt +++ b/src/graph/util/test/CMakeLists.txt @@ -46,7 +46,9 @@ nebula_add_test( $ $ $ - $ + $ + $ + $ LIBRARIES gtest gtest_main diff --git a/src/graph/validator/test/CMakeLists.txt b/src/graph/validator/test/CMakeLists.txt index ab6a41e7fbb..ae4362aee0d 100644 --- a/src/graph/validator/test/CMakeLists.txt +++ b/src/graph/validator/test/CMakeLists.txt @@ -26,7 +26,9 @@ set(VALIDATOR_TEST_LIBS $ $ $ - $ + $ + $ + $ $ $ $ diff --git a/src/graph/visitor/test/CMakeLists.txt b/src/graph/visitor/test/CMakeLists.txt index d84f3d7144a..d3e9d5e2638 100644 --- a/src/graph/visitor/test/CMakeLists.txt +++ b/src/graph/visitor/test/CMakeLists.txt @@ -31,7 +31,9 @@ nebula_add_test( $ $ $ - $ + $ + $ + $ $ $ $ diff --git a/src/kvstore/CMakeLists.txt b/src/kvstore/CMakeLists.txt index ffcc13401ab..549be980087 100644 --- a/src/kvstore/CMakeLists.txt +++ b/src/kvstore/CMakeLists.txt @@ -19,6 +19,7 @@ nebula_add_library( nebula_add_subdirectory(raftex) nebula_add_subdirectory(wal) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) #nebula_add_subdirectory(plugins) diff --git a/src/kvstore/Part.cpp b/src/kvstore/Part.cpp index f3f2830fcd4..c6416b05c75 100644 --- a/src/kvstore/Part.cpp +++ b/src/kvstore/Part.cpp @@ -5,6 +5,7 @@ #include "kvstore/Part.h" +#include "common/time/ScopedTimer.h" #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" @@ -213,6 +214,7 @@ void Part::onDiscoverNewLeader(HostAddr nLeader) { } cpp2::ErrorCode Part::commitLogs(std::unique_ptr iter, bool wait) { + SCOPED_TIMER(&execTime_); auto batch = engine_->startBatchWrite(); LogID lastId = -1; TermID lastTerm = -1; @@ -354,6 +356,7 @@ std::pair Part::commitSnapshot(const std::vector& LogID committedLogId, TermID committedLogTerm, bool finished) { + SCOPED_TIMER(&execTime_); auto batch = engine_->startBatchWrite(); int64_t count = 0; int64_t size = 0; diff --git a/src/kvstore/raftex/RaftPart.cpp b/src/kvstore/raftex/RaftPart.cpp index bfa99392102..04600009911 100644 --- a/src/kvstore/raftex/RaftPart.cpp +++ b/src/kvstore/raftex/RaftPart.cpp @@ -14,6 +14,7 @@ #include "common/base/CollectNSucceeded.h" #include "common/base/SlowOpTracker.h" #include "common/network/NetworkUtils.h" +#include "common/stats/StatsManager.h" #include "common/thread/NamedThread.h" #include "common/thrift/ThriftClientManager.h" #include "common/time/WallClock.h" @@ -21,6 +22,7 @@ #include "interface/gen-cpp2/RaftexServiceAsyncClient.h" #include "kvstore/LogEncoder.h" #include "kvstore/raftex/Host.h" +#include "kvstore/stats/KVStats.h" #include "kvstore/wal/FileBasedWal.h" DEFINE_uint32(raft_heartbeat_interval_secs, 5, "Seconds between each heartbeat"); @@ -872,6 +874,7 @@ void RaftPart::processAppendLogResponses(const AppendLogResponses& resps, SlowOpTracker tracker; // Step 3: Commit the batch if (commitLogs(std::move(walIt), true) == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kCommitLogLatencyUs, execTime_); std::lock_guard g(raftLock_); committedLogId_ = lastLogId; firstLogId = lastLogId_ + 1; @@ -1387,6 +1390,7 @@ void RaftPart::processAskForVoteRequest(const cpp2::AskForVoteRequest& req, // Reset the last message time lastMsgRecvDur_.reset(); isBlindFollower_ = false; + stats::StatsManager::addValue(kNumRaftVotes); return; } @@ -1570,6 +1574,7 @@ void RaftPart::processAppendLogRequest(const cpp2::AppendLogRequest& req, // lack of log auto code = commitLogs(wal_->iterator(committedLogId_ + 1, lastLogIdCanCommit), false); if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kCommitLogLatencyUs, execTime_); VLOG(1) << idStr_ << "Follower succeeded committing log " << committedLogId_ + 1 << " to " << lastLogIdCanCommit; committedLogId_ = lastLogIdCanCommit; @@ -1751,6 +1756,7 @@ void RaftPart::processSendSnapshotRequest(const cpp2::SendSnapshotRequest& req, // TODO(heng): Maybe we should save them into one sst firstly? auto ret = commitSnapshot( req.get_rows(), req.get_committed_log_id(), req.get_committed_log_term(), req.get_done()); + stats::StatsManager::addValue(kCommitSnapshotLatencyUs, execTime_); lastTotalCount_ += ret.first; lastTotalSize_ += ret.second; if (lastTotalCount_ != req.get_total_count() || lastTotalSize_ != req.get_total_size()) { diff --git a/src/kvstore/raftex/RaftPart.h b/src/kvstore/raftex/RaftPart.h index 346ab53cee4..4821581acff 100644 --- a/src/kvstore/raftex/RaftPart.h +++ b/src/kvstore/raftex/RaftPart.h @@ -224,6 +224,8 @@ class RaftPart : public std::enable_shared_from_this { // Reset the part, clean up all data and WALs. void reset(); + uint64_t execTime() const { return execTime_; } + protected: // Protected constructor to prevent from instantiating directly RaftPart(ClusterID clusterId, @@ -563,6 +565,9 @@ class RaftPart : public std::enable_shared_from_this { int64_t startTimeMs_ = 0; std::atomic blocking_{false}; + + // For stats info + uint64_t execTime_{0}; }; } // namespace raftex diff --git a/src/kvstore/raftex/RaftexService.cpp b/src/kvstore/raftex/RaftexService.cpp index b1a26f8763c..3506dee52b9 100644 --- a/src/kvstore/raftex/RaftexService.cpp +++ b/src/kvstore/raftex/RaftexService.cpp @@ -8,6 +8,7 @@ #include #include "common/base/Base.h" +#include "common/base/ErrorOr.h" #include "common/ssl/SSLConfig.h" #include "kvstore/raftex/RaftPart.h" diff --git a/src/kvstore/raftex/test/CMakeLists.txt b/src/kvstore/raftex/test/CMakeLists.txt index 40982da8a59..b826c5b36f5 100644 --- a/src/kvstore/raftex/test/CMakeLists.txt +++ b/src/kvstore/raftex/test/CMakeLists.txt @@ -14,6 +14,10 @@ set(RAFTEX_TEST_LIBS $ $ $ + $ + $ + $ + $ ) diff --git a/src/kvstore/stats/CMakeLists.txt b/src/kvstore/stats/CMakeLists.txt new file mode 100644 index 00000000000..ff585725728 --- /dev/null +++ b/src/kvstore/stats/CMakeLists.txt @@ -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( + kv_stats_obj + OBJECT + KVStats.cpp + ) diff --git a/src/kvstore/stats/KVStats.cpp b/src/kvstore/stats/KVStats.cpp new file mode 100644 index 00000000000..6b8996f9b58 --- /dev/null +++ b/src/kvstore/stats/KVStats.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "kvstore/stats/KVStats.h" + +#include "common/base/Base.h" +#include "common/stats/StatsManager.h" + +namespace nebula { + +stats::CounterId kCommitLogLatencyUs; +stats::CounterId kCommitSnapshotLatencyUs; +stats::CounterId kTransferLeaderLatencyUs; +stats::CounterId kNumRaftVotes; + +void initKVStats() { + kCommitLogLatencyUs = stats::StatsManager::registerHisto( + "commit_log_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kCommitSnapshotLatencyUs = stats::StatsManager::registerHisto( + "commit_snapshot_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kTransferLeaderLatencyUs = stats::StatsManager::registerHisto( + "transfer_leader_latency_us", 1000, 0, 2000, "avg, p75, p95, p99, p999"); + kNumRaftVotes = stats::StatsManager::registerStats("num_raft_votes", "rate, sum"); +} + +} // namespace nebula diff --git a/src/kvstore/stats/KVStats.h b/src/kvstore/stats/KVStats.h new file mode 100644 index 00000000000..90da33a5f2a --- /dev/null +++ b/src/kvstore/stats/KVStats.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#pragma once + +#include "common/base/Base.h" +#include "common/stats/StatsManager.h" + +namespace nebula { + +extern stats::CounterId kCommitLogLatencyUs; +extern stats::CounterId kCommitSnapshotLatencyUs; +extern stats::CounterId kTransferLeaderLatencyUs; +extern stats::CounterId kNumRaftVotes; + +void initKVStats(); + +} // namespace nebula diff --git a/src/kvstore/test/CMakeLists.txt b/src/kvstore/test/CMakeLists.txt index cdcb719cf33..97eb868396c 100644 --- a/src/kvstore/test/CMakeLists.txt +++ b/src/kvstore/test/CMakeLists.txt @@ -38,6 +38,10 @@ set(KVSTORE_TEST_LIBS $ $ $ + $ + $ + $ + $ ) nebula_add_test( diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index 77449574b61..919f6ebacd2 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -160,8 +160,14 @@ set(meta_test_deps $ $ $ + $ + $ + $ + $ + $ ) nebula_add_subdirectory(http) nebula_add_subdirectory(test) nebula_add_subdirectory(upgrade) +nebula_add_subdirectory(stats) diff --git a/src/meta/stats/CMakeLists.txt b/src/meta/stats/CMakeLists.txt new file mode 100644 index 00000000000..91bcf68755d --- /dev/null +++ b/src/meta/stats/CMakeLists.txt @@ -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_stats_obj + OBJECT + MetaStats.cpp + ) diff --git a/src/meta/stats/MetaStats.cpp b/src/meta/stats/MetaStats.cpp new file mode 100644 index 00000000000..124c72f1b3b --- /dev/null +++ b/src/meta/stats/MetaStats.cpp @@ -0,0 +1,12 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "kvstore/stats/KVStats.h" + +namespace nebula { + +void initMetaStats() { initKVStats(); } + +} // namespace nebula diff --git a/src/meta/stats/MetaStats.h b/src/meta/stats/MetaStats.h new file mode 100644 index 00000000000..a8a5fba750e --- /dev/null +++ b/src/meta/stats/MetaStats.h @@ -0,0 +1,14 @@ +/* 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 { + +void initMetaStats(); + +} // namespace nebula diff --git a/src/parser/test/CMakeLists.txt b/src/parser/test/CMakeLists.txt index c6fc74dfbf6..755d2c7a350 100644 --- a/src/parser/test/CMakeLists.txt +++ b/src/parser/test/CMakeLists.txt @@ -9,7 +9,9 @@ set(PARSER_TEST_LIBS $ $ $ - $ + $ + $ + $ $ $ $ diff --git a/src/storage/CMakeLists.txt b/src/storage/CMakeLists.txt index 4f263476edc..6e58d6d2815 100644 --- a/src/storage/CMakeLists.txt +++ b/src/storage/CMakeLists.txt @@ -90,4 +90,5 @@ nebula_add_library( StorageServer.cpp ) +nebula_add_subdirectory(stats) nebula_add_subdirectory(test) diff --git a/src/storage/GraphStorageServiceHandler.cpp b/src/storage/GraphStorageServiceHandler.cpp index 8fa037a65eb..7f7f027af5e 100644 --- a/src/storage/GraphStorageServiceHandler.cpp +++ b/src/storage/GraphStorageServiceHandler.cpp @@ -63,12 +63,6 @@ GraphStorageServiceHandler::GraphStorageServiceHandler(StorageEnv* env) : env_(e kPutCounters.init("kv_put"); kGetCounters.init("kv_get"); kRemoveCounters.init("kv_remove"); - - kNumVerticesInserted = stats::StatsManager::registerStats("num_vertices_inserted", "rate, sum"); - kNumEdgesInserted = stats::StatsManager::registerStats("num_edges_inserted", "rate, sum"); - kNumEdgesDeleted = stats::StatsManager::registerStats("num_edges_deleted", "rate, sum"); - kNumTagsDeleted = stats::StatsManager::registerStats("num_tags_deleted", "rate, sum"); - kNumVerticesDeleted = stats::StatsManager::registerStats("num_vertices_deleted", "rate, sum"); } // Vertice section diff --git a/src/storage/admin/AdminProcessor.h b/src/storage/admin/AdminProcessor.h index bd55ef10955..0faceb75abe 100644 --- a/src/storage/admin/AdminProcessor.h +++ b/src/storage/admin/AdminProcessor.h @@ -11,6 +11,7 @@ #include "common/base/Base.h" #include "kvstore/NebulaStore.h" #include "kvstore/Part.h" +#include "kvstore/stats/KVStats.h" #include "storage/BaseProcessor.h" #include "storage/StorageFlags.h" @@ -66,6 +67,7 @@ class TransLeaderProcessor : public BaseProcessor { onFinished(); return; } else if (code == nebula::cpp2::ErrorCode::SUCCEEDED) { + stats::StatsManager::addValue(kTransferLeaderLatencyUs, part->execTime()); // To avoid dead lock, we use another ioThreadPool to check the // leader information. folly::via(folly::getIOExecutor().get(), [this, part, spaceId, partId] { diff --git a/src/storage/mutate/AddEdgesProcessor.cpp b/src/storage/mutate/AddEdgesProcessor.cpp index 640e3fb0516..cf0f9d6082f 100644 --- a/src/storage/mutate/AddEdgesProcessor.cpp +++ b/src/storage/mutate/AddEdgesProcessor.cpp @@ -13,12 +13,12 @@ #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { ProcessorCounters kAddEdgesCounters; -stats::CounterId kNumEdgesInserted; void AddEdgesProcessor::process(const cpp2::AddEdgesRequest& req) { spaceId_ = req.get_space_id(); diff --git a/src/storage/mutate/AddEdgesProcessor.h b/src/storage/mutate/AddEdgesProcessor.h index 9495bb0377a..bacc212bd06 100644 --- a/src/storage/mutate/AddEdgesProcessor.h +++ b/src/storage/mutate/AddEdgesProcessor.h @@ -16,7 +16,6 @@ namespace nebula { namespace storage { extern ProcessorCounters kAddEdgesCounters; -extern stats::CounterId kNumEdgesInserted; class AddEdgesProcessor : public BaseProcessor { friend class TransactionManager; diff --git a/src/storage/mutate/AddVerticesProcessor.cpp b/src/storage/mutate/AddVerticesProcessor.cpp index a7a80f64c20..b6854009107 100644 --- a/src/storage/mutate/AddVerticesProcessor.cpp +++ b/src/storage/mutate/AddVerticesProcessor.cpp @@ -14,12 +14,12 @@ #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { ProcessorCounters kAddVerticesCounters; -stats::CounterId kNumVerticesInserted; void AddVerticesProcessor::process(const cpp2::AddVerticesRequest& req) { spaceId_ = req.get_space_id(); diff --git a/src/storage/mutate/AddVerticesProcessor.h b/src/storage/mutate/AddVerticesProcessor.h index 295bea0374f..ea8e34b56e4 100644 --- a/src/storage/mutate/AddVerticesProcessor.h +++ b/src/storage/mutate/AddVerticesProcessor.h @@ -16,7 +16,6 @@ namespace nebula { namespace storage { extern ProcessorCounters kAddVerticesCounters; -extern stats::CounterId kNumVerticesInserted; class AddVerticesProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteEdgesProcessor.cpp b/src/storage/mutate/DeleteEdgesProcessor.cpp index def7c9aceaf..ebe20930ac1 100644 --- a/src/storage/mutate/DeleteEdgesProcessor.cpp +++ b/src/storage/mutate/DeleteEdgesProcessor.cpp @@ -11,12 +11,12 @@ #include "common/utils/IndexKeyUtils.h" #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { ProcessorCounters kDelEdgesCounters; -stats::CounterId kNumEdgesDeleted; void DeleteEdgesProcessor::process(const cpp2::DeleteEdgesRequest& req) { spaceId_ = req.get_space_id(); diff --git a/src/storage/mutate/DeleteEdgesProcessor.h b/src/storage/mutate/DeleteEdgesProcessor.h index 8bcd7553409..9e240b624f9 100644 --- a/src/storage/mutate/DeleteEdgesProcessor.h +++ b/src/storage/mutate/DeleteEdgesProcessor.h @@ -14,7 +14,6 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelEdgesCounters; -extern stats::CounterId kNumEdgesDeleted; class DeleteEdgesProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteTagsProcessor.cpp b/src/storage/mutate/DeleteTagsProcessor.cpp index 5285223160e..60093d6ab28 100644 --- a/src/storage/mutate/DeleteTagsProcessor.cpp +++ b/src/storage/mutate/DeleteTagsProcessor.cpp @@ -10,12 +10,12 @@ #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { ProcessorCounters kDelTagsCounters; -stats::CounterId kNumTagsDeleted; void DeleteTagsProcessor::process(const cpp2::DeleteTagsRequest& req) { spaceId_ = req.get_space_id(); diff --git a/src/storage/mutate/DeleteTagsProcessor.h b/src/storage/mutate/DeleteTagsProcessor.h index 37128a3cea8..5c473f16b66 100644 --- a/src/storage/mutate/DeleteTagsProcessor.h +++ b/src/storage/mutate/DeleteTagsProcessor.h @@ -15,7 +15,6 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelTagsCounters; -extern stats::CounterId kNumTagsDeleted; class DeleteTagsProcessor : public BaseProcessor { public: diff --git a/src/storage/mutate/DeleteVerticesProcessor.cpp b/src/storage/mutate/DeleteVerticesProcessor.cpp index 4b637005db2..0b4134f3771 100644 --- a/src/storage/mutate/DeleteVerticesProcessor.cpp +++ b/src/storage/mutate/DeleteVerticesProcessor.cpp @@ -9,12 +9,12 @@ #include "common/utils/NebulaKeyUtils.h" #include "common/utils/OperationKeyUtils.h" #include "storage/StorageFlags.h" +#include "storage/stats/StorageStats.h" namespace nebula { namespace storage { ProcessorCounters kDelVerticesCounters; -stats::CounterId kNumVerticesDeleted; void DeleteVerticesProcessor::process(const cpp2::DeleteVerticesRequest& req) { spaceId_ = req.get_space_id(); diff --git a/src/storage/mutate/DeleteVerticesProcessor.h b/src/storage/mutate/DeleteVerticesProcessor.h index be326819fa9..a5ec2f0b678 100644 --- a/src/storage/mutate/DeleteVerticesProcessor.h +++ b/src/storage/mutate/DeleteVerticesProcessor.h @@ -15,7 +15,6 @@ namespace nebula { namespace storage { extern ProcessorCounters kDelVerticesCounters; -extern stats::CounterId kNumVerticesDeleted; class DeleteVerticesProcessor : public BaseProcessor { public: diff --git a/src/storage/stats/CMakeLists.txt b/src/storage/stats/CMakeLists.txt new file mode 100644 index 00000000000..6d5db5f3f4f --- /dev/null +++ b/src/storage/stats/CMakeLists.txt @@ -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_stats_obj + OBJECT + StorageStats.cpp + ) diff --git a/src/storage/stats/StorageStats.cpp b/src/storage/stats/StorageStats.cpp new file mode 100644 index 00000000000..40f5181c195 --- /dev/null +++ b/src/storage/stats/StorageStats.cpp @@ -0,0 +1,28 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License. + */ + +#include "clients/meta/stats/MetaClientStats.h" +#include "kvstore/stats/KVStats.h" + +namespace nebula { + +stats::CounterId kNumEdgesInserted; +stats::CounterId kNumVerticesInserted; +stats::CounterId kNumEdgesDeleted; +stats::CounterId kNumTagsDeleted; +stats::CounterId kNumVerticesDeleted; + +void initStorageStats() { + kNumEdgesInserted = stats::StatsManager::registerStats("num_edges_inserted", "rate, sum"); + kNumVerticesInserted = stats::StatsManager::registerStats("num_vertices_inserted", "rate, sum"); + kNumEdgesDeleted = stats::StatsManager::registerStats("num_edges_deleted", "rate, sum"); + kNumTagsDeleted = stats::StatsManager::registerStats("num_tags_deleted", "rate, sum"); + kNumVerticesDeleted = stats::StatsManager::registerStats("num_vertices_deleted", "rate, sum"); + + initMetaClientStats(); + initKVStats(); +} + +} // namespace nebula diff --git a/src/storage/stats/StorageStats.h b/src/storage/stats/StorageStats.h new file mode 100644 index 00000000000..11bf1a76315 --- /dev/null +++ b/src/storage/stats/StorageStats.h @@ -0,0 +1,20 @@ +/* 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 kNumEdgesInserted; +extern stats::CounterId kNumVerticesInserted; +extern stats::CounterId kNumEdgesDeleted; +extern stats::CounterId kNumTagsDeleted; +extern stats::CounterId kNumVerticesDeleted; + +void initStorageStats(); + +} // namespace nebula diff --git a/src/storage/test/CMakeLists.txt b/src/storage/test/CMakeLists.txt index 2c6e0ea5a3c..3d8363f6a2a 100644 --- a/src/storage/test/CMakeLists.txt +++ b/src/storage/test/CMakeLists.txt @@ -52,6 +52,10 @@ set(storage_test_deps $ $ $ + $ + $ + $ + $ ) nebula_add_test( diff --git a/src/tools/db-dump/CMakeLists.txt b/src/tools/db-dump/CMakeLists.txt index a90c14639ed..80919a420a6 100644 --- a/src/tools/db-dump/CMakeLists.txt +++ b/src/tools/db-dump/CMakeLists.txt @@ -34,6 +34,10 @@ set(tools_test_deps $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/db-upgrade/CMakeLists.txt b/src/tools/db-upgrade/CMakeLists.txt index 3a5985fa4dd..2f4bbdbee17 100644 --- a/src/tools/db-upgrade/CMakeLists.txt +++ b/src/tools/db-upgrade/CMakeLists.txt @@ -42,6 +42,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/meta-dump/CMakeLists.txt b/src/tools/meta-dump/CMakeLists.txt index 37a804eac3e..466b91ef62d 100644 --- a/src/tools/meta-dump/CMakeLists.txt +++ b/src/tools/meta-dump/CMakeLists.txt @@ -39,6 +39,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/simple-kv-verify/CMakeLists.txt b/src/tools/simple-kv-verify/CMakeLists.txt index e5c95581711..81de926c583 100644 --- a/src/tools/simple-kv-verify/CMakeLists.txt +++ b/src/tools/simple-kv-verify/CMakeLists.txt @@ -38,6 +38,10 @@ nebula_add_executable( $ $ $ + $ + $ + $ + $ $ $ $ diff --git a/src/tools/storage-perf/CMakeLists.txt b/src/tools/storage-perf/CMakeLists.txt index 5bff542fca6..41f9b0a18a5 100644 --- a/src/tools/storage-perf/CMakeLists.txt +++ b/src/tools/storage-perf/CMakeLists.txt @@ -34,6 +34,10 @@ set(perf_test_deps $ $ $ + $ + $ + $ + $ $ $ $ From 88f823eedb5dcee48ee1e495a9e5cccf0bbb227d Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Wed, 22 Dec 2021 10:53:23 +0800 Subject: [PATCH 08/10] fix cherry pick --- src/graph/executor/admin/SpaceExecutor.cpp | 2 +- src/graph/executor/test/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/graph/executor/admin/SpaceExecutor.cpp b/src/graph/executor/admin/SpaceExecutor.cpp index cb18bdfd6c7..9591b734b32 100644 --- a/src/graph/executor/admin/SpaceExecutor.cpp +++ b/src/graph/executor/admin/SpaceExecutor.cpp @@ -10,7 +10,7 @@ #include "graph/context/QueryContext.h" #include "graph/planner/plan/Admin.h" #include "graph/service/PermissionManager.h" -#include "graph/stats/StatsDef.h" +#include "graph/stats/GraphStats.h" #include "graph/util/FTIndexUtils.h" #include "graph/util/SchemaUtil.h" diff --git a/src/graph/executor/test/CMakeLists.txt b/src/graph/executor/test/CMakeLists.txt index 50030fc2053..5f8aba7d7fb 100644 --- a/src/graph/executor/test/CMakeLists.txt +++ b/src/graph/executor/test/CMakeLists.txt @@ -12,7 +12,6 @@ SET(EXEC_QUERY_TEST_OBJS $ $ $ - $ $ $ $ From 5a519530f8e64205ffd4f15ba55c37d126e9cff3 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Wed, 22 Dec 2021 15:00:13 +0800 Subject: [PATCH 09/10] add test cases for dyncamically register stats --- src/common/stats/StatsManager.cpp | 3 +- src/common/stats/test/StatsManagerTest.cpp | 33 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/common/stats/StatsManager.cpp b/src/common/stats/StatsManager.cpp index 6db76f83be7..b3da2d8cba2 100644 --- a/src/common/stats/StatsManager.cpp +++ b/src/common/stats/StatsManager.cpp @@ -261,7 +261,8 @@ void StatsManager::addValue(const CounterId& id, VT value) { auto& sm = get(); if (!id.valid()) { - LOG(FATAL) << "Invalid counter id"; + // The counter is not registered + return; } std::string index = id.index(); bool isHisto = id.isHisto(); diff --git a/src/common/stats/test/StatsManagerTest.cpp b/src/common/stats/test/StatsManagerTest.cpp index 513181b400a..92c1f82677e 100644 --- a/src/common/stats/test/StatsManagerTest.cpp +++ b/src/common/stats/test/StatsManagerTest.cpp @@ -107,6 +107,14 @@ TEST(StatsManager, ReadAllTest) { StatsManager::addValue(statId2, 1); StatsManager::addValue(statId2, 2); + // Dynamically register some metrics + auto statId3 = StatsManager::counterWithLabels(statId1, {{"space", "test"}}); + auto statId4 = StatsManager::histoWithLabels(statId2, {{"space", "test"}}); + StatsManager::addValue(statId3, 1); + StatsManager::addValue(statId3, 2); + StatsManager::addValue(statId4, 1); + StatsManager::addValue(statId4, 2); + auto stats = folly::dynamic::array(); StatsManager::readAllValue(stats); @@ -128,6 +136,31 @@ TEST(StatsManager, ReadAllTest) { EXPECT_FALSE(counterExists(stats, "stat04.count.60", val)); EXPECT_FALSE(counterExists(stats, "stat04.avg.3600", val)); EXPECT_FALSE(counterExists(stats, "stat04.p75.5", val)); + + EXPECT_TRUE(counterExists(stats, "space_test_stat04.sum.5", val)); + EXPECT_EQ(3, val); + EXPECT_TRUE(counterExists(stats, "space_test_stat04.p95.5", val)); + EXPECT_EQ(2, val); + EXPECT_TRUE(counterExists(stats, "space_test_stat04.p99.3600", val)); + EXPECT_EQ(2, val); + + EXPECT_TRUE(counterExists(stats, "space_test_stat03.sum.3600", val)); + EXPECT_EQ(3, val); + + EXPECT_FALSE(counterExists(stats, "space_test_stat03.count.600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat03.avg.3600", val)); + + EXPECT_FALSE(counterExists(stats, "space_test_stat04.rate.600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.count.60", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.avg.3600", val)); + EXPECT_FALSE(counterExists(stats, "space_test_stat04.p75.5", val)); + // Remove the dynamically registered metrics + StatsManager::removeCounterWithLabels(statId1, {{"space", "test"}}); + StatsManager::removeHistoWithLabels(statId2, {{"space", "test"}}); + auto stats2 = folly::dynamic::array(); + StatsManager::readAllValue(stats2); + EXPECT_FALSE(counterExists(stats2, "space_test_stat03.sum.3600", val)); + EXPECT_FALSE(counterExists(stats2, "space_test_stat04.p95.5", val)); } } // namespace stats From d6934341c22e59e0baf920593414d3b4652af661 Mon Sep 17 00:00:00 2001 From: jievince <38901892+jievince@users.noreply.github.com> Date: Wed, 22 Dec 2021 15:48:02 +0800 Subject: [PATCH 10/10] remove job metrics --- src/meta/MetaServiceHandler.h | 2 -- src/meta/processors/job/AdminJobProcessor.cpp | 3 --- src/meta/processors/job/AdminJobProcessor.h | 1 - 3 files changed, 6 deletions(-) diff --git a/src/meta/MetaServiceHandler.h b/src/meta/MetaServiceHandler.h index 9be896c2ac7..f6fccff22cb 100644 --- a/src/meta/MetaServiceHandler.h +++ b/src/meta/MetaServiceHandler.h @@ -25,8 +25,6 @@ class MetaServiceHandler final : public cpp2::MetaServiceSvIf { // Initialize counters kHBCounters.init(); - kNumActiveJobs = stats::StatsManager::registerStats("num_active_jobs", "sum"); - kNumRunningJobs = stats::StatsManager::registerStats("num_running_jobs", "sum"); } /** diff --git a/src/meta/processors/job/AdminJobProcessor.cpp b/src/meta/processors/job/AdminJobProcessor.cpp index dfbdf9af4f0..c41249e9b40 100644 --- a/src/meta/processors/job/AdminJobProcessor.cpp +++ b/src/meta/processors/job/AdminJobProcessor.cpp @@ -12,7 +12,6 @@ namespace nebula { namespace meta { -stats::CounterId kNumActiveJobs; void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { cpp2::AdminJobResult result; @@ -61,7 +60,6 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { errorCode = jobMgr->addJob(jobDesc, adminClient_); if (errorCode == nebula::cpp2::ErrorCode::SUCCEEDED) { result.set_job_id(nebula::value(jobId)); - stats::StatsManager::addValue(kNumActiveJobs); } break; } @@ -124,7 +122,6 @@ void AdminJobProcessor::process(const cpp2::AdminJobReq& req) { auto ret = jobMgr->recoverJob(spaceName, adminClient_, jobIds); if (nebula::ok(ret)) { result.set_recovered_job_num(nebula::value(ret)); - stats::StatsManager::addValue(kNumActiveJobs); } else { errorCode = nebula::error(ret); } diff --git a/src/meta/processors/job/AdminJobProcessor.h b/src/meta/processors/job/AdminJobProcessor.h index 3a920f01358..21ab6fac3a9 100644 --- a/src/meta/processors/job/AdminJobProcessor.h +++ b/src/meta/processors/job/AdminJobProcessor.h @@ -12,7 +12,6 @@ namespace nebula { namespace meta { -extern stats::CounterId kNumActiveJobs; class AdminJobProcessor : public BaseProcessor { public: