adminhandler

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package adminhandler implements the go-faster/fs admin API: instance info and runtime access-key management, backed by an auth.Manager.

Index

Constants

This section is empty.

Variables

View Source
var ErrBucketNotFound = errors.New("bucket not found")

ErrBucketNotFound is returned by a BucketSchemeStore when the named bucket does not exist; the handler maps it to 404.

View Source
var ErrMigrationConflict = errors.New("migration conflict")

ErrMigrationConflict marks a migration request that cannot run now — one is already in flight, or the cluster's schema is newer than this binary implements. It maps to 409.

View Source
var ErrPublicReadRejected = errors.New("public-read bucket list rejected")

ErrPublicReadRejected is returned by a PublicReadStore when a bucket name is invalid; the handler maps it to 400.

View Source
var ErrRebalanceConflict = errors.New("invalid rebalance transition")

ErrRebalanceConflict marks an invalid rebalance transition (starting a running rebalance, pausing an idle one); it maps to 409.

View Source
var ErrSchemeRejected = errors.New("scheme rejected")

ErrSchemeRejected is returned by a BucketSchemeStore when a scheme is invalid or the topology cannot host it; the handler maps it to 400.

Functions

func UIMiddleware

func UIMiddleware() func(http.Handler) http.Handler

UIMiddleware serves the embedded admin SPA for non-API requests, delegating everything under /api/ to the next handler (the ogen server). Unknown paths fall back to index.html so client-side routing works. When the SPA was not built, a placeholder page is served instead.

Types

type AdminAPI

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

AdminAPI implements adminapi.Handler.

func NewAdminAPI

func NewAdminAPI(opts Options) *AdminAPI

NewAdminAPI builds an AdminAPI.

func (*AdminAPI) ApplyMigrations added in v0.9.0

func (a *AdminAPI) ApplyMigrations(ctx context.Context) (*adminapi.MigrationStatus, error)

ApplyMigrations applies every pending migration.

func (*AdminAPI) ControlRebalance

ControlRebalance starts, pauses or resumes the rebalance runner.

func (*AdminAPI) CreateAccessKey

CreateAccessKey creates a runtime credential.

func (*AdminAPI) DeleteAccessKey

func (a *AdminAPI) DeleteAccessKey(_ context.Context, params adminapi.DeleteAccessKeyParams) error

DeleteAccessKey removes a runtime credential.

func (*AdminAPI) GetBucketScheme added in v0.7.0

func (a *AdminAPI) GetBucketScheme(ctx context.Context, params adminapi.GetBucketSchemeParams) (*adminapi.BucketScheme, error)

GetBucketScheme reports a bucket's effective scheme, its override and the cluster default.

func (*AdminAPI) GetBucketUsage added in v0.11.0

func (a *AdminAPI) GetBucketUsage(ctx context.Context) (*adminapi.BucketUsageList, error)

GetBucketUsage reports per-bucket object counts and sizes, plus the totals across every bucket.

func (*AdminAPI) GetClusterStatus added in v0.6.0

func (a *AdminAPI) GetClusterStatus(ctx context.Context) (*adminapi.ClusterStatus, error)

GetClusterStatus reports the cluster-wide view.

func (*AdminAPI) GetInfo

func (a *AdminAPI) GetInfo(_ context.Context) (*adminapi.InstanceInfo, error)

GetInfo returns build info, uptime and the loaded config revision.

func (*AdminAPI) GetMigrationStatus added in v0.9.0

func (a *AdminAPI) GetMigrationStatus(ctx context.Context) (*adminapi.MigrationStatus, error)

GetMigrationStatus reports the cluster schema state and pending migrations.

func (*AdminAPI) GetPublicReadBuckets added in v0.8.0

func (a *AdminAPI) GetPublicReadBuckets(ctx context.Context) (*adminapi.PublicReadBuckets, error)

GetPublicReadBuckets returns the cluster-wide public-read bucket list.

func (*AdminAPI) GetRebalanceStatus

func (a *AdminAPI) GetRebalanceStatus(ctx context.Context) (*adminapi.RebalanceStatus, error)

GetRebalanceStatus reports the node's rebalance runner state.

func (*AdminAPI) ListAccessKeys

func (a *AdminAPI) ListAccessKeys(_ context.Context) (*adminapi.AccessKeyList, error)

ListAccessKeys returns all credentials, secrets omitted.

