users

package
v1.21.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIndexFilename           = "user-index.json"
	UserIndexCompressedFilename = UserIndexFilename + ".gz"
)
View Source
const (
	UserScanStrategyList      = "list"
	UserScanStrategyUserIndex = "user_index"
)
View Source
const GlobalMarkersDir = "__markers__"
View Source
const TenantDeletionMarkFile = "tenant-deletion-mark.json"

Variables

View Source
var (
	ErrIndexNotFound  = errors.New("user index not found")
	ErrIndexCorrupted = errors.New("user index corrupted")
)
View Source
var (
	ErrInvalidUserScannerStrategy = errors.New("invalid user scanner strategy")
	ErrInvalidMaxStalePeriod      = errors.New("max stale period must be positive")
	ErrInvalidCacheTTL            = errors.New("cache TTL must be >= 0")
)

Functions

func CheckTenantIDIsSupported

func CheckTenantIDIsSupported(s string) error

func CheckTenantIDLength

func CheckTenantIDLength(s string) error

func DeleteTenantDeletionMark

func DeleteTenantDeletionMark(ctx context.Context, bkt objstore.Bucket, userID string) error

Deletes the tenant deletion mark for given user if it exists.

func ExtractTenantIDFromHTTPRequest

func ExtractTenantIDFromHTTPRequest(req *http.Request) (string, context.Context, error)

ExtractTenantIDFromHTTPRequest extracts a single TenantID through a given resolver directly from a HTTP request.

func GetGlobalDeletionMarkPath

func GetGlobalDeletionMarkPath(userID string) string

func GetLocalDeletionMarkPath

func GetLocalDeletionMarkPath(userID string) string

func JoinTenantIDs

func JoinTenantIDs(tenantIDs []string) string

func NormalizeTenantIDs

func NormalizeTenantIDs(tenantIDs []string) []string

NormalizeTenantIDs is creating a normalized form by sorting and de-duplicating the list of tenantIDs

func ShardByUser

func ShardByUser(userID string) uint32

func TenantDeletionMarkExists

func TenantDeletionMarkExists(ctx context.Context, bkt objstore.BucketReader, userID string) (bool, error)

Checks for deletion mark for tenant. Errors other than "object not found" are returned.

func TenantID

func TenantID(ctx context.Context) (string, error)

TenantID returns exactly a single tenant ID from the context. It should be used when a certain endpoint should only support exactly a single tenant ID. It returns an error user.ErrNoOrgID if there is no tenant ID supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present.

ignore stutter warning

func TenantIDs

func TenantIDs(ctx context.Context) ([]string, error)

TenantIDs returns all tenant IDs from the context. It should return normalized list of ordered and distinct tenant IDs (as produced by NormalizeTenantIDs).

ignore stutter warning

func TenantIDsFromOrgID

func TenantIDsFromOrgID(orgID string) ([]string, error)

TenantIDsFromOrgID extracts different tenants from an orgID string value

ignore stutter warning

func ValidTenantID

func ValidTenantID(s string) error

ValidTenantID validate tenantID

func ValidateOrgIDs

func ValidateOrgIDs(orgIDs []string) ([]string, error)

func WithDefaultResolver

func WithDefaultResolver(r Resolver)

WithDefaultResolver updates the resolver used for the package methods.

func WriteTenantDeletionMark

func WriteTenantDeletionMark(ctx context.Context, bkt objstore.InstrumentedBucket, userID string, mark *TenantDeletionMark) error

Uploads deletion mark to the tenant location in the bucket.

func WriteUserIndex

func WriteUserIndex(ctx context.Context, bkt objstore.Bucket, idx *UserIndex) error

WriteUserIndex uploads the provided index to the storage.

Types

type ActiveUsers

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

ActiveUsers keeps track of latest user's activity timestamp, and allows purging users that are no longer active.

func NewActiveUsers

func NewActiveUsers() *ActiveUsers

func (*ActiveUsers) ActiveUsers

func (m *ActiveUsers) ActiveUsers(deadline int64) []string

func (*ActiveUsers) PurgeInactiveUsers

func (m *ActiveUsers) PurgeInactiveUsers(deadline int64) []string

PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.

func (*ActiveUsers) UpdateUserTimestamp

func (m *ActiveUsers) UpdateUserTimestamp(userID string, ts int64)

type ActiveUsersCleanupService

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

ActiveUsersCleanupService tracks active users, and periodically purges inactive ones while running.

func NewActiveUsersCleanupService

func NewActiveUsersCleanupService(cleanupInterval, inactiveTimeout time.Duration, cleanupFn func(string)) *ActiveUsersCleanupService

func NewActiveUsersCleanupWithDefaultValues

func NewActiveUsersCleanupWithDefaultValues(cleanupFn func(string)) *ActiveUsersCleanupService

func (*ActiveUsersCleanupService) ActiveUsers

func (s *ActiveUsersCleanupService) ActiveUsers() []string

func (*ActiveUsersCleanupService) UpdateUserTimestamp

func (s *ActiveUsersCleanupService) UpdateUserTimestamp(user string, now time.Time)

type AllowedTenants

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

