async

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: AGPL-3.0 Imports: 22 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, reg prometheus.Registerer) *Coordinator

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) Register

func (c *Coordinator) Register(ctx context.Context, tenantID string, resultCh <-chan QueryResult) (string, error)

Register reserves the per-tenant concurrency slot, persists the in-progress metadata, and starts watching resultCh. The caller is responsible for dispatching the query and sending its outcome on resultCh; the coordinator owns reads from the channel, store writes, and the heartbeat loop. Returns the assigned request ID, or an error if the slot could not be acquired.

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(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"`
}

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

type QueryResult

type QueryResult struct {
	Response *querierv1.SelectMergeStacktracesResponse
	Err      error
}

QueryResult is the result of a query execution sent over a channel. On success, Response carries the raw SelectMergeStacktracesResponse from the wrapped handler (its Async field is unset); the coordinator/store own request_id and status.

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.

func NewStore

func NewStore(logger log.Logger, bucket objstore.Bucket) *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; callers are responsible for starting and stopping it via its embedded Service.

Jump to

Keyboard shortcuts

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