Documentation ¶
Index ¶
- Variables
- func ExtractMetricNameFromMetric(m model.Metric) (model.LabelValue, error)
- func ExtractMetricNameMatcherFromMatchers(matchers []*labels.Matcher) (*labels.Matcher, []*labels.Matcher, bool)
- func FromLabelPairs(labelPairs []client.LabelPair) model.Metric
- func FromMetricsForLabelMatchersRequest(req *client.MetricsForLabelMatchersRequest) (model.Time, model.Time, [][]*labels.Matcher, error)
- func FromMetricsForLabelMatchersResponse(resp *client.MetricsForLabelMatchersResponse) []model.Metric
- func FromQueryRequest(req *client.QueryRequest) (model.Time, model.Time, []*labels.Matcher, error)
- func FromQueryResponse(resp *client.QueryResponse) model.Matrix
- func FromWriteRequest(req *client.WriteRequest) []model.Sample
- func GetFirstAddressOf(name string) (string, error)
- func InitLogger(level promlog.AllowedLevel)
- func Max64(a, b int64) int64
- func MergeNSampleSets(sampleSets ...[]model.SamplePair) []model.SamplePair
- func MergeSampleSets(a, b []model.SamplePair) []model.SamplePair
- func Min(a, b int) int
- func Min64(a, b int64) int64
- func ParseProtoRequest(ctx context.Context, r *http.Request, req proto.Message, ...) ([]byte, error)
- func RegisterFlags(rs ...Registerer)
- func SerializeProtoResponse(w http.ResponseWriter, resp proto.Message, compression CompressionType) error
- func SplitFiltersAndMatchers(allMatchers []*labels.Matcher) (filters, matchers []*labels.Matcher)
- func ToLabelPairs(metric model.Metric) []client.LabelPair
- func ToMetricsForLabelMatchersRequest(from, to model.Time, matchers []*labels.Matcher) (*client.MetricsForLabelMatchersRequest, error)
- func ToMetricsForLabelMatchersResponse(metrics []model.Metric) *client.MetricsForLabelMatchersResponse
- func ToQueryRequest(from, to model.Time, matchers []*labels.Matcher) (*client.QueryRequest, error)
- func ToQueryResponse(matrix model.Matrix) *client.QueryResponse
- func ToWriteRequest(samples []model.Sample) *client.WriteRequest
- func ValidateSample(s *model.Sample) error
- func WithContext(ctx context.Context, l log.Logger) log.Logger
- func WithUserID(userID string, l log.Logger) log.Logger
- func WriteJSONResponse(w http.ResponseWriter, v interface{})
- type Backoff
- type BackoffConfig
- type CompressionType
- type DayValue
- type HashBucketHistogram
- type HashBucketHistogramOpts
- type LogLevel
- type Op
- type PriorityQueue
- type PrometheusLogger
- type Registerer
- type SampleStreamIterator
- type URLValue
Constants ¶
This section is empty.
Variables ¶
var Logger = log.NewNopLogger()
Logger is a shared go-kit logger. TODO: Change all components to take a non-global logger via their constructors.
Functions ¶
func ExtractMetricNameFromMetric ¶
func ExtractMetricNameFromMetric(m model.Metric) (model.LabelValue, error)
ExtractMetricNameFromMetric extract the metric name from a model.Metric
func ExtractMetricNameMatcherFromMatchers ¶
func ExtractMetricNameMatcherFromMatchers(matchers []*labels.Matcher) (*labels.Matcher, []*labels.Matcher, bool)
ExtractMetricNameMatcherFromMatchers extracts the metric name from a set of matchers
func FromLabelPairs ¶
FromLabelPairs unpack a []client.LabelPair to a model.Metric
func FromMetricsForLabelMatchersRequest ¶
func FromMetricsForLabelMatchersRequest(req *client.MetricsForLabelMatchersRequest) (model.Time, model.Time, [][]*labels.Matcher, error)
FromMetricsForLabelMatchersRequest unpacks a MetricsForLabelMatchersRequest proto
func FromMetricsForLabelMatchersResponse ¶
func FromMetricsForLabelMatchersResponse(resp *client.MetricsForLabelMatchersResponse) []model.Metric
FromMetricsForLabelMatchersResponse unpacks a MetricsForLabelMatchersResponse proto
func FromQueryRequest ¶
FromQueryRequest unpacks a QueryRequest proto.
func FromQueryResponse ¶
func FromQueryResponse(resp *client.QueryResponse) model.Matrix
FromQueryResponse unpacks a QueryResponse proto.
func FromWriteRequest ¶
func FromWriteRequest(req *client.WriteRequest) []model.Sample
FromWriteRequest converts a WriteRequest proto into an array of samples.
func GetFirstAddressOf ¶
GetFirstAddressOf returns the first IPv4 address of the supplied interface name.
func InitLogger ¶
func InitLogger(level promlog.AllowedLevel)
InitLogger initializes the global logger according to the allowed log level.
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 ParseProtoRequest ¶
func ParseProtoRequest(ctx context.Context, r *http.Request, req proto.Message, compression CompressionType) ([]byte, error)
ParseProtoRequest parses a proto from the body of an HTTP request.
func RegisterFlags ¶
func RegisterFlags(rs ...Registerer)
RegisterFlags registers flags with the provided Registerers
func SerializeProtoResponse ¶
func SerializeProtoResponse(w http.ResponseWriter, resp proto.Message, compression CompressionType) error
SerializeProtoResponse serializes a protobuf response into an HTTP response.
func SplitFiltersAndMatchers ¶
SplitFiltersAndMatchers splits empty matchers off, which are treated as filters, see #220
func ToLabelPairs ¶
ToLabelPairs builds a []client.LabelPair from a model.Metric
func ToMetricsForLabelMatchersRequest ¶
func ToMetricsForLabelMatchersRequest(from, to model.Time, matchers []*labels.Matcher) (*client.MetricsForLabelMatchersRequest, error)
ToMetricsForLabelMatchersRequest builds a MetricsForLabelMatchersRequest proto
func ToMetricsForLabelMatchersResponse ¶
func ToMetricsForLabelMatchersResponse(metrics []model.Metric) *client.MetricsForLabelMatchersResponse
ToMetricsForLabelMatchersResponse builds a MetricsForLabelMatchersResponse proto
func ToQueryRequest ¶
ToQueryRequest builds a QueryRequest proto.
func ToQueryResponse ¶
func ToQueryResponse(matrix model.Matrix) *client.QueryResponse
ToQueryResponse builds a QueryResponse proto.
func ToWriteRequest ¶
func ToWriteRequest(samples []model.Sample) *client.WriteRequest
ToWriteRequest converts an array of samples into a WriteRequest proto.
func ValidateSample ¶
ValidateSample returns an err if the sample is invalid
func WithContext ¶
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 WithUserID ¶
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 ¶
Err returns the reason for terminating the backoff, or nil if it didn't terminate
func (*Backoff) NumRetries ¶
NumRetries returns the number of retries so far
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
func (*Backoff) WaitWithoutCounting ¶
func (b *Backoff) WaitWithoutCounting()
WaitWithoutCounting sleeps for the backoff time then increases 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
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 DayValue ¶
DayValue is a model.Time that can be used as a flag. NB it only parses days!
func NewDayValue ¶
NewDayValue makes a new DayValue; will round t down to the nearest midnight.
type HashBucketHistogram ¶
type HashBucketHistogram interface { prometheus.Metric prometheus.Collector Observe(string, uint32) Stop() }
HashBucketHistogram is used to track a histogram of per-bucket rates.
For instance, I want to know that 50% of rows are getting X QPS or lower and 99% are getting Y QPS of lower. At first glance, this would involve tracking write rate per row, and periodically sticking those numbers in a histogram. To make this fit in memory: instead of per-row, we keep N buckets of counters and hash the key to a bucket. Then every second we update a histogram with the bucket values (and zero the buckets).
Note, we want this metric to be relatively independent of the number of hash buckets and QPS of the service - we're trying to measure how well load balanced the write load is. So we normalise the values in the hash buckets such that if all buckets are '1', then we have even load. We do this by multiplying the number of ops per bucket by the number of buckets, and dividing by the number of ops.
func NewHashBucketHistogram ¶
func NewHashBucketHistogram(opts HashBucketHistogramOpts) HashBucketHistogram
NewHashBucketHistogram makes a new HashBucketHistogram
type HashBucketHistogramOpts ¶
type HashBucketHistogramOpts struct { prometheus.HistogramOpts HashBuckets int }
HashBucketHistogramOpts are the options for making a HashBucketHistogram
type LogLevel ¶
type LogLevel struct {
promlog.AllowedLevel
}
LogLevel supports registering a flag for the desired log level.
func (*LogLevel) RegisterFlags ¶
RegisterFlags adds the log level flag to the provided flagset.
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() *PriorityQueue
NewPriorityQueue makes a new priority queue.
func (*PriorityQueue) Close ¶
func (pq *PriorityQueue) Close()
Close signals that the queue is closed. 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) DrainAndClose ¶
func (pq *PriorityQueue) DrainAndClose()
DrainAndClose closed the queue and removes all the items from it.
func (*PriorityQueue) Enqueue ¶
func (pq *PriorityQueue) Enqueue(op Op)
Enqueue adds an operation to the queue in priority order. If the operation is already on the queue, it will be ignored.
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 MustNewPrometheusLogger ¶
func MustNewPrometheusLogger(l log.Logger) *PrometheusLogger
MustNewPrometheusLogger creates a new instance of PrometheusLogger which exposes Prometheus counters for various log levels. Contrarily to NewPrometheusLogger, it does not return any error to the caller, but panics instead. Use MustNewPrometheusLogger if you want a less verbose logger creation. Use NewPrometheusLogger if you want more control.
func NewPrometheusLogger ¶
func NewPrometheusLogger(l log.Logger) (*PrometheusLogger, error)
NewPrometheusLogger creates a new instance of PrometheusLogger which exposes Prometheus counters for various log levels. Contrarily to MustNewPrometheusLogger, it returns an error to the caller in case of issue. Use NewPrometheusLogger if you want more control. Use MustNewPrometheusLogger if you want a less verbose logger creation.
func (*PrometheusLogger) Log ¶
func (pl *PrometheusLogger) Log(kv ...interface{}) error
Log increments the appropriate Prometheus counter depending on the log level.
type Registerer ¶
Registerer is a thing that can RegisterFlags
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.