aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Doronin <dorooleg@yandex.ru>2024-12-20 13:48:17 +0100
committerGitHub <noreply@github.com>2024-12-20 15:48:17 +0300
commitd30aab14a644965dd83df55c3d2a9f3424fcdf9b (patch)
tree42301ab9aeaa58012d184bbae555e2eaae70ddc5
parenta8bfeee3e3af5b6b9ecae214f4beeeeba0c6ca5a (diff)
downloadydb-d30aab14a644965dd83df55c3d2a9f3424fcdf9b.tar.gz
Rate Limiter metrics have been added in control plane proxy (#10652)
-rw-r--r--ydb/core/fq/libs/control_plane_proxy/actors/counters.h2
-rw-r--r--ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h38
-rw-r--r--ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp1
3 files changed, 40 insertions, 1 deletions
diff --git a/ydb/core/fq/libs/control_plane_proxy/actors/counters.h b/ydb/core/fq/libs/control_plane_proxy/actors/counters.h
index 32dec96a72..cb73258c11 100644
--- a/ydb/core/fq/libs/control_plane_proxy/actors/counters.h
+++ b/ydb/core/fq/libs/control_plane_proxy/actors/counters.h
@@ -171,6 +171,7 @@ enum ERequestTypeCommon {
RTC_DELETE_BINDING_IN_YDB,
RTC_CREATE_COMPUTE_DATABASE,
RTC_LIST_CPS_ENTITY,
+ RTC_RATE_LIMITER,
RTC_MAX,
};
@@ -228,6 +229,7 @@ class TCounters : public virtual TThrRefBase {
{MakeIntrusive<TRequestCommonCounters>("DeleteBindingInYDB")},
{MakeIntrusive<TRequestCommonCounters>("CreateComputeDatabase")},
{MakeIntrusive<TRequestCommonCounters>("ListCPSEntities")},
+ {MakeIntrusive<TRequestCommonCounters>("RateLimiter")},
});
TTtlCache<TMetricsScope, TScopeCountersPtr, TMap> ScopeCounters{TTtlCacheSettings{}.SetTtl(TDuration::Days(1))};
diff --git a/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h b/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h
index 2ceab95ae5..6925f9e217 100644
--- a/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h
+++ b/ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h
@@ -192,11 +192,23 @@ public:
TEvControlPlaneStorage::TEvCreateQueryResponse,
TEvControlPlaneProxy::TEvCreateQueryRequest,
TEvControlPlaneProxy::TEvCreateQueryResponse>;
- using TBaseRequestActor::TBaseRequestActor;
+
+ TCreateQueryRequestActor(typename TEvControlPlaneProxy::TEvCreateQueryRequest::TPtr requestProxy,
+ const TControlPlaneProxyConfig& config,
+ const TActorId& serviceId,
+ const TRequestCounters& counters,
+ const TRequestCommonCountersPtr& rateLimiterCounters,
+ const std::function<void(const TDuration&, bool, bool)>& probe,
+ const TPermissions& availablePermissions,
+ bool replyWithResponseOnSuccess = true)
+ : TBaseRequestActor(requestProxy, config, serviceId, counters, probe, availablePermissions, replyWithResponseOnSuccess)
+ , RateLimiterCounters(rateLimiterCounters) {
+ }
STFUNC(StateFunc) {
switch (ev->GetTypeRewrite()) {
hFunc(TEvRateLimiter::TEvCreateResourceResponse, Handle);
+ cFunc(NActors::TEvents::TSystem::Wakeup, HandleTimeout);
default:
return TBaseRequestActor::StateFunc(ev);
}
@@ -208,6 +220,16 @@ public:
|| !Config.ComputeConfig.YdbComputeControlPlaneEnabled(RequestProxy->Get()->Scope));
}
+ void HandleTimeout() {
+ // Don't need to set the RateLimiterCreationInProgress = false
+ // because of the PassAway will be called in this callback
+ if (RateLimiterCreationInProgress) {
+ RateLimiterCounters->Timeout->Inc();
+ RateLimiterCounters->InFly->Dec();
+ }
+ TBaseRequestActor::HandleTimeout();
+ }
+
void OnBootstrap() override {
this->UnsafeBecome(&TCreateQueryRequestActor::StateFunc);
if (ShouldCreateRateLimiter()) {
@@ -223,9 +245,13 @@ public:
10); // percent -> milliseconds
CPP_LOG_T("Create rate limiter resource for cloud with limit " << cloudLimit
<< "ms");
+ RateLimiterCreationInProgress = true;
+ RateLimiterCounters->InFly->Inc();
+ StartRateLimiterCreation = TInstant::Now();
Send(RateLimiterControlPlaneServiceId(),
new TEvRateLimiter::TEvCreateResource(RequestProxy->Get()->CloudId, cloudLimit));
} else {
+ RateLimiterCounters->Error->Inc();
NYql::TIssues issues;
NYql::TIssue issue =
MakeErrorIssue(TIssuesIds::INTERNAL_ERROR,
@@ -238,12 +264,17 @@ public:
}
void Handle(TEvRateLimiter::TEvCreateResourceResponse::TPtr& ev) {
+ RateLimiterCreationInProgress = false;
+ RateLimiterCounters->InFly->Dec();
+ RateLimiterCounters->LatencyMs->Collect((TInstant::Now() - StartRateLimiterCreation).MilliSeconds());
CPP_LOG_D(
"Create response from rate limiter service. Success: " << ev->Get()->Success);
if (ev->Get()->Success) {
+ RateLimiterCounters->Ok->Inc();
QuoterResourceCreated = true;
SendRequestIfCan();
} else {
+ RateLimiterCounters->Error->Inc();
NYql::TIssue issue("Failed to create rate limiter resource");
for (const NYql::TIssue& i : ev->Get()->Issues) {
issue.AddSubIssue(MakeIntrusive<NYql::TIssue>(i));
@@ -257,6 +288,11 @@ public:
bool CanSendRequest() const override {
return (QuoterResourceCreated || !ShouldCreateRateLimiter()) && TBaseRequestActor::CanSendRequest();
}
+
+private:
+ TInstant StartRateLimiterCreation;
+ bool RateLimiterCreationInProgress = false;
+ TRequestCommonCountersPtr RateLimiterCounters;
};
} // namespace NFq::NPrivate
diff --git a/ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp b/ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp
index 8e1ac1df03..cac729cf17 100644
--- a/ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp
+++ b/ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp
@@ -706,6 +706,7 @@ private:
Config,
ControlPlaneStorageServiceActorId(),
requestCounters,
+ Counters.GetCommonCounters(RTC_RATE_LIMITER),
probe,
availablePermissions));
}