resindexapi

package
v1.162.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package resindexapi is the admin REST surface for how managed resources are indexed for search (#2111): how many are under each policy, and a reclassification that applies the operator's resources.index rules to every resource no writer chose a policy for.

Index

Constants

View Source
const NoEmbedderReason = "" /* 140-byte string literal not displayed */

NoEmbedderReason is what the answers say on a deployment with no embedding provider.

Variables

This section is empty.

Functions

func Mount

func Mount(mux *http.ServeMux, wrap func(http.Handler) http.Handler, db *sql.DB, resolver *indexpolicy.Resolver, embedder bool)

Mount registers the routes over the platform's database: the counts read from it, and a reclassification under the resolver whose owed jobs are enqueued on the platform's own queue table, which wakes the workers of whichever replica claims them. With no embedder (embedder false) no worker exists to run them, so the reclassification enqueues none (#2638).

func Register

func Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler, cfg Config)

Register mounts the routes, each behind wrap, the admin API's authentication.

Types

type Config

type Config struct {
	// Store reads the counts. nil mounts nothing.
	Store        Store
	Reclassifier Reclassifier
	// Runs keeps the last reclassification for every replica. Required with
	// a Reclassifier.
	Runs Runs
	// NoIndexReason, when set, is why a reclassification owes no index work
	// on this deployment (#2638): with no embedder no worker runs the queue,
	// so the reclassifier is given no producers and the answers say so.
	NoIndexReason string
}

Config carries the store, the reclassifier and where its runs are kept.

type IndexState

type IndexState struct {
	Counts  resourceindex.PolicyCounts `json:"counts"`
	LastRun *Run                       `json:"last_run,omitempty"`
	// NoIndexReason is why a reclassification queues no index work on this
	// deployment, absent when it queues what it owes.
	NoIndexReason string `json:"no_index_reason,omitempty"`
}

IndexState is what GET answers: the counts, and the last reclassification any replica ran, absent when none has run.

type PostgresRuns

type PostgresRuns struct{ DB *sql.DB }

PostgresRuns is Runs over resource_reclassify_runs.

func (PostgresRuns) Begin

func (p PostgresRuns) Begin(ctx context.Context) (time.Time, bool, error)

Begin implements Runs. A run unfinished after an hour is taken to have stopped with its replica; the reclassifier's advisory lock still refuses a start while one truly runs.

func (PostgresRuns) Finish

Finish implements Runs.

func (PostgresRuns) Last

func (p PostgresRuns) Last(ctx context.Context) (*Run, error)

Last implements Runs.

type Reclassifier

type Reclassifier interface {
	Run(ctx context.Context) (resourcereclass.ReclassifyResult, error)
}

Reclassifier applies the rules. *resourceindex.Reclassifier satisfies it.

type Run

type Run struct {
	StartedAt  time.Time                         `json:"started_at"`
	FinishedAt *time.Time                        `json:"finished_at,omitempty"`
	Result     *resourcereclass.ReclassifyResult `json:"result,omitempty"`
	Error      string                            `json:"error,omitempty"`
	// NoIndexReason is why the reclassification queues no index work, absent
	// when it queues what it owes.
	NoIndexReason string `json:"no_index_reason,omitempty"`
}

Run is a reclassification, as every replica reports it.

type Runs

type Runs interface {
	// Begin records a run starting and reports false when one is running.
	Begin(ctx context.Context) (started time.Time, ok bool, err error)
	// Finish records how the run ended.
	Finish(ctx context.Context, res resourcereclass.ReclassifyResult, failure string) error
	// Last reads the last run, nil when none has started.
	Last(ctx context.Context) (*Run, error)
}

Runs keeps the last reclassification where every replica reads it, and refuses a second start while one runs.

type Store

type Store interface {
	Counts(ctx context.Context) (resourceindex.PolicyCounts, error)
}

Store reads the counts. *resourceindex.Store satisfies it.

Jump to

Keyboard shortcuts

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