Skip to content

Commit ad9481c

Browse files
authored
24-3: Add scale recommender for autoscaling (#12425)
1 parent ccb1ed1 commit ad9481c

37 files changed

+1698
-23
lines changed

ydb/core/base/hive.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ namespace NKikimr {
4949
EvUpdateTabletsObject,
5050
EvUpdateDomain,
5151
EvRequestTabletDistribution,
52+
EvRequestScaleRecommendation,
53+
EvConfigureScaleRecommender,
5254

5355
// replies
5456
EvBootTabletReply = EvBootTablet + 512,
@@ -84,6 +86,8 @@ namespace NKikimr {
8486
EvUpdateTabletsObjectReply,
8587
EvUpdateDomainReply,
8688
EvResponseTabletDistribution,
89+
EvResponseScaleRecommendation,
90+
EvConfigureScaleRecommenderReply,
8791

8892
EvEnd
8993
};
@@ -876,6 +880,25 @@ namespace NKikimr {
876880

877881
struct TEvResponseTabletDistribution : TEventPB<TEvResponseTabletDistribution,
878882
NKikimrHive::TEvResponseTabletDistribution, EvResponseTabletDistribution> {};
883+
884+
struct TEvRequestScaleRecommendation : TEventPB<TEvRequestScaleRecommendation,
885+
NKikimrHive::TEvRequestScaleRecommendation, EvRequestScaleRecommendation>
886+
{
887+
TEvRequestScaleRecommendation() = default;
888+
889+
TEvRequestScaleRecommendation(TSubDomainKey domainKey) {
890+
Record.MutableDomainKey()->CopyFrom(domainKey);
891+
}
892+
};
893+
894+
struct TEvResponseScaleRecommendation : TEventPB<TEvResponseScaleRecommendation,
895+
NKikimrHive::TEvResponseScaleRecommendation, EvResponseScaleRecommendation> {};
896+
897+
struct TEvConfigureScaleRecommender : TEventPB<TEvConfigureScaleRecommender,
898+
NKikimrHive::TEvConfigureScaleRecommender, EvConfigureScaleRecommender> {};
899+
900+
struct TEvConfigureScaleRecommenderReply : TEventPB<TEvConfigureScaleRecommenderReply,
901+
NKikimrHive::TEvConfigureScaleRecommenderReply, EvConfigureScaleRecommenderReply> {};
879902
};
880903

881904
IActor* CreateDefaultHive(const TActorId &tablet, TTabletStorageInfo *info);

ydb/core/cms/console/console__alter_tenant.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,48 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
201201
return Error(Ydb::StatusIds::BAD_REQUEST, "Data size soft quota cannot be larger than hard quota", ctx);
202202
}
203203
}
204+
205+
// Check scale recommender policies.
206+
if (rec.has_scale_recommender_policies()) {
207+
if (!Self->FeatureFlags.GetEnableScaleRecommender()) {
208+
return Error(Ydb::StatusIds::UNSUPPORTED, "Feature flag EnableScaleRecommender is off", ctx);
209+
}
210+
211+
const auto& policies = rec.scale_recommender_policies();
212+
if (policies.policies().size() > 1) {
213+
return Error(Ydb::StatusIds::BAD_REQUEST, "Currently, no more than one policy is supported at a time", ctx);
214+
}
215+
216+
if (!policies.policies().empty()) {
217+
using enum Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy_TargetTrackingPolicy::TargetCase;
218+
using enum Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy::PolicyCase;
219+
220+
const auto& policy = policies.policies()[0];
221+
switch (policy.GetPolicyCase()) {
222+
case kTargetTrackingPolicy: {
223+
const auto& targetTracking = policy.target_tracking_policy();
224+
switch (targetTracking.GetTargetCase()) {
225+
case kAverageCpuUtilizationPercent: {
226+
auto cpuUtilization = targetTracking.average_cpu_utilization_percent();
227+
if (cpuUtilization < 10 || cpuUtilization > 90) {
228+
return Error(Ydb::StatusIds::BAD_REQUEST, "Average CPU utilization target must be from 10% to 90%", ctx);
229+
}
230+
break;
231+
}
232+
case TARGET_NOT_SET:
233+
return Error(Ydb::StatusIds::BAD_REQUEST, "Target type for target tracking policy is not set", ctx);
234+
default:
235+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported target type for target tracking policy", ctx);
236+
}
237+
break;
238+
}
239+
case POLICY_NOT_SET:
240+
return Error(Ydb::StatusIds::BAD_REQUEST, "Policy type is not set", ctx);
241+
default:
242+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported policy type", ctx);
243+
}
244+
}
245+
}
204246

205247
// Check attributes.
206248
THashSet<TString> attrNames;
@@ -274,6 +316,11 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
274316
updateSubdomainVersion = true;
275317
}
276318

