Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

feat: Add config-based SRE Recipe Implementation #826

Merged
merged 68 commits into from
Sep 10, 2021

Conversation

Gan-Tu
Copy link
Contributor

@Gan-Tu Gan-Tu commented Aug 21, 2021

In this PR, we support both config-based and implementation-based SRE Recipe implementation.

Recipe Types

  • The config-based SRE Recipe makes it fast to iterate and add new SRE Recipes, as discussed in the internal design review. It also helps reduce redundant, and hacky code.
  • The implementation-based SRE Recipe is kept for backward compatibility and allows for complex implementation needs that config-based SRE Recipe cannot do.
  • Documentations are added for both, with support for hiding/disabling recipes.

Refactoring

  • Migrated all existing SRE Recipe implementation to config-based YAML recipes
  • Added one dummy implementation-based recipe for future reference.
  • Updated sandboxctl to support running both types of recipes, using the samesandboxctl syntax right now.
  • Refactored generic, reusable shell commands to a standalone 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 and sandboxctl describe still work as intended.

Gan-Tu added 30 commits June 4, 2021 16:25
@Gan-Tu Gan-Tu marked this pull request as ready for review August 31, 2021 00:04
Copy link
Member

@daniel-sanche daniel-sanche left a 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

sre-recipes/recipes/impl_based/dummy_recipe.py Outdated Show resolved Hide resolved
sre-recipes/recipe_runner.py Show resolved Hide resolved
sre-recipes/recipe_runner.py Outdated Show resolved Hide resolved
sre-recipes/recipe_runner.py Outdated Show resolved Hide resolved
sre-recipes/recipes/configs_based/README.md Outdated Show resolved Hide resolved
sre-recipes/recipes/configs_based/README.md Outdated Show resolved Hide resolved
sre-recipes/recipes/configs_based/README.md Outdated Show resolved Hide resolved
sre-recipes/recipes/configs_based/README.md Outdated Show resolved Hide resolved
sre-recipes/recipe_runner.py Outdated Show resolved Hide resolved
@@ -0,0 +1,61 @@
# Copyright 2021 Google LLC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I want to start writing simple tests for the recipes like this one. It's probably out of scope for this PR, but we should probably add more before the next release to be safe. Let me know if you have thoughts

(bug here)

@Gan-Tu Gan-Tu requested a review from daniel-sanche September 4, 2021 02:57
Copy link

@simonz130 simonz130 left a 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!

sre-recipes/recipe_runner.py Outdated Show resolved Hide resolved

def __init__(self, recipe_name):
filepath = path.join(path.dirname(
path.abspath(__file__)), f"recipes/configs_based/{recipe_name}.yaml")

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

Copy link
Contributor Author

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

https://yaml.org/faq.html

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())

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?

Copy link
Contributor Author

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

sre-recipes/recipe_runner.py Outdated Show resolved Hide resolved

def run_restore(self):
print('Restoring broken service...')
for action in self.config.get("restore", []):

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?

sre-recipes/recipe_runner.py Show resolved Hide resolved
sre-recipes/recipes/configs_based/README.md Show resolved Hide resolved
sre-recipes/utils.py Outdated Show resolved Hide resolved
Copy link
Member

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@Gan-Tu Gan-Tu added this to the v0.8.0 milestone Sep 10, 2021
@Gan-Tu Gan-Tu linked an issue Sep 10, 2021 that may be closed by this pull request
@Gan-Tu Gan-Tu merged commit 13e46f7 into develop Sep 10, 2021
@Gan-Tu Gan-Tu deleted the gan-refactor-sre-recipe branch September 10, 2021 22:28
@github-actions github-actions bot mentioned this pull request Oct 19, 2021
@github-actions github-actions bot mentioned this pull request Oct 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Support both config based and implementation based SRE Recipes
3 participants