Skip to content

Commit

Permalink
Refactor README.md to include architectural overview, getting started…
Browse files Browse the repository at this point in the history
… guide, and plugin execution order in Midori
  • Loading branch information
cyanxiao committed May 2, 2024
1 parent 8e3fafa commit fc5ff8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ To help you better understand this, the green boxes in the following illustratio

Clearly there are 4 parameters that invoke the plugins to be run at different stages of the experiment. The 4 parameters are lists of **class definitions** (not instances).

Plugins defined in `before_experiment_plugins`, `setup_plugins`, `end_trial_plugins`, `end_experiment_plugins` are run in the order. `[A, B, C]` means `A` is run first, then `B`, and finally `C`, with the output of `A` passed to `B` and the output of `B` passed to `C`.

The way we define these plugins is by inheriting from the `PluginHelper` class and overriding the `action` method. Here is an example:

```python
from .helpers import PluginHelper
from midori.plugins.helpers import PluginHelper

class SkaffoldSetup(PluginHelper):
def action(self) -> str:
Expand All @@ -82,6 +84,10 @@ class CheckRam(PluginHelper):
- `self.previous_output`: The output of the previous plugin. For example, if `end_trial_plugins = [CheckRam, NewPlugin]`, where `CheckRam` is the plugin shown above, the `NewPlugin` will have access to the output of `CheckRam` in `self.previous_output` as `MemTotal: 900000000 kB`.
- `self.treatment`: The treatment of the current trial.

### Escape Hatch

- If you really want access to the SSH client in the plugin `action()` method, you can access it via `self._ssh` (it's `paramiko.SSHClient`). Most of the time it's not necessary to use it. The only reason I kept it is to make my old plugins work with the new version of Midori.

## 🚧 Development and Contribution

1. Install [poetry](https://python-poetry.org/docs/#installation).
Expand All @@ -90,6 +96,15 @@ class CheckRam(PluginHelper):
4. Run `pre-commit install` to install [pre-commit](https://pre-commit.com/) hooks.
5. Develop on `dev` branch and create a pull request to `dev` branch.

```
## 📝 Citation

```
@misc{midori,
author = {Xingwen Xiao},
title = {Midori},
year = {2024},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/imchell/midori}},
}
```
4 changes: 2 additions & 2 deletions midori/plugins/example_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def action(self) -> str:
class EnergyDataCollection(PluginHelper):
def action(self) -> None:
energy_collector: PodHelper = PodHelper(
self.ssh, "prometheus-server", "default"
self._ssh, "prometheus-server", "default"
)
energy_node_save_path = f"~/research/results/{self.treatment}/energy.json"
energy_collector.execute_query_in_pod(
Expand All @@ -21,5 +21,5 @@ def action(self) -> None:
class LoadTestingDataCollection(PluginHelper):
def action(self) -> None:
treatment_node_save_path = f"~/research/results/{self.treatment}"
pft: PodHelper = PodHelper(self.ssh, "loadgenerator", "default")
pft: PodHelper = PodHelper(self._ssh, "loadgenerator", "default")
pft.transfer_file_from_pod("/loadgen", treatment_node_save_path)
4 changes: 2 additions & 2 deletions midori/plugins/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(
treatment: str,
previous_output: Optional[str] = None,
):
self.ssh = ssh
self._ssh = ssh
self.subject_path = subject_path
self.previous_output = previous_output
self.treatment = treatment
Expand All @@ -21,7 +21,7 @@ def __init__(
def execute(self) -> Optional[str]:
command = self.action()
if command:
return execute(command, self.ssh)
return execute(command, self._ssh)
return None

def action(self) -> Optional[str]:
Expand Down

0 comments on commit fc5ff8d

Please sign in to comment.