htstorage

package
v0.0.0-...-7251252 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a host tags storage implementation that caches the values for individual hosts.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, hostName string) ([]prompb.Label, error)

Get tries to retrieve the labels from cache - if labels are found in cache, they're returned - if cache fails to respond successfully, then request will be done to the underlying storage - if cache responds with a miss, then value is retrieved from the storage and it's tried to be _added_ to the cache We are using the ADD operation instead of SET for cache, to avoid overwriting the recently set value by Set() method in a race condition If the value retrieved can't be unmarshaled, then the key will be deleted and it will be treated as a cache miss.

func (*Cache) GetAll

func (c *Cache) GetAll(ctx context.Context, from time.Time) (map[string]Host, error)

GetAll does not cache values

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, hostName string, labels []prompb.Label) error

Set will try to store the value in the storage, and if succeeds, it will overwrite the cached value with the new one. If cache write fails, a retry will be scheduled (unless disabled by setting CacheConfig.CacheInvalidationRetryDelay to 0) After which the cache will be invalidated. The values retrieved from storage within this period (between Set call and invalidation) can be inconsistent.

type CacheConfig

type CacheConfig struct {
	Expiration                  time.Duration `yaml:"expiration"`
	CacheInvalidationRetryDelay time.Duration `yaml:"cache_invalidation_retry_delay"`
}

func (*CacheConfig) RegisterFlags

func (c *CacheConfig) RegisterFlags(flags *flag.FlagSet)

func (*CacheConfig) RegisterFlagsWithPrefix

func (c *CacheConfig) RegisterFlagsWithPrefix(prefix string, flags *flag.FlagSet)

RegisterFlagsWithPrefix registers flags, adding the provided prefix if needed. If the prefix is not blank and doesn't end with '.', a '.' is appended to it.

type CacheKeygen

type CacheKeygen interface {
	HostKey(orgID, hostName string) string
}

type CacheRecorder

type CacheRecorder interface {
	// contains filtered or unexported methods
}

func NewCacheRecorder

func NewCacheRecorder(reg prometheus.Registerer) CacheRecorder

type Cortex

type Cortex struct {
	// contains filtered or unexported fields
}

func (*Cortex) Get

func (c *Cortex) Get(ctx context.Context, hostName string) ([]prompb.Label, error)

Get fetches the labels for a given host, or returns a NotFoundError if no labels were defined for that host. Labels are sorted lexicographically by label name.

func (*Cortex) GetAll

func (c *Cortex) GetAll(ctx context.Context, from time.Time) (map[string]Host, error)

GetAll fetches all host tags in the specified time window and returns a map where the key elements are host names and the values are prometheus labels. For each host, labels are sorted lexicographically by label name. The actual LastReportedField value may be up to 5 minutes earlier compared to the actual value due to Cortex staleness handling

func (*Cortex) Set

func (c *Cortex) Set(ctx context.Context, hostName string, lbls []prompb.Label) error

type Getter

type Getter interface {
	Get(ctx context.Context, hostName string) ([]prompb.Label, error)
	GetAll(ctx context.Context, from time.Time) (map[string]Host, error)
}

func NewCachedGetter

func NewCachedGetter(
	log ctxlog.Provider,
	getter Getter,
	cache memcached.Client,
	keygen CacheKeygen,
	recorder CacheRecorder,
	tracer opentracing.Tracer,
	cfg CacheConfig,
	timeAfterFunc func(d time.Duration, f func()) *time.Timer,
) Getter

func NewCortexGetter

func NewCortexGetter(read remoteread.API, timeNow func() time.Time) Getter

type Host

type Host struct {
	Labels []prompb.Label
	// The last time the host reported their labels. The accuracy of the timestamp depends on the Getter implementation
	LastReportedTime time.Time
}

type MemcacheKeygen

type MemcacheKeygen struct{}

MemcacheKeygen generates keys shorter than 250 characters and don't contain whitespaces

func (MemcacheKeygen) HostKey

func (MemcacheKeygen) HostKey(orgID, hostName string) string

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Message

func (e NotFoundError) Message() string

func (NotFoundError) Unwrap

func (e NotFoundError) Unwrap() error

type Storage

type Storage interface {
	Getter
	Set(ctx context.Context, hostName string, labels []prompb.Label) error
}

Storage specifies necessary methods to storage and fetch datadog host labels that are periodically sent by the agents

func NewCachedStorage

func NewCachedStorage(
	log ctxlog.Provider,
	storage Storage,
	cache memcached.Client,
	keygen CacheKeygen,
	recorder CacheRecorder,
	tracer opentracing.Tracer,
	cfg CacheConfig,
	timeAfterFunc func(d time.Duration, f func()) *time.Timer,
) Storage

func NewCortexStorage

func NewCortexStorage(write remotewrite.Client, read remoteread.API, timeNow func() time.Time) Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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