@@ -40,7 +40,7 @@ import (
4040)
4141
4242// Currently, due to incorrect types in the API, the maximum recursion level for child routes is set to 1.
43- // Once this is fixed, the value should be set to 10.
43+ // Once this is fixed, the value should be set to 10 and toRoutePayload needs to be adjusted, to support it .
4444const childRouteMaxRecursionLevel = 1
4545
4646// Ensure the implementation satisfies the expected interfaces.
@@ -2036,7 +2036,7 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
20362036 }
20372037
20382038 var groupByPayload * []string
2039- var childRoutesPayload * []observability.CreateAlertConfigRoutePayloadRoutesInner
2039+ var childRoutesPayload * []observability.UpdateAlertConfigsPayloadRouteRoutesInner
20402040
20412041 if ! routeTF .GroupBy .IsNull () && ! routeTF .GroupBy .IsUnknown () {
20422042 groupByPayload = & []string {}
@@ -2074,14 +2074,14 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
20742074 }
20752075 }
20762076
2077- childRoutesList := []observability.CreateAlertConfigRoutePayloadRoutesInner {}
2077+ childRoutesList := []observability.UpdateAlertConfigsPayloadRouteRoutesInner {}
20782078 for i := range childRoutes {
20792079 childRoute := childRoutes [i ]
2080- childRoutePayload , err := toMiddleRoutesToPayload (ctx , & childRoute )
2080+ childRoutePayload , err := toChildRoutePayload (ctx , & childRoute )
20812081 if err != nil {
20822082 return nil , fmt .Errorf ("mapping child route: %w" , err )
20832083 }
2084- childRoutesList = append (childRoutesList , * toChildRoutePayload ( childRoutePayload ) )
2084+ childRoutesList = append (childRoutesList , * childRoutePayload )
20852085 }
20862086
20872087 childRoutesPayload = & childRoutesList
@@ -2097,15 +2097,14 @@ func toRoutePayload(ctx context.Context, routeTF *mainRouteModel) (*observabilit
20972097 }, nil
20982098}
20992099
2100- func toMiddleRoutesToPayload (ctx context.Context , routeTF * routeModelMiddle ) (* observability.UpdateAlertConfigsPayloadRoute , error ) {
2100+ func toChildRoutePayload (ctx context.Context , routeTF * routeModelMiddle ) (* observability.UpdateAlertConfigsPayloadRouteRoutesInner , error ) {
21012101 if routeTF == nil {
21022102 return nil , fmt .Errorf ("nil route model" )
21032103 }
21042104
21052105 var groupByPayload * []string
21062106 var matchPayload * map [string ]interface {}
21072107 var matchRegexPayload * map [string ]interface {}
2108- var childRoutesPayload * []observability.UpdateAlertConfigsPayloadRouteRoutesInner
21092108 var matchersPayload * []string
21102109
21112110 if ! utils .IsUndefined (routeTF .GroupBy ) {
@@ -2140,48 +2139,7 @@ func toMiddleRoutesToPayload(ctx context.Context, routeTF *routeModelMiddle) (*o
21402139 matchersPayload = matchersList
21412140 }
21422141
2143- if ! routeTF .Routes .IsNull () && ! routeTF .Routes .IsUnknown () {
2144- childRoutes := []routeModelMiddle {}
2145- diags := routeTF .Routes .ElementsAs (ctx , & childRoutes , false )
2146- if diags .HasError () {
2147- // If there is an error, we will try to map the child routes as if they are the last child routes
2148- // This is done because the last child routes in the recursion have a different structure (don't have the `routes` fields)
2149- // and need to be unpacked to a different struct (routeModelNoRoutes)
2150- lastChildRoutes := []routeModelNoRoutes {}
2151- diags = routeTF .Routes .ElementsAs (ctx , & lastChildRoutes , true )
2152- if diags .HasError () {
2153- return nil , fmt .Errorf ("mapping child routes: %w" , core .DiagsToError (diags ))
2154- }
2155- for i := range lastChildRoutes {
2156- childRoute := routeModelMiddle {
2157- GroupBy : lastChildRoutes [i ].GroupBy ,
2158- GroupInterval : lastChildRoutes [i ].GroupInterval ,
2159- GroupWait : lastChildRoutes [i ].GroupWait ,
2160- Match : lastChildRoutes [i ].Match ,
2161- MatchRegex : lastChildRoutes [i ].MatchRegex ,
2162- Matchers : lastChildRoutes [i ].Matchers ,
2163- Receiver : lastChildRoutes [i ].Receiver ,
2164- RepeatInterval : lastChildRoutes [i ].RepeatInterval ,
2165- Routes : types .ListNull (getRouteListType ()),
2166- }
2167- childRoutes = append (childRoutes , childRoute )
2168- }
2169- }
2170-
2171- childRoutesList := []observability.UpdateAlertConfigsPayloadRouteRoutesInner {}
2172- for i := range childRoutes {
2173- childRoute := childRoutes [i ]
2174- childRoutePayload , err := toMiddleRoutesToPayload (ctx , & childRoute )
2175- if err != nil {
2176- return nil , fmt .Errorf ("mapping child route: %w" , err )
2177- }
2178- childRoutesList = append (childRoutesList , * toChildRoutePayload (childRoutePayload ))
2179- }
2180-
2181- childRoutesPayload = & childRoutesList
2182- }
2183-
2184- return & observability.UpdateAlertConfigsPayloadRoute {
2142+ return & observability.UpdateAlertConfigsPayloadRouteRoutesInner {
21852143 GroupBy : groupByPayload ,
21862144 GroupInterval : conversion .StringValueToPointer (routeTF .GroupInterval ),
21872145 GroupWait : conversion .StringValueToPointer (routeTF .GroupWait ),
@@ -2190,27 +2148,10 @@ func toMiddleRoutesToPayload(ctx context.Context, routeTF *routeModelMiddle) (*o
21902148 Matchers : matchersPayload ,
21912149 Receiver : conversion .StringValueToPointer (routeTF .Receiver ),
21922150 RepeatInterval : conversion .StringValueToPointer (routeTF .RepeatInterval ),
2193- Routes : childRoutesPayload ,
2151+ // Routes: childRoutesPayload,
21942152 }, nil
21952153}
21962154
2197- func toChildRoutePayload (in * observability.UpdateAlertConfigsPayloadRoute ) * observability.UpdateAlertConfigsPayloadRouteRoutesInner {
2198- if in == nil {
2199- return nil
2200- }
2201- return & observability.UpdateAlertConfigsPayloadRouteRoutesInner {
2202- GroupBy : in .GroupBy ,
2203- GroupInterval : in .GroupInterval ,
2204- GroupWait : in .GroupWait ,
2205- Match : in .Match ,
2206- MatchRe : in .MatchRe ,
2207- Matchers : in .Matchers ,
2208- Receiver : in .Receiver ,
2209- RepeatInterval : in .RepeatInterval ,
2210- // Routes not currently supported
2211- }
2212- }
2213-
22142155func toGlobalConfigPayload (ctx context.Context , model * alertConfigModel ) (* observability.UpdateAlertConfigsPayloadGlobal , error ) {
22152156 globalConfigModel := globalConfigurationModel {}
22162157 diags := model .GlobalConfiguration .As (ctx , & globalConfigModel , basetypes.ObjectAsOptions {})
0 commit comments