mimir
mimir copied to clipboard
feat: add save to directory option for mimirtool rules get
What this PR does
Adds the ability to save a rule to a file via mimirtool rules get
. The command in the current state only prints the rule out to console and the format is not a valid rule file for mimirtool rules load
. Adds two new flag --save-file
and --output-dir
, which may seem to be a bit of over engineering but the hope is that we build on from here and have a "save all rules" ability which allows an easy one-liner backup in the future.
Which issue(s) this PR fixes or relates to
Fixes #7054
Checklist
- [x] Tests updated.
- [x] Documentation added.
- [x]
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
. - [ ]
about-versioning.md
updated with experimental features.
Why not imply --save-file
from output-dir
. ie, if output-dir
is set, then we are saving the files.
Why not imply
--save-file
fromoutput-dir
. ie, ifoutput-dir
is set, then we are saving the files.
Actually there is no reason, we had this for something else and were double using this flag without much thought. Good spot and I have removed it and now just use output-dir
.
I should have added in the original description but the choice of using <namespace>.yaml
as the file name is a limitation that can cause issues down the line. This is because mimirtool
cannot load multiple files with the same namespace. More concretely, let's say we have two files as test1.yaml
namespace: test
groups:
- name: test.rules
rules:
- record: build
expr: build_tag_info > 1
and then another as test2.yaml
namespace: test
groups:
- name: test.rules.2
rules:
- record: up
expr: up
then mimirtool rules load test1.yaml test2.yaml
it will error out due to multiple namespace being read.
In this PR, the choice was made to not use <namespace>_<group>.yaml
which means that using mimirtool rules get --output-dir="."
will overwrite the existing file. Anyone using this flag to iterate all the namespace-group combination and save them to file for edit and re-upload will lead to losing alerts! Any recommendation to remediate this issue is welcomed (maybe the solution is to allow loading of multiple files using the same namespace?).
The CHANGELOG has just been cut to prepare for the next Mimir release. Please rebase main
and eventually move the CHANGELOG entry added / updated in this PR to the top of the CHANGELOG document. Thanks!