From abb422d5dec6f379e2d49da2f65cd4dbc1590a8c Mon Sep 17 00:00:00 2001 From: anastasia Date: Mon, 21 Feb 2022 11:30:45 +0300 Subject: [PATCH] Fix SafekeeperMetrics parsing in python tests --- test_runner/batch_others/test_wal_acceptor.py | 4 ++-- test_runner/fixtures/zenith_fixtures.py | 24 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/test_runner/batch_others/test_wal_acceptor.py b/test_runner/batch_others/test_wal_acceptor.py index 193afc1b86..4d9e18bb58 100644 --- a/test_runner/batch_others/test_wal_acceptor.py +++ b/test_runner/batch_others/test_wal_acceptor.py @@ -90,8 +90,8 @@ def test_many_timelines(zenith_env_builder: ZenithEnvBuilder): latest_valid_lsn=branch_detail["latest_valid_lsn"], ) for sk_m in sk_metrics: - m.flush_lsns.append(sk_m.flush_lsn_inexact[timeline_id]) - m.commit_lsns.append(sk_m.commit_lsn_inexact[timeline_id]) + m.flush_lsns.append(sk_m.flush_lsn_inexact[(tenant_id.hex, timeline_id)]) + m.commit_lsns.append(sk_m.commit_lsn_inexact[(tenant_id.hex, timeline_id)]) for flush_lsn, commit_lsn in zip(m.flush_lsns, m.commit_lsns): # Invariant. May be < when transaction is in progress. diff --git a/test_runner/fixtures/zenith_fixtures.py b/test_runner/fixtures/zenith_fixtures.py index cafae1b63a..6238ad745f 100644 --- a/test_runner/fixtures/zenith_fixtures.py +++ b/test_runner/fixtures/zenith_fixtures.py @@ -27,7 +27,7 @@ from dataclasses import dataclass # Type-related stuff from psycopg2.extensions import connection as PgConnection -from typing import Any, Callable, Dict, Iterator, List, Optional, TypeVar, cast, Union +from typing import Any, Callable, Dict, Iterator, List, Optional, TypeVar, cast, Union, Tuple from typing_extensions import Literal import pytest @@ -1465,8 +1465,8 @@ class SafekeeperTimelineStatus: class SafekeeperMetrics: # These are metrics from Prometheus which uses float64 internally. # As a consequence, values may differ from real original int64s. - flush_lsn_inexact: Dict[str, int] = field(default_factory=dict) - commit_lsn_inexact: Dict[str, int] = field(default_factory=dict) + flush_lsn_inexact: Dict[Tuple[str, str], int] = field(default_factory=dict) + commit_lsn_inexact: Dict[Tuple[str, str], int] = field(default_factory=dict) class SafekeeperHttpClient(requests.Session): @@ -1490,14 +1490,16 @@ class SafekeeperHttpClient(requests.Session): all_metrics_text = request_result.text metrics = SafekeeperMetrics() - for match in re.finditer(r'^safekeeper_flush_lsn{ztli="([0-9a-f]+)"} (\S+)$', - all_metrics_text, - re.MULTILINE): - metrics.flush_lsn_inexact[match.group(1)] = int(match.group(2)) - for match in re.finditer(r'^safekeeper_commit_lsn{ztli="([0-9a-f]+)"} (\S+)$', - all_metrics_text, - re.MULTILINE): - metrics.commit_lsn_inexact[match.group(1)] = int(match.group(2)) + for match in re.finditer( + r'^safekeeper_flush_lsn{tenant_id="([0-9a-f]+)",timeline_id="([0-9a-f]+)"} (\S+)$', + all_metrics_text, + re.MULTILINE): + metrics.flush_lsn_inexact[(match.group(1), match.group(2))] = int(match.group(3)) + for match in re.finditer( + r'^safekeeper_commit_lsn{tenant_id="([0-9a-f]+)",timeline_id="([0-9a-f]+)"} (\S+)$', + all_metrics_text, + re.MULTILINE): + metrics.commit_lsn_inexact[(match.group(1), match.group(2))] = int(match.group(3)) return metrics