util

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: AGPL-3.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FakeTenantID is the tenant ID to be used when operating with authorization disabled
	FakeTenantID = "single-tenant"
)
View Source
const (
	QueryTraceEndpoint = "/api/traces"
)

Variables

View Source
var (
	// ErrTraceNotFound can be used when we don't find a trace
	ErrTraceNotFound = errors.New("trace not found")

	// ErrSearchKeyValueNotFound is used to indicate the requested key/value pair was not found.
	ErrSearchKeyValueNotFound = errors.New("key/value not found")

	ErrUnsupported = fmt.Errorf("unsupported")
)

Functions

func DeleteMatchingLabels added in v1.4.0

func DeleteMatchingLabels(c CollectorVec, filter map[string]string) error

DeleteMatchingLabels removes metric with labels matching the filter.

func DiffConfig added in v1.4.0

func DiffConfig(defaultConfig, actualConfig map[interface{}]interface{}) (map[interface{}]interface{}, error)

DiffConfig utility function that returns the diff between two config map objects

func EqualHexStringTraceIDs added in v1.2.0

func EqualHexStringTraceIDs(a, b string) (bool, error)

EqualHexStringTraceIDs compares two trace ID strings and compares the resulting bytes after padding. Returns true unless there is a reason not to.

func ExtractTraceID added in v1.1.0

func ExtractTraceID(ctx context.Context) (string, bool)

ExtractTraceID extracts the trace id, if any from the context.

func FromLabelPairsToLabels added in v1.4.0

func FromLabelPairsToLabels(pairs []*dto.LabelPair) labels.Labels

FromLabelPairsToLabels converts dto.LabelPair into labels.Labels.

func GetFirstAddressOf added in v1.4.0

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

GetFirstAddressOf returns the first IPv4 address of the supplied interface names, omitting any 169.254.x.x automatic private IPs if possible.

func GetLabels added in v1.4.0

func GetLabels(c prometheus.Collector, filter map[string]string) ([]labels.Labels, error)

GetLables returns list of label combinations used by this collector at the time of call. This can be used to find and delete unused metrics.

func GetSumOfHistogramSampleCount added in v1.4.0

func GetSumOfHistogramSampleCount(families []*dto.MetricFamily, metricName string, matchers labels.Selector) uint64

GetSumOfHistogramSampleCount returns the sum of samples count of histograms matching the provided metric name and optional label matchers. Returns 0 if no metric matches.

func HexStringToTraceID

func HexStringToTraceID(id string) ([]byte, error)

func IsConnCanceled

func IsConnCanceled(err error) bool

IsConnCanceled returns true, if error is from a closed gRPC connection. copied from https://github.com/etcd-io/etcd/blob/7f47de84146bdc9225d2080ec8678ca8189a2d2b/clientv3/client.go#L646

func IsRequestBodyTooLarge added in v1.4.0

func IsRequestBodyTooLarge(err error) bool

IsRequestBodyTooLarge returns true if the error is "http: request body too large".

func MapSizeWithinLimit added in v1.3.0

func MapSizeWithinLimit(uniqueMap map[string]struct{}, limit int) bool

MapSizeWithinLimit evaluates the total size of all keys in the map against the limit

func NewDNSWatcher added in v1.4.0

func NewDNSWatcher(address string, dnsLookupPeriod time.Duration, notifications DNSNotifications) (services.Service, error)

NewDNSWatcher creates a new DNS watcher and returns a service that is wrapping it.

func ParseProtoReader added in v1.4.0

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

ParseProtoReader parses a compressed proto from an io.Reader.

func PrefixConfig

func PrefixConfig(prefix string, option string) string

func RandomAttrFromTrace added in v1.2.0

func RandomAttrFromTrace(t *tempopb.Trace) *v1common.KeyValue

func RenderHTTPResponse added in v1.4.0

func RenderHTTPResponse(w http.ResponseWriter, v interface{}, t *template.Template, r *http.Request)

RenderHTTPResponse either responds with json or a rendered html page using the passed in template by checking the Accepts header

