Alerting: Handle namespace and group query string params in Ruler API (#91533)
* Handle namespace and group query string params in Ruler API * Use the new namespace and group query params when slashes in names * Add validation, add group handling in GMA Api * Move constants * Use checkForPathSeparator function * Fix linter issue
This commit is contained in:
@@ -26,6 +26,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
const (
|
||||
namespaceQueryTag = "QUERY_NAMESPACE"
|
||||
groupQueryTag = "QUERY_GROUP"
|
||||
)
|
||||
|
||||
var searchRegex = regexp.MustCompile(`\{(\w+)\}`)
|
||||
|
||||
func toMacaronPath(path string) string {
|
||||
@@ -240,3 +245,29 @@ func getHash(hashSlice []string) uint64 {
|
||||
hash := sum.Sum64()
|
||||
return hash
|
||||
}
|
||||
|
||||
func getRulesGroupParam(ctx *contextmodel.ReqContext, pathGroup string) (string, error) {
|
||||
if pathGroup == groupQueryTag {
|
||||
group := ctx.Query("group")
|
||||
if group == "" {
|
||||
return "", fmt.Errorf("group query parameter is empty")
|
||||
}
|
||||
|
||||
return group, nil
|
||||
}
|
||||
|
||||
return pathGroup, nil
|
||||
}
|
||||
|
||||
func getRulesNamespaceParam(ctx *contextmodel.ReqContext, pathNamespace string) (string, error) {
|
||||
if pathNamespace == namespaceQueryTag {
|
||||
namespace := ctx.Query("namespace")
|
||||
if namespace == "" {
|
||||
return "", fmt.Errorf("namespace query parameter is empty")
|
||||
}
|
||||
|
||||
return namespace, nil
|
||||
}
|
||||
|
||||
return pathNamespace, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user