async

package
v2.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

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

func NewCoordinator

func NewCoordinator(logger log.Logger, store *Store, limits Limits, next querierv1connect.QuerierServiceHandler, reg prometheus.Registerer) *Coordinator

func (*Coordinator) Dispatch added in v2.3.0

func (c *Coordinator) Dispatch(tenantID, requestID string, spec *querierv1.SelectMergeStacktracesRequest)

Dispatch implements Store's Dispatcher interface: it (re-)runs a query whose record and spec are already persisted. A declined dispatch (tenant at its concurrency limit) never rolls back the store's claim on the record; it is simply retried by a later adoption scan once the lease expires again.

func (*Coordinator) HasCapacity added in v2.3.0

func (c *Coordinator) HasCapacity(tenantID string) bool

HasCapacity implements Store's Dispatcher interface: a read-only peek at whether tenantID currently has spare capacity.

func (*Coordinator) PollQuery

func (c *Coordinator) PollQuery(ctx context.Context, tenantID, requestID string) (*Result, error)

PollQuery checks the status of an async query for the given tenant. Returns nil if the request is not found (caller should return NotFound).

func (*Coordinator) Submit added in v2.3.0

Submit reserves the tenant's concurrency slot, strips the Async marker from req, persists the resulting spec as a new in-progress query, and dispatches it in the background. Returns the assigned request ID.

type Dispatcher added in v2.3.0

type Dispatcher interface {
	// HasCapacity is a read-only capacity peek, not a reservation: it makes
	// no guarantee that a following Dispatch call will actually run the
	// query (Dispatch has its own gate and may still decline).
	HasCapacity(tenantID string) bool
	Dispatch(tenantID, requestID string, spec *querierv1.SelectMergeStacktracesRequest)
}

Dispatcher re-runs a query that Store has adopted after its owner's lease expired. Implemented by Coordinator; wired into Store via SetDispatcher.

type Handler

type Handler struct {
	querierv1connect.QuerierServiceHandler
	// contains filtered or unexported fields
}

Handler decorates a QuerierServiceHandler with async query support for SelectMergeStacktraces. All other RPCs pass through to the embedded handler unchanged.

func NewHandler

func NewHandler(logger log.Logger, next querierv1connect.QuerierServiceHandler, coordinator *Coordinator) *Handler

func (*Handler) SelectMergeStacktraces

SelectMergeStacktraces honors the request's optional Async field:

  • Async == nil or Type == DISABLED: run synchronously, return the wrapped handler's response unchanged (Async stays nil).
  • Async.RequestId != "": treat as a poll. All other request fields are ignored. The response carries only the Async metadata, plus the result payload on SUCCESS.
  • Async.Type == FORCE with empty RequestId: dispatch in the background and return a response carrying only the Async metadata in IN_PROGRESS.

type Limits

type Limits interface {
	MaxAsyncQueryConcurrency(tenantID string) int
}

type Metadata

type Metadata struct {
	RequestID     string    `json:"request_id"`
	TenantID      string    `json:"tenant_id"`
	Status        Status    `json:"status"`
	CreatedAt     time.Time `json:"created_at"`
	LastHeartbeat time.Time `json:"last_heartbeat,omitempty"`
	ErrorMessage  string    `json:"error_message,omitempty"`
	Owner         string    `json:"owner,omitempty"`
	AdoptionCount int       `json:"adoption_count,omitempty"`
}

Metadata describes the state of a single async query. It is persisted as metadata.json alongside the query's result in object storage.

type Result

type Result struct {
	Metadata Metadata
	Response *querierv1.SelectMergeStacktracesResponse
}

Result bundles a query's Metadata with its decoded Response. Response is only populated when Metadata.Status is StatusSuccess.

type Status

type Status string

Status represents the lifecycle state of an async query.

const (
	// StatusInProgress indicates the query is still executing.
	StatusInProgress Status = "in_progress"
	// StatusSuccess indicates the query completed and a result is available.
	StatusSuccess Status = "success"
	// StatusFailure indicates the query failed; ErrorMessage holds the reason.
	StatusFailure Status = "failure"
)

type Store

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

Store persists async query state and results in object storage. It also runs as a dskit service that periodically removes expired entries and adopts queries whose owner's lease has expired.

func NewStore

func NewStore(logger log.Logger, bucket objstore.Bucket, reg prometheus.Registerer) *Store

NewStore returns a Store backed by the given bucket. The returned Store is a dskit service that, once started, periodically deletes entries older than the configured TTL and scans for adoptable queries; callers are responsible for starting and stopping it via its embedded Service.

func (*Store) SetDispatcher added in v2.3.0

func (s *Store) SetDispatcher(d Dispatcher)

SetDispatcher wires the adoption scan to a Dispatcher. Must be called before the Store's Service is started: s.dispatcher is a plain field, never synchronized against running()'s reads of it. A late call is a programming error, so it panics rather than risk an unsynchronized write racing the running service. nil is safe (adoption is then a no-op), e.g. when Store runs standalone or in tests.

Jump to

Keyboard shortcuts

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