New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alerting: MuteTiming service return errutil + GetTiming by name #79772
Alerting: MuteTiming service return errutil + GetTiming by name #79772
Conversation
7644446
to
af3ceba
Compare
af3ceba
to
48fec7a
Compare
48fec7a
to
db7c716
Compare
40a987d
to
df0f18f
Compare
c13534f
to
0f7a8bb
Compare
0f7a8bb
to
457e2f5
Compare
and update spec to mention the code
Mute timings are deprecated in Alertmanager and will be replaced by time intervals in future
457e2f5
to
61da747
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted some string references to mute timing(s), rest of the PR looks good!
} | ||
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timings -> time intervals
@@ -272,15 +268,15 @@ 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timings -> time interval
} | ||
return response.JSON(http.StatusOK, timings) | ||
} | ||
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timings -> time intervals
return ErrResp(http.StatusBadRequest, err, "") | ||
} | ||
return ErrResp(http.StatusInternalServerError, err, "") | ||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to create mute timing", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timing -> time interval
if name == timing.Name { | ||
return response.JSON(http.StatusOK, timing) | ||
} | ||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get mute timing by name", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timing -> time interval
} | ||
return response.JSON(http.StatusAccepted, updated) | ||
} | ||
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timing -> time interval
@@ -5461,6 +5461,10 @@ | |||
"responses": { | |||
"204": { | |||
"description": " The mute timing was deleted successfully." | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timing -> time interval
@@ -63,6 +63,7 @@ import ( | |||
// | |||
// Responses: | |||
// 204: description: The mute timing was deleted successfully. | |||
// 409: GenericError description: The mute timing is in use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mute timing -> time interval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is provisioning API and it still uses mute timing terminology. I think we should keep it as it is.
Thanks! The reason I kept "mute-timings" in those places is because that's mute timing provisioning API whereas service will be used in a new time interval API, and eventually, mute timings will be deprecated (hopefully in G11) |
…ana#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
What is this feature?
This PR refactors MuteTiming service to return errutil.Error that contains statuses.
Adds a new method to get mute timing by name and removes this logic from the request handler.
Replaces errors with errutil.Error that is resolved to response status. It simplifies the API request handler logic.
Updates method UpdateMuteTiming to return an error if mute timing is not found by name. Currently, it returns nil, and nil is translated to a NotFound response by API. This does not change the file-provisioning logic because it determines operation based on the current config.
Note: All errors mention
time interval
insteadmute timing
because the latter is deprecated and will be removed in the future. Also, the new "regular" API will use time interval semantic and will reuse the errors.Why do we need this feature?
This will let us reuse this service in a new non-provisioning API and avoid duplication of logic and necessity of separate unit-tests.
Who is this feature for?
Special notes for your reviewer:
Please check that: