cache

package
v0.0.0-...-03c16c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufferFromCache

func BufferFromCache(cloud string, services []string, logger log.Logger) (bytes.Buffer, error)

BufferFromCache reads cloud's MetricsFamily data from cache and writes into a buffer.

func CollectCache

func CollectCache(
	enableExporterFunc func(
		string, string, string, []string, string, bool, bool, bool, bool, string, string, func() (string, error), log.Logger,
	) (*exporters.OpenStackExporter, error),
	multiCloud bool,
	services map[string]*bool, prefix,
	cloud string,
	disabledMetrics []string,
	endpointType string,
	collectTime bool,
	disableSlowMetrics bool,
	disableDeprecatedMetrics bool,
	disableCinderAgentUUID bool,
	domainID string,
	tenantID string,
	uuidGenFunc func() (string, error),
	logger log.Logger,
) error

CollectCache collects the MetricsFamily for required clouds and services and stores in the cache.

func FlushExpiredCloudCaches

func FlushExpiredCloudCaches(ttl time.Duration)

FlushExpiredCloudCaches flush expired caches based on cloud's update time

func WriteCacheToResponse

func WriteCacheToResponse(w http.ResponseWriter, r *http.Request, cloud string, enabledServices []string, logger log.Logger) error

WriteCacheToResponse read cache and write to the connection as part of an HTTP reply.

Types

type CacheBackend

type CacheBackend interface {
	// Set CloudCache in CacheBackend with cloud name.
	SetCloudCache(cloud string, cloudCache CloudCache)
	// Get CloudCache from CacheBackend with cloud name.
	GetCloudCache(cloud string) (CloudCache, bool)
	// Flush expired caches based on cloud's update time.
	// Cache will be deleted if their update time is older than the ttl.
	FlushExpiredCloudCaches(ttl time.Duration)
}

func GetCache

func GetCache() CacheBackend

GetCache return a singleton CacheBackend

type CloudCache

type CloudCache struct {
	// Latest update time.
	Time time.Time
	// The key of MetricFamilyCaches is metric family name
	// to avoid duplicate MFs in the map.
	MetricFamilyCaches map[string]*MetricFamilyCache
}

Cloud Cache Data

func NewCloudCache

func NewCloudCache() CloudCache

NewCloudCache return a new CloudCache object.

func (*CloudCache) SetMetricFamilyCache

func (c *CloudCache) SetMetricFamilyCache(mfName string, data MetricFamilyCache)

SetMetricFamilyCache updates the MetricFamilyCaches by associating a key, which is the metric family name.

type InMemoryCache

type InMemoryCache struct {
	CloudCaches map[string]*CloudCache
	// contains filtered or unexported fields
}

InMemoryCache is a in-memory store based CacheBackend implementation.

func (*InMemoryCache) FlushExpiredCloudCaches

func (c *InMemoryCache) FlushExpiredCloudCaches(ttl time.Duration)

Flush expired caches based on cloud's update time. Cache will be deleted if their update time is older than the ttl.

func (*InMemoryCache) GetCloudCache

func (c *InMemoryCache) GetCloudCache(cloud string) (CloudCache, bool)

GetCloudCache return CloudCache from in-memory map.

func (*InMemoryCache) SetCloudCache

func (c *InMemoryCache) SetCloudCache(cloud string, data CloudCache)

SetCloudCache store CloudCache in a in-memory map with key cloud's name. The CloudCache's Time attribute will be updated to now.

type MetricFamilyCache

type MetricFamilyCache struct {
	Service string
	MF      *dto.MetricFamily
}

MetricFamily Cache Data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL