Help us shape the future of Go! Take the 2026 Go Developer Survey

prometheus

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package prometheus provides tenant-bound OTLP metric storage and PromQL, using either the local database and embedded engine or an external server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorResponse

func ErrorResponse(err error) (int, json.RawMessage)

ErrorResponse is shared by HTTP adapters; callers can also errors.As APIError.

Types

type APIError

type APIError struct {
	StatusCode int
	ErrorType  string
	Message    string
	Body       json.RawMessage
}

APIError retains the upstream envelope, including warnings and partial data. Local transport/limit errors use the same public Prometheus error shape.

func NewError

func NewError(status int, kind, message string) *APIError

func (*APIError) Error

func (e *APIError) Error() string

type Backend added in v0.6.4

type Backend interface {
	Query(context.Context, url.Values, bool) (json.RawMessage, error)
	MetricNames(context.Context, url.Values) (json.RawMessage, error)
	Export(context.Context, *colmetricspb.ExportMetricsServiceRequest) (*colmetricspb.ExportMetricsServiceResponse, error)
	TenantID() string
	SupportsTenant(context.Context) bool
	MaxQueryBytes() int
	MaxQueryRange() time.Duration
	MaxResponseBytes() int64
	Ready(context.Context) error
	Close()
	Source() string
}

Backend is shared by OTLP ingest, HTTP and MCP. Local uses the main database; Client retains the opt-in remote Prometheus behavior.

type Client

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

func NewClient

func NewClient(cfg Config) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Export

Export sends the original resource/scope/metric protobuf without converting names, units, temporality, histograms, exemplars, flags or attributes. Ingest must resolve and select resource tenants before calling Export.

func (*Client) MaxQueryBytes

func (c *Client) MaxQueryBytes() int

func (*Client) MaxQueryRange

func (c *Client) MaxQueryRange() time.Duration

func (*Client) MaxResponseBytes

func (c *Client) MaxResponseBytes() int64

func (*Client) MetricNames

func (c *Client) MetricNames(ctx context.Context, params url.Values) (json.RawMessage, error)

MetricNames discovers retained series through Prometheus's label API. The caller supplies bounded start/end and optional match[] selectors.

func (*Client) Query

func (c *Client) Query(ctx context.Context, params url.Values, rangeQuery bool) (json.RawMessage, error)

Query returns the complete Prometheus response envelope on success AND on an upstream API error. It does not parse, rewrite or restrict PromQL expressions.

func (*Client) Ready

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

Ready probes the configured backend independently of queries and ingest. The caller should supply a short readiness deadline. It proves reachability and Prometheus readiness, not the retention configuration or OTLP enablement.

func (*Client) Source added in v0.6.4

func (*Client) Source() string

func (*Client) SupportsTenant

func (c *Client) SupportsTenant(ctx context.Context) bool

SupportsTenant follows the existing bound-principal precedence. It does not introduce authentication: missing tenant context still means "default".

func (*Client) TenantID

func (c *Client) TenantID() string

type Config

type Config struct {
	URL                 string
	TenantID            string
	Timeout             time.Duration
	MaxConcurrent       int
	MaxIngestConcurrent int
	MaxIngestWaiters    int
	MaxRequestBytes     int64
	MaxResponseBytes    int64
	MaxQueryBytes       int
	MaxQueryRange       time.Duration
	MaxSeries           int

	// MaxIngestBytes bounds the sum of proto.Size across active and waiting
	// exports. Zero selects 128 MiB, leaving headroom on a 4 GiB app for decoded
	// objects, active encoded copies and other work. This is a protobuf wire-size
	// budget, not a Go heap/RSS limit; inbound network decoding precedes Export
	// and is not covered. Decoded objects can be much larger than proto.Size.
	MaxIngestBytes int64
}

Config bounds requests and shared ingest admission. Zero values select defaults; negative values fail construction. URL is operator configuration, never taken from a request.

type Local added in v0.6.4

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

Local evaluates PromQL against original samples in OtelContext's main DB. Client supplies only shared tenant checks and bounded admission; there is no HTTP client, remote endpoint, separate TSDB, or network call in this backend.

func NewLocal added in v0.6.4

func NewLocal(db *gorm.DB, cfg Config, retention time.Duration) (*Local, error)

func (*Local) Close added in v0.6.4

func (*Local) Close()

func (*Local) Export added in v0.6.4

Export converts and validates the entire batch before opening a transaction. A rejection or storage failure rolls back all samples. Retries with identical series/timestamps/payloads are idempotent; conflicting duplicates are rejected.

func (*Local) MetricNames added in v0.6.4

func (l *Local) MetricNames(ctx context.Context, params url.Values) (json.RawMessage, error)

func (*Local) Query added in v0.6.4

func (l *Local) Query(ctx context.Context, params url.Values, ranged bool) (json.RawMessage, error)

func (*Local) Ready added in v0.6.4

func (l *Local) Ready(ctx context.Context) error

func (*Local) Source added in v0.6.4

func (*Local) Source() string

Jump to

Keyboard shortcuts

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