func SerializeProtoResponse added in v1.4.0

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

SerializeProtoResponse serializes a protobuf response into an HTTP response.

func StreamWriteYAMLResponse added in v1.4.0

func StreamWriteYAMLResponse(w http.ResponseWriter, iter chan interface{}, logger log.Logger)

StreamWriteYAMLResponse stream writes data as http response

func StringifyAnyValue added in v1.4.0

func StringifyAnyValue(anyValue *v1common.AnyValue) string

func TokenFor

func TokenFor(userID string, b []byte) uint32

TokenFor generates a token used for finding ingesters from ring

func TokenForTraceID

func TokenForTraceID(b []byte) uint32

TokenForTraceID generates a hashed value for a trace id

func TraceIDToHexString added in v1.2.0

func TraceIDToHexString(byteID []byte) string

TraceIDToHexString converts a trace ID to its string representation and removes any leading zeros.

func WriteHTMLResponse added in v1.4.0

func WriteHTMLResponse(w http.ResponseWriter, message string)

Sends message as text/html response with 200 status code.

func WriteJSONResponse added in v1.4.0

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

WriteJSONResponse writes some JSON as a HTTP response.

func WriteTextResponse added in v1.4.0

func WriteTextResponse(w http.ResponseWriter, message string)

Sends message as text/plain response with 200 status code.

func WriteYAMLResponse added in v1.4.0

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

WriteYAMLResponse writes some YAML as a HTTP response.

func YAMLMarshalUnmarshal added in v1.4.0

func YAMLMarshalUnmarshal(in interface{}) (map[interface{}]interface{}, error)

YAMLMarshalUnmarshal utility function that converts a YAML interface in a map doing marshal and unmarshal of the parameter

Types

type ActiveUsers added in v1.4.0

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

ActiveUsers keeps track of latest user's activity timestamp, and allows purging users that are no longer active.

func NewActiveUsers added in v1.4.0

func NewActiveUsers() *ActiveUsers

func (*ActiveUsers) PurgeInactiveUsers added in v1.4.0

func (m *ActiveUsers) PurgeInactiveUsers(deadline int64) []string

PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.

func (*ActiveUsers) UpdateUserTimestamp added in v1.4.0

func (m *ActiveUsers) UpdateUserTimestamp(userID string, ts int64)

type ActiveUsersCleanupService added in v1.4.0

type ActiveUsersCleanupService struct {
	services.Service
	// contains filtered or unexported fields
}

ActiveUsersCleanupService tracks active users, and periodically purges inactive ones while running.

func NewActiveUsersCleanupService added in v1.4.0

func NewActiveUsersCleanupService(cleanupInterval, inactiveTimeout time.Duration, cleanupFn func(string)) *ActiveUsersCleanupService

func NewActiveUsersCleanupWithDefaultValues added in v1.4.0

func NewActiveUsersCleanupWithDefaultValues(cleanupFn func(string)) *ActiveUsersCleanupService

func (*ActiveUsersCleanupService) UpdateUserTimestamp added in v1.4.0

func (s *ActiveUsersCleanupService) UpdateUserTimestamp(user string, now time.Time)

type BasicAuth added in v1.4.0

type BasicAuth struct {
	Username string `yaml:"basic_auth_username"`
	Password string `yaml:"basic_auth_password"`
}

BasicAuth configures basic authentication for HTTP clients.

func (BasicAuth) IsEnabled added in v1.4.0

func (b BasicAuth) IsEnabled() bool

IsEnabled returns false if basic authentication isn't enabled.

func (*BasicAuth) RegisterFlagsWithPrefix added in v1.4.0

func (b *BasicAuth) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

type Client added in v1.2.0

type Client struct {
	BaseURL string
	OrgID   string
	// contains filtered or unexported fields
}

Client is client to the Tempo API.

func NewClient added in v1.2.0

func NewClient(baseURL, orgID string) *Client

func NewClientWithCompression added in v1.3.0

func NewClientWithCompression(baseURL, orgID string) *Client

func (*Client) Do added in v1.3.0

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) QueryTrace added in v1.2.0

