deletes

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package deletes implements Loki's delete API: requests are stored in ClickHouse and applied at query time by Loki's own filtering pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewQueryClient

NewQueryClient returns the delete-requests client queries filter with: the store behind Loki's per-tenant cache (refreshed every 5 minutes) and its deletion_mode check. The stack mirrors deleteRequestsClient in grafana/loki@39c256e50a80 pkg/loki/modules.go. The caller must call Stop.

Types

type Handler

type Handler struct {
	Store        *Store
	Limits       deletionLimits
	MaxInterval  time.Duration
	CancelPeriod time.Duration
}

Handler serves the delete API endpoints.

func (*Handler) Add

func (h *Handler) Add(w http.ResponseWriter, r *http.Request)

Add handles addition of a new delete request.

func (*Handler) Cancel

func (h *Handler) Cancel(w http.ResponseWriter, r *http.Request)

Cancel handles delete request cancellation.

func (*Handler) Gate

func (h *Handler) Gate(next http.Handler) http.Handler

Gate wraps h with the tenant + deletion-mode check, exactly as Loki's TenantMiddleware does.

func (*Handler) List

func (h *Handler) List(w http.ResponseWriter, r *http.Request)

List handles get all delete requests.

type Processor

type Processor struct {
	Store        *Store
	Conn         driver.Conn
	DB           string
	Topo         chstore.Topology
	CancelPeriod time.Duration
	Interval     time.Duration
	Logger       log.Logger
	// Now returns the "current time" for the cancel-period check (default time.Now).
	Now func() time.Time
	// contains filtered or unexported fields
}

Processor physically deletes delete requests that are past their cancel period. Query-time filtering already hides the matching lines; the processor makes the deletion permanent and marks the request processed (which also stops query-time filtering for it).

func (*Processor) ProcessDue

func (p *Processor) ProcessDue(ctx context.Context, now time.Time) error

ProcessDue physically deletes every received request older than CancelPeriod, then marks it processed. lightweight_deletes_sync=2 makes the rows invisible on every replica before the call returns. Requests are fault-isolated: a failing request is logged, retried on the next pass (the rows are still hidden by query-time filtering) and does not stop the others. After a pass that deleted rows it runs APPLY DELETED MASK so the rows leave the disk too; a failed mask step is retried on the next pass.

func (*Processor) Run

func (p *Processor) Run(ctx context.Context)

Run calls ProcessDue every Interval until ctx ends; errors are logged.

type Store

type Store struct {
	Conn driver.Conn
	Now  func() time.Time // default time.Now
	// contains filtered or unexported fields
}

Store keeps delete requests in ClickHouse; it implements Loki's querier/deletion.DeleteGetter for query-time filtering.

func (*Store) Add

func (s *Store) Add(ctx context.Context, tenant, query string, start, end model.Time) (string, error)

Add stores a new delete request and returns its id. The id is 8 random hex characters; Loki's format and ids differ (docs/divergences.md).

func (*Store) Cancel

func (s *Store) Cancel(ctx context.Context, tenant, id string) error

Cancel marks the request cancelled; cancelled requests are hidden from all reads.

func (*Store) Get

func (s *Store) Get(ctx context.Context, tenant, id string) (deletionproto.DeleteRequest, error)

Get returns the latest version of the request, or deletion.ErrDeleteRequestNotFound.

func (*Store) GetAllDeleteRequestsForUser

func (s *Store) GetAllDeleteRequestsForUser(ctx context.Context, userID string, forQuerytimeFiltering bool, tr *deletion.TimeRange) ([]deletionproto.DeleteRequest, error)

GetAllDeleteRequestsForUser implements querier/deletion.DeleteGetter. With forQuerytimeFiltering only pending (received) requests are returned, since those are the ones a query must hide lines for; tr, when set, keeps only requests overlapping it.

func (*Store) MarkProcessed

func (s *Store) MarkProcessed(ctx context.Context, r deletionproto.DeleteRequest) error

MarkProcessed records that the request has been processed.

func (*Store) Unprocessed

func (s *Store) Unprocessed(ctx context.Context) ([]deletionproto.DeleteRequest, error)

Unprocessed returns every pending (received) request, all tenants.

Jump to

Keyboard shortcuts

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