Documentation
¶
Index ¶
- Constants
- Variables
- func CheckTenantIDIsSupported(s string) error
- func CheckTenantIDLength(s string) error
- func DeleteTenantDeletionMark(ctx context.Context, bkt objstore.Bucket, userID string) error
- func ExtractTenantIDFromHTTPRequest(req *http.Request) (string, context.Context, error)
- func GetGlobalDeletionMarkPath(userID string) string
- func GetLocalDeletionMarkPath(userID string) string
- func JoinTenantIDs(tenantIDs []string) string
- func NormalizeTenantIDs(tenantIDs []string) []string
- func ShardByUser(userID string) uint32
- func TenantDeletionMarkExists(ctx context.Context, bkt objstore.BucketReader, userID string) (bool, error)
- func TenantID(ctx context.Context) (string, error)
- func TenantIDs(ctx context.Context) ([]string, error)
- func TenantIDsFromOrgID(orgID string) ([]string, error)
- func ValidTenantID(s string) error
- func ValidateOrgIDs(orgIDs []string) ([]string, error)
- func WithDefaultResolver(r Resolver)
- func WriteTenantDeletionMark(ctx context.Context, bkt objstore.InstrumentedBucket, userID string, ...) error
- func WriteUserIndex(ctx context.Context, bkt objstore.Bucket, idx *UserIndex) error
- type ActiveUsers
- type ActiveUsersCleanupService
- type AllowedTenants
- type MultiResolver
- type Resolver
- type Scanner
- type SingleResolver
- type TenantDeletionMark
- type UserIndex
- type UserIndexUpdater
- type UsersScannerConfig
Constants ¶
const ( UserIndexFilename = "user-index.json" UserIndexCompressedFilename = UserIndexFilename + ".gz" )
const ( UserScanStrategyList = "list" UserScanStrategyUserIndex = "user_index" )
const GlobalMarkersDir = "__markers__"
const TenantDeletionMarkFile = "tenant-deletion-mark.json"
Variables ¶
var ( ErrIndexNotFound = errors.New("user index not found") ErrIndexCorrupted = errors.New("user index corrupted") )
Functions ¶
func CheckTenantIDLength ¶
func DeleteTenantDeletionMark ¶
Deletes the tenant deletion mark for given user if it exists.
func ExtractTenantIDFromHTTPRequest ¶
ExtractTenantIDFromHTTPRequest extracts a single TenantID through a given resolver directly from a HTTP request.
func JoinTenantIDs ¶
func NormalizeTenantIDs ¶
NormalizeTenantIDs is creating a normalized form by sorting and de-duplicating the list of tenantIDs
func ShardByUser ¶
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 ¶
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 ¶
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 ¶
TenantIDsFromOrgID extracts different tenants from an orgID string value
ignore stutter warning
func ValidateOrgIDs ¶
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.
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)
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 NewScanner ¶
func NewScanner(cfg UsersScannerConfig, bkt objstore.InstrumentedBucket, logger log.Logger, reg prometheus.Registerer) (Scanner, error)
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.
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 (*UserIndex) GetUpdatedAt ¶
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