diff --git a/api.go b/api.go index 7c3b17250..c9c998848 100644 --- a/api.go +++ b/api.go @@ -910,6 +910,7 @@ type usageCache struct { resetTrigger chan bool lastCalcDuration time.Duration waitMultiplier float64 + disable bool muCalculate sync.Mutex muAssign sync.Mutex @@ -962,6 +963,11 @@ func (api *API) Usage(ctx context.Context, remote bool) (map[string]NodeUsage, e span, _ := tracing.StartSpanFromContext(ctx, "API.Usage") defer span.Finish() + if api.usageCache.disable { + resp := make(map[string]NodeUsage) + return resp, nil + } + if api.usageCache.lastCalcDuration < usageCacheMinDuration { err := api.ResetUsageCache() if err != nil { @@ -1070,6 +1076,15 @@ func (api *API) calculateUsage() { // time that is spent recalculating this cache. It is specified relatively, rather than by a set interval, because // scans can take an unpredictably long time. func (api *API) RefreshUsageCache(dutyCycle float64) { + + if dutyCycle == 0 { + api.server.logger.Warnf("usage-duty-cycle set to 0, usage cache and /ui/usage endpoint are disabled") + api.usageCache = &usageCache{ + disable: true, + } + return + } + trigger := make(chan bool) defer close(trigger) diff --git a/ctl/server.go b/ctl/server.go index 2660a8b37..2aa617295 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -113,7 +113,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) { flags.Uint16Var(&srv.Config.Postgres.ConnectionLimit, "postgres.connection-limit", srv.Config.Postgres.ConnectionLimit, "Maximum number of simultaneous postgres connections to allow. (set 0 to disable)") // Disk and Memory usage cache for ui/usage endpoint - flags.Float64Var(&srv.Config.UsageDutyCycle, "usage-duty-cycle", srv.Config.UsageDutyCycle, "Sets the percentage of time that is spent recalculating the disk and memory usage cache. 100.0 for always-running, must be > 0.") + flags.Float64Var(&srv.Config.UsageDutyCycle, "usage-duty-cycle", srv.Config.UsageDutyCycle, "Sets the percentage of time that is spent recalculating the disk and memory usage cache. 100.0 for always-running, 0 disables the cache and the /ui/usage endpoint.") // Future flags. flags.BoolVar(&srv.Config.Future.Rename, "future.rename", false, "Present application name as FeatureBase. Defaults to false, will default to true in an upcoming release.") diff --git a/server/server.go b/server/server.go index dd5488561..5a8478513 100644 --- a/server/server.go +++ b/server/server.go @@ -277,9 +277,7 @@ func (m *Command) Start() (err error) { } } - if m.Config.UsageDutyCycle > 0 { - go m.API.RefreshUsageCache(m.Config.UsageDutyCycle) - } + go m.API.RefreshUsageCache(m.Config.UsageDutyCycle) _ = testhook.Opened(pilosa.NewAuditor(), m, nil) close(m.Started)