func (c *Client) QueryTrace(id string) (*tempopb.Trace, error)

func (*Client) Search added in v1.2.0

func (c *Client) Search(tags string) (*tempopb.SearchResponse, error)

Search Tempo. tags must be in logfmt format, that is "key1=value1 key2=value2"

func (*Client) SearchTagValues added in v1.2.0

func (c *Client) SearchTagValues(key string) (*tempopb.SearchTagValuesResponse, error)

func (*Client) SearchTags added in v1.2.0

func (c *Client) SearchTags() (*tempopb.SearchTagsResponse, error)

func (*Client) SearchWithRange added in v1.3.0

func (c *Client) SearchWithRange(tags string, start int64, end int64) (*tempopb.SearchResponse, error)

SearchWithRange calls the /api/search endpoint. tags is expected to be in logfmt format and start/end are unix epoch timestamps in seconds.

func (*Client) WithTransport added in v1.3.0

func (c *Client) WithTransport(t http.RoundTripper)

type CollectorVec added in v1.4.0

type CollectorVec interface {
	prometheus.Collector
	Delete(labels prometheus.Labels) bool
}

CollectorVec is a collector that can delete metrics by labels. Implemented by *prometheus.MetricVec (used by CounterVec, GaugeVec, SummaryVec, and HistogramVec).

type CompressionType added in v1.4.0

type CompressionType int

CompressionType for encoding and decoding requests and responses.

const (
	NoCompression CompressionType = iota
	RawSnappy
)

Values for CompressionType

type DNSNotifications added in v1.4.0

type DNSNotifications interface {
	// New address has been discovered by DNS watcher for supplied hostname.
	AddressAdded(address string)

	// Previously-discovered address is no longer resolved for the hostname.
	AddressRemoved(address string)
}

Notifications about address resolution. All notifications are sent on the same goroutine.

type HistogramData added in v1.4.0

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

HistogramData keeps data required to build histogram Metric.

func (*HistogramData) AddHistogram added in v1.4.0

func (d *HistogramData) AddHistogram(histo *dto.Histogram)

AddHistogram adds histogram from gathered metrics to this histogram data. Do not call this function after Metric() has been invoked, because histogram created by Metric is using the buckets map (doesn't make a copy), and it's not allowed to change the buckets after they've been passed to a prometheus.Metric.

func (*HistogramData) AddHistogramData added in v1.4.0

func (d *HistogramData) AddHistogramData(histo HistogramData)

AddHistogramData merges another histogram data into this one. Do not call this function after Metric() has been invoked, because histogram created by Metric is using the buckets map (doesn't make a copy), and it's not allowed to change the buckets after they've been passed to a prometheus.Metric.

func (*HistogramData) Copy added in v1.4.0

func (d *HistogramData) Copy() *HistogramData

Copy returns a copy of this histogram data.

func (*HistogramData) Metric added in v1.4.0

func (d *HistogramData) Metric(desc *prometheus.Desc, labelValues ...string) prometheus.Metric

Metric returns prometheus metric from this histogram data.

Note that returned metric shares bucket with this HistogramData, so avoid doing more modifications to this HistogramData after calling Metric.

type HistogramDataCollector added in v1.4.0

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

HistogramDataCollector combines histogram data, with prometheus descriptor. It can be registered into prometheus to report histogram with stored data. Data can be updated via Add method.

func NewHistogramDataCollector added in v1.4.0

func NewHistogramDataCollector(desc *prometheus.Desc) *HistogramDataCollector

NewHistogramDataCollector creates new histogram data collector.

func (*HistogramDataCollector) Add added in v1.4.0

func (*HistogramDataCollector) Collect added in v1.4.0

func (h *HistogramDataCollector) Collect(out chan<- prometheus.Metric)

func (*HistogramDataCollector) Describe added in v1.4.0

func (h *HistogramDataCollector) Describe(out chan<- *prometheus.Desc)

type MetricFamiliesPerUser added in v1.4.0

type MetricFamiliesPerUser []struct {
	// contains filtered or unexported fields
}

MetricFamiliesPerUser is a collection of metrics gathered via calling Gatherer.Gather() method on different gatherers, one per user.

func (MetricFamiliesPerUser) GetSumOfCounters added in v1.4.0

func (d MetricFamiliesPerUser) GetSumOfCounters(counter string) float64

func (MetricFamiliesPerUser) GetSumOfGauges added in v1.4.0

func (d MetricFamiliesPerUser) GetSumOfGauges(gauge string) float64

func (MetricFamiliesPerUser) SendMaxOfGauges added in v1.4.0

func (d MetricFamiliesPerUser) SendMaxOfGauges(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerUser) SendMaxOfGaugesPerUser added in v1.4.0

func (d MetricFamiliesPerUser) SendMaxOfGaugesPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerUser) SendSumOfCounters added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfCounters(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string)

func (MetricFamiliesPerUser) SendSumOfCountersPerUser added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfCountersPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string)

