mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore: add tracing to quote API and service methods with contexts (#92211)
* chore: add tracing to quote API and service methods with contexts I also fixed a typo (overriden -> overridden) and removed a method that looked like it wasn't useful anymore. (It seemed to exist to return an error, but never returned an error, and so just added many lines of unnecessary error checking).
This commit is contained in:
@@ -47,7 +47,9 @@ func (hs *HTTPServer) GetOrgQuotas(c *contextmodel.ReqContext) response.Response
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) getOrgQuotasHelper(c *contextmodel.ReqContext, orgID int64) response.Response {
|
||||
q, err := hs.QuotaService.GetQuotasByScope(c.Req.Context(), quota.OrgScope, orgID)
|
||||
ctx, span := hs.tracer.Start(c.Req.Context(), "api.getOrgQuotasHelper")
|
||||
defer span.End()
|
||||
q, err := hs.QuotaService.GetQuotasByScope(ctx, quota.OrgScope, orgID)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "failed to get quota", err)
|
||||
}
|
||||
@@ -70,6 +72,8 @@ func (hs *HTTPServer) getOrgQuotasHelper(c *contextmodel.ReqContext, orgID int64
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) UpdateOrgQuota(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := hs.tracer.Start(c.Req.Context(), "api.UpdateOrgQuota")
|
||||
defer span.End()
|
||||
cmd := quota.UpdateQuotaCmd{}
|
||||
var err error
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
@@ -81,7 +85,7 @@ func (hs *HTTPServer) UpdateOrgQuota(c *contextmodel.ReqContext) response.Respon
|
||||
}
|
||||
cmd.Target = web.Params(c.Req)[":target"]
|
||||
|
||||
if err := hs.QuotaService.Update(c.Req.Context(), &cmd); err != nil {
|
||||
if err := hs.QuotaService.Update(ctx, &cmd); err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to update org quotas", err)
|
||||
}
|
||||
return response.Success("Organization quota updated")
|
||||
@@ -114,12 +118,14 @@ func (hs *HTTPServer) UpdateOrgQuota(c *contextmodel.ReqContext) response.Respon
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetUserQuotas(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := hs.tracer.Start(c.Req.Context(), "api.GetUserQuotas")
|
||||
defer span.End()
|
||||
id, err := strconv.ParseInt(web.Params(c.Req)[":id"], 10, 64)
|
||||
if err != nil {
|
||||
return response.Err(quota.ErrBadRequest.Errorf("id is invalid: %w", err))
|
||||
}
|
||||
|
||||
q, err := hs.QuotaService.GetQuotasByScope(c.Req.Context(), quota.UserScope, id)
|
||||
q, err := hs.QuotaService.GetQuotasByScope(ctx, quota.UserScope, id)
|
||||
if err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to get org quotas", err)
|
||||
}
|
||||
@@ -143,6 +149,8 @@ func (hs *HTTPServer) GetUserQuotas(c *contextmodel.ReqContext) response.Respons
|
||||
// 404: notFoundError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) UpdateUserQuota(c *contextmodel.ReqContext) response.Response {
|
||||
ctx, span := hs.tracer.Start(c.Req.Context(), "api.UpdateUserQuota")
|
||||
defer span.End()
|
||||
cmd := quota.UpdateQuotaCmd{}
|
||||
var err error
|
||||
if err := web.Bind(c.Req, &cmd); err != nil {
|
||||
@@ -154,7 +162,7 @@ func (hs *HTTPServer) UpdateUserQuota(c *contextmodel.ReqContext) response.Respo
|
||||
}
|
||||
cmd.Target = web.Params(c.Req)[":target"]
|
||||
|
||||
if err := hs.QuotaService.Update(c.Req.Context(), &cmd); err != nil {
|
||||
if err := hs.QuotaService.Update(ctx, &cmd); err != nil {
|
||||
return response.ErrOrFallback(http.StatusInternalServerError, "Failed to update org quotas", err)
|
||||
}
|
||||
return response.Success("Organization quota updated")
|
||||
|
||||
Reference in New Issue
Block a user