util

package
v0.4.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2019 License: Apache-2.0 Imports: 31 Imported by: 181

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Logger is a shared go-kit logger.
	// TODO: Change all components to take a non-global logger via their constructors.
	Logger = log.NewNopLogger()
)

Functions

func CheckFatal

func CheckFatal(location string, err error)

CheckFatal prints an error and exits with error code 1 if err is non-nil

func Event

func Event() log.Logger

Event is the log-like API for event sampling

func GetFirstAddressOf

func GetFirstAddressOf(names []string) (string, error)

GetFirstAddressOf returns the first IPv4 address of the supplied interface names.

func HashFP

func HashFP(fp model.Fingerprint) uint32

HashFP simply moves entropy from the most significant 48 bits of the fingerprint into the least significant 16 bits (by XORing) so that a simple MOD on the result can be used to pick a mutex while still making use of changes in more significant bits of the fingerprint. (The fast fingerprinting function we use is prone to only change a few bits for similar metrics. We really want to make use of every change in the fingerprint to vary mutex selection.)

func InitEvents

func InitEvents(freq int)

InitEvents initializes event sampling, with the given frequency. Zero=off.

func InitLogger

func InitLogger(cfg *server.Config)

InitLogger initialises the global gokit logger (util.Logger) and overrides the default logger for the server.

func LabelsToMetric

func LabelsToMetric(ls labels.Labels) model.Metric

LabelsToMetric converts a Labels to Metric Don't do this on any performance sensitive paths.

func Max64

func Max64(a, b int64) int64

Max64 returns the maximum of two int64s

func MergeNSampleSets

func MergeNSampleSets(sampleSets ...[]model.SamplePair) []model.SamplePair

MergeNSampleSets merges and dedupes n sets of already sorted sample pairs.

func MergeSampleSets

func MergeSampleSets(a, b []model.SamplePair) []model.SamplePair

MergeSampleSets merges and dedupes two sets of already sorted sample pairs.

func Min

func Min(a, b int) int

Min returns the minimum of two ints

func Min64

func Min64(a, b int64) int64

Min64 returns the minimum of two int64s

func NewPrometheusLogger

func NewPrometheusLogger(l logging.Level) (log.Logger, error)

NewPrometheusLogger creates a new instance of PrometheusLogger which exposes Prometheus counters for various log levels.

func ParseProtoReader

func ParseProtoReader(ctx context.Context, reader io.Reader, expectedSize, maxSize int, req proto.Message, compression CompressionType) ([]byte, error)

ParseProtoReader parses a compressed proto from an io.Reader.

func SerializeProtoResponse

func SerializeProtoResponse(w http.ResponseWriter, resp proto.Message, compression CompressionType) error

SerializeProtoResponse serializes a protobuf response into an HTTP response.

func SplitFiltersAndMatchers

func SplitFiltersAndMatchers(allMatchers []*labels.Matcher) (filters, matchers []*labels.Matcher)

SplitFiltersAndMatchers splits empty matchers off, which are treated as filters, see #220

func WithContext

func WithContext(ctx context.Context, l log.Logger) log.Logger

WithContext returns a Logger that has information about the current user in its details.

e.g.

log := util.WithContext(ctx)
log.Errorf("Could not chunk chunks: %v", err)

func WithTraceID

func WithTraceID(traceID string, l log.Logger) log.Logger

WithTraceID returns a Logger that has information about the traceID in its details.

func WithUserID

func WithUserID(userID string, l log.Logger) log.Logger

WithUserID returns a Logger that has information about the current user in its details.

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, v interface{})

WriteJSONResponse writes some JSON as a HTTP response.

Types

type Backoff

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

Backoff implements exponential backoff with randomized wait times

func NewBackoff

func NewBackoff(ctx context.Context, cfg BackoffConfig) *Backoff

NewBackoff creates a Backoff object. Pass a Context that can also terminate the operation.

func (*Backoff) Err

