diagnostics

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestHeader = "X-Pyroscope-Collect-Diagnostics"
	IdHeader      = "X-Pyroscope-Diagnostics-Id"
)

Variables

View Source
var Interceptor = &interceptor{}

Interceptor is a connect interceptor that extracts the diagnostics collection flag from request headers and injects it into the context.

Functions

func InjectCollectDiagnostics

func InjectCollectDiagnostics(ctx context.Context, collect bool) context.Context

InjectCollectDiagnostics injects the diagnostics collection flag and start time into the context.

func InjectCollectDiagnosticsFromHeader

func InjectCollectDiagnosticsFromHeader(ctx context.Context, headers map[string][]string) context.Context

InjectCollectDiagnosticsFromHeader checks the request header and injects the flag into context.

Types

type Context

type Context struct {
	Collect bool

	ID string
	// contains filtered or unexported fields
}

Context holds diagnostics collection state injected into the context.

func From

func From(ctx context.Context) *Context

From reads the diagnostics context from the context.

type DiagnosticSummary

type DiagnosticSummary struct {
	ID                string          `json:"id"`
	CreatedAt         time.Time       `json:"created_at"`
	Method            string          `json:"method"`
	ResponseTimeMs    int64           `json:"response_time_ms"`
	ResponseSizeBytes int64           `json:"response_size_bytes"`
	Request           json.RawMessage `json:"request,omitempty"`
}

DiagnosticSummary contains minimal info for listing diagnostics.

type Store

type Store struct {
	services.Service
	// contains filtered or unexported fields
}

Store manages query diagnostics storage and retrieval.

func NewStore

func NewStore(logger log.Logger, bucket objstore.Bucket, opts ...StoreOption) *Store

NewStore creates a new diagnostics store.

func (*Store) Add

func (s *Store) Add(id string, diag *queryv1.Diagnostics)

Add stores diagnostics in memory for later flushing.

func (*Store) AddRequest

func (s *Store) AddRequest(id string, method string, request any)

AddRequest stores request related data for later flushing.

func (*Store) AddResponse

func (s *Store) AddResponse(id string, response any, sizeBytes int64, responseTimeMs int64)

AddResponse stores response related data for later flushing.

func (*Store) Cleanup

func (s *Store) Cleanup(ctx context.Context) (int, error)

Cleanup removes diagnostics older than the TTL.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, tenantID, id string) error

Delete removes diagnostics by tenant and ID.

func (*Store) Export

func (s *Store) Export(ctx context.Context, tenantID, id string) ([]byte, error)

Export creates a zip archive containing all files for a diagnostic.

func (*Store) Flush

func (s *Store) Flush(ctx context.Context, tenantID, id string) error

Flush saves the in-memory diagnostics to the bucket and removes from memory.

func (*Store) Get

func (s *Store) Get(ctx context.Context, tenantID, id string) (*StoredDiagnostics, error)

Get retrieves diagnostics by tenant and ID.

func (*Store) Import

func (s *Store) Import(ctx context.Context, tenantID string, newID string, zipData []byte) (string, error)

Import extracts a zip archive and stores the diagnostic files. The files are stored under the tenantID provided as an argument; the tenantID from the zip file is ignored.

func (*Store) ListByTenant

func (s *Store) ListByTenant(ctx context.Context, tenant string) ([]*DiagnosticSummary, error)

ListByTenant returns all diagnostics for a given tenant.

type StoreOption

type StoreOption func(*Store)

StoreOption is a functional option for configuring a Store.

func WithTTL

func WithTTL(ttl time.Duration) StoreOption

WithTTL sets the TTL for stored diagnostics.

type StoredDiagnostics

type StoredDiagnostics struct {
	ID                string                 `json:"id"`
	CreatedAt         time.Time              `json:"created_at"`
	TenantID          string                 `json:"tenant_id"`
	ResponseTimeMs    int64                  `json:"response_time_ms,omitempty"`
	ResponseSizeBytes int64                  `json:"response_size_bytes,omitempty"`
	Method            string                 `json:"method,omitempty"`
	Request           json.RawMessage        `json:"request,omitempty"`
	Response          json.RawMessage        `json:"response,omitempty"`
	Plan              *queryv1.QueryPlan     `json:"plan,omitempty"`
	Execution         *queryv1.ExecutionNode `json:"execution,omitempty"`
}

StoredDiagnostics wraps the query diagnostics with metadata.

type Wrapper

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

Wrapper wraps a QuerierServiceClient to handle query diagnostics.

func NewWrapper

func NewWrapper(logger log.Logger, client querierv1connect.QuerierServiceClient, writer Writer) *Wrapper

type Writer

type Writer interface {
	AddRequest(id string, method string, req any)
	AddResponse(id string, resp any, responseSizeBytes int64, responseTimeMs int64)
	Flush(ctx context.Context, tenantID string, id string) error
}

Jump to

Keyboard shortcuts

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