Skip to content

Commit

Permalink
[cluster] library: prom: with-queries: load the 'metrics.txt' file fr…
Browse files Browse the repository at this point in the history
…om the 'testing_dir' (#582)
  • Loading branch information
kpouget authored Nov 7, 2024
2 parents a0fdb5b + 6ff659e commit 5d13472
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
7 changes: 6 additions & 1 deletion projects/cluster/library/prom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ def dump_prometheus(prom_start_ts, namespace, delay=60):
prom_end_ts = datetime.datetime.now()
args = dict(
duration_s = (prom_end_ts - prom_start_ts).total_seconds(),
promquery_file = TESTING_THIS_DIR / "metrics.txt",
promquery_file = config.project.testing_dir / "metrics.txt",
dest_dir = env.ARTIFACT_DIR / "metrics",
namespace = namespace,
)

if not args["promquery_file"].exists():
msg = f"Requested tests.capture_prom=with-queries, but '{args['promquery_file']}' does not exist. Cannot proceed."
logging.fatal(msg)
raise FileNotFoundError(msg)

with env.NextArtifactDir("cluster__dump_prometheus_dbs"):
run.run_toolbox("cluster", "query_prometheus_db", **args)
with env.NextArtifactDir("cluster__dump_prometheus_db"):
Expand Down
15 changes: 8 additions & 7 deletions projects/core/library/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __exit__(self, ex_type, ex_value, exc_traceback):


class Config:
def __init__(self, config_path):
def __init__(self, testing_dir, config_path):
self.testing_dir = testing_dir
self.config_path = config_path

if not self.config_path.exists():
Expand Down Expand Up @@ -242,7 +243,7 @@ def detect_apply_cluster_profile(self, node_profiles):
return False


def _set_config_environ(base_dir):
def _set_config_environ(testing_dir):
reloading = False
config_path_final = pathlib.Path(env.ARTIFACT_DIR / "config.yaml")

Expand All @@ -256,13 +257,13 @@ def _set_config_environ(base_dir):
config_file_src = shared_dir_file_src
logging.info(f"Reloading the config file from SHARED_DIR {config_file_src} ...")
else:
config_file_src = base_dir / "config.yaml"
config_file_src = testing_dir / "config.yaml"
logging.info(f"Reloading the config file from TOPSAIL project directory {config_file_src} ...")

os.environ["TOPSAIL_FROM_CONFIG_FILE"] = str(config_path_final)

if "TOPSAIL_FROM_COMMAND_ARGS_FILE" not in os.environ:
os.environ["TOPSAIL_FROM_COMMAND_ARGS_FILE"] = str(base_dir / "command_args.yml.j2")
os.environ["TOPSAIL_FROM_COMMAND_ARGS_FILE"] = str(testing_dir / "command_args.yml.j2")

if not pathlib.Path(config_file_src) == config_path_final:

Expand Down Expand Up @@ -296,15 +297,15 @@ def get_jsonpath(config, jsonpath):
return jsonpath_ng.parse(jsonpath).find(config)[0].value


def init(base_dir, apply_preset_from_pr_args=False):
def init(testing_dir, apply_preset_from_pr_args=False):
global project

if project:
logging.info("config.init: project config already configured.")
return

config_path = _set_config_environ(base_dir)
project = Config(config_path)
config_path = _set_config_environ(testing_dir)
project = Config(testing_dir, config_path)

if os.environ.get("TOPSAIL_LOCAL_CI_MULTI") == "true":
logging.info("config.init: running in a local-ci multi Pod, skipping apply_config_overrides and apply_preset_from_pr_args.")
Expand Down
2 changes: 1 addition & 1 deletion projects/matrix_benchmarking/library/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def init(allow_no_config_file=False):
config.project.set_config("matbench.config_file", f"{matbench_preset}.yaml", dump_command_args=False)
config.project.set_config("matbench.download.url_file", workload_storage_dir / "data" / f"{matbench_preset}.yaml", dump_command_args=False)

matbench_config = config.Config(workload_storage_dir / "data" / config.project.get_config("matbench.config_file"))
matbench_config = config.Config(workload_storage_dir, workload_storage_dir / "data" / config.project.get_config("matbench.config_file"))


def entrypoint(allow_no_config_file=False):
Expand Down

0 comments on commit 5d13472

Please sign in to comment.