5
5
#include < ydb/library/grpc/server/actors/logger.h>
6
6
#include < library/cpp/http/misc/parsed_request.h>
7
7
#include < library/cpp/json/json_writer.h>
8
+ #include < library/cpp/logger/global/global.h>
8
9
#include < library/cpp/resource/resource.h>
9
10
#include < library/cpp/testing/unittest/registar.h>
10
11
@@ -81,10 +82,10 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
81
82
InitAll ();
82
83
}
83
84
84
- void InitAll (bool yandexCloudMode = true ) {
85
+ void InitAll (bool yandexCloudMode = true , bool enableMetering = false ) {
85
86
AccessServicePort = PortManager.GetPort (8443 );
86
87
AccessServiceEndpoint = " 127.0.0.1:" + ToString (AccessServicePort);
87
- InitKikimr (yandexCloudMode);
88
+ InitKikimr (yandexCloudMode, enableMetering );
88
89
InitAccessServiceService ();
89
90
InitHttpServer (yandexCloudMode);
90
91
}
@@ -365,7 +366,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
365
366
return resultSet;
366
367
}
367
368
368
- void InitKikimr (bool yandexCloudMode) {
369
+ void InitKikimr (bool yandexCloudMode, bool enableMetering ) {
369
370
AuthFactory = std::make_shared<TIamAuthFactory>();
370
371
NKikimrConfig::TAppConfig appConfig;
371
372
appConfig.MutablePQConfig ()->SetTopicsAreFirstClassCitizen (true );
@@ -379,6 +380,21 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
379
380
appConfig.MutableSqsConfig ()->SetYandexCloudMode (yandexCloudMode);
380
381
appConfig.MutableSqsConfig ()->SetEnableDeadLetterQueues (true );
381
382
383
+ if (enableMetering) {
384
+ auto & sqsConfig = *appConfig.MutableSqsConfig ();
385
+
386
+ sqsConfig.SetMeteringFlushingIntervalMs (100 );
387
+ sqsConfig.SetMeteringLogFilePath (" sqs_metering.log" );
388
+ TFsPath (sqsConfig.GetMeteringLogFilePath ()).DeleteIfExists ();
389
+
390
+ sqsConfig.AddMeteringCloudNetCidr (" 5.45.196.0/24" );
391
+ sqsConfig.AddMeteringCloudNetCidr (" 2a0d:d6c0::/29" );
392
+ sqsConfig.AddMeteringYandexNetCidr (" 127.0.0.0/8" );
393
+ sqsConfig.AddMeteringYandexNetCidr (" 5.45.217.0/24" );
394
+
395
+ DoInitGlobalLog (CreateOwningThreadedLogBackend (sqsConfig.GetMeteringLogFilePath (), 0 ));
396
+ }
397
+
382
398
auto limit = appConfig.MutablePQConfig ()->AddValidRetentionLimits ();
383
399
limit->SetMinPeriodSeconds (0 );
384
400
limit->SetMaxPeriodSeconds (TDuration::Days (1 ).Seconds ());
@@ -414,6 +430,13 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
414
430
ActorRuntime->SetLogPriority (NActorsServices::EServiceCommon::HTTP, NLog::PRI_DEBUG);
415
431
ActorRuntime->SetLogPriority (NKikimrServices::TICKET_PARSER, NLog::PRI_TRACE);
416
432
433
+ if (enableMetering) {
434
+ ActorRuntime->RegisterService (
435
+ NSQS::MakeSqsMeteringServiceID (),
436
+ ActorRuntime->Register(NSQS::CreateSqsMeteringService())
437
+ );
438
+ }
439
+
417
440
NYdb::TClient client (*(KikimrServer->ServerSettings ));
418
441
UNIT_ASSERT_VALUES_EQUAL (NMsgBusProxy::MSTATUS_OK,
419
442
client.AlterUserAttributes (" /" , " Root" , {{" folder_id" , " folder4" },
@@ -477,7 +500,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
477
500
);
478
501
479
502
client.MkDir (" /Root/SQS" , " .FIFO" );
480
- client.CreateTable (" /Root/SQS/.FIFO" ,
503
+ client.CreateTable (" /Root/SQS/.FIFO" ,
481
504
" Name: \" Messages\" "
482
505
" Columns { Name: \" QueueIdNumberHash\" Type: \" Uint64\" }"
483
506
" Columns { Name: \" QueueIdNumber\" Type: \" Uint64\" }"
@@ -537,7 +560,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
537
560
" KeyColumnNames: [\" Account\" , \" QueueName\" , \" EventType\" ]"
538
561
);
539
562
540
- auto stateTableCommon =
563
+ auto stateTableCommon =
541
564
" Name: \" State\" "
542
565
" Columns { Name: \" QueueIdNumberHash\" Type: \" Uint64\" }"
543
566
" Columns { Name: \" QueueIdNumber\" Type: \" Uint64\" }"
@@ -581,7 +604,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
581
604
" KeyColumnNames: [\" QueueIdNumberAndShardHash\" , \" QueueIdNumber\" , \" Shard\" , \" Offset\" ]"
582
605
);
583
606
584
- auto sentTimestampIdxCommonColumns=
607
+ auto sentTimestampIdxCommonColumns=
585
608
" Columns { Name: \" QueueIdNumberAndShardHash\" Type: \" Uint64\" }"
586
609
" Columns { Name: \" QueueIdNumber\" Type: \" Uint64\" }"
587
610
" Columns { Name: \" Shard\" Type: \" Uint32\" }"
@@ -700,7 +723,7 @@ class THttpProxyTestMock : public NUnitTest::TBaseFixture {
700
723
folderServiceConfig.SetEnable (false );
701
724
actorId = as->Register (NKikimr::NFolderService::CreateFolderServiceActor (folderServiceConfig, " cloud4" ));
702
725
as->RegisterLocalService (NFolderService::FolderServiceActorId (), actorId);
703
-
726
+
704
727
actorId = as->Register (NKikimr::NFolderService::CreateFolderServiceActor (folderServiceConfig, " cloud4" ));
705
728
as->RegisterLocalService (NSQS::MakeSqsFolderServiceID (), actorId);
706
729
@@ -766,3 +789,9 @@ class THttpProxyTestMockForSQS : public THttpProxyTestMock {
766
789
InitAll (false );
767
790
}
768
791
};
792
+
793
+ class THttpProxyTestMockWithMetering : public THttpProxyTestMock {
794
+ void SetUp (NUnitTest::TTestContext&) override {
795
+ InitAll (true , true );
796
+ }
797
+ };
0 commit comments