util

package
v0.0.0-...-bfa2730 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: AGPL-3.0 Imports: 42 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 (
	QuerySnapshotsEndpoint = "/api/snapshots"
)
View Source
const (
	// TenantIDHeaderName denotes the TenantID the request has been authenticated as
	TenantIDHeaderName = user.OrgIDHeaderName
)

Variables

View Source
var (
	// ErrSnapshotNotFound can be used when we don't find a snapshot
	ErrSnapshotNotFound = errors.New("snaplshot 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 DiffConfig

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

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

func EqualHexStringSnapshotIDs

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

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

func ExtractTenantID

func ExtractTenantID(ctx context.Context) (string, error)

ExtractTenantID will extract the tenant ID from the context

func ExtractTraceID

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

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

func GetFirstAddressOf

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 HexStringToSnapshotID

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

func HexStringToSnapshotIDUnsafe

func HexStringToSnapshotIDUnsafe(id string) []byte

func InjectTenantID

func InjectTenantID(ctx context.Context, tenantID string) context.Context

InjectTenantID will inject the tenant ID into the context

func InjectTenantIDIntoHTTPRequest

func InjectTenantIDIntoHTTPRequest(ctx context.Context, r *http.Request) error

InjectTenantIDIntoHTTPRequest will inject the tenant ID into the request

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

func IsRequestBodyTooLarge(err error) bool

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

func NewDNSWatcher

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 PadSnapshotIDTo16Bytes

func PadSnapshotIDTo16Bytes(snapshotID []byte) []byte

func ParseProtoReader

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 Remove

func Remove[S ~[]E, E any](array S, index int) S

func RemoveAll

func RemoveAll[S ~[]E, E any](slice S, idxs ...int) S

func RenderHTTPResponse

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

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

SerializeProtoResponse serializes a protobuf response into an HTTP response.

func SnapshotIDToHexString

func SnapshotIDToHexString(byteID []byte) string

SnapshotIDToHexString converts a snapshot ID to its string representation and removes any leading zeros.

func StreamWriteYAMLResponse

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

StreamWriteYAMLResponse stream writes data as http response

func StringifyAnyValue

func StringifyAnyValue(anyValue *v1common.AnyValue) string

func TabOut

func TabOut(s fmt.Stringer) string

func TokenFor

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

TokenFor generates a token used for finding ingesters from ring

func TokenForSnapshotID

func TokenForSnapshotID(b []byte) uint32

TokenForSnapshotID generates a hashed value for a snapshot id

func WriteHTMLResponse

func WriteHTMLResponse(w http.ResponseWriter, message string)

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

func WriteJSONResponse

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

WriteJSONResponse writes some JSON as a HTTP response.

func WriteTextResponse

func WriteTextResponse(w http.ResponseWriter, message string)

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

func WriteYAMLResponse

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

WriteYAMLResponse writes some YAML as a HTTP response.

func YAMLMarshalUnmarshal

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

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

func NewActiveUsers() *ActiveUsers

func (*ActiveUsers) PurgeInactiveUsers

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

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

func (*ActiveUsers) UpdateUserTimestamp

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

type ActiveUsersCleanupService

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

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

func NewActiveUsersCleanupService

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

func NewActiveUsersCleanupWithDefaultValues

func NewActiveUsersCleanupWithDefaultValues(cleanupFn func(string)) *ActiveUsersCleanupService

func (*ActiveUsersCleanupService) UpdateUserTimestamp

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

type BasicAuth

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

func (b BasicAuth) IsEnabled() bool

IsEnabled returns false if basic authentication isn't enabled.

func (*BasicAuth) RegisterFlagsWithPrefix

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

type Client

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

Client is client to the Deep API.

func NewClient

func NewClient(baseURL, tenantID string) *Client

func NewClientWithCompression

func NewClientWithCompression(baseURL, tenantID string) *Client

func (*Client) Do

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

func (*Client) QuerySnapshot

func (c *Client) QuerySnapshot(id string) (*deep_tp.Snapshot, error)

func (*Client) Search

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

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

func (*Client) SearchDeepQL

func (c *Client) SearchDeepQL(query string) (*deeppb.SearchResponse, error)

func (*Client) SearchTagValues

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

func (*Client) SearchTags

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

func (*Client) SearchWithRange

func (c *Client) SearchWithRange(tags string, start int64, end int64) (*deeppb.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

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

type CompressionType

type CompressionType int

CompressionType for encoding and decoding requests and responses.

const (
	NoCompression CompressionType = iota
	RawSnappy
)

Values for CompressionType

type DNSNotifications

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 DistinctStringCollector

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

func NewDistinctStringCollector

func NewDistinctStringCollector(maxDataSize int) *DistinctStringCollector

NewDistinctStringCollector with the given maximum data size. This is calculated as the total length of the recorded strings. For ease of use, maximum=0 is interpreted as unlimited.

func (*DistinctStringCollector) Collect

func (d *DistinctStringCollector) Collect(s string)

func (*DistinctStringCollector) Exceeded

func (d *DistinctStringCollector) Exceeded() bool

Exceeded indicates if some values were lost because the maximum size limit was met.

func (*DistinctStringCollector) Strings

func (d *DistinctStringCollector) Strings() []string

Strings returns the final list of distinct values collected and sorted.

func (*DistinctStringCollector) TotalDataSize

func (d *DistinctStringCollector) TotalDataSize() int

TotalDataSize is the total size of all distinct strings encountered.

type DistinctValueCollector

type DistinctValueCollector[T comparable] struct {
	// contains filtered or unexported fields
}

func NewDistinctValueCollector

func NewDistinctValueCollector[T comparable](maxDataSize int, len func(T) int) *DistinctValueCollector[T]

NewDistinctStringCollector with the given maximum data size. This is calculated as the total length of the recorded strings. For ease of use, maximum=0 is interpreted as unlimited.

func (*DistinctValueCollector[T]) Collect

func (d *DistinctValueCollector[T]) Collect(v T) (exceeded bool)

func (*DistinctValueCollector[T]) Exceeded

func (d *DistinctValueCollector[T]) Exceeded() bool

Exceeded indicates if some values were lost because the maximum size limit was met.

func (*DistinctValueCollector[T]) TotalDataSize

func (d *DistinctValueCollector[T]) TotalDataSize() int

TotalDataSize is the total size of all distinct strings encountered.

func (*DistinctValueCollector[T]) Values

func (d *DistinctValueCollector[T]) Values() []T

Strings returns the final list of distinct values collected and sorted.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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