mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
make subnet subsys dynamic and simplify callhome (#15927)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
package callhome
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/internal/config"
|
||||
@@ -42,6 +43,9 @@ var DefaultKVS = config.KVS{
|
||||
},
|
||||
}
|
||||
|
||||
// callhomeCycleDefault is the default interval between two callhome cycles (24hrs)
|
||||
const callhomeCycleDefault = 24 * time.Hour
|
||||
|
||||
// Config represents the subnet related configuration
|
||||
type Config struct {
|
||||
// Flag indicating whether callhome is enabled.
|
||||
@@ -51,6 +55,37 @@ type Config struct {
|
||||
Frequency time.Duration `json:"frequency"`
|
||||
}
|
||||
|
||||
var configLock sync.RWMutex
|
||||
|
||||
// Enabled - indicates if callhome is enabled or not
|
||||
func (c *Config) Enabled() bool {
|
||||
configLock.RLock()
|
||||
defer configLock.RUnlock()
|
||||
|
||||
return c.Enable
|
||||
}
|
||||
|
||||
// FrequencyDur - returns the currently configured callhome frequency
|
||||
func (c *Config) FrequencyDur() time.Duration {
|
||||
configLock.RLock()
|
||||
defer configLock.RUnlock()
|
||||
|
||||
if c.Frequency == 0 {
|
||||
return callhomeCycleDefault
|
||||
}
|
||||
|
||||
return c.Frequency
|
||||
}
|
||||
|
||||
// Update updates new callhome frequency
|
||||
func (c *Config) Update(ncfg Config) {
|
||||
configLock.Lock()
|
||||
defer configLock.Unlock()
|
||||
|
||||
c.Enable = ncfg.Enable
|
||||
c.Frequency = ncfg.Frequency
|
||||
}
|
||||
|
||||
// LookupConfig - lookup config and override with valid environment settings if any.
|
||||
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
||||
if err = config.CheckValidKeys(config.CallhomeSubSys, kvs, DefaultKVS); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user