func (b *Backoff) Err() error

Err returns the reason for terminating the backoff, or nil if it didn't terminate

func (*Backoff) NumRetries

func (b *Backoff) NumRetries() int

NumRetries returns the number of retries so far

func (*Backoff) Ongoing

func (b *Backoff) Ongoing() bool

Ongoing returns true if caller should keep going

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset the Backoff back to its initial condition

func (*Backoff) Wait

func (b *Backoff) Wait()

Wait sleeps for the backoff time then increases the retry count and backoff time Returns immediately if Context is terminated

type BackoffConfig

type BackoffConfig struct {
	MinBackoff time.Duration // start backoff at this level
	MaxBackoff time.Duration // increase exponentially to this level
	MaxRetries int           // give up after this many; zero means infinite retries
}

BackoffConfig configures a Backoff

func (*BackoffConfig) RegisterFlags

func (cfg *BackoffConfig) RegisterFlags(prefix string, f *flag.FlagSet)

RegisterFlags for BackoffConfig.

type CompressionType

type CompressionType int

CompressionType for encoding and decoding requests and responses.

const (
	NoCompression CompressionType = iota
	FramedSnappy
	RawSnappy
)

Values for CompressionType

func CompressionTypeFor

func CompressionTypeFor(version string) CompressionType

CompressionTypeFor a given version of the Prometheus remote storage protocol. See https://github.com/prometheus/prometheus/issues/2692.

type Op

type Op interface {
	Key() string
	Priority() int64 // The larger the number the higher the priority.
}

Op is an operation on the priority queue.

type PriorityQueue

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

PriorityQueue is a priority queue.

func NewPriorityQueue

func NewPriorityQueue(lengthGauge prometheus.Gauge) *PriorityQueue

NewPriorityQueue makes a new priority queue.

func (*PriorityQueue) Close

func (pq *PriorityQueue) Close()

Close signals that the queue should be closed when it is empty. A closed queue will not accept new items.

func (*PriorityQueue) Dequeue

func (pq *PriorityQueue) Dequeue() Op

Dequeue will return the op with the highest priority; block if queue is empty; returns nil if queue is closed.

func (*PriorityQueue) DiscardAndClose

func (pq *PriorityQueue) DiscardAndClose()

DiscardAndClose closes the queue and removes all the items from it.

func (*PriorityQueue) Enqueue

func (pq *PriorityQueue) Enqueue(op Op) bool

Enqueue adds an operation to the queue in priority order. Returns true if added; false if the operation was already on the queue.

func (*PriorityQueue) Length

func (pq *PriorityQueue) Length() int

Length returns the length of the queue.

type PrometheusLogger

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

PrometheusLogger exposes Prometheus counters for each of go-kit's log levels.

func (*PrometheusLogger) Log

func (pl *PrometheusLogger) Log(kv ...interface{}) error

Log increments the appropriate Prometheus counter depending on the log level.

type SampleStreamIterator

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

SampleStreamIterator is a struct and not just a renamed type because otherwise the Metric field and Metric() methods would clash.

func NewSampleStreamIterator

func NewSampleStreamIterator(ss *model.SampleStream) SampleStreamIterator

NewSampleStreamIterator creates a SampleStreamIterator

func (SampleStreamIterator) Close

func (it SampleStreamIterator) Close()

Close implements the SeriesIterator interface.

func (SampleStreamIterator) Metric

func (it SampleStreamIterator) Metric() metric.Metric

Metric implements the SeriesIterator interface.

func (SampleStreamIterator) RangeValues

func (it SampleStreamIterator) RangeValues(in metric.Interval) []model.SamplePair

RangeValues implements the SeriesIterator interface.

func (SampleStreamIterator) ValueAtOrBeforeTime

func (it SampleStreamIterator) ValueAtOrBeforeTime(ts model.Time) model.SamplePair

ValueAtOrBeforeTime implements the SeriesIterator interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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