Skip to content

Commit 3dfda14

Browse files
It always shows mirror failures when there is any. (#2019)
In order to store connectivity statistics we would like to create a file to be consumed by filebeat with all the informations required for investigating corpora download issue and monitor its reliability and speed. With this purpose the esrally-storage ls sub-command now always shows mirror failures, without requiring --mirror-failures flag which is intended to ignore those transfers that have any mirror failure (for example in order to populate a mirror bucket using esrally-storage put sub-command).
1 parent 42d0b97 commit 3dfda14

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

esrally/storage/_cli.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def main():
156156
fmt = "json"
157157
elif args.filebeat:
158158
fmt = "filebeat"
159-
ls(transfers, fmt=fmt, stats=args.stats, mirror_failures=args.mirror_failures, file_types=file_types)
159+
ls(transfers, fmt=fmt, stats=args.stats, file_types=file_types)
160160
case "get":
161161
get(transfers, todo=storage.rangeset(args.range), monitor_interval=cfg.monitor_interval)
162162
case "put":
@@ -173,7 +173,6 @@ def ls(
173173
*,
174174
fmt: LsFormat = "json",
175175
stats: bool = False,
176-
mirror_failures: bool = False,
177176
file_types: set[storage.TransferFileType] | None = None,
178177
) -> None:
179178
LOG.info("Found %d transfer(s).", len(transfers))
@@ -185,19 +184,19 @@ def ls(
185184
sys.stdout.write("\n".join(sorted(filenames)) + "\n")
186185
case "json":
187186
json.dump(
188-
[transfer_to_dict(tr, stats=stats, mirror_failures=mirror_failures) for tr in transfers],
187+
[transfer_to_dict(tr, stats=stats) for tr in transfers],
189188
sys.stdout,
190189
indent=2,
191190
sort_keys=True,
192191
)
193192
case "filebeat":
194193
for tr in transfers:
195194
# Filebeat format is made of the root object (without stats), plus a separate object for each transfer stat.
196-
for d in transfer_to_filebeat(tr, stats=stats, mirror_failures=mirror_failures):
195+
for d in transfer_to_filebeat(tr, stats=stats):
197196
line = json.dumps({"rally": {"storage": d}})
198197
sys.stdout.write(f"{line}\n")
199198
case "pretty":
200-
json.dump([t.pretty(stats=stats, mirror_failures=mirror_failures) for t in transfers], sys.stdout, indent=2)
199+
json.dump([t.pretty(stats=stats) for t in transfers], sys.stdout, indent=2)
201200

202201

203202
class BaseTransferDict(TypedDict):
@@ -239,7 +238,7 @@ class StatsDict(TypedDict):
239238
write_time: float
240239

241240

242-
def transfer_to_dict(tr: storage.Transfer, *, stats: bool = False, mirror_failures: bool = False) -> TransferDict:
241+
def transfer_to_dict(tr: storage.Transfer, *, stats: bool = False) -> TransferDict:
243242
"""It obtains dictionaries from transfer status in the format to be serialized as JSON."""
244243
d = TransferDict(
245244
url=tr.url,
@@ -252,9 +251,9 @@ def transfer_to_dict(tr: storage.Transfer, *, stats: bool = False, mirror_failur
252251
todo=str(tr.todo),
253252
finished=tr.finished,
254253
)
255-
if mirror_failures:
254+
if tr.mirror_failures:
256255
d["mirror_failures"] = [MirrorFailureDict(url=f.url, error=f.error) for f in tr.mirror_failures]
257-
if stats:
256+
if stats and tr.stats:
258257
d["stats"] = [
259258
StatsDict(
260259
url=s.url,
@@ -270,7 +269,7 @@ def transfer_to_dict(tr: storage.Transfer, *, stats: bool = False, mirror_failur
270269

271270

272271
def transfer_to_filebeat(
273-
tr: storage.Transfer, stats: bool = False, mirror_failures: bool = False
272+
tr: storage.Transfer, stats: bool = False
274273
) -> Generator[TransferDict | FilebeatStatsDict | FilebeatMirrorFailureDict]:
275274
"""It obtains dictionaries from transfer in the format to be ingested to filebeat.
276275
@@ -279,7 +278,7 @@ def transfer_to_filebeat(
279278
- a FilebeatMirrorFailureDict for every MirrorFailureDict in 'mirror_failures' list.
280279
- a FilebeatStatsDict for every TransferStatsDict in 'stats' list.
281280
"""
282-
root: TransferDict = transfer_to_dict(tr, stats=stats, mirror_failures=mirror_failures)
281+
root: TransferDict = transfer_to_dict(tr, stats=stats)
283282
_mirror_failures: list[MirrorFailureDict] = root.pop("mirror_failures", [])
284283
_stats: list[StatsDict] = root.pop("stats", [])
285284
yield root

esrally/storage/_transfer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def average_speed(self) -> float:
701701
return 0.0
702702
return (done.size - self._resumed_size) / self.duration.s()
703703

704-
def pretty(self, *, stats: bool = False, mirror_failures: bool = False) -> dict[str, Any]:
704+
def pretty(self, *, stats: bool = False) -> dict[str, Any]:
705705
details: dict[str, Any] = {
706706
"url": self.url,
707707
"path": self.path,
@@ -712,14 +712,14 @@ def pretty(self, *, stats: bool = False, mirror_failures: bool = False) -> dict[
712712
"duration": self.duration and pretty.duration(self.duration),
713713
"throughput": self.average_speed and pretty.throughput(self.average_speed),
714714
}
715-
if mirror_failures:
715+
if self.mirror_failures:
716716
details["mirror_failures"] = [dataclasses.asdict(f) for f in self.mirror_failures]
717717
if stats:
718718
details["stats"] = [s.pretty() for s in self.stats]
719719
return {k: v for k, v in details.items() if v}
720720

721-
def info(self, *, stats: bool = False, mirror_failures: bool = False) -> str:
722-
return json.dumps(self.pretty(stats=stats, mirror_failures=mirror_failures), indent=2)
721+
def info(self, *, stats: bool = False) -> str:
722+
return json.dumps(self.pretty(stats=stats), indent=2)
723723

724724
def wait(self, timeout: float | None = None) -> None:
725725
"""It waits for transfer termination."""

0 commit comments

Comments
 (0)