Skip to content

Commit ad8b24c

Browse files
authored
25-1: Storage billing labels (ydb-platform#16739)
1 parent b3d304f commit ad8b24c

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

ydb/core/tx/schemeshard/schemeshard__serverless_storage_billing.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ struct TSchemeShard::TTxServerlessStorageBilling : public TTransactionBase<TSche
167167
}},
168168
};
169169

170+
for (const auto& [k, v] : dbRootEl->UserAttrs->Attrs) {
171+
auto label = TStringBuf(k);
172+
if (!label.SkipPrefix("label_")) {
173+
continue;
174+
}
175+
176+
json["labels"][label] = v;
177+
}
178+
170179
TStringBuilder billRecord;
171180
NJson::WriteJson(&billRecord.Out, &json, /*formatOutput=*/false, /*sortkeys=*/false);
172181
billRecord << Endl;

ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#include <ydb/core/metering/metering.h>
2+
#include <ydb/core/testlib/actors/block_events.h>
13
#include <ydb/core/tx/schemeshard/ut_helpers/helpers.h>
24
#include <ydb/core/tx/schemeshard/schemeshard_private.h>
35

4-
#include <ydb/core/metering/metering.h>
5-
66
using namespace NKikimr;
77
using namespace NSchemeShard;
88
using namespace NSchemeShardUT_Private;
@@ -263,6 +263,72 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
263263
}
264264
}
265265

266+
Y_UNIT_TEST(StorageBillingLabels) {
267+
TTestBasicRuntime runtime;
268+
TTestEnv env(runtime);
269+
ui64 txId = 100;
270+
271+
SetAllowServerlessStorageBilling(&runtime, true);
272+
TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", R"(
273+
Name: "SharedDB"
274+
)");
275+
env.TestWaitNotification(runtime, txId);
276+
277+
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
278+
Name: "SharedDB"
279+
StoragePools {
280+
Name: "pool-1"
281+
Kind: "pool-kind-1"
282+
}
283+
PlanResolution: 50
284+
Coordinators: 1
285+
Mediators: 1
286+
TimeCastBucketsPerMediator: 2
287+
ExternalSchemeShard: true
288+
)");
289+
env.TestWaitNotification(runtime, txId);
290+
291+
TestCreateExtSubDomain(runtime, ++txId, "/MyRoot", Sprintf(R"(
292+
Name: "ServerlessDB"
293+
ResourcesDomainKey {
294+
SchemeShard: %lu
295+
PathId: 2
296+
}
297+
)", TTestTxConfig::SchemeShard));
298+
env.TestWaitNotification(runtime, txId);
299+
300+
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot", R"(
301+
Name: "ServerlessDB"
302+
StoragePools {
303+
Name: "pool-1"
304+
Kind: "pool-kind-1"
305+
}
306+
PlanResolution: 50
307+
Coordinators: 1
308+
Mediators: 1
309+
TimeCastBucketsPerMediator: 2
310+
ExternalSchemeShard: true
311+
ExternalHive: false
312+
)");
313+
env.TestWaitNotification(runtime, txId);
314+
315+
TestUserAttrs(runtime, ++txId, "/MyRoot", "ServerlessDB", AlterUserAttrs({
316+
{"cloud_id", "CLOUD_ID_VAL"},
317+
{"folder_id", "FOLDER_ID_VAL"},
318+
{"database_id", "DATABASE_ID_VAL"},
319+
{"label_k", "v"},
320+
{"not_a_label_x", "y"},
321+
}));
322+
env.TestWaitNotification(runtime, txId);
323+
324+
TBlockEvents<NMetering::TEvMetering::TEvWriteMeteringJson> block(runtime);
325+
runtime.WaitFor("metering", [&]{ return block.size() >= 1; });
326+
327+
const auto& jsonStr = block[0]->Get()->MeteringJson;
328+
UNIT_ASSERT_C(jsonStr.Contains(R"("labels":{"k":"v"})"), jsonStr);
329+
UNIT_ASSERT_C(!jsonStr.Contains("not_a_label"), jsonStr);
330+
}
331+
266332
Y_UNIT_TEST(TestServerlessComputeResourcesMode) {
267333
TTestBasicRuntime runtime;
268334
TTestEnv env(runtime, TTestEnvOptions().EnableServerlessExclusiveDynamicNodes(true));

0 commit comments

Comments
 (0)