func (*AdminAPI) NewError

func (a *AdminAPI) NewError(_ context.Context, err error) *adminapi.ErrorStatusCode

NewError maps an unhandled error to a 500 structured response.

func (*AdminAPI) ReloadConfig added in v0.6.0

func (a *AdminAPI) ReloadConfig(ctx context.Context) (*adminapi.ReloadResult, error)

ReloadConfig re-applies the hot-reloadable configuration and reports what changed.

func (*AdminAPI) SetBucketScheme added in v0.7.0

SetBucketScheme sets or clears a bucket's scheme override and returns the effective scheme after applying.

func (*AdminAPI) SetPublicReadBuckets added in v0.8.0

SetPublicReadBuckets replaces the cluster-wide public-read bucket list and returns the stored result.

type BucketSchemeStore added in v0.7.0

type BucketSchemeStore interface {
	// SchemeOverride returns the bucket's explicit scheme override, empty when
	// the bucket follows the cluster default. It returns ErrBucketNotFound when
	// the bucket does not exist.
	SchemeOverride(ctx context.Context, bucket string) (string, error)
	// SetScheme sets the bucket's override, or clears it when scheme is empty.
	// It returns ErrBucketNotFound when the bucket does not exist and
	// ErrSchemeRejected when the scheme is invalid or the topology cannot host
	// it.
	SetScheme(ctx context.Context, bucket, scheme string) error
}

BucketSchemeStore reads and writes a bucket's replication-scheme override in the cluster control plane. It is nil outside cluster mode, where the scheme endpoints return 501.

type BucketUsage added in v0.11.0

type BucketUsage struct {
	Bucket  string
	Objects int64
	Bytes   int64
	// Updated is when an incremental change last moved the counters.
	Updated time.Time
	// Counted is when a full recount last anchored them; zero when none has.
	Counted time.Time
}

BucketUsage is one bucket's object count and total size, as the usage index holds it.

type BucketUsageSource added in v0.11.0

type BucketUsageSource interface {
	// BucketUsage returns every accounted bucket, sorted by name.
	BucketUsage(ctx context.Context) ([]BucketUsage, error)
}

BucketUsageSource reads the cluster's durable per-bucket object accounting.

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
}

BuildInfo is static build metadata reported by GetInfo.

type ClusterDisk added in v0.6.0

type ClusterDisk struct {
	ID         string
	Weight     float64
	TotalBytes uint64
	FreeBytes  uint64
}

ClusterDisk is one disk's placement weight and reported capacity.

type ClusterNode added in v0.6.0

type ClusterNode struct {
	ID    string
	Addr  string
	Rack  string
	Disks []ClusterDisk
	// Live is the node's live runtime state, fetched from the node itself; nil
	// when it did not report.
	Live *NodeLive
	// LiveError says why Live is nil (unreachable, or a binary that does not
	// serve live state).
	LiveError string
}

ClusterNode is a cluster member and its disks.

type ClusterStatus added in v0.6.0

type ClusterStatus struct {
	SchemaVersion       int
	BinarySchemaVersion int
	Nodes               []ClusterNode
	// RebalanceRunning reports whether a runner holds the cluster-wide
	// election; the cursor is the in-progress/last resume point.
	RebalanceRunning              bool
	RebalanceCursorBucket, Cursor string
}

ClusterStatus is the cluster-wide view assembled from the control plane.

type ClusterStatusSource added in v0.6.0

type ClusterStatusSource interface {
	ClusterStatus(ctx context.Context) (ClusterStatus, error)
}

ClusterStatusSource assembles the cluster-wide status from etcd (topology, schema version, rebalance election/cursor). Implemented by the cluster runtime and the headless admin; nil outside cluster mode.

type CredentialManager added in v0.8.0

type CredentialManager interface {
	// List returns every credential, secrets omitted, sorted by access key.
	List() []auth.KeyInfo
	// Create adds a credential, generating the access key and/or secret when
	// CreateInput leaves them empty, and returns the secret exactly once.
	Create(in auth.CreateInput) (*auth.Created, error)
	// Delete removes a credential by access key.
	Delete(accessKey string) error
}

CredentialManager is the runtime access-key store the admin API manages. Both the local file-backed store (*auth.Manager) and the etcd-backed cluster store satisfy it, so the same endpoints serve single-node and cluster-wide credentials. Its methods do not take a context: the file store is in-memory, and the cluster store reads from a watch-maintained snapshot for List while bounding its own etcd writes for Create/Delete.

