-
Notifications
You must be signed in to change notification settings - Fork 148
feat: Add config-based SRE Recipe Implementation #826
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great Gan, I'm super excited about this change! I added some comments, but I think most of it is non-blocking. Maybe we can turn some comments into issues to address later.
Also, I haven't tested the recipes much yet. I'll try to do a final manual run through after the code is fully reviewed, and possibly open a new PR with recipe tests
@@ -0,0 +1,61 @@ | |||
# Copyright 2021 Google LLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! Thank you @Gan-Tu!
|
||
def __init__(self, recipe_name): | ||
filepath = path.join(path.dirname( | ||
path.abspath(__file__)), f"recipes/configs_based/{recipe_name}.yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we might want to be tolerant and allow yml extension too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given .yaml
is recommended by YAML and we own this repo. Let's go with the consistent .yaml
extension
filepath = path.join(path.dirname( | ||
path.abspath(__file__)), f"recipes/configs_based/{recipe_name}.yaml") | ||
with open(filepath, "r") as file: | ||
self.recipe = yaml.safe_load(file.read()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to define a grammar(structure) for the yaml config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot. But since the parsed YAML is in JSON format, we can use JSON-Schema library to do validation checks. I am planning to do that as a part of the follow-up PR for integration testing and validations.
https://stackoverflow.com/questions/3262569/validating-a-yaml-document-in-python
|
||
def run_restore(self): | ||
print('Restoring broken service...') | ||
for action in self.config.get("restore", []): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extract all the operation names into consts so it's consolidated in one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
In this PR, we support both config-based and implementation-based SRE Recipe implementation.
Recipe Types
Refactoring
sandboxctl
to support running both types of recipes, using the samesandboxctl
syntax right now.utils
file, instead of putting them as static methods in (conceptually irrelevant) recipe classes.Future Work
I have native validation tests for config-based recipes themselves during runtime as of now. Since this PR is getting too large, I plan to have a dedicated PR for adding integration tests for config validations during e2e CI and release.
Many SRE Recipes (except the one added in #817) don't have integration tests either, so tests for SRE Recipes prob deserve a new PR and teamwork for the future anyways.
Manually verified all
sandboxctl sre-recipes
command andsandboxctl describe
still work as intended.