Documentation ¶
Index ¶
- Constants
- Variables
- func CalculatePriority(entry IndexEntry, minHits, maxHits int64, oldest, newest time.Time) float64
- func InjectCacheInto(obj interface{}, cache Cache) error
- func NewCache(log logr.Logger, options ...Option) (*layeredCache, error)
- func NewInMemoryCache() *inmemoryCache
- func Path(desc ocispecv1.Descriptor) string
- func RegisterStoreMetrics(reg prometheus.Registerer)
- type Cache
- type FileSystem
- func (fs *FileSystem) Close() error
- func (fs *FileSystem) Create(path string, size int64) (vfs.File, error)
- func (fs *FileSystem) CurrentSize() int64
- func (fs *FileSystem) DeleteAll() error
- func (fs *FileSystem) OpenFile(name string, flags int, perm os.FileMode) (vfs.File, error)
- func (fs *FileSystem) Remove(name string) error
- func (fs *FileSystem) RunGarbageCollection()
- func (fs *FileSystem) StartResetInterval()
- func (fs *FileSystem) WithMetrics(itemsCount, usage prometheus.Gauge, hits prometheus.Counter)
- type GarbageCollectionConfiguration
- type Index
- func (i *Index) Add(name string, size int64, createdAt time.Time)
- func (i *Index) DeepCopy() *Index
- func (i *Index) Get(name string) IndexEntry
- func (i *Index) Hit(name string)
- func (i *Index) Len() int
- func (i *Index) PriorityList() []IndexEntry
- func (i *Index) Remove(name string)
- func (i *Index) Reset()
- type IndexEntry
- type Info
- type InfoInterface
- type InjectCache
- type Option
- type Options
- type PruneInterface
- type WithBaseGCConfig
- type WithBasePath
- type WithBaseSize
- type WithGCConfig
- type WithInMemoryGCConfig
- type WithInMemoryOverlay
- type WithInMemoryOverlaySize
- type WithUID
Constants ¶
const CacheDirEnvName = "OCI_CACHE_DIR"
CacheDirEnvName is the name of the environment variable that configures cache directory.
const GCHighThreshold float64 = 0.85
GCHighThreshold defines the default percent of disk usage which triggers files garbage collection.
const GCLowThreshold float64 = 0.80
GCLowThreshold defines the default percent of disk usage to which files garbage collection attempts to free.
const PreservedHitsProportion = 0.5
PreservedHitsProportion defines the default percent of hits that should be preserved.
const ResetInterval time.Duration = 1 * time.Hour
ResetInterval defines the default interval when the hit reset should run.
Variables ¶
var ( // DiskUsage discloses disk used by the blueprint store DiskUsage = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: lsv1alpha1.LandscaperMetricsNamespaceName, Subsystem: storeSubsystemName, Name: "disk_usage_bytes", Help: "Bytes on disk currently used by blueprint store instance.", }, ) // StoredItems discloses the number of items stored by the blueprint store. StoredItems = prometheus.NewGauge( prometheus.GaugeOpts{ Namespace: lsv1alpha1.LandscaperMetricsNamespaceName, Subsystem: storeSubsystemName, Name: "items_total", Help: "Total number of items currently stored by the blueprint store.", }, ) // CacheMemoryUsage discloses memory used by caches CacheMemoryUsage = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: ociClientNamespaceName, Subsystem: cacheSubsystemName, Name: "memory_usage_bytes", Help: "Bytes in memory currently used by cache instance.", }, []string{"id"}, ) // CacheDiskUsage discloses disk used by caches CacheDiskUsage = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: ociClientNamespaceName, Subsystem: cacheSubsystemName, Name: "disk_usage_bytes", Help: "Bytes on disk currently used by cache instance.", }, []string{"id"}, ) // CachedItems discloses the number of items stored by caches CachedItems = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: ociClientNamespaceName, Subsystem: cacheSubsystemName, Name: "items_total", Help: "Total number of items currently cached by instance.", }, []string{"id"}, ) // CacheHitsDisk discloses the number of hits for items cached on disk CacheHitsDisk = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: ociClientNamespaceName, Subsystem: cacheSubsystemName, Name: "disk_hits_total", Help: "Total number of hits for items cached on disk by an instance.", }, []string{"id"}, ) // CacheHitsMemory discloses the number of hits for items cached in memory CacheHitsMemory = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: ociClientNamespaceName, Subsystem: cacheSubsystemName, Name: "memory_hits_total", Help: "Total number of hits for items cached in memory by an instance.", }, []string{"id"}, ) )
var ( // ErrNotFound is a error that indicates that the file is not cached ErrNotFound = errors.New("not cached") )
Functions ¶
func CalculatePriority ¶
func CalculatePriority(entry IndexEntry, minHits, maxHits int64, oldest, newest time.Time) float64
CalculatePriority calculates the gc priority of a index entry. A lower priority means that is more likely to be deleted.
func InjectCacheInto ¶
InjectCacheInto injects a cache if the given object implements the InjectCache interface.
func NewInMemoryCache ¶
func NewInMemoryCache() *inmemoryCache
NewInMemoryCache creates a new in memory cache.
func Path ¶
func Path(desc ocispecv1.Descriptor) string
func RegisterStoreMetrics ¶
func RegisterStoreMetrics(reg prometheus.Registerer)
RegisterStoreMetrics allows to register blueprint store metrics with a given prometheus registerer
Types ¶
type Cache ¶
type Cache interface { io.Closer Get(desc ocispecv1.Descriptor) (io.ReadCloser, error) Add(desc ocispecv1.Descriptor, reader io.ReadCloser) error }
Cache is the interface for a oci cache
type FileSystem ¶
type FileSystem struct { // Configuration vfs.FileSystem // Size is the size of the filesystem in bytes. // If the value is 0 there is no limit and no garbage collection will happen. Size int64 // GCHighThreshold defines the percent of disk usage which triggers files garbage collection. GCHighThreshold float64 // GCLowThreshold defines the percent of disk usage to which files garbage collection attempts to free. GCLowThreshold float64 // ResetInterval defines the interval when the hit reset should run. ResetInterval time.Duration // PreservedHitsProportion defines the percent of hits that should be preserved. PreservedHitsProportion float64 // contains filtered or unexported fields }
FileSystem is a internal representation of FileSystem with a optional max size and a garbage collection.
func NewCacheFilesystem ¶
func NewCacheFilesystem(log logr.Logger, fs vfs.FileSystem, gcOpts GarbageCollectionConfiguration) (*FileSystem, error)
NewCacheFilesystem creates a new FileSystem cache. It acts as a replacement for a vfs filesystem that restricts the size of the filesystem. The garbage collection is triggered when a file is created. When the filesystem is not used anymore fs.Close() should be called to gracefully free resources.
func (*FileSystem) Close ¶
func (fs *FileSystem) Close() error
Close implements the io.Closer interface. It should be called when the cache is not used anymore.
func (*FileSystem) CurrentSize ¶
func (fs *FileSystem) CurrentSize() int64
CurrentSize returns the current size of the filesystem
func (*FileSystem) DeleteAll ¶
func (fs *FileSystem) DeleteAll() error
DeleteAll removes all files in the filesystem
func (*FileSystem) Remove ¶
func (fs *FileSystem) Remove(name string) error
func (*FileSystem) RunGarbageCollection ¶
func (fs *FileSystem) RunGarbageCollection()
RunGarbageCollection runs the garbage collection of the filesystem. The gc only deletes items when the max size reached a certain threshold. If that threshold is reached the files are deleted with the following priority: - least hits - oldest - random
func (*FileSystem) StartResetInterval ¶
func (fs *FileSystem) StartResetInterval()
StartResetInterval starts the reset counter for the cache hits.
func (*FileSystem) WithMetrics ¶
func (fs *FileSystem) WithMetrics(itemsCount, usage prometheus.Gauge, hits prometheus.Counter)
WithMetrics adds prometheus metrics to the filesystem that are set by the filesystem.
type GarbageCollectionConfiguration ¶
type GarbageCollectionConfiguration struct { // Size is the size of the filesystem. // If the value is 0 there is no limit and no garbage collection will happen. // See the kubernetes quantity docs for detailed description of the format // https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go Size string // GCHighThreshold defines the percent of disk usage which triggers files garbage collection. GCHighThreshold float64 // GCLowThreshold defines the percent of disk usage to which files garbage collection attempts to free. GCLowThreshold float64 // ResetInterval defines the interval when the hit reset should run. ResetInterval time.Duration // PreservedHitsProportion defines the percent of hits that should be preserved. PreservedHitsProportion float64 }
GarbageCollectionConfiguration contains all options for the cache garbage collection.
func (GarbageCollectionConfiguration) ApplyOptions ¶
func (o GarbageCollectionConfiguration) ApplyOptions(fs *FileSystem) error
ApplyOptions parses and applies the options to the filesystem. It also applies defaults
func (GarbageCollectionConfiguration) Merge ¶
func (o GarbageCollectionConfiguration) Merge(cfg *GarbageCollectionConfiguration)
Merge merges 2 gc configurations whereas the defined values are overwritten.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
func (*Index) Get ¶
func (i *Index) Get(name string) IndexEntry
Get return the index entry with the given name.
func (*Index) PriorityList ¶
func (i *Index) PriorityList() []IndexEntry
PriorityList returns a entries of all entries sorted by their gc priority. The entry with the lowest priority is the first item.
type IndexEntry ¶
type IndexEntry struct { // Name is the name if the file. Name string // Size is the size of the file in bytes. Size int64 // Is the number of hits since the last gc Hits int64 // CreatedAt is the time when the file ha been created. CreatedAt time.Time // HitsSinceLastReset is the number hits since the last reset interval HitsSinceLastReset int64 }
type Info ¶
type Info struct { // Size is the max size of the filesystem in bytes. // If the value is 0 there is no limit and no garbage collection will happen. // +optional Size int64 `json:"size"` // CurrentSize is the current size of the cache CurrentSize int64 `json:"currentSize"` // ItemsCount is the number of items that are currently managed by the cache. ItemsCount int64 `json:"items"` }
Info contains additional information about the cache
type InfoInterface ¶
InfoInterface describes an interface that can be optionally exposed by a cache to give additional information.
type InjectCache ¶
InjectCache is a interface to inject a cache.
type Option ¶
type Option interface {
ApplyOption(options *Options)
}
Option is the interface to specify different cache options
type Options ¶
type Options struct { // InMemoryOverlay specifies if a overlayFs InMemory cache should be used InMemoryOverlay bool // InMemoryGCConfig defines the garbage collection configuration for the in memory cache. InMemoryGCConfig GarbageCollectionConfiguration // BasePath specifies the Base path for the os filepath. // Will be defaulted to a temp filepath if not specified BasePath string // BaseGCConfig defines the garbage collection configuration for the in base cache. BaseGCConfig GarbageCollectionConfiguration // UID is the identity of a cache, if not specified a UID will be generated UID string }
Options contains all oci cache options to configure the oci cache.
func (*Options) ApplyDefaults ¶
func (o *Options) ApplyDefaults()
ApplyDefaults sets defaults for the options.
func (*Options) ApplyOptions ¶
ApplyOptions applies the given entries options on these options, and then returns itself (for convenient chaining).
type PruneInterface ¶
type PruneInterface interface {
Prune() error
}
PruneInterface describes an interface that can be optionally exposed by a cache to manually prune the cache.
type WithBaseGCConfig ¶
type WithBaseGCConfig GarbageCollectionConfiguration
WithBaseGCConfig overwrites the base garbage collection settings.
func (WithBaseGCConfig) ApplyOption ¶
func (p WithBaseGCConfig) ApplyOption(options *Options)
type WithBasePath ¶
type WithBasePath string
WithBasePath is the options to specify a base path
func (WithBasePath) ApplyOption ¶
func (p WithBasePath) ApplyOption(options *Options)
type WithBaseSize ¶
type WithBaseSize string
WithBaseSize sets the max size of the base file system. See the kubernetes quantity docs for detailed description of the format https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go
func (WithBaseSize) ApplyOption ¶
func (p WithBaseSize) ApplyOption(options *Options)
type WithGCConfig ¶
type WithGCConfig GarbageCollectionConfiguration
WithGCConfig overwrites the garbage collection settings for all caches.
func (WithGCConfig) ApplyOption ¶
func (p WithGCConfig) ApplyOption(options *Options)
type WithInMemoryGCConfig ¶
type WithInMemoryGCConfig GarbageCollectionConfiguration
WithBaseGCConfig overwrites the in memory garbage collection settings.
func (WithInMemoryGCConfig) ApplyOption ¶
func (p WithInMemoryGCConfig) ApplyOption(options *Options)
type WithInMemoryOverlay ¶
type WithInMemoryOverlay bool
WithInMemoryOverlay is the options to specify the usage of a in memory overlayFs
func (WithInMemoryOverlay) ApplyOption ¶
func (w WithInMemoryOverlay) ApplyOption(options *Options)
type WithInMemoryOverlaySize ¶
type WithInMemoryOverlaySize string
WithInMemoryOverlaySize sets the max size of the overly file system. See the kubernetes quantity docs for detailed description of the format https://github.com/kubernetes/apimachinery/blob/master/pkg/api/resource/quantity.go
func (WithInMemoryOverlaySize) ApplyOption ¶
func (p WithInMemoryOverlaySize) ApplyOption(options *Options)