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 ¶
- func ErrorResponse(err error) (int, json.RawMessage)
- type APIError
- type Backend
- type Client
- func (c *Client) Close()
- func (c *Client) Export(ctx context.Context, req *colmetricspb.ExportMetricsServiceRequest) (*colmetricspb.ExportMetricsServiceResponse, error)
- func (c *Client) MaxQueryBytes() int
- func (c *Client) MaxQueryRange() time.Duration
- func (c *Client) MaxResponseBytes() int64
- func (c *Client) MetricNames(ctx context.Context, params url.Values) (json.RawMessage, error)
- func (c *Client) Query(ctx context.Context, params url.Values, rangeQuery bool) (json.RawMessage, error)
- func (c *Client) Ready(ctx context.Context) error
- func (*Client) Source() string
- func (c *Client) SupportsTenant(ctx context.Context) bool
- func (c *Client) TenantID() string
- type Config
- type Local
- func (*Local) Close()
- func (l *Local) Export(ctx context.Context, req *colmetricspb.ExportMetricsServiceRequest) (*colmetricspb.ExportMetricsServiceResponse, error)
- func (l *Local) MetricNames(ctx context.Context, params url.Values) (json.RawMessage, error)
- func (l *Local) Query(ctx context.Context, params url.Values, ranged bool) (json.RawMessage, error)
- func (l *Local) Ready(ctx context.Context) error
- func (*Local) Source() string
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.
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 (*Client) Export ¶
func (c *Client) Export(ctx context.Context, req *colmetricspb.ExportMetricsServiceRequest) (*colmetricspb.ExportMetricsServiceResponse, error)
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 (*Client) MaxQueryRange ¶
func (*Client) MaxResponseBytes ¶
func (*Client) MetricNames ¶
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 ¶
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) SupportsTenant ¶
SupportsTenant follows the existing bound-principal precedence. It does not introduce authentication: missing tenant context still means "default".
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 (*Local) Export ¶ added in v0.6.4
func (l *Local) Export(ctx context.Context, req *colmetricspb.ExportMetricsServiceRequest) (*colmetricspb.ExportMetricsServiceResponse, error)
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.