mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
app/vmselect/promql: allow calling InitRollupResultCache+StopRollupResultCache multiple times during tests
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2406
This commit is contained in:
parent
b89e846ce3
commit
61c7f6beae
@ -97,6 +97,11 @@ var (
|
||||
)
|
||||
|
||||
// InitRollupResultCache initializes the rollupResult cache
|
||||
//
|
||||
// if cachePath is empty, then the cache isn't stored to persistent disk.
|
||||
//
|
||||
// ResetRollupResultCache must be called when the cache must be reset.
|
||||
// StopRollupResultCache must be called when the cache isn't needed anymore.
|
||||
func InitRollupResultCache(cachePath string) {
|
||||
rollupResultCachePath = cachePath
|
||||
startTime := time.Now()
|
||||
@ -133,16 +138,19 @@ func InitRollupResultCache(cachePath string) {
|
||||
rollupResultCachePath, time.Since(startTime).Seconds(), fcs().EntriesCount, fcs().BytesSize)
|
||||
}
|
||||
|
||||
metrics.NewGauge(`vm_cache_entries{type="promql/rollupResult"}`, func() float64 {
|
||||
// Use metrics.GetOrCreateGauge instead of metrics.NewGauge,
|
||||
// so InitRollupResultCache+StopRollupResultCache could be called multiple times in tests.
|
||||
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2406
|
||||
metrics.GetOrCreateGauge(`vm_cache_entries{type="promql/rollupResult"}`, func() float64 {
|
||||
return float64(fcs().EntriesCount)
|
||||
})
|
||||
metrics.NewGauge(`vm_cache_size_bytes{type="promql/rollupResult"}`, func() float64 {
|
||||
metrics.GetOrCreateGauge(`vm_cache_size_bytes{type="promql/rollupResult"}`, func() float64 {
|
||||
return float64(fcs().BytesSize)
|
||||
})
|
||||
metrics.NewGauge(`vm_cache_requests_total{type="promql/rollupResult"}`, func() float64 {
|
||||
metrics.GetOrCreateGauge(`vm_cache_requests_total{type="promql/rollupResult"}`, func() float64 {
|
||||
return float64(fcs().GetCalls)
|
||||
})
|
||||
metrics.NewGauge(`vm_cache_misses_total{type="promql/rollupResult"}`, func() float64 {
|
||||
metrics.GetOrCreateGauge(`vm_cache_misses_total{type="promql/rollupResult"}`, func() float64 {
|
||||
return float64(fcs().Misses)
|
||||
})
|
||||
|
||||
|
@ -3,11 +3,32 @@ package promql
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
||||
"github.com/VictoriaMetrics/metricsql"
|
||||
)
|
||||
|
||||
func TestRollupResultCacheInitStop(t *testing.T) {
|
||||
t.Run("inmemory", func(t *testing.T) {
|
||||
for i := 0; i < 5; i++ {
|
||||
InitRollupResultCache("")
|
||||
StopRollupResultCache()
|
||||
}
|
||||
})
|
||||
t.Run("file-based", func(t *testing.T) {
|
||||
cacheFilePath := "test-rollup-result-cache"
|
||||
for i := 0; i < 3; i++ {
|
||||
InitRollupResultCache(cacheFilePath)
|
||||
StopRollupResultCache()
|
||||
}
|
||||
fs.MustRemoveAll(cacheFilePath)
|
||||
})
|
||||
}
|
||||
|
||||
func TestRollupResultCache(t *testing.T) {
|
||||
InitRollupResultCache("")
|
||||
defer StopRollupResultCache()
|
||||
|
||||
ResetRollupResultCache()
|
||||
window := int64(456)
|
||||
ec := &EvalConfig{
|
||||
|
Loading…
Reference in New Issue
Block a user