Skip to content

Commit 94fcb4a

Browse files
vporyadkeCyberROFL
andauthored
only accept post requests in hive for effectful http operations (#30038)
Co-authored-by: Ilnaz Nizametdinov <i.nizametdinov@gmail.com>
1 parent 5966533 commit 94fcb4a

File tree

9 files changed

+262
-130
lines changed

9 files changed

+262
-130
lines changed

ydb/core/kqp/ut/query/kqp_stats_ut.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <ydb/core/base/hive.h>
12
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
23
#include <ydb/core/kqp/counters/kqp_counters.h>
34
#include <ydb/public/sdk/cpp/include/ydb-cpp-sdk/client/table/table.h>
@@ -665,7 +666,6 @@ Y_UNIT_TEST_TWIN(OneShardNonLocalExec, UseSink) {
665666
TKikimrRunner kikimr(TKikimrSettings(app).SetNodeCount(2));
666667
auto db = kikimr.GetTableClient();
667668
auto session = db.CreateSession().GetValueSync().GetSession();
668-
auto monPort = kikimr.GetTestServer().GetRuntime()->GetMonPort();
669669

670670
auto firstNodeId = kikimr.GetTestServer().GetRuntime()->GetFirstNodeId();
671671

@@ -674,22 +674,15 @@ Y_UNIT_TEST_TWIN(OneShardNonLocalExec, UseSink) {
674674
auto expectedTotalSingleNodeReqCount = counters.TotalSingleNodeReqCount->Val();
675675
auto expectedNonLocalSingleNodeReqCount = counters.NonLocalSingleNodeReqCount->Val();
676676

677-
auto drainNode = [monPort](size_t nodeId, bool undrain = false) {
678-
TNetworkAddress addr("localhost", monPort);
679-
TSocket s(addr);
680-
TString url;
677+
auto drainNode = [runtime = kikimr.GetTestServer().GetRuntime()](size_t nodeId, bool undrain = false) {
678+
auto sender = runtime->AllocateEdgeActor();
679+
IEventBase* ev = nullptr;
681680
if (undrain) {
682-
url = "/tablets/app?TabletID=72057594037968897&node=" + std::to_string(nodeId) + "&page=SetDown&down=0";
681+
ev = new TEvHive::TEvSetDown(nodeId, false);
683682
} else {
684-
url = "/tablets/app?TabletID=72057594037968897&node=" + std::to_string(nodeId) + "&page=DrainNode";
683+
ev = new TEvHive::TEvDrainNode(nodeId);
685684
}
686-
SendMinimalHttpRequest(s, "localhost", url);
687-
TSocketInput si(s);
688-
THttpInput input(&si);
689-
TString firstLine = input.FirstLine();
690-
691-
const auto httpCode = ParseHttpRetCode(firstLine);
692-
UNIT_ASSERT_VALUES_EQUAL(httpCode, 200);
685+
runtime->SendToPipe(72057594037968897, sender, ev, 0, GetPipeConfigWithRetries());
693686
};
694687

695688
auto waitTablets = [&session](size_t nodeId) mutable {
@@ -700,7 +693,7 @@ Y_UNIT_TEST_TWIN(OneShardNonLocalExec, UseSink) {
700693
.WithShardNodesInfo(true);
701694

702695
bool done = false;
703-
for (int i = 0; i < 10; i++) {
696+
for (int i = 0; i < 5; i++) {
704697
std::unordered_set<ui32> nodeIds;
705698
auto res = session.DescribeTable("Root/EightShard", describeTableSettings)
706699
.ExtractValueSync();
@@ -716,7 +709,7 @@ Y_UNIT_TEST_TWIN(OneShardNonLocalExec, UseSink) {
716709
done = true;
717710
break;
718711
}
719-
Sleep(TDuration::Seconds(1));
712+
Sleep(TDuration::Seconds(5));
720713
}
721714
UNIT_ASSERT_C(done, "unable to wait tablets move on specific node");
722715
};

ydb/core/mind/hive/hive_ut.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7838,7 +7838,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
78387838

78397839
{
78407840
NActorsProto::TRemoteHttpInfo pb;
7841-
pb.SetMethod(HTTP_METHOD_GET);
7841+
pb.SetMethod(HTTP_METHOD_POST);
78427842
pb.SetPath("/app");
78437843
auto* p1 = pb.AddQueryParams();
78447844
p1->SetKey("TabletID");
@@ -7866,7 +7866,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
78667866

78677867
{
78687868
NActorsProto::TRemoteHttpInfo pb;
7869-
pb.SetMethod(HTTP_METHOD_GET);
7869+
pb.SetMethod(HTTP_METHOD_POST);
78707870
pb.SetPath("/app");
78717871
auto* p1 = pb.AddQueryParams();
78727872
p1->SetKey("TabletID");
@@ -7914,7 +7914,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
79147914
}
79157915
{
79167916
NActorsProto::TRemoteHttpInfo pb;
7917-
pb.SetMethod(HTTP_METHOD_GET);
7917+
pb.SetMethod(HTTP_METHOD_POST);
79187918
pb.SetPath("/app");
79197919
auto* p1 = pb.AddQueryParams();
79207920
p1->SetKey("TabletID");
@@ -7943,7 +7943,7 @@ Y_UNIT_TEST_SUITE(THiveTest) {
79437943

79447944
{
79457945
NActorsProto::TRemoteHttpInfo pb;
7946-
pb.SetMethod(HTTP_METHOD_GET);
7946+
pb.SetMethod(HTTP_METHOD_POST);
79477947
pb.SetPath("/app");
79487948
auto* p1 = pb.AddQueryParams();
79497949
p1->SetKey("TabletID");

ydb/core/mind/hive/monitoring.cpp

Lines changed: 220 additions & 85 deletions
Large diffs are not rendered by default.

ydb/core/mind/hive/monitoring.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ class TLoggedMonTransaction {
1818
void WriteOperation(NIceDb::TNiceDb& db, const NJson::TJsonValue& op);
1919
};
2020

21+
TCgiParameters GetParams(const NMon::TEvRemoteHttpInfo* ev);
22+
2123
}
2224
}

ydb/core/testlib/test_client.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,9 +3120,10 @@ namespace Tests {
31203120
return FlatQuery(runtime, mkql, opts, result);
31213121
}
31223122

3123-
TString TClient::SendTabletMonQuery(TTestActorRuntime* runtime, ui64 tabletId, TString query) {
3123+
template <typename... TArgs>
3124+
TString TClient::SendTabletMonQuery(TTestActorRuntime* runtime, ui64 tabletId, TArgs&&... args) {
31243125
TActorId sender = runtime->AllocateEdgeActor(0);
3125-
ForwardToTablet(*runtime, tabletId, sender, new NActors::NMon::TEvRemoteHttpInfo(query), 0);
3126+
ForwardToTablet(*runtime, tabletId, sender, new NActors::NMon::TEvRemoteHttpInfo(args...), 0);
31263127
TAutoPtr<IEventHandle> handle;
31273128
// Timeout for DEBUG purposes only
31283129
runtime->GrabEdgeEvent<NMon::TEvRemoteJsonInfoRes>(handle);
@@ -3136,7 +3137,7 @@ namespace Tests {
31363137
ui64 hive = ChangeStateStorage(Tests::Hive, Domain);
31373138
TInstant deadline = TInstant::Now() + TIMEOUT;
31383139
while (TInstant::Now() <= deadline) {
3139-
TString res = SendTabletMonQuery(runtime, hive, TString("/app?page=SetDown&node=") + ToString(nodeId) + "&down=" + (up ? "0" : "1"));
3140+
TString res = SendTabletMonQuery(runtime, hive, TString("/app?page=SetDown&node=") + ToString(nodeId) + "&down=" + (up ? "0" : "1"), HTTP_METHOD_POST);
31403141
if (!res.empty() && !res.Contains("Error"))
31413142
return res;
31423143

@@ -3148,7 +3149,7 @@ namespace Tests {
31483149
TString TClient::KickNodeInHive(TTestActorRuntime* runtime, ui32 nodeIdx) {
31493150
ui32 nodeId = runtime->GetNodeId(nodeIdx);
31503151
ui64 hive = ChangeStateStorage(Tests::Hive, Domain);
3151-
return SendTabletMonQuery(runtime, hive, TString("/app?page=KickNode&node=") + ToString(nodeId));
3152+
return SendTabletMonQuery(runtime, hive, TString("/app?page=KickNode&node=") + ToString(nodeId), HTTP_METHOD_POST);
31523153
}
31533154

31543155
bool TClient::WaitForTabletAlive(TTestActorRuntime* runtime, ui64 tabletId, bool leader, TDuration timeout) {

ydb/core/testlib/test_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ namespace Tests {
708708
TAutoPtr<NMsgBusProxy::TBusResponse> HiveCreateTablet(ui32 domainUid, ui64 owner, ui64 owner_index, TTabletTypes::EType tablet_type,
709709
const TVector<ui32>& allowed_node_ids, const TVector<TSubDomainKey>& allowed_domains = {}, const TChannelsBindings& binding = {});
710710

711-
TString SendTabletMonQuery(TTestActorRuntime* runtime, ui64 tabletId, TString query);
711+
template <typename... TArgs>
712+
TString SendTabletMonQuery(TTestActorRuntime* runtime, ui64 tabletId, TArgs&&... args);
712713
TString MarkNodeInHive(TTestActorRuntime* runtime, ui32 nodeIdx, bool up);
713714
TString KickNodeInHive(TTestActorRuntime* runtime, ui32 nodeIdx);
714715
bool WaitForTabletAlive(TTestActorRuntime* runtime, ui64 tabletId, bool leader, TDuration timeout);

ydb/core/viewer/tests/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,31 +1510,31 @@ def test_security(cls):
15101510
'Cookie': 'ydb_session_id=' + cls.database_session_id,
15111511
})
15121512

1513-
result['down_node_root'] = cls.get_viewer("/tablets/app", params={
1513+
result['down_node_root'] = cls.post_viewer("/tablets/app", params={
15141514
'TabletID': '72057594037968897',
15151515
'page': 'SetDown',
15161516
'node': '1',
15171517
'down': '0',
15181518
}, headers={
15191519
'Cookie': 'ydb_session_id=' + cls.root_session_id,
15201520
})
1521-
result['down_node_monitoring'] = cls.get_viewer("/tablets/app", params={
1521+
result['down_node_monitoring'] = cls.post_viewer("/tablets/app", params={
15221522
'TabletID': '72057594037968897',
15231523
'page': 'SetDown',
15241524
'node': '1',
15251525
'down': '0',
15261526
}, headers={
15271527
'Cookie': 'ydb_session_id=' + cls.monitoring_session_id,
15281528
})
1529-
result['down_node_viewer'] = cls.get_viewer("/tablets/app", params={
1529+
result['down_node_viewer'] = cls.post_viewer("/tablets/app", params={
15301530
'TabletID': '72057594037968897',
15311531
'page': 'SetDown',
15321532
'node': '1',
15331533
'down': '0',
15341534
}, headers={
15351535
'Cookie': 'ydb_session_id=' + cls.viewer_session_id,
15361536
})
1537-
result['down_node_database'] = cls.get_viewer("/tablets/app", params={
1537+
result['down_node_database'] = cls.post_viewer("/tablets/app", params={
15381538
'TabletID': '72057594037968897',
15391539
'page': 'SetDown',
15401540
'node': '1',

ydb/tests/library/clients/kikimr_http_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import logging
44

5-
from six.moves.urllib.request import urlopen
5+
from six.moves.urllib.request import urlopen, Request
66
from six.moves.urllib.parse import urlencode
77

88
logger = logging.getLogger()
@@ -20,12 +20,12 @@ def __init__(self, server, mon_port, hive_id=DEFAULT_HIVE_ID):
2020
hive_id=self.__hive_id
2121
)
2222

23-
def __get(self, url, timeout):
24-
u = urlopen(url, timeout=TIMEOUT)
23+
def __post(self, url, timeout):
24+
u = urlopen(Request(url, method='POST'), timeout=TIMEOUT)
2525
u.read()
2626

2727
def rebalance_all_tablets(self):
28-
self.__get(
28+
self.__post(
2929
self.__url + '&page=Rebalance',
3030
timeout=TIMEOUT
3131
)
@@ -39,7 +39,7 @@ def change_tablet_group(self, tablet_id, channels=()):
3939
if channels:
4040
url_lst.append('channel=' + ','.join(map(str, channels)))
4141

42-
self.__get('&'.join(url_lst), timeout=TIMEOUT)
42+
self.__post('&'.join(url_lst), timeout=TIMEOUT)
4343

4444
def change_tablet_group_by_tablet_type(self, tablet_type, percent=None, channels=()):
4545
url_lst = [
@@ -53,17 +53,17 @@ def change_tablet_group_by_tablet_type(self, tablet_type, percent=None, channels
5353
)
5454
if channels:
5555
url_lst.append('channel=' + ','.join(map(str, channels)))
56-
self.__get('&'.join(url_lst), timeout=TIMEOUT)
56+
self.__post('&'.join(url_lst), timeout=TIMEOUT)
5757

5858
def kick_tablets_from_node(self, node_id):
59-
self.__get(
59+
self.__post(
6060
self.__url + "&page=KickNode&node={node}".format(node=node_id),
6161
timeout=TIMEOUT
6262
)
6363

6464
def block_node(self, node_id, block=True):
6565
block = '1' if block else '0'
66-
self.__get(
66+
self.__post(
6767
self.__url + "&page=SetDown&node={node}&down={down}".format(node=node_id, down=block),
6868
timeout=TIMEOUT
6969
)
@@ -72,7 +72,7 @@ def unblock_node(self, node_id):
7272
self.block_node(node_id, block=False)
7373

7474
def change_tablet_weight(self, tablet_id, tablet_weight):
75-
self.__get(
75+
self.__post(
7676
self.__url + "&page=UpdateResources&tablet={tablet}&kv={size}".format(
7777
tablet=tablet_id,
7878
size=tablet_weight
@@ -81,7 +81,7 @@ def change_tablet_weight(self, tablet_id, tablet_weight):
8181
)
8282

8383
def change_tablet_cpu_usage(self, tablet_id, cpu_usage):
84-
self.__get(
84+
self.__post(
8585
self.__url + "&page=UpdateResources&tablet={tablet}&cpu={size}".format(
8686
tablet=tablet_id,
8787
size=cpu_usage
@@ -93,21 +93,21 @@ def set_min_scatter_to_balance(self, min_scatter_to_balance=101):
9393
"""
9494
min_scatter_to_balance=101 -- effectively disables auto rebalancing
9595
"""
96-
self.__get(
96+
self.__post(
9797
self.__url + "&page=Settings&minScatterToBalance={min_scatter_to_balance}".format(
9898
min_scatter_to_balance=min_scatter_to_balance), timeout=TIMEOUT
9999
)
100100

101101
def set_max_scheduled_tablets(self, max_scheduled_tablets=10):
102-
self.__get(
102+
self.__post(
103103
self.__url + "&page=Settings&maxScheduledTablets={max_scheduled_tablets}".format(
104104
max_scheduled_tablets=max_scheduled_tablets
105105
),
106106
timeout=TIMEOUT
107107
)
108108

109109
def set_max_boot_batch_size(self, max_boot_batch_size=10):
110-
self.__get(
110+
self.__post(
111111
self.__url + "&page=Settings&maxBootBatchSize={max_boot_batch_size}".format(
112112
max_boot_batch_size=max_boot_batch_size
113113
),

ydb/tests/library/sqs/test_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,12 @@ def _kick_tablets_from_node(self, node_index):
624624
mon_port = self._get_mon_port(0)
625625

626626
toggle_down_url = 'http://localhost:{}/tablets/app?TabletID=72057594037968897&node={}&page=SetDown&down=1'.format(mon_port, node_index + 1)
627-
toggle_down_reply = requests.get(toggle_down_url)
627+
toggle_down_reply = requests.post(toggle_down_url)
628628
assert_that(toggle_down_reply.status_code, equal_to(200))
629629
logging.debug('Toggle down reply: {}'.format(toggle_down_reply.text))
630630

631631
kick_url = 'http://localhost:{}/tablets/app?TabletID=72057594037968897&node={}&page=KickNode'.format(mon_port, node_index + 1)
632-
kick_reply = requests.get(kick_url)
632+
kick_reply = requests.post(kick_url)
633633
assert_that(kick_reply.status_code, equal_to(200))
634634
logging.debug('Kick reply: {}'.format(kick_reply.text))
635635

@@ -644,7 +644,7 @@ def _enable_tablets_on_node(self, node_index):
644644
try:
645645
mon_port = self._get_mon_port(0)
646646
toggle_up_url = 'http://localhost:{}/tablets/app?TabletID=72057594037968897&node={}&page=SetDown&down=0'.format(mon_port, node_index + 1)
647-
toggle_up_reply = requests.get(toggle_up_url)
647+
toggle_up_reply = requests.post(toggle_up_url)
648648

649649
logging.debug('Toggle up reply: {}'.format(toggle_up_reply.text))
650650
if toggle_up_reply.status_code != 200 and attempts:

0 commit comments

Comments
 (0)