Skip to content

Commit fd1e65b

Browse files
authored
24-4-4-hotfix: Storage billing labels (#16741)
1 parent 2777dea commit fd1e65b

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

+9
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

+68-2
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;
@@ -253,6 +253,72 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
253253
}
254254
}
255255

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

0 commit comments

Comments
 (0)