type Migration added in v0.9.0

type Migration struct {
	Version     int
	Description string
}

Migration is one pending schema migration.

type MigrationControl added in v0.9.0

type MigrationControl interface {
	// Status reads the cluster's schema version and computes what is pending.
	Status(ctx context.Context) (MigrationStatus, error)
	// Apply runs every pending migration under the cluster-wide election and
	// returns the resulting status. Returns ErrMigrationConflict when an apply
	// is already running or the cluster schema is newer than this binary.
	Apply(ctx context.Context) (MigrationStatus, error)
}

MigrationControl reports and applies cluster schema migrations. Implemented by the cluster runtime and the headless admin; nil outside cluster mode (the endpoints then report "disabled" / refuse to apply).

type MigrationStatus added in v0.9.0

type MigrationStatus struct {
	// ClusterVersion is the version recorded in etcd; 0 when none is recorded
	// yet (no node has joined).
	ClusterVersion int
	// BinaryVersion is the schema version this binary implements.
	BinaryVersion int
	// Pending are the migrations between the two, in order.
	Pending []Migration
	// Running reports an apply in flight on this process.
	Running bool
	// LastApplied and LastErr describe the most recent apply on this process.
	LastApplied []int
	LastErr     string
}

MigrationStatus is the cluster's schema state as this process sees it.

type NodeDisk added in v0.10.0

type NodeDisk struct {
	ID      string
	HasData bool
	// Err is why the disk could not be probed. A disk that failed to answer is
	// unknown, never drained.
	Err string
	// Fragments and Bytes are what the node's occupancy index says the disk
	// holds, so a drain in progress has a number attached. Meaningful only
	// when Counted; HasData remains what decides "empty".
	Fragments int64
	Bytes     int64
	Counted   bool
}

NodeDisk is what one of a node's disks holds right now, reported by the node itself. It is the drain signal: an orchestrator decommissioning a node waits for HasData to go false before it deletes the volume.

type NodeLive added in v0.9.0

type NodeLive struct {
	Version       string
	SchemaVersion int
	UptimeSeconds float64
	// RepairQueueDepth is the node's pending async remainder/repair backlog.
	RepairQueueDepth int
	// Rebalance* is the node's rebalance runner and its current/last run.
	RebalanceState                                        RebalanceState
	RebalanceObjects, RebalanceRelocated, RebalanceFailed int
	RebalanceErr                                          string
	// Scrub* and the repair totals are cumulative since the node started.
	ScrubPasses, ScrubObjects, ScrubRepaired, ScrubFailed int64
	RebuiltFragments, SweptStale                          int64
	CorruptReplicas, Converted                            int64
	// ECUnverified reports that the node's last scrub pass saw an EC set
	// failing parity verification.
	ECUnverified bool
	// Disks is what each of the node's disks holds, as only the node can know.
	Disks []NodeDisk
}

NodeLive is what only a running node knows: its queue depths, runner progress and scrub totals. The control plane (etcd) carries none of this, so it is collected from the nodes over the peer transport.

type Options

type Options struct {
	// Manager is the access-key store to manage. Optional: nil disables the
	// access-key endpoints (they return 501) — e.g. a headless cluster admin
	// with file-backed credentials, which live on the data nodes.
	Manager CredentialManager
	// Build is reported by GetInfo.
	Build BuildInfo
	// AuthEnabled reports whether the S3 server enforces SigV4.
	AuthEnabled bool
	// StartTime is the process start, for uptime. Defaults to now.
	StartTime time.Time
	// Rebalance drives the cluster rebalance runner; nil outside cluster mode
	// (the endpoints then report "disabled" / refuse control).
	Rebalance RebalanceControl
	// ClusterStatus assembles the cluster-wide status; nil outside cluster mode
	// (the endpoint then reports "disabled").
	ClusterStatus ClusterStatusSource
	// Migrations reports and applies cluster schema migrations; nil outside
	// cluster mode (the endpoint then reports "disabled" and refuses to apply).
	Migrations MigrationControl
	// Reloader applies hot-reloadable configuration on demand (POST
	// /api/v1/reload); nil on a listener with nothing to reload (the headless
	// cluster admin), where the endpoint returns 501.
	Reloader Reloader
	// ConfigRevision returns the config revision currently in effect, reported
	// by GetInfo; nil reports none.
	ConfigRevision func() string
	// BucketSchemes reads and writes per-bucket replication-scheme overrides
	// via the control plane; nil outside cluster mode (the scheme endpoints
	// then return 501).
	BucketSchemes BucketSchemeStore
	// BucketUsage reads the durable per-bucket object accounting; nil outside
	// cluster mode (the endpoint then returns 501), where the index lives in
	// the control plane.
	BucketUsage BucketUsageSource
	// PublicRead reads and writes the cluster-wide public-read bucket list; nil
	// unless the server uses cluster-wide credentials (the public-read endpoints
	// then return 501).
	PublicRead PublicReadStore
	// ClusterDefaultScheme is the scheme applied to buckets without an override,
	// echoed by the scheme endpoints. Empty when unknown.
	ClusterDefaultScheme string
	// contains filtered or unexported fields
}

