Skip to content

Commit fb228ee

Browse files
authored
Support configuring scale recommender policies in console (#11798)
1 parent 0d355e6 commit fb228ee

File tree

12 files changed

+616
-17
lines changed

12 files changed

+616
-17
lines changed

ydb/core/base/hive.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace NKikimr {
5050
EvUpdateDomain,
5151
EvRequestTabletDistribution,
5252
EvRequestScaleRecommendation,
53+
EvConfigureScaleRecommender,
5354

5455
// replies
5556
EvBootTabletReply = EvBootTablet + 512,
@@ -86,6 +87,7 @@ namespace NKikimr {
8687
EvUpdateDomainReply,
8788
EvResponseTabletDistribution,
8889
EvResponseScaleRecommendation,
90+
EvConfigureScaleRecommenderReply,
8991

9092
EvEnd
9193
};
@@ -891,6 +893,12 @@ namespace NKikimr {
891893

892894
struct TEvResponseScaleRecommendation : TEventPB<TEvResponseScaleRecommendation,
893895
NKikimrHive::TEvResponseScaleRecommendation, EvResponseScaleRecommendation> {};
896+
897+
struct TEvConfigureScaleRecommender : TEventPB<TEvConfigureScaleRecommender,
898+
NKikimrHive::TEvConfigureScaleRecommender, EvConfigureScaleRecommender> {};
899+
900+
struct TEvConfigureScaleRecommenderReply : TEventPB<TEvConfigureScaleRecommenderReply,
901+
NKikimrHive::TEvConfigureScaleRecommenderReply, EvConfigureScaleRecommenderReply> {};
894902
};
895903

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

ydb/core/cms/console/console__alter_tenant.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,41 @@ 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+
const auto& policies = rec.scale_recommender_policies();
208+
if (policies.policies().size() > 1) {
209+
return Error(Ydb::StatusIds::BAD_REQUEST, "Currently, no more than one policy is supported at a time", ctx);
210+
}
211+
212+
if (!policies.policies().empty()) {
213+
const auto& policy = policies.policies()[0];
214+
switch (policy.GetPolicyCase()) {
215+
case Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy::kTargetTrackingPolicy: {
216+
const auto& targetTracking = policy.target_tracking_policy();
217+
switch (targetTracking.GetTargetCase()) {
218+
case Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy_TargetTrackingPolicy::kAverageCpuUtilizationPercent: {
219+
auto cpuUtilization = targetTracking.average_cpu_utilization_percent();
220+
if (cpuUtilization < 10 || cpuUtilization > 90) {
221+
return Error(Ydb::StatusIds::BAD_REQUEST, "Average CPU utilization target must be from 10% to 90%", ctx);
222+
}
223+
break;
224+
}
225+
case Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy_TargetTrackingPolicy::TARGET_NOT_SET:
226+
return Error(Ydb::StatusIds::BAD_REQUEST, "Target type for target tracking policy is not set", ctx);
227+
default:
228+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported target type for target tracking policy", ctx);
229+
}
230+
break;
231+
}
232+
case Ydb::Cms::ScaleRecommenderPolicies_ScaleRecommenderPolicy::POLICY_NOT_SET:
233+
return Error(Ydb::StatusIds::BAD_REQUEST, "Policy type is not set", ctx);
234+
default:
235+
return Error(Ydb::StatusIds::BAD_REQUEST, "Unsupported policy type", ctx);
236+
}
237+
}
238+
}
204239

205240
// Check attributes.
206241
THashSet<TString> attrNames;
@@ -274,6 +309,11 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
274309
updateSubdomainVersion = true;
275310
}
276311

312+
if (rec.has_scale_recommender_policies()) {
313+
ScaleRecommenderPolicies.ConstructInPlace(rec.scale_recommender_policies());
314+
Self->DbUpdateScaleRecommenderPolicies(Tenant, *ScaleRecommenderPolicies, txc, ctx);
315+
}
316+
277317
if (rec.idempotency_key() || Tenant->AlterIdempotencyKey) {
278318
Tenant->AlterIdempotencyKey = rec.idempotency_key();
279319
Self->DbUpdateTenantAlterIdempotencyKey(Tenant, Tenant->AlterIdempotencyKey, txc, ctx);
@@ -367,6 +407,9 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
367407
if (DatabaseQuotas) {
368408
Tenant->DatabaseQuotas.ConstructInPlace(*DatabaseQuotas);
369409
}
410+
if (ScaleRecommenderPolicies) {
411+
Tenant->ScaleRecommenderPolicies.ConstructInPlace(*ScaleRecommenderPolicies);
412+
}
370413
if (SubdomainVersion) {
371414
Tenant->SubdomainVersion = *SubdomainVersion;
372415
}
@@ -389,6 +432,7 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
389432
THashMap<TString, ui64> PoolsToAdd;
390433
TMaybe<Ydb::Cms::SchemaOperationQuotas> SchemaOperationQuotas;
391434
TMaybe<Ydb::Cms::DatabaseQuotas> DatabaseQuotas;
435+
TMaybe<Ydb::Cms::ScaleRecommenderPolicies> ScaleRecommenderPolicies;
392436
TMaybe<ui64> SubdomainVersion;
393437
bool ComputationalUnitsModified;
394438
TTenant::TPtr Tenant;

ydb/core/cms/console/console__create_tenant.cpp

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

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

ydb/core/cms/console/console__scheme.h

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

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

6465
struct TenantPools : Table<3> {

0 commit comments

Comments
 (0)