You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
This is possibly two different feature requests but combining them here in the first instance for clarity.
The current command mimirtool rules get <namespace> <group> prints the output of the rule to the console but it is not a valid yaml. The path /prometheus/config/v1/rules/<namespace>/<group> is printed out here, and even if we ignore this line the output fails mimirtool rules lint since the output is a []rwrulefmt.RuleGroup and should be nested under groups. I would like the option to output a valid yaml, preferably save it to disk directly.
Following on, there is no way to get all the rules from mimir without looping through all the namespaces and groups. This is also partially solved by mimirtool rules print which does print out all the rules, but like above, the output is not a yaml that is ready for consumption by mimirtool itself.
The main driving force here is that using the UI to create rules initially to validate and test it is common, then the rules will be exported into a repo which runs through normal CI/CD (or even use mimirtool diff/sync) at some later point . However, this migration from UI -> repo step is proving to be rather cumbersome. We would like to remove the need to wrap mimirtool inside a bash script, and every developer can just use mimirtool directly to perform simple commands.
Describe the solution you'd like
I have the bare-bone solution, but the UX is really quite poor at this point. A simple solution to item 1. is probably just add the function below to pkg/mimirtool/commands/rules.go
funcsaveNamespaceRuleGroup(nsstring, ruleGroup []rwrulefmt.RuleGroup) {
rule:=map[string]rules.RuleNamespace{ns: rules.RuleNamespace{
Namespace: ns,
Filepath: fmt.Sprintf("%s.yaml", ns),
Groups: ruleGroup,
}}
iferr:=save(rule, true); err!=nil {
log.Infof("Failed to save rule to %s.yaml", ns)
}
}
then code block below to func (r *RuleCommand) getRuleGroup(_ *kingpin.ParseContext) error {} which will write a valid rule file as <namespace>.yaml. This will also preserve the existing behaviour.
ifr.SaveFile {
log.Debugf("Writing to file %s.yaml", r.Namespace)
saveNamespaceRuleGroup(r.Namespace, []rwrulefmt.RuleGroup{*group})
}
Unfortunately, this means we can't change the file path or name. Personally I am not sure whether the option to change the file name is that important, but the path is probably desirable in most cases. We can probably add another flag - yup, I am well aware that adding two flags for one feature is not ideal - say --output-dir="." to allow a different path.
We can re-use the same function for item 2.; either add the write to file ability to mimirtool rules print (seems to be self contradicting now that print also writes), i.e. add to func (r *RuleCommand) printRules(_ *kingpin.ParseContext) error {}
or add a new command (I can hear people screaming at me already) like get-all which would essentially be printRules without the print and instead write to file.
Describe alternatives you've considered
For 1., we can sort of achieve this with bash via a tail -n +2 and yq to massage the existing output.
For 2., we can do an awk on first and third column from the output of mimirtool rules list and loop through the namespace/group combination using the tools we developed to solve for item 1.
Additional context
Adding the code blocks above as a git patch as attachment.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
This is possibly two different feature requests but combining them here in the first instance for clarity.
mimirtool rules get <namespace> <group>
prints the output of the rule to the console but it is not a valid yaml. The path/prometheus/config/v1/rules/<namespace>/<group>
is printed out here, and even if we ignore this line the output failsmimirtool rules lint
since the output is a[]rwrulefmt.RuleGroup
and should be nested undergroups
. I would like the option to output a valid yaml, preferably save it to disk directly.mimirtool rules print
which does print out all the rules, but like above, the output is not a yaml that is ready for consumption by mimirtool itself.The main driving force here is that using the UI to create rules initially to validate and test it is common, then the rules will be exported into a repo which runs through normal CI/CD (or even use
mimirtool diff/sync
) at some later point . However, this migration from UI -> repo step is proving to be rather cumbersome. We would like to remove the need to wrap mimirtool inside a bash script, and every developer can just use mimirtool directly to perform simple commands.Describe the solution you'd like
I have the bare-bone solution, but the UX is really quite poor at this point. A simple solution to item 1. is probably just add the function below to
pkg/mimirtool/commands/rules.go
then code block below to
func (r *RuleCommand) getRuleGroup(_ *kingpin.ParseContext) error {}
which will write a valid rule file as<namespace>.yaml
. This will also preserve the existing behaviour.Unfortunately, this means we can't change the file path or name. Personally I am not sure whether the option to change the file name is that important, but the path is probably desirable in most cases. We can probably add another flag - yup, I am well aware that adding two flags for one feature is not ideal - say
--output-dir="."
to allow a different path.We can re-use the same function for item 2.; either add the write to file ability to
mimirtool rules print
(seems to be self contradicting now that print also writes), i.e. add tofunc (r *RuleCommand) printRules(_ *kingpin.ParseContext) error {}
or add a new command (I can hear people screaming at me already) like
get-all
which would essentially beprintRules
without the print and instead write to file.Describe alternatives you've considered
For 1., we can sort of achieve this with bash via a
tail -n +2
andyq
to massage the existing output.For 2., we can do an awk on first and third column from the output of
mimirtool rules list
and loop through the namespace/group combination using the tools we developed to solve for item 1.Additional context
Adding the code blocks above as a git patch as attachment.
The text was updated successfully, but these errors were encountered: