client

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDuration

func ParseDuration(value any, unixTimeUnit UnixTimeUnit) (time.Duration, error)

ParseDuration parses duration from an unknown value

func ParseTimestamp

func ParseTimestamp(s any, unixTimeUnit UnixTimeUnit) (*time.Time, error)

ParseTimestamp parses timestamp from an unknown value

Types

type AuthConfig added in v0.0.2

type AuthConfig struct {
	// The HTTP basic authentication credentials for the targets.
	BasicAuth *BasicAuthConfig `yaml:"basic,omitempty" json:"basic,omitempty"`
	// The HTTP authorization credentials for the targets.
	Authorization *AuthorizationConfig `yaml:"authorization,omitempty" json:"authorization,omitempty"`
	// The OAuth2 client credentials used to fetch a token for the targets.
	OAuth2 *OAuth2Config `yaml:"oauth2,omitempty" json:"oauth2,omitempty"`
	// The Google client credentials used to fetch a token for the targets.
	Google *GoogleAuthConfig `yaml:"google,omitempty" json:"google,omitempty"`
}

AuthConfig the authentication configuration

type AuthorizationConfig added in v0.0.2

type AuthorizationConfig struct {
	Type        types.EnvironmentValue `yaml:"type" json:"type"`
	Credentials types.EnvironmentValue `yaml:"credentials" json:"credentials"`
}

AuthorizationConfig the HTTP authorization credentials for the targets

type BasicAuthConfig added in v0.0.2

type BasicAuthConfig struct {
	Username types.EnvironmentValue `yaml:"username" json:"username"`
	Password types.EnvironmentValue `yaml:"password" json:"password"`
}

BasicAuth the HTTP basic authentication credentials for the targets

type Client

type Client struct {
	v1.API
	// contains filtered or unexported fields
}

Client extends the Prometheus API client with advanced methods for the Prometheus connector

func NewClient

func NewClient(ctx context.Context, cfg ClientSettings, options ...Option) (*Client, error)

NewClient creates a new Prometheus client instance

func (*Client) ApplyOptions

func (c *Client) ApplyOptions(span trace.Span, timeout any) ([]v1.Option, error)

ApplyOptions apply options to the Prometheus request

func (*Client) FormatQuery

func (c *Client) FormatQuery(ctx context.Context, queryString string) (string, error)

FormatQuery [formats a PromQL expression] in a prettified way

[formats a PromQL expression](https://prometheus.io/docs/prometheus/latest/querying/api/#formatting-query-expressions)

func (*Client) Healthy

func (c *Client) Healthy(ctx context.Context) error

Healthy sends a [health check] request to check

[health check](https://prometheus.io/docs/prometheus/latest/management_api/#health-check)

func (*Client) LabelNames added in v0.0.5

func (c *Client) LabelNames(ctx context.Context, matches []string, startTime, endTime time.Time, limit uint64) ([]string, v1.Warnings, error)

LabelNames return a list of label names

func (*Client) Query

func (c *Client) Query(ctx context.Context, queryString string, timestamp any, timeout any) (model.Vector, v1.Warnings, error)

Query evaluates an instant query at a single point in time

func (*Client) QueryRange

func (c *Client) QueryRange(ctx context.Context, queryString string, start any, end any, step any, timeout any) (model.Matrix, v1.Warnings, error)

QueryRange evaluates a [range query] that performs query over a range of time

[range query](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries)

func (*Client) Series added in v0.0.3

func (c *Client) Series(ctx context.Context, matches []string, startTime, endTime time.Time, limit uint64) ([]model.LabelSet, v1.Warnings, error)

Series returns the list of [time series] that match a certain label set. Google Managed Prometheus supports GET method only so the base API library doesn't work. [time series](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers)

type ClientSettings added in v0.0.2

type ClientSettings struct {
	// The endpoint of the Prometheus server.
	URL types.EnvironmentValue `json:"url" yaml:"url"`
	// The authentication configuration
	Authentication *AuthConfig `json:"authentication,omitempty" yaml:"authentication,omitempty"`
	// The default timeout in seconds for Prometheus requests. The default is no timeout.
	Timeout *model.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	// TLSConfig to use to connect to the targets.
	TLSConfig config.TLSConfig `yaml:"tls_config,omitempty" json:"tls_config,omitempty"`
	// FollowRedirects specifies whether the client should follow HTTP 3xx redirects.
	// The omitempty flag is not set, because it would be hidden from the
	// marshalled configuration when set to false.
	FollowRedirects bool `yaml:"follow_redirects,omitempty" json:"follow_redirects,omitempty"`
	// EnableHTTP2 specifies whether the client should configure HTTP2.
	// The omitempty flag is not set, because it would be hidden from the
	// marshalled configuration when set to false.
	EnableHTTP2 bool `yaml:"enable_http2,omitempty" json:"enable_http2,omitempty"`
	// HTTPHeaders specify headers to inject in the requests. Those headers
	// could be marshalled back to the users.
	HTTPHeaders http.Header `yaml:"http_headers,omitempty" json:"http_headers,omitempty"`
	// Proxy configuration.
	*ProxyConfig `yaml:",inline"`
}

ClientSettings contain information for the Prometheus server that the client connects to

func (*ClientSettings) UnmarshalJSON added in v0.0.2

func (cs *ClientSettings) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type CredentialsEncoding added in v0.0.3

type CredentialsEncoding string

CredentialsEncoding the encoding of credentials string

const (
	CredentialsEncodingPlainText CredentialsEncoding = "plaintext"
	CredentialsEncodingBase64    CredentialsEncoding = "base64"
)

type GoogleAuthConfig added in v0.0.2

type GoogleAuthConfig struct {
	Encoding *CredentialsEncoding `yaml:"encoding,omitempty" json:"encoding,omitempty" jsonschema:"enum=plaintext,enum=base64,default=plaintext"`
	// Text of the Google credential JSON
	Credentials *types.EnvironmentValue `yaml:"credentials,omitempty" json:"credentials,omitempty"`
	// Path of the Google credential file
	CredentialsFile *types.EnvironmentValue `yaml:"credentials_file,omitempty" json:"credentials_file,omitempty"`
}

GoogleAuth the Google client credentials used to fetch a token for the targets

type OAuth2Config added in v0.0.2

type OAuth2Config struct {
	ClientID       types.EnvironmentValue `yaml:"client_id" json:"client_id"`
	ClientSecret   types.EnvironmentValue `yaml:"client_secret" json:"client_secret"`
	TokenURL       types.EnvironmentValue `yaml:"token_url" json:"token_url"`
	Scopes         []string               `yaml:"scopes,omitempty" json:"scopes,omitempty"`
	EndpointParams map[string]string      `yaml:"endpoint_params,omitempty" json:"endpoint_params,omitempty"`
	TLSConfig      config.TLSConfig       `yaml:"tls_config,omitempty"`

	*ProxyConfig `yaml:",inline"`
}

OAuth2Config the OAuth2 client credentials used to fetch a token for the targets

type Option added in v0.0.5

type Option func(opts *clientOptions)

Option the wrapper function to set optional client options

func WithTimeout added in v0.0.5

func WithTimeout(t *model.Duration) Option

WithTimeout sets the default timeout option to the client

func WithUnixTimeUnit added in v0.0.5

func WithUnixTimeUnit(u UnixTimeUnit) Option

WithTimeout sets the default timeout option to the client

type ProxyConfig added in v0.0.3

type ProxyConfig struct {
	// HTTP proxy server to use to connect to the targets.
	ProxyURL string `yaml:"proxy_url,omitempty" json:"proxy_url,omitempty"`
	// NoProxy contains addresses that should not use a proxy.
	NoProxy string `yaml:"no_proxy,omitempty" json:"no_proxy,omitempty"`
	// ProxyFromEnvironment makes use of net/http ProxyFromEnvironment function
	// to determine proxies.
	ProxyFromEnvironment bool `yaml:"proxy_from_environment,omitempty" json:"proxy_from_environment,omitempty"`
	// ProxyConnectHeader optionally specifies headers to send to
	// proxies during CONNECT requests. Assume that at least _some_ of
	// these headers are going to contain secrets and use Secret as the
	// value type instead of string.
	ProxyConnectHeader config.ProxyHeader `yaml:"proxy_connect_header,omitempty" json:"proxy_connect_header,omitempty"`
}

ProxyConfig the proxy configuration

type RangeResolution added in v0.1.1

type RangeResolution struct {
	Range      model.Duration
	Resolution model.Duration
}

RangeResolution represents the given range and resolution with format xx:xx

func ParseRangeResolution added in v0.1.1

func ParseRangeResolution(input any, unixTimeUnit UnixTimeUnit) (*RangeResolution, error)

ParseRangeResolution parses the range resolution from a string

func (RangeResolution) String added in v0.1.1

func (rr RangeResolution) String() string

String implements the fmt.Stringer interface

type UnixTimeUnit added in v0.0.5

type UnixTimeUnit string

UnixTimeUnit the unit for unix timestamp

const (
	UnixTimeSecond UnixTimeUnit = "s"
	UnixTimeMilli  UnixTimeUnit = "ms"
	UnixTimeMicro  UnixTimeUnit = "us"
	UnixTimeNano   UnixTimeUnit = "ns"
)

func (UnixTimeUnit) Duration added in v0.0.5

func (ut UnixTimeUnit) Duration() time.Duration

Duration returns the duration of the unit

Jump to

Keyboard shortcuts

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