promapi

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildinfoHandlerFunc added in v0.17.0

func BuildinfoHandlerFunc(logger log.Logger, binaryName, binaryVersion string) func(http.ResponseWriter, *http.Request)

BuildinfoHandlerFunc simulates the /api/v1/status/buildinfo prometheus endpoint. It is used by Grafana to determine the Prometheus flavor, e.g. to check whether the ruler-api is enabled. binary: e.g. "frontend" or "rule-evaluator".

func WriteError

func WriteError(logger log.Logger, w http.ResponseWriter, errType ErrorType, errMsg string, httpResponseCode int, endpointURI string)

WriteError writes an error Response to the given responseWriter w.

func WriteSuccessResponse

func WriteSuccessResponse[T RulesResponseData | AlertsResponseData | promapiv1.PrometheusVersion](logger log.Logger, w http.ResponseWriter, httpResponseCode int, endpointURI string, responseData T)

WriteSuccessResponse writes a successful Response to the given responseWriter w.

Types

type AlertsResponseData

type AlertsResponseData struct {
	Alerts []*promapiv1.Alert `json:"alerts"`
}

type ErrorType

type ErrorType string
const (
	ErrorNone        ErrorType = ""
	ErrorTimeout     ErrorType = "timeout"
	ErrorCanceled    ErrorType = "canceled"
	ErrorExec        ErrorType = "execution"
	ErrorBadData     ErrorType = "bad_data"
	ErrorInternal    ErrorType = "internal"
	ErrorUnavailable ErrorType = "unavailable"
	ErrorNotFound    ErrorType = "not_found"
)

type GenericResponseData

type GenericResponseData interface{}

type Response

type Response[T RulesResponseData | AlertsResponseData | GenericResponseData] struct {
	Status    status    `json:"status"`
	Data      T         `json:"data,omitempty"`
	ErrorType ErrorType `json:"errorType,omitempty"`
	Error     string    `json:"error,omitempty"`
	Warnings  []string  `json:"warnings,omitempty"`
	Infos     []string  `json:"infos,omitempty"`
}

https://prometheus.io/docs/prometheus/latest/querying/api/#format-overview Response is the prometheus-compatible Response format.

type RulesResponseData

type RulesResponseData struct {
	Groups []*promapiv1.RuleGroup `json:"groups"`
}

Jump to

Keyboard shortcuts

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