Skip to content

Commit 2c83dd6

Browse files
committed
YQ WM added unit tests for sls disable (#8687)
1 parent fac9434 commit 2c83dd6

File tree

6 files changed

+117
-5
lines changed

6 files changed

+117
-5
lines changed

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
22
#include <ydb/core/kqp/ut/common/columnshard.h>
3+
#include <ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.h>
34
#include <ydb/core/tx/columnshard/hooks/testing/controller.h>
45
#include <ydb/core/formats/arrow/arrow_helpers.h>
56
#include <ydb/core/tx/tx_proxy/proxy.h>

ydb/core/kqp/ut/scheme/ya.make

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PEERDIR(
2222
library/cpp/threading/local_executor
2323
ydb/core/kqp
2424
ydb/core/kqp/ut/common
25+
ydb/core/kqp/workload_service/ut/common
2526
ydb/core/tx/columnshard/hooks/testing
2627
ydb/library/yql/sql/pg
2728
ydb/library/yql/parser/pg_wrapper

ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.cpp

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
237237
void SetLoggerSettings(TServerSettings& serverSettings) const {
238238
auto loggerInitializer = [](TTestActorRuntime& runtime) {
239239
runtime.SetLogPriority(NKikimrServices::KQP_WORKLOAD_SERVICE, NLog::EPriority::PRI_TRACE);
240-
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_DEBUG);
240+
runtime.SetLogPriority(NKikimrServices::KQP_SESSION, NLog::EPriority::PRI_TRACE);
241241
};
242242

243243
serverSettings.SetLoggerInitializer(loggerInitializer);
@@ -254,16 +254,50 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
254254
.SetAppConfig(appConfig)
255255
.SetFeatureFlags(appConfig.GetFeatureFlags());
256256

257+
if (Settings_.CreateSampleTenants_) {
258+
serverSettings
259+
.SetDynamicNodeCount(2)
260+
.AddStoragePoolType(Settings_.GetDedicatedTenantName())
261+
.AddStoragePoolType(Settings_.GetSharedTenantName());
262+
}
263+
257264
SetLoggerSettings(serverSettings);
258265

259266
return serverSettings;
260267
}
261268

269+
void SetupResourcesTenant(Ydb::Cms::CreateDatabaseRequest& request, Ydb::Cms::StorageUnits* storage, const TString& name) {
270+
request.set_path(name);
271+
storage->set_unit_kind(name);
272+
storage->set_count(1);
273+
}
274+
275+
void CreateTenants() {
276+
{ // Dedicated
277+
Ydb::Cms::CreateDatabaseRequest request;
278+
SetupResourcesTenant(request, request.mutable_resources()->add_storage_units(), Settings_.GetDedicatedTenantName());
279+
Tenants_->CreateTenant(std::move(request));
280+
}
281+
282+
{ // Shared
283+
Ydb::Cms::CreateDatabaseRequest request;
284+
SetupResourcesTenant(request, request.mutable_shared_resources()->add_storage_units(), Settings_.GetSharedTenantName());
285+
Tenants_->CreateTenant(std::move(request));
286+
}
287+
288+
{ // Serverless
289+
Ydb::Cms::CreateDatabaseRequest request;
290+
request.set_path(Settings_.GetServerlessTenantName());
291+
request.mutable_serverless_resources()->set_shared_database_path(Settings_.GetSharedTenantName());
292+
Tenants_->CreateTenant(std::move(request));
293+
}
294+
}
295+
262296
void InitializeServer() {
263297
ui32 grpcPort = PortManager_.GetPort();
264298
TServerSettings serverSettings = GetServerSettings(grpcPort);
265299

266-
Server_ = std::make_unique<TServer>(serverSettings);
300+
Server_ = MakeIntrusive<TServer>(serverSettings);
267301
Server_->EnableGRpc(grpcPort);
268302
GetRuntime()->SetDispatchTimeout(FUTURE_WAIT_TIMEOUT);
269303

@@ -276,10 +310,15 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
276310

277311
TableClient_ = std::make_unique<NYdb::NTable::TTableClient>(*YdbDriver_, NYdb::NTable::TClientSettings().AuthToken("user@" BUILTIN_SYSTEM_DOMAIN));
278312
TableClientSession_ = std::make_unique<NYdb::NTable::TSession>(TableClient_->CreateSession().GetValueSync().GetSession());
313+
314+
Tenants_ = std::make_unique<TTenants>(Server_);
315+
if (Settings_.CreateSampleTenants_) {
316+
CreateTenants();
317+
}
279318
}
280319

281320
void CreateSamplePool() const {
282-
if (!Settings_.EnableResourcePools_) {
321+
if (!Settings_.EnableResourcePools_ || Settings_.CreateSampleTenants_) {
283322
return;
284323
}
285324

@@ -488,7 +527,7 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
488527
request->SetType(NKikimrKqp::QUERY_TYPE_SQL_GENERIC_QUERY);
489528
request->SetAction(NKikimrKqp::QUERY_ACTION_EXECUTE);
490529
request->SetDatabase(Settings_.DomainName_);
491-
request->SetPoolId(settings.PoolId_);
530+
request->SetPoolId(*settings.PoolId_);
492531

493532
return event;
494533
}
@@ -529,9 +568,10 @@ class TWorkloadServiceYdbSetup : public IYdbSetup {
529568
const TYdbSetupSettings Settings_;
530569

531570
TPortManager PortManager_;
532-
std::unique_ptr<TServer> Server_;
571+
TServer::TPtr Server_;
533572
std::unique_ptr<TClient> Client_;
534573
std::unique_ptr<TDriver> YdbDriver_;
574+
std::unique_ptr<TTenants> Tenants_;
535575

536576
std::unique_ptr<NYdb::NTable::TTableClient> TableClient_;
537577
std::unique_ptr<NYdb::NTable::TSession> TableClientSession_;
@@ -580,6 +620,18 @@ TIntrusivePtr<IYdbSetup> TYdbSetupSettings::Create() const {
580620
return MakeIntrusive<TWorkloadServiceYdbSetup>(*this);
581621
}
582622

623+
TString TYdbSetupSettings::GetDedicatedTenantName() const {
624+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-dedicated";
625+
}
626+
627+
TString TYdbSetupSettings::GetSharedTenantName() const {
628+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-shared";
629+
}
630+
631+
TString TYdbSetupSettings::GetServerlessTenantName() const {
632+
return TStringBuilder() << CanonizePath(DomainName_) << "/test-serverless";
633+
}
634+
583635
//// IYdbSetup
584636

585637
void IYdbSetup::WaitFor(TDuration timeout, TString description, std::function<bool(TString&)> callback) {

ydb/core/kqp/workload_service/ut/common/kqp_workload_service_ut_common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct TQueryRunnerSettings {
2626
FLUENT_SETTING_DEFAULT(ui32, NodeIndex, 0);
2727
FLUENT_SETTING_DEFAULT(TString, PoolId, "");
2828
FLUENT_SETTING_DEFAULT(TString, UserSID, "user@" BUILTIN_SYSTEM_DOMAIN);
29+
FLUENT_SETTING_DEFAULT(TString, Database, "");
2930

3031
// Runner settings
3132
FLUENT_SETTING_DEFAULT(bool, HangUpDuringExecution, false);
@@ -66,6 +67,7 @@ struct TYdbSetupSettings {
6667
// Cluster settings
6768
FLUENT_SETTING_DEFAULT(ui32, NodeCount, 1);
6869
FLUENT_SETTING_DEFAULT(TString, DomainName, "Root");
70+
FLUENT_SETTING_DEFAULT(bool, CreateSampleTenants, false);
6971
FLUENT_SETTING_DEFAULT(bool, EnableResourcePools, true);
7072

7173
// Default pool settings
@@ -77,6 +79,10 @@ struct TYdbSetupSettings {
7779
FLUENT_SETTING_DEFAULT(double, DatabaseLoadCpuThreshold, -1);
7880

7981
TIntrusivePtr<IYdbSetup> Create() const;
82+
83+
TString GetDedicatedTenantName() const;
84+
TString GetSharedTenantName() const;
85+
TString GetServerlessTenantName() const;
8086
};
8187

8288
class IYdbSetup : public TThrRefBase {
@@ -132,6 +138,12 @@ struct TSampleQueries {
132138
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Request timeout exceeded, cancelling after");
133139
}
134140

141+
template <typename TResult>
142+
static void CheckNotFound(const TResult& result, const TString& poolId) {
143+
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), NYdb::EStatus::NOT_FOUND, result.GetIssues().ToString());
144+
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), TStringBuilder() << "Resource pool " << poolId << " not found or you don't have access permissions");
145+
}
146+
135147
struct TSelect42 {
136148
static constexpr char Query[] = "SELECT 42;";
137149

ydb/core/testlib/test_client.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,50 @@ namespace Tests {
26942694
return Server->DynamicNodes();
26952695
}
26962696

2697+
void TTenants::CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes, TDuration timeout) {
2698+
const TString path = request.path();
2699+
const bool serverless = request.has_serverless_resources();
2700+
2701+
// Create new tenant
2702+
auto& runtime = *Server->GetRuntime();
2703+
const auto result = NKikimr::NRpcService::DoLocalRpc<NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Cms::CreateDatabaseRequest, Ydb::Cms::CreateDatabaseResponse>>(
2704+
std::move(request), "", "", runtime.GetActorSystem(0), true
2705+
).ExtractValueSync();
2706+
2707+
if (result.operation().status() != Ydb::StatusIds::SUCCESS) {
2708+
NYql::TIssues issues;
2709+
NYql::IssuesFromMessage(result.operation().issues(), issues);
2710+
ythrow yexception() << "Failed to create tenant " << path << ", " << result.operation().status() << ", reason:\n" << issues.ToString();
2711+
}
2712+
2713+
// Run new tenant
2714+
if (!serverless) {
2715+
Run(path, nodes);
2716+
}
2717+
2718+
// Wait tenant is up
2719+
Ydb::Cms::GetDatabaseStatusResult getTenantResult;
2720+
const TActorId edgeActor = runtime.AllocateEdgeActor();
2721+
const TInstant start = TInstant::Now();
2722+
while (TInstant::Now() - start <= timeout) {
2723+
auto getTenantRequest = std::make_unique<NConsole::TEvConsole::TEvGetTenantStatusRequest>();
2724+
getTenantRequest->Record.MutableRequest()->set_path(path);
2725+
runtime.SendToPipe(MakeConsoleID(), edgeActor, getTenantRequest.release(), 0, GetPipeConfigWithRetries());
2726+
2727+
auto response = runtime.GrabEdgeEvent<NConsole::TEvConsole::TEvGetTenantStatusResponse>(edgeActor, timeout);
2728+
if (!response) {
2729+
ythrow yexception() << "Waiting CMS get tenant response timeout. Last tenant description:\n" << getTenantResult.DebugString();
2730+
}
2731+
response->Get()->Record.GetResponse().operation().result().UnpackTo(&getTenantResult);
2732+
if (getTenantResult.state() == Ydb::Cms::GetDatabaseStatusResult::RUNNING) {
2733+
return;
2734+
}
2735+
2736+
Sleep(TDuration::MilliSeconds(100));
2737+
}
2738+
ythrow yexception() << "Waiting tenant status RUNNING timeout. Spent time " << TInstant::Now() - start << " exceeds limit " << timeout << ". Last tenant description:\n" << getTenantResult.DebugString();
2739+
}
2740+
26972741
TVector<ui32> &TTenants::Nodes(const TString &name) {
26982742
return Tenants[name];
26992743
}

ydb/core/testlib/test_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,8 @@ namespace Tests {
630630
ui32 Availabe() const;
631631
ui32 Capacity() const;
632632

633+
void CreateTenant(Ydb::Cms::CreateDatabaseRequest request, ui32 nodes = 1, TDuration timeout = TDuration::Seconds(30));
634+
633635
private:
634636
TVector<ui32>& Nodes(const TString &name);
635637
void StopNode(const TString /*name*/, ui32 nodeIdx);

0 commit comments

Comments
 (0)