@@ -201,6 +201,48 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
201
201
return Error (Ydb::StatusIds::BAD_REQUEST, " Data size soft quota cannot be larger than hard quota" , ctx);
202
202
}
203
203
}
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
+ }
204
246
205
247
// Check attributes.
206
248
THashSet<TString> attrNames;
@@ -274,6 +316,11 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
274
316
updateSubdomainVersion = true ;
275
317
}
276
318
319
+ if (rec.has_scale_recommender_policies ()) {
320
+ ScaleRecommenderPolicies.ConstructInPlace (rec.scale_recommender_policies ());
321
+ Self->DbUpdateScaleRecommenderPolicies (Tenant, *ScaleRecommenderPolicies, txc, ctx);
322
+ }
323
+
277
324
if (rec.idempotency_key () || Tenant->AlterIdempotencyKey ) {
278
325
Tenant->AlterIdempotencyKey = rec.idempotency_key ();
279
326
Self->DbUpdateTenantAlterIdempotencyKey (Tenant, Tenant->AlterIdempotencyKey , txc, ctx);
@@ -367,6 +414,10 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
367
414
if (DatabaseQuotas) {
368
415
Tenant->DatabaseQuotas .ConstructInPlace (*DatabaseQuotas);
369
416
}
417
+ if (ScaleRecommenderPolicies) {
418
+ Tenant->ScaleRecommenderPolicies .ConstructInPlace (*ScaleRecommenderPolicies);
419
+ Tenant->ScaleRecommenderPoliciesConfirmed = false ;
420
+ }
370
421
if (SubdomainVersion) {
371
422
Tenant->SubdomainVersion = *SubdomainVersion;
372
423
}
@@ -389,6 +440,7 @@ class TTenantsManager::TTxAlterTenant : public TTransactionBase<TTenantsManager>
389
440
THashMap<TString, ui64> PoolsToAdd;
390
441
TMaybe<Ydb::Cms::SchemaOperationQuotas> SchemaOperationQuotas;
391
442
TMaybe<Ydb::Cms::DatabaseQuotas> DatabaseQuotas;
443
+ TMaybe<Ydb::Cms::ScaleRecommenderPolicies> ScaleRecommenderPolicies;
392
444
TMaybe<ui64> SubdomainVersion;
393
445
bool ComputationalUnitsModified;
394
446
TTenant::TPtr Tenant;
0 commit comments