Skip to content

Commit c2dac27

Browse files
authored
Use im avtorization in perf tests (#28842)
1 parent 8b44c82 commit c2dac27

File tree

2 files changed

+60
-53
lines changed

2 files changed

+60
-53
lines changed

ydb/tests/olap/lib/ydb_cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ def get_cli_path() -> str:
4040

4141
@staticmethod
4242
def get_cli_command() -> list[str]:
43-
return [
43+
result = [
4444
YdbCliHelper.get_cli_path(),
4545
'-e', YdbCluster.ydb_endpoint,
4646
'-d', f'/{YdbCluster.ydb_database}'
4747
]
48+
if YdbCluster.ydb_iam_file:
49+
result += ['--sa-key-file', YdbCluster.ydb_iam_file]
50+
return result
4851

4952
class QueryPlan:
5053
def __init__(self) -> None:

ydb/tests/olap/lib/ydb_cluster.py

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def slot(self) -> str:
6666
_cluster_info = None
6767
ydb_endpoint = get_external_param('ydb-endpoint', 'grpc://ydb-olap-testing-vla-0002.search.yandex.net:2135')
6868
ydb_database = get_external_param('ydb-db', 'olap-testing/kikimr/testing/acceptance-2').lstrip('/')
69-
ydb_mon_port = 8765
69+
ydb_mon_port = int(get_external_param('ydb-mon-port', 8765))
70+
ydb_iam_file = get_external_param('ydb-iam-file', os.getenv('YDB_IAM_FILE'))
7071
_tables_path = get_external_param('tables-path', 'olap_yatests').rstrip('/')
7172
_monitoring_urls: list[YdbCluster.MonitoringUrl] = None
7273
_dyn_nodes_count: Optional[int] = None
@@ -108,6 +109,8 @@ def _get_service_url(cls):
108109
def get_cluster_nodes(cls, path: Optional[str] = None, db_only: bool = False,
109110
role: Optional[YdbCluster.Node.Role] = None
110111
) -> list[YdbCluster.Node]:
112+
if cls.ydb_mon_port == 0:
113+
return []
111114

112115
# Получаем таймаут из переменной окружения, как в wait_ydb_alive
113116
timeout = int(os.getenv('WAIT_CLUSTER_ALIVE_TIMEOUT', 2 * 60)) # По умолчанию 20 минут
@@ -203,7 +206,7 @@ def get_cluster_info(cls):
203206
@staticmethod
204207
def _create_ydb_driver(endpoint, database, oauth=None, iam_file=None):
205208
credentials = None
206-
LOGGER.info(f"Connecting to {endpoint} to {database} ydb_access_token is set {oauth is not None}")
209+
LOGGER.info(f"Connecting to {endpoint} to {database} ydb_access_token is set {oauth is not None}, iam file path is {iam_file}")
207210

208211
if oauth is not None:
209212
credentials = ydb.AccessTokenCredentials(oauth)
@@ -239,7 +242,7 @@ def reset(cls, ydb_endpoint, ydb_database, ydb_mon_port, dyn_nodes_count):
239242
def get_ydb_driver(cls):
240243
if cls._ydb_driver is None:
241244
cls._ydb_driver = cls._create_ydb_driver(
242-
cls.ydb_endpoint, cls.ydb_database, oauth=os.getenv('OLAP_YDB_OAUTH', None)
245+
cls.ydb_endpoint, cls.ydb_database, oauth=os.getenv('OLAP_YDB_OAUTH', None), iam_file=cls.ydb_iam_file
243246
)
244247
return cls._ydb_driver
245248

@@ -294,13 +297,13 @@ def _join_errors(log_level: int, errors: list[str]):
294297
@allure.step('Execute scan query')
295298
def execute_single_result_query(cls, query, timeout=10):
296299
allure.attach(query, 'query', attachment_type=allure.attachment_type.TEXT)
297-
query = ydb.ScanQuery(query, {})
298300
settings = ydb.BaseRequestSettings()
299301
settings = settings.with_timeout(timeout)
300302
try:
301-
it = cls.get_ydb_driver().table_client.scan_query(query, settings=settings)
303+
session = ydb.query.QueryClientSync(cls.get_ydb_driver()).session().create()
304+
it = session.execute(query, settings=settings)
302305
result = next(it)
303-
return result.result_set.rows[0][0]
306+
return result.rows[0][0]
304307
except BaseException:
305308
LOGGER.error("Cannot connect to YDB")
306309
raise
@@ -363,53 +366,54 @@ def _check_node(n: YdbCluster.Node):
363366
errors = []
364367
warnings = []
365368
try:
366-
nodes = cls.get_cluster_nodes(db_only=True)
367-
expected_nodes_count = cls.get_dyn_nodes_count()
368-
nodes_count = len(nodes)
369-
if expected_nodes_count:
370-
LOGGER.debug(f'Expected nodes count: {expected_nodes_count}')
371-
if nodes_count < expected_nodes_count:
372-
errors.append(f"{expected_nodes_count - nodes_count} nodes from {expected_nodes_count} don't alive")
373-
ok_node_count = 0
374-
node_errors = []
375-
for n in nodes:
376-
error = _check_node(n)
377-
if error:
378-
node_errors.append(error)
379-
else:
380-
ok_node_count += 1
381-
if ok_node_count < nodes_count:
382-
errors.append(f'Only {ok_node_count} from {nodes_count} dynnodes are ok: {",".join(node_errors)}')
383-
paths_to_balance = []
384-
if isinstance(balanced_paths, str):
385-
paths_to_balance += cls.get_tables(balanced_paths)
386-
elif isinstance(balanced_paths, list):
387-
for path in balanced_paths:
388-
paths_to_balance += cls.get_tables(path)
389-
for p in paths_to_balance:
390-
table_nodes = cls.get_cluster_nodes(p)
391-
min = None
392-
max = None
369+
if cls.ydb_mon_port != 0:
370+
nodes = cls.get_cluster_nodes(db_only=True)
371+
expected_nodes_count = cls.get_dyn_nodes_count()
372+
nodes_count = len(nodes)
393373
if expected_nodes_count:
394-
if len(table_nodes) < expected_nodes_count:
395-
min = 0
396-
for tn in table_nodes:
397-
tablet_count = 0
398-
for tablet in tn.tablets:
399-
if tablet.count > 0 and tablet.state != "Green":
400-
warnings.append(f'Node {tn.host}: {tablet.count} tablets of type {tablet.type} in {tablet.state} state')
401-
if tablet.type in {"ColumnShard", "DataShard"}:
402-
tablet_count += tablet.count
403-
if tablet_count > 0:
404-
if min is None or tablet_count < min:
405-
min = tablet_count
406-
if max is None or tablet_count > max:
407-
max = tablet_count
408-
if min is None or max is None:
409-
warnings.append(f'Table {p} has no tablets')
410-
elif max - min > 1:
411-
warnings.append(f'Table {p} is not balanced: {min}-{max} shards.')
412-
LOGGER.info(f'Table {p} balance: {min}-{max} shards.')
374+
LOGGER.debug(f'Expected nodes count: {expected_nodes_count}')
375+
if nodes_count < expected_nodes_count:
376+
errors.append(f"{expected_nodes_count - nodes_count} nodes from {expected_nodes_count} don't alive")
377+
ok_node_count = 0
378+
node_errors = []
379+
for n in nodes:
380+
error = _check_node(n)
381+
if error:
382+
node_errors.append(error)
383+
else:
384+
ok_node_count += 1
385+
if ok_node_count < nodes_count:
386+
errors.append(f'Only {ok_node_count} from {nodes_count} dynnodes are ok: {",".join(node_errors)}')
387+
paths_to_balance = []
388+
if isinstance(balanced_paths, str):
389+
paths_to_balance += cls.get_tables(balanced_paths)
390+
elif isinstance(balanced_paths, list):
391+
for path in balanced_paths:
392+
paths_to_balance += cls.get_tables(path)
393+
for p in paths_to_balance:
394+
table_nodes = cls.get_cluster_nodes(p)
395+
min = None
396+
max = None
397+
if expected_nodes_count:
398+
if len(table_nodes) < expected_nodes_count:
399+
min = 0
400+
for tn in table_nodes:
401+
tablet_count = 0
402+
for tablet in tn.tablets:
403+
if tablet.count > 0 and tablet.state != "Green":
404+
warnings.append(f'Node {tn.host}: {tablet.count} tablets of type {tablet.type} in {tablet.state} state')
405+
if tablet.type in {"ColumnShard", "DataShard"}:
406+
tablet_count += tablet.count
407+
if tablet_count > 0:
408+
if min is None or tablet_count < min:
409+
min = tablet_count
410+
if max is None or tablet_count > max:
411+
max = tablet_count
412+
if min is None or max is None:
413+
warnings.append(f'Table {p} has no tablets')
414+
elif max - min > 1:
415+
warnings.append(f'Table {p} is not balanced: {min}-{max} shards.')
416+
LOGGER.info(f'Table {p} balance: {min}-{max} shards.')
413417

414418
cls.execute_single_result_query("select 1", timeout)
415419
except BaseException as ex:

0 commit comments

Comments
 (0)