prometheus

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurlExecViaPod added in v1.6.0

func CurlExecViaPod(ns, name, url string) (int, string, error)

CurlExecViaPod attempts connection to url via exec pod and returns the HTTP status code and the error message reported by curl.

func ExpectHTTPStatusCode

func ExpectHTTPStatusCode(url, bearerToken string, statusCodes ...int) error

ExpectHTTPStatusCode sends a GET request to the URL and checks the expected status code. If bearerToken isn't empty, it will be used to authenticate against the endpoint. It returns an error if the request fails or the status return code is not equal to any of the statusCodes.

func ExpectPrometheusEndpoint

func ExpectPrometheusEndpoint(url string)

ExpectPrometheusEndpoint attempts to connect to the metrics endpoint with delayed retries upon failure.

func ExpectURLStatusCodeExecViaPod

func ExpectURLStatusCodeExecViaPod(ns, execPodName, url string, statusCodes ...int) error

ExpectURLStatusCodeExecViaPod attempts connection to url via exec pod and returns an error upon failure or if status return code is not equal to any of the statusCodes.

func FetchAlertingRules

func FetchAlertingRules(promURL, bearerToken string) (map[string][]prometheusv1.AlertingRule, error)

FetchAlertingRules fetchs all alerting rules from the Prometheus at the given URL using the given bearer token. The results are returned as a map of group names to lists of alerting rules.

func ForEachAlertingRule

func ForEachAlertingRule(rules map[string][]prometheusv1.AlertingRule, f func(a prometheusv1.AlertingRule) sets.String) error

ForEachAlertingRule takes a map of rule group names to a list of alerting rules, and for each rule in each group runs the given function. The function takes the alerting rule, and returns a set of violations, which maye be empty or nil. If after all rules are checked, there are any violations, an error is returned.

func GetBearerTokenURLViaPod

func GetBearerTokenURLViaPod(oc *exutil.CLI, execPodName, url, bearer string) (string, error)

func GetURLWithToken

func GetURLWithToken(url, bearerToken string) (string, error)

GetURLWithToken makes an HTTP request with a bearer token.

func MustJoinUrlPath

func MustJoinUrlPath(base string, paths ...string) string

MustJoinUrlPath behaves like url.JoinPath but it will panic in case of error.

func PrometheusRouteURL

func PrometheusRouteURL(ctx context.Context, oc *exutil.CLI) (string, error)

PrometheusRouteURL returns the public url of the cluster prometheus service or an error if the route is not found.

func PrometheusServiceURL

func PrometheusServiceURL(ctx context.Context, oc *exutil.CLI) (string, error)

PrometheusServiceURL returns the url of the cluster prometheus service or an error if the service is not found.

func QueryURL

func QueryURL(rawURL string, timeout time.Duration) error

QueryURL takes a URL as a string and a timeout. The URL is parsed, then fetched until a 200 response is received or the timeout is reached.

func RequestPrometheusServiceAccountAPIToken

func RequestPrometheusServiceAccountAPIToken(ctx context.Context, oc *exutil.CLI) (string, error)

RequestPrometheusServiceAccountAPIToken returns a time-bound (24hr) API token for the prometheus service account.

func RunQueries

func RunQueries(ctx context.Context, prometheusClient prometheusv1.API, promQueries map[string]bool, oc *exutil.CLI) error

RunQueries executes Prometheus queries and checks provided expected result.

func ThanosQuerierRouteURL

func ThanosQuerierRouteURL(ctx context.Context, oc *exutil.CLI) (string, error)

ThanosQuerierRouteURL returns the public url of the thanos querier service or an error if the route is not found.

func ThanosQuerierServiceURL

func ThanosQuerierServiceURL(ctx context.Context, oc *exutil.CLI) (string, error)

ThanosQuerierServiceURL returns the url of the thanos querier service or an error if the service is not found.

func ValidateURL

func ValidateURL(rawURL string) error

Types

type PrometheusResponse

type PrometheusResponse struct {
	Data prometheusResponseData `json:"data"`
}

PrometheusResponse is used to contain prometheus query results

func RunQuery

func RunQuery(ctx context.Context, prometheusClient prometheusv1.API, query string) (*PrometheusResponse, error)

func RunQueryAtTime

func RunQueryAtTime(ctx context.Context, prometheusClient prometheusv1.API, query string, evaluationTime time.Time) (*PrometheusResponse, error)

Jump to

Keyboard shortcuts

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