func (MetricFamiliesPerUser) SendSumOfCountersPerUserWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfCountersPerUserWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, labelNames ...string)

SendSumOfCountersPerUserWithLabels provides metrics with the provided label names on a per-user basis. This function assumes that `user` is the first label on the provided metric Desc

func (MetricFamiliesPerUser) SendSumOfCountersWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfCountersWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, counter string, labelNames ...string)

func (MetricFamiliesPerUser) SendSumOfGauges added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfGauges(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerUser) SendSumOfGaugesPerUser added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfGaugesPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string)

func (MetricFamiliesPerUser) SendSumOfGaugesPerUserWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfGaugesPerUserWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, metric string, labelNames ...string)

SendSumOfGaugesPerUserWithLabels provides metrics with the provided label names on a per-user basis. This function assumes that `user` is the first label on the provided metric Desc

func (MetricFamiliesPerUser) SendSumOfGaugesWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfGaugesWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, gauge string, labelNames ...string)

func (MetricFamiliesPerUser) SendSumOfHistograms added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfHistograms(out chan<- prometheus.Metric, desc *prometheus.Desc, histogramName string)

func (MetricFamiliesPerUser) SendSumOfHistogramsWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfHistogramsWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, histogramName string, labelNames ...string)

func (MetricFamiliesPerUser) SendSumOfSummaries added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfSummaries(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string)

func (MetricFamiliesPerUser) SendSumOfSummariesPerUser added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfSummariesPerUser(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string)

func (MetricFamiliesPerUser) SendSumOfSummariesWithLabels added in v1.4.0

func (d MetricFamiliesPerUser) SendSumOfSummariesWithLabels(out chan<- prometheus.Metric, desc *prometheus.Desc, summaryName string, labelNames ...string)

type MetricFamilyMap added in v1.4.0

type MetricFamilyMap map[string]*dto.MetricFamily

MetricFamilyMap is a map of metric names to their family (metrics with same name, but different labels) Keeping map of metric name to its family makes it easier to do searches later.

func NewMetricFamilyMap added in v1.4.0

func NewMetricFamilyMap(metrics []*dto.MetricFamily) (MetricFamilyMap, error)

NewMetricFamilyMap sorts output from Gatherer.Gather method into a map. Gatherer.Gather specifies that there metric families are uniquely named, and we use that fact here. If they are not, this method returns error.

func (MetricFamilyMap) MaxGauges added in v1.4.0

func (mfm MetricFamilyMap) MaxGauges(name string) float64

func (MetricFamilyMap) SumCounters added in v1.4.0

func (mfm MetricFamilyMap) SumCounters(name string) float64

func (MetricFamilyMap) SumGauges added in v1.4.0

func (mfm MetricFamilyMap) SumGauges(name string) float64

func (MetricFamilyMap) SumHistograms added in v1.4.0

func (mfm MetricFamilyMap) SumHistograms(name string) HistogramData

func (MetricFamilyMap) SumHistogramsTo added in v1.4.0

func (mfm MetricFamilyMap) SumHistogramsTo(name string, output *HistogramData)

