2015-09-10 12:47:33 -05:00
|
|
|
package setting
|
|
|
|
|
2015-09-15 04:18:26 -05:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
2015-09-11 10:17:10 -05:00
|
|
|
type OrgQuota struct {
|
|
|
|
User int64 `target:"org_user"`
|
|
|
|
DataSource int64 `target:"data_source"`
|
|
|
|
Dashboard int64 `target:"dashboard"`
|
|
|
|
ApiKey int64 `target:"api_key"`
|
2021-05-04 11:16:28 -05:00
|
|
|
AlertRule int64 `target:"alert_rule"`
|
2015-09-11 10:17:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type UserQuota struct {
|
|
|
|
Org int64 `target:"org_user"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GlobalQuota struct {
|
|
|
|
Org int64 `target:"org"`
|
|
|
|
User int64 `target:"user"`
|
|
|
|
DataSource int64 `target:"data_source"`
|
|
|
|
Dashboard int64 `target:"dashboard"`
|
|
|
|
ApiKey int64 `target:"api_key"`
|
|
|
|
Session int64 `target:"-"`
|
2021-05-04 11:16:28 -05:00
|
|
|
AlertRule int64 `target:"alert_rule"`
|
2022-07-18 06:24:39 -05:00
|
|
|
File int64 `target:"file"`
|
2015-09-11 10:17:10 -05:00
|
|
|
}
|
|
|
|
|
2015-09-15 04:18:26 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-09-10 12:47:33 -05:00
|
|
|
type QuotaSettings struct {
|
|
|
|
Enabled bool
|
2015-09-11 10:17:10 -05:00
|
|
|
Org *OrgQuota
|
|
|
|
User *UserQuota
|
|
|
|
Global *GlobalQuota
|
2015-09-10 12:47:33 -05:00
|
|
|
}
|
|
|
|
|
2018-04-30 09:21:04 -05:00
|
|
|
func (cfg *Cfg) readQuotaSettings() {
|
2015-09-10 12:47:33 -05:00
|
|
|
// set global defaults.
|
2018-04-30 09:21:04 -05:00
|
|
|
quota := cfg.Raw.Section("quota")
|
2015-09-10 12:47:33 -05:00
|
|
|
Quota.Enabled = quota.Key("enabled").MustBool(false)
|
2015-09-11 10:17:10 -05:00
|
|
|
|
2021-05-04 11:16:28 -05:00
|
|
|
var alertOrgQuota int64
|
|
|
|
var alertGlobalQuota int64
|
2021-11-24 13:56:07 -06:00
|
|
|
if cfg.UnifiedAlerting.IsEnabled() {
|
2021-05-04 11:16:28 -05:00
|
|
|
alertOrgQuota = quota.Key("org_alert_rule").MustInt64(100)
|
|
|
|
alertGlobalQuota = quota.Key("global_alert_rule").MustInt64(-1)
|
|
|
|
}
|
2015-09-11 10:17:10 -05:00
|
|
|
// per ORG Limits
|
|
|
|
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),
|
|
|
|
ApiKey: quota.Key("org_api_key").MustInt64(10),
|
2021-05-04 11:16:28 -05:00
|
|
|
AlertRule: alertOrgQuota,
|
2015-09-11 10:17:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// per User limits
|
|
|
|
Quota.User = &UserQuota{
|
|
|
|
Org: quota.Key("user_org").MustInt64(10),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Global Limits
|
|
|
|
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),
|
|
|
|
Dashboard: quota.Key("global_dashboard").MustInt64(-1),
|
|
|
|
ApiKey: quota.Key("global_api_key").MustInt64(-1),
|
|
|
|
Session: quota.Key("global_session").MustInt64(-1),
|
2022-07-18 06:24:39 -05:00
|
|
|
File: quota.Key("global_file").MustInt64(-1),
|
2021-05-04 11:16:28 -05:00
|
|
|
AlertRule: alertGlobalQuota,
|
2015-09-11 10:17:10 -05:00
|
|
|
}
|
2020-12-11 04:44:44 -06:00
|
|
|
|
|
|
|
cfg.Quota = Quota
|
2015-09-10 12:47:33 -05:00
|
|
|
}
|