mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Decouple quota configuration logic from API interfaces and add tests (#78930)
* Separate usage reporter from API * Extract quota registration * Decouple from API store interface * Move to ngalert package and add tests * linter
This commit is contained in:
@@ -148,34 +148,3 @@ func (api *API) RegisterAPIEndpoints(m *metrics.API) {
|
||||
hist: api.Historian,
|
||||
}), m)
|
||||
}
|
||||
|
||||
func (api *API) Usage(ctx context.Context, scopeParams *quota.ScopeParameters) (*quota.Map, error) {
|
||||
u := "a.Map{}
|
||||
|
||||
var orgID int64 = 0
|
||||
if scopeParams != nil {
|
||||
orgID = scopeParams.OrgID
|
||||
}
|
||||
|
||||
if orgUsage, err := api.RuleStore.Count(ctx, orgID); err != nil {
|
||||
return u, err
|
||||
} else {
|
||||
tag, err := quota.NewTag(models.QuotaTargetSrv, models.QuotaTarget, quota.OrgScope)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
u.Set(tag, orgUsage)
|
||||
}
|
||||
|
||||
if globalUsage, err := api.RuleStore.Count(ctx, 0); err != nil {
|
||||
return u, err
|
||||
} else {
|
||||
tag, err := quota.NewTag(models.QuotaTargetSrv, models.QuotaTarget, quota.GlobalScope)
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
u.Set(tag, globalUsage)
|
||||
}
|
||||
|
||||
return u, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user