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:
Konrad Lalik
2024-08-13 08:31:07 +02:00
committed by GitHub
parent d54fdba322
commit b67bcdb9b8
7 changed files with 252 additions and 82 deletions
+31
View File
@@ -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
}