diff --git a/esrally/metrics.py b/esrally/metrics.py index 7a7e30d73..b1a8f401d 100644 --- a/esrally/metrics.py +++ b/esrally/metrics.py @@ -18,6 +18,7 @@ import collections import logging import math +import os import pickle import random import statistics @@ -1387,32 +1388,26 @@ def list(self): class FileRaceStore(RaceStore): def __init__(self, cfg): super().__init__(cfg) - self.user_provided_start_timestamp = self.cfg.opts("system", "time.start.user_provided", mandatory=False, default_value=False) self.races_path = paths.races_root(self.cfg) self.race_path = paths.race_root(self.cfg) def _store(self, doc): import json io.ensure_dir(self.race_path) - # if the user has overridden the effective start date we guarantee a unique file name but do not let them use them for tournaments. - with open(self._output_file_name(doc), mode="wt", encoding="utf-8") as f: + with open(self._race_file(), mode="wt", encoding="utf-8") as f: f.write(json.dumps(doc, indent=True, ensure_ascii=False)) - def _output_file_name(self, doc): - if self.user_provided_start_timestamp: - suffix = "_{}".format(doc.get("user-tags", {}).get("name", doc["trial-id"])) - else: - suffix = "" - return "%s/race%s.json" % (self.race_path, suffix) + def _race_file(self, trial_id=None): + return os.path.join(paths.race_root(cfg=self.cfg, trial_id=trial_id), "race.json") def list(self): import glob - results = glob.glob("%s/*/race*.json" % self.races_path) + results = glob.glob(self._race_file(trial_id="*")) all_races = self._to_races(results) return all_races[:self._max_results()] def find_by_trial_id(self, trial_id): - race_file = "%s/race.json" % paths.race_root(cfg=self.cfg, trial_id=trial_id) + race_file = self._race_file(trial_id=trial_id) if io.exists(race_file): races = self._to_races([race_file]) if races: diff --git a/esrally/paths.py b/esrally/paths.py index 13b6afa20..341f4d955 100644 --- a/esrally/paths.py +++ b/esrally/paths.py @@ -22,11 +22,11 @@ def rally_root(): def races_root(cfg): - return "%s/races" % cfg.opts("node", "root.dir") + return os.path.join(cfg.opts("node", "root.dir"), "races") def race_root(cfg=None, trial_id=None): if not trial_id: trial_id = cfg.opts("system", "trial.id") - return "%s/%s" % (races_root(cfg), trial_id) + return os.path.join(races_root(cfg), trial_id) diff --git a/tests/metrics_test.py b/tests/metrics_test.py index ae15aedbb..c62241cc5 100644 --- a/tests/metrics_test.py +++ b/tests/metrics_test.py @@ -1378,5 +1378,6 @@ def test_store_race(self): self.race_store.store_race(race) retrieved_race = self.race_store.find_by_trial_id(trial_id=FileRaceStoreTests.TRIAL_ID) + self.assertEqual(race.trial_id, retrieved_race.trial_id) self.assertEqual(race.trial_timestamp, retrieved_race.trial_timestamp) self.assertEqual(1, len(self.race_store.list()))