func (MetricFamilyMap) SumSummaries added in v1.4.0

func (mfm MetricFamilyMap) SumSummaries(name string) SummaryData

func (MetricFamilyMap) SumSummariesTo added in v1.4.0

func (mfm MetricFamilyMap) SumSummariesTo(name string, output *SummaryData)

type MultiError

type MultiError []error

The MultiError type implements the error interface, and contains the Errors used to construct it.

func (*MultiError) Add

func (es *MultiError) Add(err error)

Add adds the error to the error list if it is not nil.

func (MultiError) Err

func (es MultiError) Err() error

Err returns the error list as an error or nil if it is empty.

func (MultiError) Error

func (es MultiError) Error() string

Returns a concatenated string of the contained errors

type SummaryData added in v1.4.0

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

SummaryData keeps all data needed to create summary metric

func (*SummaryData) AddSummary added in v1.4.0

func (s *SummaryData) AddSummary(sum *dto.Summary)

func (*SummaryData) Metric added in v1.4.0

func (s *SummaryData) Metric(desc *prometheus.Desc, labelValues ...string) prometheus.Metric

type TraceInfo added in v1.2.0

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

TraceInfo is used to construct synthetic traces and manage the expectations.

func NewTraceInfo added in v1.2.0

func NewTraceInfo(timestamp time.Time, tempoOrgID string) *TraceInfo

NewTraceInfo is used to produce a new TraceInfo.

func (*TraceInfo) ConstructTraceFromEpoch added in v1.2.0

func (t *TraceInfo) ConstructTraceFromEpoch() (*tempopb.Trace, error)

func (*TraceInfo) Done added in v1.2.0

func (t *TraceInfo) Done()

func (*TraceInfo) EmitAllBatches added in v1.2.0

func (t *TraceInfo) EmitAllBatches(c *jaeger_grpc.Reporter) error

EmitAllBatches sends all the batches that would normally be sent at some interval when using EmitBatches.

func (*TraceInfo) EmitBatches added in v1.2.0

func (t *TraceInfo) EmitBatches(c *jaeger_grpc.Reporter) error

func (*TraceInfo) HexID added in v1.2.0

func (t *TraceInfo) HexID() string

func (*TraceInfo) LongWritesRemaining added in v1.2.0

func (t *TraceInfo) LongWritesRemaining() int64

func (*TraceInfo) Ready added in v1.2.0

func (t *TraceInfo) Ready(now time.Time, writeBackoff, longWriteBackoff time.Duration) bool

func (*TraceInfo) Timestamp added in v1.2.0

func (t *TraceInfo) Timestamp() time.Time

func (*TraceInfo) TraceID added in v1.2.0

func (t *TraceInfo) TraceID() ([]byte, error)

type UserRegistries added in v1.4.0

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

UserRegistries holds Prometheus registries for multiple users, guaranteeing multi-thread safety and stable ordering.

func NewUserRegistries added in v1.4.0

func NewUserRegistries() *UserRegistries

NewUserRegistries makes new UserRegistries.

func (*UserRegistries) AddUserRegistry added in v1.4.0

func (r *UserRegistries) AddUserRegistry(user string, reg *prometheus.Registry)

AddUserRegistry adds an user registry. If user already has a registry, previous registry is removed, but latest metric values are preserved in order to avoid counter resets.

func (*UserRegistries) BuildMetricFamiliesPerUser added in v1.4.0

func (r *UserRegistries) BuildMetricFamiliesPerUser() MetricFamiliesPerUser

func (*UserRegistries) Registries added in v1.4.0

func (r *UserRegistries) Registries() []UserRegistry

Registries returns a copy of the user registries list.

func (*UserRegistries) RemoveUserRegistry added in v1.4.0

func (r *UserRegistries) RemoveUserRegistry(user string, hard bool)

RemoveUserRegistry removes all Prometheus registries for a given user. If hard is true, registry is removed completely. If hard is false, latest registry values are preserved for future aggregations.

type UserRegistry added in v1.4.0

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

UserRegistry holds a Prometheus registry associated to a specific user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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