Options configures an AdminAPI.

type PublicReadStore added in v0.8.0

type PublicReadStore interface {
	// PublicReadBuckets returns the current public-read bucket list.
	PublicReadBuckets(ctx context.Context) ([]string, error)
	// SetPublicReadBuckets replaces the list. It returns ErrPublicReadRejected
	// when a bucket name is invalid.
	SetPublicReadBuckets(ctx context.Context, buckets []string) error
}

PublicReadStore reads and writes the cluster-wide list of anonymously-readable buckets in the control plane. It is nil unless the server uses cluster-wide credentials (auth.source: etcd), where the public-read endpoints return 501.

type RebalanceControl

type RebalanceControl interface {
	// Start launches the rebalance (campaigning for the cluster-wide slot).
	// Returns ErrRebalanceConflict when one is already waiting or running.
	Start(ctx context.Context) error
	// Pause stops this node's runner, keeping the resume cursor. Returns
	// ErrRebalanceConflict when nothing is waiting or running.
	Pause(ctx context.Context) error
	// Resume relaunches a paused rebalance from the persisted cursor. Returns
	// ErrRebalanceConflict unless the runner is paused.
	Resume(ctx context.Context) error
	// Status snapshots the runner.
	Status(ctx context.Context) RebalanceStatus
}

RebalanceControl drives the node's cluster rebalance runner. Implemented by the cluster runtime; absent (nil) outside cluster mode.

type RebalanceState

type RebalanceState string

RebalanceState is the node-local runner state.

const (
	RebalanceIdle    RebalanceState = "idle"
	RebalanceWaiting RebalanceState = "waiting"
	RebalanceRunning RebalanceState = "running"
	RebalancePaused  RebalanceState = "paused"
	RebalanceDone    RebalanceState = "done"
	RebalanceFailed  RebalanceState = "failed"
)

Runner states; see the admin API schema for semantics.

type RebalanceStatus

type RebalanceStatus struct {
	State RebalanceState
	// Objects, Relocated and Failed are the current or last run's progress.
	Objects, Relocated, Failed int
	// CursorBucket/CursorKey is the persisted resume cursor (empty when none).
	CursorBucket, CursorKey string
	// StartedAt/FinishedAt frame the current or last run; zero when unset.
	StartedAt, FinishedAt time.Time
	// Err is why the last run failed.
	Err string
	// RepairQueueDepth is the node's pending async remainder backlog.
	RepairQueueDepth int
}

RebalanceStatus is a snapshot of the node's rebalance runner.

type ReloadResult added in v0.6.0

type ReloadResult struct {
	// Reloaded names the hot-reloadable parts the reload applied, any of
	// "credentials", "tls".
	Reloaded []string
	// ConfigRevision is the config file's revision marker after the reload;
	// empty when the config sets none.
	ConfigRevision string
}

ReloadResult reports what a reload applied and the config revision left in effect.

type Reloader added in v0.6.0

type Reloader interface {
	// Reload re-reads the config file and applies the hot-reloadable parts,
	// returning what it changed and the config revision now in effect.
	Reload(ctx context.Context) (ReloadResult, error)
}

Reloader re-applies hot-reloadable configuration on demand — the same work SIGHUP does. Implemented by the S3 data node; absent (nil) on a listener with nothing to reload (the headless cluster admin serves no S3 data), where the endpoint returns 501.

Jump to

Keyboard shortcuts

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