github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/config.go (about)

     1  package storage
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/pyroscope-io/pyroscope/pkg/config"
     7  	"github.com/pyroscope-io/pyroscope/pkg/storage/cache"
     8  	"github.com/sirupsen/logrus"
     9  )
    10  
    11  type Config struct {
    12  	badgerLogLevel          logrus.Level
    13  	badgerNoTruncate        bool
    14  	badgerBasePath          string
    15  	cacheEvictThreshold     float64
    16  	cacheEvictVolume        float64
    17  	maxNodesSerialization   int
    18  	hideApplications        []string
    19  	inMemory                bool
    20  	retention               time.Duration
    21  	retentionExemplars      time.Duration
    22  	retentionLevels         config.RetentionLevels
    23  	queueWorkers            int
    24  	queueSize               int
    25  	exemplarsBatchSize      int
    26  	exemplarsBatchQueueSize int
    27  	exemplarsBatchDuration  time.Duration
    28  
    29  	NewBadger func(name string, p Prefix, codec cache.Codec) (BadgerDBWithCache, error)
    30  }
    31  
    32  // NewConfig returns a new storage config from a server config
    33  func NewConfig(server *config.Server) *Config {
    34  	level := logrus.ErrorLevel
    35  	if l, err := logrus.ParseLevel(server.BadgerLogLevel); err == nil {
    36  		level = l
    37  	}
    38  	return &Config{
    39  		badgerLogLevel:          level,
    40  		badgerBasePath:          server.StoragePath,
    41  		badgerNoTruncate:        server.BadgerNoTruncate,
    42  		cacheEvictThreshold:     server.CacheEvictThreshold,
    43  		cacheEvictVolume:        server.CacheEvictVolume,
    44  		maxNodesSerialization:   server.MaxNodesSerialization,
    45  		retention:               server.Retention,
    46  		retentionExemplars:      server.ExemplarsRetention,
    47  		retentionLevels:         server.RetentionLevels,
    48  		hideApplications:        server.HideApplications,
    49  		queueSize:               server.StorageQueueSize,
    50  		queueWorkers:            server.StorageQueueWorkers,
    51  		exemplarsBatchSize:      server.ExemplarsBatchSize,
    52  		exemplarsBatchQueueSize: server.ExemplarsBatchQueueSize,
    53  		exemplarsBatchDuration:  server.ExemplarsBatchDuration,
    54  		inMemory:                false,
    55  	}
    56  }
    57  
    58  // WithPath sets the storage base path
    59  func (c *Config) WithPath(path string) *Config {
    60  	c.badgerBasePath = path
    61  	return c
    62  }
    63  
    64  // WithInMemory makes the storage in-memory.
    65  func (c *Config) WithInMemory() *Config {
    66  	c.inMemory = true
    67  	return c
    68  }