319+
if (rec.has_scale_recommender_policies()) {
320+
ScaleRecommenderPolicies.ConstructInPlace(rec.scale_recommender_policies());
321+
Self->DbUpdateScaleRecommenderPolicies(Tenant, *ScaleRecommenderPolicies, txc, ctx);
322+
}
323+
277324
if (rec.idempotency_key() || Tenant->AlterIdempotencyKey) {
278325
Tenant->AlterIdempotencyKey = rec.idempotency_key();
279326
Self->DbUpdateTenantAlterIdempotencyKey(Tenant, Tenant->AlterIdempotencyKey, txc, ctx);
@@ -367,6 +414,10 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
367414
if (DatabaseQuotas) {
368415
Tenant->DatabaseQuotas.ConstructInPlace(*DatabaseQuotas);
369416
}
417+
if (ScaleRecommenderPolicies) {
418+
Tenant->ScaleRecommenderPolicies.ConstructInPlace(*ScaleRecommenderPolicies);
419+
Tenant->ScaleRecommenderPoliciesConfirmed = false;
420+
}
370421
if (SubdomainVersion) {
371422
Tenant->SubdomainVersion = *SubdomainVersion;
372423
}
@@ -389,6 +440,7 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
389440
THashMap<TString, ui64> PoolsToAdd;
390441
TMaybe<Ydb::Cms::SchemaOperationQuotas> SchemaOperationQuotas;
391442
TMaybe<Ydb::Cms::DatabaseQuotas> DatabaseQuotas;
443+
TMaybe<Ydb::Cms::ScaleRecommenderPolicies> ScaleRecommenderPolicies;
392444
TMaybe<ui64> SubdomainVersion;
393445
bool ComputationalUnitsModified;
394446
TTenant::TPtr Tenant;

ydb/core/cms/console/console__create_tenant.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,49 @@ class TTenantsManager::TTxCreateTenant : public TTransactionBase<TTenantsManager
300300
Tenant->DatabaseQuotas.ConstructInPlace(quotas);
301301
}
302302

303+
if (rec.has_scale_recommender_policies()) {
304+
if (!Self->FeatureFlags.GetEnableScaleRecommender()) {
305+
return Error(Ydb::StatusIds::UNSUPPORTED, "Feature flag EnableScaleRecommender is off", ctx);
306+
}
307+
308+
const auto& policies = rec.scale_recommender_policies();
309+
if (policies.policies().size() > 1) {
310+
return Error(Ydb::StatusIds::BAD_REQUEST, "Currently, no more than one policy is supported at a time", ctx);
311+
}
312+
313+
if (!policies.policies().empty()) {
314+
using enum Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy_TargetTrackingPolicy::TargetCase;
315+
using enum Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy::PolicyCase;
316+
317+
const auto& policy = policies.policies()[0];
318+
switch (policy.GetPolicyCase()) {
319+
case kTargetTrackingPolicy: {
320+
const auto& targetTracking = policy.target_tracking_policy();
321+
switch (targetTracking.GetTargetCase()) {
322+
case kAverageCpuUtilizationPercent: {
323+
auto cpuUtilization = targetTracking.average_cpu_utilization_percent();
324+
if (cpuUtilization < 10 || cpuUtilization > 90) {
325+
return Error(Ydb::StatusIds::BAD_REQUEST, "Average CPU utilization target must be from 10% to 90%", ctx);
326+
}
327+
break;
328+
}
329+
case TARGET_NOT_SET:
330+
return Error(Ydb::StatusIds::BAD_REQUEST, "Target type for target tracking policy is not set", ctx);
331+
default:
332+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported target type for target tracking policy", ctx);
333+
}
334+
break;
335+
}
336+
case POLICY_NOT_SET:
337+
return Error(Ydb::StatusIds::BAD_REQUEST, "Policy type is not set", ctx);
338+
default:
339+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported policy type", ctx);
340+
}
341+
}
342+
Tenant->ScaleRecommenderPolicies.ConstructInPlace(policies);
343+
Tenant->ScaleRecommenderPoliciesConfirmed = false;
344+
}
345+
303346
if (rec.idempotency_key()) {
304347
Tenant->CreateIdempotencyKey = rec.idempotency_key();
305348
}

ydb/core/cms/console/console__scheme.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ struct Schema : NIceDb::Schema {
4949
struct DatabaseQuotas : Column<27, NScheme::NTypeIds::String> {};
5050
struct IsExternalStatisticsAggregator : Column<28, NScheme::NTypeIds::Bool> {};
5151
struct IsExternalBackupController : Column<29, NScheme::NTypeIds::Bool> {};
52+
struct ScaleRecommenderPolicies : Column<30, NScheme::NTypeIds::String> {};
5253

5354
using TKey = TableKey<Path>;
5455
using TColumns = TableColumns<Path, State, Coordinators, Mediators, PlanResolution,
5556
Issue, TxId, UserToken, SubdomainVersion, ConfirmedSubdomain, TimeCastBucketsPerMediator,
5657
Attributes, Generation, SchemeShardId, PathId, ErrorCode, IsExternalSubDomain, IsExternalHive,
5758
AreResourcesShared, SharedDomainSchemeShardId, SharedDomainPathId, IsExternalSysViewProcessor,
5859
SchemaOperationQuotas, CreateIdempotencyKey, AlterIdempotencyKey, DatabaseQuotas, IsExternalStatisticsAggregator,
59-
IsExternalBackupController>;
60+
IsExternalBackupController, ScaleRecommenderPolicies>;
6061
};
6162

6263
struct TenantPools : Table<3> {

0 commit comments

Comments
 (0)