AllowedTenants that can answer whether tenant is allowed or not based on configuration. Default value (nil) allows all tenants.

func NewAllowedTenants

func NewAllowedTenants(enabled []string, disabled []string) *AllowedTenants

NewAllowedTenants builds new allowed tenants based on enabled and disabled tenants. If there are any enabled tenants, then only those tenants are allowed. If there are any disabled tenants, then tenant from that list, that would normally be allowed, is disabled instead.

func (*AllowedTenants) IsAllowed

func (a *AllowedTenants) IsAllowed(tenantID string) bool

type MultiResolver

type MultiResolver struct {
}

func NewMultiResolver

func NewMultiResolver() *MultiResolver

NewMultiResolver creates a tenant resolver, which allows request to have multiple tenant ids submitted separated by a '|' character. This enforces further limits on the character set allowed within tenants as detailed here: https://cortexmetrics.io/docs/guides/limitations/#tenant-id-naming)

func (*MultiResolver) TenantID

func (t *MultiResolver) TenantID(ctx context.Context) (string, error)

func (*MultiResolver) TenantIDs

func (t *MultiResolver) TenantIDs(ctx context.Context) ([]string, error)

type Resolver

type Resolver interface {
	// TenantID returns exactly a single tenant ID from the context. It should be
	// used when a certain endpoint should only support exactly a single
	// tenant ID. It returns an error user.ErrNoOrgID if there is no tenant ID
	// supplied or user.ErrTooManyOrgIDs if there are multiple tenant IDs present.
	TenantID(context.Context) (string, error)

	// TenantIDs returns all tenant IDs from the context. It should return
	// normalized list of ordered and distinct tenant IDs (as produced by
	// NormalizeTenantIDs).
	TenantIDs(context.Context) ([]string, error)
}

type Scanner

type Scanner interface {
	// ScanUsers returns the list of active, deleting and deleted users.
	// Both deleting and deleted users are marked for deletion. The difference is that
	// deleting users might still have data in the bucket, while deleted users don't.
	ScanUsers(ctx context.Context) (active, deleting, deleted []string, err error)
}

func NewShardedScanner

func NewShardedScanner(scanner Scanner, isOwned func(userID string) (bool, error), logger log.Logger) Scanner

type SingleResolver

type SingleResolver struct {
}

func NewSingleResolver

func NewSingleResolver() *SingleResolver

NewSingleResolver creates a tenant resolver, which restricts all requests to be using a single tenant only. This allows a wider set of characters to be used within the tenant ID and should not impose a breaking change.

func (*SingleResolver) TenantID

func (t *SingleResolver) TenantID(ctx context.Context) (string, error)

func (*SingleResolver) TenantIDs

func (t *SingleResolver) TenantIDs(ctx context.Context) ([]string, error)

type TenantDeletionMark

type TenantDeletionMark struct {
	// Unix timestamp when deletion marker was created.
	DeletionTime int64 `json:"deletion_time"`

	// Unix timestamp when cleanup was finished.
	FinishedTime int64 `json:"finished_time,omitempty"`
}

func NewTenantDeletionMark

func NewTenantDeletionMark(deletionTime time.Time) *TenantDeletionMark

func ReadTenantDeletionMark

func ReadTenantDeletionMark(ctx context.Context, bkt objstore.InstrumentedBucket, userID string, logger log.Logger) (*TenantDeletionMark, error)

Returns tenant deletion mark for given user, if it exists. If it doesn't exist, returns nil mark, and no error.

type UserIndex

type UserIndex struct {
	Version   int   `json:"version"`
	UpdatedAt int64 `json:"updated_at"`

	ActiveUsers   []string `json:"active"`
	DeletingUsers []string `json:"deleting"`
	DeletedUsers  []string `json:"deleted"`
}

func ReadUserIndex

func ReadUserIndex(ctx context.Context, bkt objstore.InstrumentedBucket, logger log.Logger) (*UserIndex, error)

func (*UserIndex) GetUpdatedAt

func (idx *UserIndex) GetUpdatedAt() time.Time

type UserIndexUpdater

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

func NewUserIndexUpdater

func NewUserIndexUpdater(bkt objstore.InstrumentedBucket, updateInterval time.Duration, scanner Scanner, reg prometheus.Registerer) *UserIndexUpdater

func (*UserIndexUpdater) GetUpdateInterval

func (u *UserIndexUpdater) GetUpdateInterval() time.Duration

func (*UserIndexUpdater) UpdateUserIndex

func (u *UserIndexUpdater) UpdateUserIndex(ctx context.Context) error

type UsersScannerConfig

type UsersScannerConfig struct {
	Strategy       string        `yaml:"strategy"`
	MaxStalePeriod time.Duration `yaml:"max_stale_period"`
	UpdateInterval time.Duration `yaml:"update_interval"`
	CacheTTL       time.Duration `yaml:"cache_ttl"`
}

func (*UsersScannerConfig) RegisterFlagsWithPrefix

func (c *UsersScannerConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

func (*UsersScannerConfig) Validate

func (c *UsersScannerConfig) Validate() error

Jump to

Keyboard shortcuts

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