Revert "Chore: Refactor quota service (#57586)" (#58394)

This reverts commit 326ea86a57.
This commit is contained in:
Sofia Papagiannaki
2022-11-08 11:52:07 +02:00
committed by GitHub
parent 228ec4c0f3
commit 96cdf77995
99 changed files with 1398 additions and 2596 deletions

View File

@@ -1,5 +1,9 @@
package setting
import (
"reflect"
)
type OrgQuota struct {
User int64 `target:"org_user"`
DataSource int64 `target:"data_source"`
@@ -23,17 +27,45 @@ type GlobalQuota struct {
File int64 `target:"file"`
}
func (q *OrgQuota) ToMap() map[string]int64 {
return quotaToMap(*q)
}
func (q *UserQuota) ToMap() map[string]int64 {
return quotaToMap(*q)
}
func quotaToMap(q interface{}) map[string]int64 {
qMap := make(map[string]int64)
typ := reflect.TypeOf(q)
val := reflect.ValueOf(q)
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
name := field.Tag.Get("target")
if name == "" {
name = field.Name
}
if name == "-" {
continue
}
value := val.Field(i)
qMap[name] = value.Int()
}
return qMap
}
type QuotaSettings struct {
Enabled bool
Org OrgQuota
User UserQuota
Global GlobalQuota
Org *OrgQuota
User *UserQuota
Global *GlobalQuota
}
func (cfg *Cfg) readQuotaSettings() {
// set global defaults.
quota := cfg.Raw.Section("quota")
cfg.Quota.Enabled = quota.Key("enabled").MustBool(false)
Quota.Enabled = quota.Key("enabled").MustBool(false)
var alertOrgQuota int64
var alertGlobalQuota int64
@@ -42,7 +74,7 @@ func (cfg *Cfg) readQuotaSettings() {
alertGlobalQuota = quota.Key("global_alert_rule").MustInt64(-1)
}
// per ORG Limits
cfg.Quota.Org = OrgQuota{
Quota.Org = &OrgQuota{
User: quota.Key("org_user").MustInt64(10),
DataSource: quota.Key("org_data_source").MustInt64(10),
Dashboard: quota.Key("org_dashboard").MustInt64(10),
@@ -51,12 +83,12 @@ func (cfg *Cfg) readQuotaSettings() {
}
// per User limits
cfg.Quota.User = UserQuota{
Quota.User = &UserQuota{
Org: quota.Key("user_org").MustInt64(10),
}
// Global Limits
cfg.Quota.Global = GlobalQuota{
Quota.Global = &GlobalQuota{
User: quota.Key("global_user").MustInt64(-1),
Org: quota.Key("global_org").MustInt64(-1),
DataSource: quota.Key("global_data_source").MustInt64(-1),
@@ -66,4 +98,6 @@ func (cfg *Cfg) readQuotaSettings() {
File: quota.Key("global_file").MustInt64(-1),
AlertRule: alertGlobalQuota,
}
cfg.Quota = Quota
}