Skip to content

Commit

Permalink
Rate Limiter metrics have been added in control plane proxy (#10652)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorooleg authored Dec 20, 2024
1 parent a8bfeee commit d30aab1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ydb/core/fq/libs/control_plane_proxy/actors/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum ERequestTypeCommon {
RTC_DELETE_BINDING_IN_YDB,
RTC_CREATE_COMPUTE_DATABASE,
RTC_LIST_CPS_ENTITY,
RTC_RATE_LIMITER,
RTC_MAX,
};

Expand Down Expand Up @@ -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))};
Expand Down
38 changes: 37 additions & 1 deletion ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,23 @@ class TCreateQueryRequestActor :
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);
}
Expand All @@ -208,6 +220,16 @@ class TCreateQueryRequestActor :
|| !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()) {
Expand All @@ -223,9 +245,13 @@ class TCreateQueryRequestActor :
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,
Expand All @@ -238,12 +264,17 @@ class TCreateQueryRequestActor :
}

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));
Expand All @@ -257,6 +288,11 @@ class TCreateQueryRequestActor :
bool CanSendRequest() const override {
return (QuoterResourceCreated || !ShouldCreateRateLimiter()) && TBaseRequestActor::CanSendRequest();
}

private:
TInstant StartRateLimiterCreation;
bool RateLimiterCreationInProgress = false;
TRequestCommonCountersPtr RateLimiterCounters;
};

} // namespace NFq::NPrivate
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane
Config,
ControlPlaneStorageServiceActorId(),
requestCounters,
Counters.GetCommonCounters(RTC_RATE_LIMITER),
probe,
availablePermissions));
}
Expand Down

0 comments on commit d30aab1

Please sign in to comment.