|
1 | 1 | import subprocess
|
2 | 2 | from pathlib import Path
|
3 |
| -from typing import Optional |
| 3 | +from typing import Any, Optional |
4 | 4 |
|
5 | 5 | import yaml
|
6 | 6 |
|
7 |
| -from util.workspace import DBGymConfig |
| 7 | +from env.tuning_agent import DBMSConfigDelta, TuningAgent, TuningAgentMetadata |
| 8 | +from util.workspace import ( |
| 9 | + DBGymConfig, |
| 10 | + fully_resolve_path, |
| 11 | + get_default_dbdata_parent_dpath, |
| 12 | + get_default_pgbin_path, |
| 13 | + get_default_pristine_dbdata_snapshot_path, |
| 14 | + get_default_workload_name_suffix, |
| 15 | + get_default_workload_path, |
| 16 | + get_workload_name, |
| 17 | +) |
8 | 18 |
|
9 | 19 | # These are the values used by set_up_env_integtests.sh.
|
10 | 20 | # TODO: make set_up_env_integtests.sh take in these values directly as envvars.
|
@@ -45,3 +55,51 @@ def get_dbgym_cfg() -> DBGymConfig:
|
45 | 55 | def get_workspace_path() -> Path:
|
46 | 56 | with open(IntegtestWorkspace.ENV_INTEGTESTS_DBGYM_CONFIG_FPATH) as f:
|
47 | 57 | return Path(yaml.safe_load(f)["dbgym_workspace_path"])
|
| 58 | + |
| 59 | + @staticmethod |
| 60 | + def get_default_metadata() -> TuningAgentMetadata: |
| 61 | + dbgym_cfg = IntegtestWorkspace.get_dbgym_cfg() |
| 62 | + workspace_path = fully_resolve_path( |
| 63 | + dbgym_cfg, IntegtestWorkspace.get_workspace_path() |
| 64 | + ) |
| 65 | + return TuningAgentMetadata( |
| 66 | + workload_path=fully_resolve_path( |
| 67 | + dbgym_cfg, |
| 68 | + get_default_workload_path( |
| 69 | + workspace_path, |
| 70 | + INTEGTEST_BENCHMARK, |
| 71 | + get_workload_name( |
| 72 | + INTEGTEST_SCALE_FACTOR, |
| 73 | + get_default_workload_name_suffix(INTEGTEST_BENCHMARK), |
| 74 | + ), |
| 75 | + ), |
| 76 | + ), |
| 77 | + pristine_dbdata_snapshot_path=fully_resolve_path( |
| 78 | + dbgym_cfg, |
| 79 | + get_default_pristine_dbdata_snapshot_path( |
| 80 | + workspace_path, INTEGTEST_BENCHMARK, INTEGTEST_SCALE_FACTOR |
| 81 | + ), |
| 82 | + ), |
| 83 | + dbdata_parent_path=fully_resolve_path( |
| 84 | + dbgym_cfg, get_default_dbdata_parent_dpath(workspace_path) |
| 85 | + ), |
| 86 | + pgbin_path=fully_resolve_path( |
| 87 | + dbgym_cfg, get_default_pgbin_path(workspace_path) |
| 88 | + ), |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +class MockTuningAgent(TuningAgent): |
| 93 | + def __init__(self, *args: Any, **kwargs: Any) -> None: |
| 94 | + super().__init__(*args, **kwargs) |
| 95 | + self.config_to_return: Optional[DBMSConfigDelta] = None |
| 96 | + |
| 97 | + def _get_metadata(self) -> TuningAgentMetadata: |
| 98 | + return IntegtestWorkspace.get_default_metadata() |
| 99 | + |
| 100 | + def _step(self) -> DBMSConfigDelta: |
| 101 | + assert self.config_to_return is not None |
| 102 | + ret = self.config_to_return |
| 103 | + # Setting this ensures you must set self.config_to_return every time. |
| 104 | + self.config_to_return = None |
| 105 | + return ret |
0 commit comments