Skip to content

Commit

Permalink
Cache update
Browse files Browse the repository at this point in the history
* Cache miss metric
* Disable cache option
* Bypass cache when running out of memory limit
  • Loading branch information
alpinskiy committed Feb 27, 2025
1 parent f7945b7 commit 54452dd
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 146 deletions.
2 changes: 2 additions & 0 deletions internal/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
MaxCacheAge int // seconds
CacheStaleAcceptPeriod int64 // seconds
CacheTrimBackoffPeriod int64 // seconds
DisableCacheUsers []string
}

func (argv *Config) ValidateConfig() error {
Expand Down Expand Up @@ -56,6 +57,7 @@ func (argv *Config) Bind(f *flag.FlagSet, defaultI config.Config) {
f.IntVar(&argv.MaxCacheAge, "max-cache-age", 120, "maximum cache age in seconds")
f.Int64Var(&argv.CacheStaleAcceptPeriod, "cache-stale-accept-period", 5, "cache stale accept period in seconds")
f.Int64Var(&argv.CacheTrimBackoffPeriod, "cache-trim-backoff-period", 1, "cache trim backoff period in seconds")
config.StringSliceVar(f, &argv.DisableCacheUsers, "disable-cache-user", "", "user(s) with cache disabled")
f.StringVar(&argv.UserLimitsStr, "user-limits", "", "array of ConnLimits encoded to json")
}

Expand Down
17 changes: 17 additions & 0 deletions internal/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ type (
CacheVersion atomic.Int32
CacheStaleAcceptPeriod atomic.Int64
CacheTrimBackoffPeriod atomic.Int64
DisableCacheUsersMu sync.RWMutex
DisableCacheUsers []string

HandlerOptions
showInvisible bool
Expand Down Expand Up @@ -664,6 +666,9 @@ func NewHandler(staticDir fs.FS, jsSettings JSSettings, showInvisible bool, chV1
h.CacheStaleAcceptPeriod.Store(cfg.CacheStaleAcceptPeriod)
h.CacheTrimBackoffPeriod.Store(cfg.CacheTrimBackoffPeriod)
chV2.SetLimits(cfg.UserLimits)
h.DisableCacheUsersMu.Lock()
h.DisableCacheUsers = cfg.DisableCacheUsers
h.DisableCacheUsersMu.Unlock()
})
journal.Start(nil, nil, metadataLoader.LoadJournal)
_ = syscall.Getrusage(syscall.RUSAGE_SELF, &h.rUsage)
Expand Down Expand Up @@ -3391,6 +3396,18 @@ func (h *requestHandler) queryDuration(q string, d time.Duration) queryTopDurati
}
}

func (h *requestHandler) cacheDisabled() bool {
h.DisableCacheUsersMu.RLock()
defer h.DisableCacheUsersMu.RUnlock()
v := getStatTokenName(h.accessInfo.user)
for i := 0; i < len(h.DisableCacheUsers); i++ {
if h.DisableCacheUsers[i] == v {
return true
}
}
return false
}

func HandleTagDraftList(r *httpRequestHandler) {
m := make(map[string][]string)
for _, metric := range r.metricsStorage.GetMetaMetricList(false) {
Expand Down
Loading

0 comments on commit 54452dd

Please sign in to comment.