discoveryutil

package
v1.110.21 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockingClientReadTimeout is the maximum duration for waiting the response from GetBlockingAPI*
	BlockingClientReadTimeout = 10 * time.Minute

	// DefaultClientReadTimeout is the maximum duration for waiting the response from GetAPI*
	DefaultClientReadTimeout = time.Minute
)

Variables

This section is empty.

Functions

func AddTagsToLabels

func AddTagsToLabels(m *promutil.Labels, tags []string, prefix, tagSeparator string)

AddTagsToLabels adds <prefix>_tags (separated with tagSeparator) to labels and exposes individual tags via <prefix>_tag_* labels, so users could move all the tags into the discovered scrape target with the following relabeling rule in the way similar to kubernetes_sd_configs:

  • action: labelmap regex: <prefix>_tag_(.+)

This solves https://stackoverflow.com/questions/44339461/relabeling-in-prometheus

func EscapeIPv6Host

func EscapeIPv6Host(host string) string

EscapeIPv6Host escapes ipv6 host with square brackets. Note that host must be ipv6 address.

func GetHTTPClient

func GetHTTPClient() *http.Client

GetHTTPClient returns default client for http API requests.

func IsIPv6Host

func IsIPv6Host(host string) bool

IsIPv6Host returns true if host is ipv6 address.

func JoinHostPort

func JoinHostPort(host string, port int) string

JoinHostPort returns host:port.

Host may be dns name, ipv4 or ipv6 address.

func SanitizeLabelName

func SanitizeLabelName(name string) string

SanitizeLabelName replaces anything that doesn't match client_label.LabelNameRE with an underscore.

This has been copied from Prometheus sources at util/strutil/strconv.go

func SleepCtx

func SleepCtx(ctx context.Context, sleepDuration time.Duration) bool

SleepCtx sleeps for sleepDuration.

It immediately returns false on ctx cancel or deadline, without waiting for sleepDuration.

func TestEqualLabelss

func TestEqualLabelss(t *testing.T, got, want []*promutil.Labels)

TestEqualLabelss tests whether got are equal to want.

Types

type Client

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

Client is http client, which talks to the given apiServer passed to NewClient().

func NewClient

func NewClient(apiServer string, ac *promauth.Config, proxyURL *proxy.URL, proxyAC *promauth.Config, httpCfg *promauth.HTTPClientConfig) (*Client, error)

NewClient returns new Client for the given args.

func (*Client) APIServer

func (c *Client) APIServer() string

APIServer returns the API server address

func (*Client) Context

func (c *Client) Context() context.Context

Context returns context for the client requests.

func (*Client) GetAPIResponse

func (c *Client) GetAPIResponse(path string) ([]byte, error)

GetAPIResponse returns response for the given absolute path.

func (*Client) GetAPIResponseWithParamsCtx

func (c *Client) GetAPIResponseWithParamsCtx(ctx context.Context, path string, modifyRequest RequestCallback, inspectResponse ResponseCallback) ([]byte, error)

GetAPIResponseWithParamsCtx returns response for given absolute path with blocking client and optional callback for api response,

func (*Client) GetAPIResponseWithReqParams

func (c *Client) GetAPIResponseWithReqParams(path string, modifyRequest RequestCallback) ([]byte, error)

GetAPIResponseWithReqParams returns response for given absolute path with optional callback for request.

func (*Client) GetBlockingAPIResponse

func (c *Client) GetBlockingAPIResponse(path string, inspectResponse ResponseCallback) ([]byte, error)

GetBlockingAPIResponse returns response for given absolute path with blocking client and optional callback for api response,

func (*Client) GetBlockingAPIResponseCtx

func (c *Client) GetBlockingAPIResponseCtx(ctx context.Context, path string, inspectResponse ResponseCallback) ([]byte, error)

GetBlockingAPIResponseCtx returns response for given absolute path with blocking client and optional callback for api response,

func (*Client) Stop

func (c *Client) Stop()

Stop cancels all in-flight requests

type ConfigMap

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

ConfigMap is a map for storing discovery api configs.

It automatically removes old configs which weren't accessed recently.

func NewConfigMap

func NewConfigMap() *ConfigMap

NewConfigMap creates ConfigMap

func (*ConfigMap) Delete

func (cm *ConfigMap) Delete(key any) any

Delete deletes config for the given key from cm and returns it.

func (*ConfigMap) Get

func (cm *ConfigMap) Get(key any, newConfig func() (any, error)) (any, error)

Get returns config for the given key.

Key must be a pointer.

It creates new config map with newConfig() call if cm doesn't contain config under the given key.

type HTTPClient

type HTTPClient struct {
	ReadTimeout time.Duration
	// contains filtered or unexported fields
}

HTTPClient is a wrapper around http.Client with timeouts.

type RequestCallback

type RequestCallback func(req *http.Request)

RequestCallback is called on the request before sending the request to the server.

type ResponseCallback

type ResponseCallback func(resp *http.Response)

ResponseCallback is called on the response before validating and returning the response to the caller.

Jump to

Keyboard shortcuts

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