Alerting: Move alerting codegen to --grouping=group (#105068)
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
promModel "github.com/prometheus/common/model"
|
||||
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/routingtree/v0alpha1"
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/alerting/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
gapiutil "github.com/grafana/grafana/pkg/services/apiserver/utils"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
)
|
||||
|
||||
func ConvertToK8sResource(orgID int64, r definitions.Route, version string, namespacer request.NamespaceMapper) (*model.RoutingTree, error) {
|
||||
spec := model.Spec{
|
||||
Defaults: model.RouteDefaults{
|
||||
spec := model.RoutingTreeSpec{
|
||||
Defaults: model.RoutingTreeRouteDefaults{
|
||||
GroupBy: r.GroupByStr,
|
||||
GroupWait: optionalPrometheusDurationToString(r.GroupWait),
|
||||
GroupInterval: optionalPrometheusDurationToString(r.GroupInterval),
|
||||
@@ -49,8 +49,8 @@ func ConvertToK8sResource(orgID int64, r definitions.Route, version string, name
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func convertRouteToK8sSubRoute(r *definitions.Route) model.Route {
|
||||
result := model.Route{
|
||||
func convertRouteToK8sSubRoute(r *definitions.Route) model.RoutingTreeRoute {
|
||||
result := model.RoutingTreeRoute{
|
||||
GroupBy: r.GroupByStr,
|
||||
MuteTimeIntervals: r.MuteTimeIntervals,
|
||||
ActiveTimeIntervals: r.ActiveTimeIntervals,
|
||||
@@ -58,7 +58,7 @@ func convertRouteToK8sSubRoute(r *definitions.Route) model.Route {
|
||||
GroupWait: optionalPrometheusDurationToString(r.GroupWait),
|
||||
GroupInterval: optionalPrometheusDurationToString(r.GroupInterval),
|
||||
RepeatInterval: optionalPrometheusDurationToString(r.RepeatInterval),
|
||||
Routes: make([]model.Route, 0, len(r.Routes)),
|
||||
Routes: make([]model.RoutingTreeRoute, 0, len(r.Routes)),
|
||||
}
|
||||
if r.Receiver != "" {
|
||||
result.Receiver = util.Pointer(r.Receiver)
|
||||
@@ -68,9 +68,9 @@ func convertRouteToK8sSubRoute(r *definitions.Route) model.Route {
|
||||
keys := slices.Collect(maps.Keys(r.Match))
|
||||
slices.Sort(keys)
|
||||
for _, key := range keys {
|
||||
result.Matchers = append(result.Matchers, model.Matcher{
|
||||
result.Matchers = append(result.Matchers, model.RoutingTreeMatcher{
|
||||
Label: key,
|
||||
Type: model.MatcherTypeEqual,
|
||||
Type: model.RoutingTreeMatcherTypeEqual,
|
||||
Value: r.Match[key],
|
||||
})
|
||||
}
|
||||
@@ -80,9 +80,9 @@ func convertRouteToK8sSubRoute(r *definitions.Route) model.Route {
|
||||
keys := slices.Collect(maps.Keys(r.MatchRE))
|
||||
slices.Sort(keys)
|
||||
for _, key := range keys {
|
||||
m := model.Matcher{
|
||||
m := model.RoutingTreeMatcher{
|
||||
Label: key,
|
||||
Type: model.MatcherTypeEqualRegex,
|
||||
Type: model.RoutingTreeMatcherTypeEqualRegex,
|
||||
}
|
||||
value, _ := r.MatchRE[key].MarshalYAML()
|
||||
if s, ok := value.(string); ok {
|
||||
@@ -93,16 +93,16 @@ func convertRouteToK8sSubRoute(r *definitions.Route) model.Route {
|
||||
}
|
||||
|
||||
for _, m := range r.Matchers {
|
||||
result.Matchers = append(result.Matchers, model.Matcher{
|
||||
result.Matchers = append(result.Matchers, model.RoutingTreeMatcher{
|
||||
Label: m.Name,
|
||||
Type: model.MatcherType(m.Type.String()),
|
||||
Type: model.RoutingTreeMatcherType(m.Type.String()),
|
||||
Value: m.Value,
|
||||
})
|
||||
}
|
||||
for _, m := range r.ObjectMatchers {
|
||||
result.Matchers = append(result.Matchers, model.Matcher{
|
||||
result.Matchers = append(result.Matchers, model.RoutingTreeMatcher{
|
||||
Label: m.Name,
|
||||
Type: model.MatcherType(m.Type.String()),
|
||||
Type: model.RoutingTreeMatcherType(m.Type.String()),
|
||||
Value: m.Value,
|
||||
})
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func convertToDomainModel(obj *model.RoutingTree) (definitions.Route, string, er
|
||||
return result, obj.ResourceVersion, nil
|
||||
}
|
||||
|
||||
func convertK8sSubRouteToRoute(r model.Route, path string) (definitions.Route, []error) {
|
||||
func convertK8sSubRouteToRoute(r model.RoutingTreeRoute, path string) (definitions.Route, []error) {
|
||||
result := definitions.Route{
|
||||
GroupByStr: r.GroupBy,
|
||||
MuteTimeIntervals: r.MuteTimeIntervals,
|
||||
@@ -177,13 +177,13 @@ func convertK8sSubRouteToRoute(r model.Route, path string) (definitions.Route, [
|
||||
for _, matcher := range r.Matchers {
|
||||
var mt labels.MatchType
|
||||
switch matcher.Type {
|
||||
case model.MatcherTypeEqual:
|
||||
case model.RoutingTreeMatcherTypeEqual:
|
||||
mt = labels.MatchEqual
|
||||
case model.MatcherTypeNotEqual:
|
||||
case model.RoutingTreeMatcherTypeNotEqual:
|
||||
mt = labels.MatchNotEqual
|
||||
case model.MatcherTypeEqualRegex:
|
||||
case model.RoutingTreeMatcherTypeEqualRegex:
|
||||
mt = labels.MatchRegexp
|
||||
case model.MatcherTypeNotEqualRegex:
|
||||
case model.RoutingTreeMatcherTypeNotEqualRegex:
|
||||
mt = labels.MatchNotRegexp
|
||||
default:
|
||||
errs = append(errs, fmt.Errorf("route '%s' has unsupported matcher type: %s", path, matcher.Type))
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/routingtree/v0alpha1"
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/alerting/v0alpha1"
|
||||
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/routingtree/v0alpha1"
|
||||
model "github.com/grafana/grafana/apps/alerting/notifications/pkg/apis/alerting/v0alpha1"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
)
|
||||
|
||||
var kind = model.Kind()
|
||||
var kind = model.RoutingTreeKind()
|
||||
var ResourceInfo = utils.NewResourceInfo(kind.Group(), kind.Version(),
|
||||
kind.GroupVersionResource().Resource, strings.ToLower(kind.Kind()), kind.Kind(),
|
||||
func() runtime.Object { return kind.ZeroValue() },
|
||||
|
||||
Reference in New Issue
Block a user