Skip to content

Commit af73799

Browse files
authored
Use S3LogsReader with superregion and UTC timezone (#972)
1 parent e59b611 commit af73799

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

tests/utils/scribereader_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def test_read_log_stream_for_action_run_yelp_clog():
4040
), mock.patch("tron.config.static_config.build_configuration_watcher", autospec=True,), mock.patch(
4141
"tron.config.static_config.load_yaml_file",
4242
autospec=True,
43+
), mock.patch(
44+
"tron.utils.scribereader.get_ecosystem", autospec=True, return_value="fake"
45+
), mock.patch(
46+
"tron.utils.scribereader.get_superregion", autospec=True, return_value="fake"
4347
), mock.patch(
4448
"tron.utils.scribereader.S3LogsReader", autospec=True
4549
) as mock_s3_reader:
@@ -80,6 +84,47 @@ def test_read_log_stream_for_action_run_yelp_clog():
8084
assert output == ["line 1", "line 2"]
8185

8286

87+
@pytest.mark.parametrize(
88+
"local_datetime, expected_date",
89+
[
90+
(
91+
datetime.datetime(2024, 2, 29, 23, 59, 59, tzinfo=datetime.timezone(datetime.timedelta(hours=+3))),
92+
datetime.date(2024, 2, 29),
93+
),
94+
(
95+
datetime.datetime(2024, 2, 29, 23, 59, 59, tzinfo=datetime.timezone(datetime.timedelta(hours=-3))),
96+
datetime.date(2024, 3, 1),
97+
),
98+
],
99+
)
100+
def test_read_log_stream_for_action_run_yelp_clog_tz(local_datetime, expected_date):
101+
with mock.patch(
102+
"staticconf.read",
103+
autospec=True,
104+
side_effect=static_conf_patch({"logging.use_s3_reader": True, "logging.max_lines_to_display": 1000}),
105+
), mock.patch("tron.config.static_config.build_configuration_watcher", autospec=True,), mock.patch(
106+
"tron.config.static_config.load_yaml_file",
107+
autospec=True,
108+
), mock.patch(
109+
"tron.utils.scribereader.get_ecosystem", autospec=True, return_value="fake"
110+
), mock.patch(
111+
"tron.utils.scribereader.get_superregion", autospec=True, return_value="fake"
112+
), mock.patch(
113+
"tron.utils.scribereader.S3LogsReader", autospec=True
114+
) as mock_s3_log_reader:
115+
116+
read_log_stream_for_action_run(
117+
"namespace.job.1234.action",
118+
component="stdout",
119+
min_date=local_datetime,
120+
max_date=local_datetime,
121+
paasta_cluster="fake",
122+
)
123+
mock_s3_log_reader.return_value.get_log_reader.assert_called_once_with(
124+
log_name=mock.ANY, min_date=expected_date, max_date=expected_date
125+
)
126+
127+
83128
def test_read_log_stream_for_action_run_min_date_and_max_date_today():
84129
# NOTE: these tests don't actually depend on the current time apart from
85130
# today vs not-today and the args are forwarded to scribereader anyway

tron/utils/scribereader.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,27 @@ def read_log_stream_for_action_run(
171171

172172
paasta_logs = PaaSTALogs(component, paasta_cluster, action_run_id)
173173
stream_name = paasta_logs.stream_name
174-
175-
today = datetime.date.today()
176-
start_date = min_date.date()
177174
end_date: Optional[datetime.date]
178175

179176
# yelp_clog S3LogsReader is a newer reader that is supposed to replace scribe readers eventually.
180177
if use_s3_reader:
181-
end_date = max_date.date() if max_date else today
178+
# S3 reader uses UTC as a standard timezone
179+
# if min_date and max_date timezone is missing, astimezone() will assume local timezone and convert it to UTC
180+
start_date = min_date.astimezone(datetime.timezone.utc).date()
181+
end_date = (
182+
max_date.astimezone(datetime.timezone.utc).date()
183+
if max_date
184+
else datetime.datetime.now().astimezone(datetime.timezone.utc).date()
185+
)
182186

183187
log.debug("Using S3LogsReader to retrieve logs")
184-
s3_reader = S3LogsReader(ecosystem).get_log_reader(log_name=stream_name, min_date=start_date, max_date=end_date)
188+
s3_reader = S3LogsReader(ecosystem, superregion).get_log_reader(
189+
log_name=stream_name, min_date=start_date, max_date=end_date
190+
)
185191
paasta_logs.fetch(s3_reader, max_lines)
186192
else:
193+
today = datetime.date.today()
194+
start_date = min_date.date()
187195
end_date = max_date.date() if max_date else None
188196
use_tailer = today in {start_date, end_date}
189197
use_reader = start_date != today and end_date is not None

yelp_package/extra_requirements_yelp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ srv-configs==1.3.4 # required by monk
99
tenacity==8.2.3 # required by yelp-logging
1010
thriftpy2==0.4.20 # required by monk
1111
yelp-cgeom==1.3.1 # required by geogrid
12-
yelp-clog==7.1.1 # scribereader dependency
12+
yelp-clog==7.1.2 # scribereader dependency
1313
yelp-logging==4.17.0 # scribereader dependency
1414
yelp-meteorite==2.1.1 # used by task-processing to emit metrics, clusterman-metrics dependency

0 commit comments

Comments
 (0)