Alerting: MuteTiming service return errutil + GetTiming by name (#79772)
* add get mute timing by name to MuteTimingService * update get mute timing request handler to use the service method * replace validation, uniqueness and used errors with errutils * update mute timing methods return errutil responses * use the term "time interval" in errors bevause mute timings are deprecated in Alertmanager and will be replaced by time intervals in the future. * update create and update methods to return struct instead of pointer
This commit is contained in:
@@ -51,8 +51,9 @@ type NotificationPolicyService interface {
|
||||
|
||||
type MuteTimingService interface {
|
||||
GetMuteTimings(ctx context.Context, orgID int64) ([]definitions.MuteTimeInterval, error)
|
||||
CreateMuteTiming(ctx context.Context, mt definitions.MuteTimeInterval, orgID int64) (*definitions.MuteTimeInterval, error)
|
||||
UpdateMuteTiming(ctx context.Context, mt definitions.MuteTimeInterval, orgID int64) (*definitions.MuteTimeInterval, error)
|
||||
GetMuteTiming(ctx context.Context, name string, orgID int64) (definitions.MuteTimeInterval, error)
|
||||
CreateMuteTiming(ctx context.Context, mt definitions.MuteTimeInterval, orgID int64) (definitions.MuteTimeInterval, error)
|
||||
UpdateMuteTiming(ctx context.Context, mt definitions.MuteTimeInterval, orgID int64) (definitions.MuteTimeInterval, error)
|
||||
DeleteMuteTiming(ctx context.Context, name string, orgID int64) error
|
||||
}
|
||||
|
||||
@@ -243,22 +244,17 @@ func (srv *ProvisioningSrv) RouteDeleteTemplate(c *contextmodel.ReqContext, name
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.SignedInUser.GetOrgID())
|
||||
timing, err := srv.muteTimings.GetMuteTiming(c.Req.Context(), name, c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get mute timing by name", err)
|
||||
}
|
||||
for _, timing := range timings {
|
||||
if name == timing.Name {
|
||||
return response.JSON(http.StatusOK, timing)
|
||||
}
|
||||
}
|
||||
return response.Empty(http.StatusNotFound)
|
||||
return response.JSON(http.StatusOK, timing)
|
||||
}
|
||||
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimingExport(c *contextmodel.ReqContext, name string) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get mute timings", err)
|
||||
}
|
||||
for _, timing := range timings {
|
||||
if name == timing.Name {
|
||||
@@ -272,7 +268,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTimingExport(c *contextmodel.ReqContext,
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimings(c *contextmodel.ReqContext) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get mute timings", err)
|
||||
}
|
||||
return response.JSON(http.StatusOK, timings)
|
||||
}
|
||||
@@ -280,7 +276,7 @@ func (srv *ProvisioningSrv) RouteGetMuteTimings(c *contextmodel.ReqContext) resp
|
||||
func (srv *ProvisioningSrv) RouteGetMuteTimingsExport(c *contextmodel.ReqContext) response.Response {
|
||||
timings, err := srv.muteTimings.GetMuteTimings(c.Req.Context(), c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get mute timings", err)
|
||||
}
|
||||
e := AlertingFileExportFromMuteTimings(c.SignedInUser.GetOrgID(), timings)
|
||||
return exportResponse(c, e)
|
||||
@@ -290,10 +286,7 @@ func (srv *ProvisioningSrv) RoutePostMuteTiming(c *contextmodel.ReqContext, mt d
|
||||
mt.Provenance = determineProvenance(c)
|
||||
created, err := srv.muteTimings.CreateMuteTiming(c.Req.Context(), mt, c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
return ErrResp(http.StatusBadRequest, err, "")
|
||||
}
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to create mute timing", err)
|
||||
}
|
||||
return response.JSON(http.StatusCreated, created)
|
||||
}
|
||||
@@ -303,13 +296,7 @@ func (srv *ProvisioningSrv) RoutePutMuteTiming(c *contextmodel.ReqContext, mt de
|
||||
mt.Provenance = determineProvenance(c)
|
||||
updated, err := srv.muteTimings.UpdateMuteTiming(c.Req.Context(), mt, c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
if errors.Is(err, provisioning.ErrValidation) {
|
||||
return ErrResp(http.StatusBadRequest, err, "")
|
||||
}
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
}
|
||||
if updated == nil {
|
||||
return response.Empty(http.StatusNotFound)
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to update mute timing", err)
|
||||
}
|
||||
return response.JSON(http.StatusAccepted, updated)
|
||||
}
|
||||
@@ -317,7 +304,7 @@ func (srv *ProvisioningSrv) RoutePutMuteTiming(c *contextmodel.ReqContext, mt de
|
||||
func (srv *ProvisioningSrv) RouteDeleteMuteTiming(c *contextmodel.ReqContext, name string) response.Response {
|
||||
err := srv.muteTimings.DeleteMuteTiming(c.Req.Context(), name, c.SignedInUser.GetOrgID())
|
||||
if err != nil {
|
||||
return ErrResp(http.StatusInternalServerError, err, "")
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to delete mute timing", err)
|
||||
}
|
||||
return response.JSON(http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
@@ -1281,6 +1281,14 @@
|
||||
"title": "Frames is a slice of Frame pointers.",
|
||||
"type": "array"
|
||||
},
|
||||
"GenericPublicError": {
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/definitions/PublicError"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"GettableAlertmanagers": {
|
||||
"properties": {
|
||||
"data": {
|
||||
@@ -4405,6 +4413,7 @@
|
||||
"type": "object"
|
||||
},
|
||||
"alertGroup": {
|
||||
"description": "AlertGroup alert group",
|
||||
"properties": {
|
||||
"alerts": {
|
||||
"description": "alerts",
|
||||
@@ -4533,7 +4542,6 @@
|
||||
"type": "object"
|
||||
},
|
||||
"gettableAlert": {
|
||||
"description": "GettableAlert gettable alert",
|
||||
"properties": {
|
||||
"annotations": {
|
||||
"$ref": "#/definitions/labelSet"
|
||||
@@ -5641,6 +5649,12 @@
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": " The mute timing was deleted successfully."
|
||||
},
|
||||
"409": {
|
||||
"description": "GenericPublicError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/GenericPublicError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Delete a mute timing.",
|
||||
|
||||
@@ -63,6 +63,7 @@ import (
|
||||
//
|
||||
// Responses:
|
||||
// 204: description: The mute timing was deleted successfully.
|
||||
// 409: GenericPublicError
|
||||
|
||||
// swagger:route
|
||||
|
||||
|
||||
@@ -20,3 +20,10 @@ type ForbiddenError struct {
|
||||
// in: body
|
||||
Body errutil.PublicError `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type GenericPublicError struct {
|
||||
// The response message
|
||||
// in: body
|
||||
Body errutil.PublicError `json:"body"`
|
||||
}
|
||||
|
||||
@@ -1281,6 +1281,14 @@
|
||||
"title": "Frames is a slice of Frame pointers.",
|
||||
"type": "array"
|
||||
},
|
||||
"GenericPublicError": {
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/definitions/PublicError"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"GettableAlertmanagers": {
|
||||
"properties": {
|
||||
"data": {
|
||||
@@ -4590,13 +4598,13 @@
|
||||
"type": "object"
|
||||
},
|
||||
"gettableAlerts": {
|
||||
"description": "GettableAlerts gettable alerts",
|
||||
"items": {
|
||||
"$ref": "#/definitions/gettableAlert"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"gettableSilence": {
|
||||
"description": "GettableSilence gettable silence",
|
||||
"properties": {
|
||||
"comment": {
|
||||
"description": "comment",
|
||||
@@ -7624,6 +7632,12 @@
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": " The mute timing was deleted successfully."
|
||||
},
|
||||
"409": {
|
||||
"description": "GenericPublicError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/GenericPublicError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"summary": "Delete a mute timing.",
|
||||
|
||||
@@ -2785,6 +2785,12 @@
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": " The mute timing was deleted successfully."
|
||||
},
|
||||
"409": {
|
||||
"description": "GenericPublicError",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/GenericPublicError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4688,6 +4694,14 @@
|
||||
"$ref": "#/definitions/Frame"
|
||||
}
|
||||
},
|
||||
"GenericPublicError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"body": {
|
||||
"$ref": "#/definitions/PublicError"
|
||||
}
|
||||
}
|
||||
},
|
||||
"GettableAlertmanagers": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -8001,6 +8015,7 @@
|
||||
"$ref": "#/definitions/gettableAlert"
|
||||
},
|
||||
"gettableAlerts": {
|
||||
"description": "GettableAlerts gettable alerts",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/gettableAlert"
|
||||
@@ -8008,7 +8023,6 @@
|
||||
"$ref": "#/definitions/gettableAlerts"
|
||||
},
|
||||
"gettableSilence": {
|
||||
"description": "GettableSilence gettable silence",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"comment",
|
||||
|
||||
Reference in New Issue
Block a user