Skip to content
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

Merged
merged 14 commits into from Jan 12, 2024

Conversation

yuri-tceretian
Copy link
Contributor

@yuri-tceretian yuri-tceretian commented Dec 21, 2023

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 instead mute 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?

  • Developers
  • Introduction of errutil errors let's us to return more verbose errors and error IDs, which less users (and UI in the future) handle exceptional cases better.

Special notes for your reviewer:

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@yuri-tceretian yuri-tceretian added area/alerting Grafana Alerting type/refactor add to changelog no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels Dec 21, 2023
@yuri-tceretian yuri-tceretian added this to the 10.3.x milestone Dec 21, 2023
@yuri-tceretian yuri-tceretian requested a review from a team as a code owner December 21, 2023 01:09
@yuri-tceretian yuri-tceretian requested review from rwwiv, JacobsonMT and grobinson-grafana and removed request for a team December 21, 2023 01:09
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from 7644446 to af3ceba Compare December 21, 2023 14:48
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from af3ceba to 48fec7a Compare December 21, 2023 19:47
@yuri-tceretian yuri-tceretian marked this pull request as draft December 21, 2023 21:22
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from 48fec7a to db7c716 Compare December 21, 2023 21:26
@yuri-tceretian yuri-tceretian changed the base branch from main to yuri-tceretian/mute-timings-tests December 21, 2023 21:33
@yuri-tceretian yuri-tceretian marked this pull request as ready for review December 21, 2023 21:47
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timings-tests branch from 40a987d to df0f18f Compare January 5, 2024 21:44
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from c13534f to 0f7a8bb Compare January 5, 2024 21:52
Base automatically changed from yuri-tceretian/mute-timings-tests to main January 5, 2024 22:26
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from 0f7a8bb to 457e2f5 Compare January 5, 2024 22:29
@yuri-tceretian yuri-tceretian self-assigned this Jan 5, 2024
@yuri-tceretian yuri-tceretian force-pushed the yuri-tceretian/mute-timing-service-refactor branch from 457e2f5 to 61da747 Compare January 5, 2024 22:47
Copy link
Contributor

@rwwiv rwwiv left a 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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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."
},
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mute timing -> time interval

Copy link
Contributor Author

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.

@yuri-tceretian
Copy link
Contributor Author

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)

@yuri-tceretian yuri-tceretian enabled auto-merge (squash) January 11, 2024 20:05
@yuri-tceretian yuri-tceretian requested a review from a team as a code owner January 12, 2024 18:22
@yuri-tceretian yuri-tceretian requested review from papagian, undef1nd and suntala and removed request for a team January 12, 2024 18:22
@yuri-tceretian yuri-tceretian modified the milestones: 10.3.x, 10.4.x Jan 12, 2024
@yuri-tceretian yuri-tceretian merged commit 4479e72 into main Jan 12, 2024
12 checks passed
@yuri-tceretian yuri-tceretian deleted the yuri-tceretian/mute-timing-service-refactor branch January 12, 2024 19:23
s0lesurviv0r pushed a commit to s0lesurviv0r/grafana that referenced this pull request Feb 3, 2024
…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
@aangelisc aangelisc modified the milestones: 10.4.x, 10.4.0 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/alerting Grafana Alerting area/backend area/frontend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants