Skip to content

Commit d30aab1

Browse files
authored
Rate Limiter metrics have been added in control plane proxy (#10652)
1 parent a8bfeee commit d30aab1

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

ydb/core/fq/libs/control_plane_proxy/actors/counters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ enum ERequestTypeCommon {
171171
RTC_DELETE_BINDING_IN_YDB,
172172
RTC_CREATE_COMPUTE_DATABASE,
173173
RTC_LIST_CPS_ENTITY,
174+
RTC_RATE_LIMITER,
174175
RTC_MAX,
175176
};
176177

@@ -228,6 +229,7 @@ class TCounters : public virtual TThrRefBase {
228229
{MakeIntrusive<TRequestCommonCounters>("DeleteBindingInYDB")},
229230
{MakeIntrusive<TRequestCommonCounters>("CreateComputeDatabase")},
230231
{MakeIntrusive<TRequestCommonCounters>("ListCPSEntities")},
232+
{MakeIntrusive<TRequestCommonCounters>("RateLimiter")},
231233
});
232234

233235
TTtlCache<TMetricsScope, TScopeCountersPtr, TMap> ScopeCounters{TTtlCacheSettings{}.SetTtl(TDuration::Days(1))};

ydb/core/fq/libs/control_plane_proxy/actors/request_actor.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,23 @@ class TCreateQueryRequestActor :
192192
TEvControlPlaneStorage::TEvCreateQueryResponse,
193193
TEvControlPlaneProxy::TEvCreateQueryRequest,
194194
TEvControlPlaneProxy::TEvCreateQueryResponse>;
195-
using TBaseRequestActor::TBaseRequestActor;
195+
196+
TCreateQueryRequestActor(typename TEvControlPlaneProxy::TEvCreateQueryRequest::TPtr requestProxy,
197+
const TControlPlaneProxyConfig& config,
198+
const TActorId& serviceId,
199+
const TRequestCounters& counters,
200+
const TRequestCommonCountersPtr& rateLimiterCounters,
201+
const std::function<void(const TDuration&, bool, bool)>& probe,
202+
const TPermissions& availablePermissions,
203+
bool replyWithResponseOnSuccess = true)
204+
: TBaseRequestActor(requestProxy, config, serviceId, counters, probe, availablePermissions, replyWithResponseOnSuccess)
205+
, RateLimiterCounters(rateLimiterCounters) {
206+
}
196207

197208
STFUNC(StateFunc) {
198209
switch (ev->GetTypeRewrite()) {
199210
hFunc(TEvRateLimiter::TEvCreateResourceResponse, Handle);
211+
cFunc(NActors::TEvents::TSystem::Wakeup, HandleTimeout);
200212
default:
201213
return TBaseRequestActor::StateFunc(ev);
202214
}
@@ -208,6 +220,16 @@ class TCreateQueryRequestActor :
208220
|| !Config.ComputeConfig.YdbComputeControlPlaneEnabled(RequestProxy->Get()->Scope));
209221
}
210222

223+
void HandleTimeout() {
224+
// Don't need to set the RateLimiterCreationInProgress = false
225+
// because of the PassAway will be called in this callback
226+
if (RateLimiterCreationInProgress) {
227+
RateLimiterCounters->Timeout->Inc();
228+
RateLimiterCounters->InFly->Dec();
229+
}
230+
TBaseRequestActor::HandleTimeout();
231+
}
232+
211233
void OnBootstrap() override {
212234
this->UnsafeBecome(&TCreateQueryRequestActor::StateFunc);
213235
if (ShouldCreateRateLimiter()) {
@@ -223,9 +245,13 @@ class TCreateQueryRequestActor :
223245
10); // percent -> milliseconds
224246
CPP_LOG_T("Create rate limiter resource for cloud with limit " << cloudLimit
225247
<< "ms");
248+
RateLimiterCreationInProgress = true;
249+
RateLimiterCounters->InFly->Inc();
250+
StartRateLimiterCreation = TInstant::Now();
226251
Send(RateLimiterControlPlaneServiceId(),
227252
new TEvRateLimiter::TEvCreateResource(RequestProxy->Get()->CloudId, cloudLimit));
228253
} else {
254+
RateLimiterCounters->Error->Inc();
229255
NYql::TIssues issues;
230256
NYql::TIssue issue =
231257
MakeErrorIssue(TIssuesIds::INTERNAL_ERROR,
@@ -238,12 +264,17 @@ class TCreateQueryRequestActor :
238264
}
239265

240266
void Handle(TEvRateLimiter::TEvCreateResourceResponse::TPtr& ev) {
267+
RateLimiterCreationInProgress = false;
268+
RateLimiterCounters->InFly->Dec();
269+
RateLimiterCounters->LatencyMs->Collect((TInstant::Now() - StartRateLimiterCreation).MilliSeconds());
241270
CPP_LOG_D(
242271
"Create response from rate limiter service. Success: " << ev->Get()->Success);
243272
if (ev->Get()->Success) {
273+
RateLimiterCounters->Ok->Inc();
244274
QuoterResourceCreated = true;
245275
SendRequestIfCan();
246276
} else {
277+
RateLimiterCounters->Error->Inc();
247278
NYql::TIssue issue("Failed to create rate limiter resource");
248279
for (const NYql::TIssue& i : ev->Get()->Issues) {
249280
issue.AddSubIssue(MakeIntrusive<NYql::TIssue>(i));
@@ -257,6 +288,11 @@ class TCreateQueryRequestActor :
257288
bool CanSendRequest() const override {
258289
return (QuoterResourceCreated || !ShouldCreateRateLimiter()) && TBaseRequestActor::CanSendRequest();
259290
}
291+
292+
private:
293+
TInstant StartRateLimiterCreation;
294+
bool RateLimiterCreationInProgress = false;
295+
TRequestCommonCountersPtr RateLimiterCounters;
260296
};
261297

262298
} // namespace NFq::NPrivate

ydb/core/fq/libs/control_plane_proxy/control_plane_proxy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ class TControlPlaneProxyActor : public NActors::TActorBootstrapped<TControlPlane
706706
Config,
707707
ControlPlaneStorageServiceActorId(),
708708
requestCounters,
709+
Counters.GetCommonCounters(RTC_RATE_LIMITER),
709710
probe,
710711
availablePermissions));
711712
}

0 commit comments

Comments
 (0)