Documentation
¶
Index ¶
- type Manager
- func (m *Manager) ActivateTenant(id TenantID) error
- func (m *Manager) CheckTenantActive(id TenantID) error
- func (m *Manager) CreateTenant(id TenantID, name string, quotas *Quotas) (*Tenant, error)
- func (m *Manager) DeleteTenant(id TenantID) error
- func (m *Manager) EnforceConnectionQuota(id TenantID) error
- func (m *Manager) EnforceConsumeQuota(id TenantID, bytes, messages int64) error
- func (m *Manager) EnforceProduceQuota(id TenantID, bytes, messages int64) error
- func (m *Manager) EnforceStorageQuota(id TenantID, bytes int64) error
- func (m *Manager) EnforceTopicQuota(id TenantID, partitions int) error
- func (m *Manager) GetAllUsage() map[TenantID]*Usage
- func (m *Manager) GetTenant(id TenantID) (*Tenant, error)
- func (m *Manager) GetTenantStats(id TenantID) (*TenantStats, error)
- func (m *Manager) GetTracker(id TenantID) (*QuotaTracker, error)
- func (m *Manager) GetUsage(id TenantID) (*Usage, error)
- func (m *Manager) GetUtilization(id TenantID) (map[string]float64, error)
- func (m *Manager) ListTenants() []*Tenant
- func (m *Manager) ReleaseConnection(id TenantID)
- func (m *Manager) ReleaseTopic(id TenantID, partitions int)
- func (m *Manager) SuspendTenant(id TenantID) error
- func (m *Manager) UpdateStorageUsage(id TenantID, bytes int64) error
- func (m *Manager) UpdateTenant(id TenantID, name string, quotas *Quotas) error
- type QuotaError
- type QuotaTracker
- func (qt *QuotaTracker) AddConnection() error
- func (qt *QuotaTracker) AddProducer() error
- func (qt *QuotaTracker) AddTopic(partitions int) error
- func (qt *QuotaTracker) CheckConnection() error
- func (qt *QuotaTracker) CheckProducer() error
- func (qt *QuotaTracker) CheckStorage(additionalBytes int64) error
- func (qt *QuotaTracker) CheckThroughput(bytes, messages int64) error
- func (qt *QuotaTracker) CheckTopic() error
- func (qt *QuotaTracker) GetUsage() *Usage
- func (qt *QuotaTracker) RecordThroughput(bytes, messages int64)
- func (qt *QuotaTracker) RemoveConnection()
- func (qt *QuotaTracker) RemoveProducer()
- func (qt *QuotaTracker) RemoveTopic(partitions int)
- func (qt *QuotaTracker) UpdateStorage(bytes int64)
- func (qt *QuotaTracker) UtilizationPercent(quotaType string) float64
- type Quotas
- type RateWindow
- type Tenant
- type TenantID
- type TenantStats
- type TenantStatus
- type TenantStore
- func (s *TenantStore) ActivateTenant(id TenantID) error
- func (s *TenantStore) CreateTenant(id TenantID, name string, quotas *Quotas) (*Tenant, error)
- func (s *TenantStore) DeleteTenant(id TenantID) error
- func (s *TenantStore) GetTenant(id TenantID) (*Tenant, error)
- func (s *TenantStore) ListTenants() []*Tenant
- func (s *TenantStore) SuspendTenant(id TenantID) error
- func (s *TenantStore) UpdateTenant(id TenantID, name string, quotas *Quotas) error
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages all tenants and their quota tracking
func (*Manager) ActivateTenant ¶
ActivateTenant activates a tenant
func (*Manager) CheckTenantActive ¶
CheckTenantActive checks if a tenant exists and is active
func (*Manager) CreateTenant ¶
CreateTenant creates a new tenant with specified quotas
func (*Manager) DeleteTenant ¶
DeleteTenant deletes a tenant
func (*Manager) EnforceConnectionQuota ¶
EnforceConnectionQuota checks if a new connection can be created
func (*Manager) EnforceConsumeQuota ¶
EnforceConsumeQuota checks and records consume operation
func (*Manager) EnforceProduceQuota ¶
EnforceProduceQuota checks and records produce operation
func (*Manager) EnforceStorageQuota ¶
EnforceStorageQuota checks if storage quota allows the operation
func (*Manager) EnforceTopicQuota ¶
EnforceTopicQuota checks if a new topic can be created
func (*Manager) GetAllUsage ¶
GetAllUsage returns usage for all tenants
func (*Manager) GetTenantStats ¶
func (m *Manager) GetTenantStats(id TenantID) (*TenantStats, error)
GetTenantStats returns comprehensive stats for a tenant
func (*Manager) GetTracker ¶
func (m *Manager) GetTracker(id TenantID) (*QuotaTracker, error)
GetTracker gets the quota tracker for a tenant
func (*Manager) GetUtilization ¶
GetUtilization returns utilization percentages for a tenant
func (*Manager) ListTenants ¶
ListTenants returns all tenants
func (*Manager) ReleaseConnection ¶
ReleaseConnection releases a connection quota
func (*Manager) ReleaseTopic ¶
ReleaseTopic releases a topic quota
func (*Manager) SuspendTenant ¶
SuspendTenant suspends a tenant
func (*Manager) UpdateStorageUsage ¶
UpdateStorageUsage updates the current storage usage for a tenant
type QuotaError ¶
type QuotaError struct {
TenantID TenantID
QuotaType string
Current int64
Limit int64
Message string
}
QuotaError represents a quota exceeded error
func (*QuotaError) Error ¶
func (e *QuotaError) Error() string
type QuotaTracker ¶
type QuotaTracker struct {
// contains filtered or unexported fields
}
QuotaTracker tracks resource usage for a tenant and enforces quotas
func NewQuotaTracker ¶
func NewQuotaTracker(tenantID TenantID, quotas *Quotas) *QuotaTracker
NewQuotaTracker creates a new quota tracker for a tenant
func (*QuotaTracker) AddConnection ¶
func (qt *QuotaTracker) AddConnection() error
AddConnection increments the connection count
func (*QuotaTracker) AddProducer ¶
func (qt *QuotaTracker) AddProducer() error
AddProducer increments the producer count
func (*QuotaTracker) AddTopic ¶
func (qt *QuotaTracker) AddTopic(partitions int) error
AddTopic increments the topic count
func (*QuotaTracker) CheckConnection ¶
func (qt *QuotaTracker) CheckConnection() error
CheckConnection checks if a new connection can be added
func (*QuotaTracker) CheckProducer ¶
func (qt *QuotaTracker) CheckProducer() error
CheckProducer checks if a new producer can be added
func (*QuotaTracker) CheckStorage ¶
func (qt *QuotaTracker) CheckStorage(additionalBytes int64) error
CheckStorage checks if storage quota allows the specified bytes
func (*QuotaTracker) CheckThroughput ¶
func (qt *QuotaTracker) CheckThroughput(bytes, messages int64) error
CheckThroughput checks if the tenant can send/receive the specified bytes and messages
func (*QuotaTracker) CheckTopic ¶
func (qt *QuotaTracker) CheckTopic() error
CheckTopic checks if a new topic can be created
func (*QuotaTracker) GetUsage ¶
func (qt *QuotaTracker) GetUsage() *Usage
GetUsage returns current usage statistics
func (*QuotaTracker) RecordThroughput ¶
func (qt *QuotaTracker) RecordThroughput(bytes, messages int64)
RecordThroughput records bytes and messages used
func (*QuotaTracker) RemoveConnection ¶
func (qt *QuotaTracker) RemoveConnection()
RemoveConnection decrements the connection count
func (*QuotaTracker) RemoveProducer ¶
func (qt *QuotaTracker) RemoveProducer()
RemoveProducer decrements the producer count
func (*QuotaTracker) RemoveTopic ¶
func (qt *QuotaTracker) RemoveTopic(partitions int)
RemoveTopic decrements the topic count
func (*QuotaTracker) UpdateStorage ¶
func (qt *QuotaTracker) UpdateStorage(bytes int64)
UpdateStorage updates the current storage usage
func (*QuotaTracker) UtilizationPercent ¶
func (qt *QuotaTracker) UtilizationPercent(quotaType string) float64
UtilizationPercent calculates quota utilization percentage
type Quotas ¶
type Quotas struct {
// Throughput quotas (per second)
MaxBytesPerSecond int64 // Maximum bytes/sec for produce + consume
MaxMessagesPerSecond int64 // Maximum messages/sec for produce + consume
// Storage quotas
MaxStorageBytes int64 // Maximum total storage in bytes
MaxTopics int // Maximum number of topics
MaxPartitions int // Maximum total partitions across all topics
// Connection quotas
MaxConnections int // Maximum concurrent connections
MaxProducers int // Maximum concurrent producers
MaxConsumers int // Maximum concurrent consumers
MaxConsumerGroups int // Maximum consumer groups
// Request quotas
MaxRequestsPerSecond int64 // Maximum requests/sec
// Advanced quotas
MaxRetentionHours int64 // Maximum message retention in hours
}
Quotas define resource limits for a tenant
func DefaultQuotas ¶
func DefaultQuotas() *Quotas
DefaultQuotas returns sensible default quotas for a new tenant
func UnlimitedQuotas ¶
func UnlimitedQuotas() *Quotas
UnlimitedQuotas returns quotas with no limits (for testing or admin tenants)
type RateWindow ¶
type RateWindow struct {
// contains filtered or unexported fields
}
RateWindow tracks usage over a sliding time window for rate limiting
func NewRateWindow ¶
func NewRateWindow(windowSize, bucketSize time.Duration) *RateWindow
NewRateWindow creates a new rate tracking window
func (*RateWindow) Add ¶
func (w *RateWindow) Add(value int64)
Add adds a value to the current bucket
func (*RateWindow) Rate ¶
func (w *RateWindow) Rate() float64
Rate returns the current rate (total in window / window duration in seconds)
type Tenant ¶
type Tenant struct {
ID TenantID
Name string
Description string
CreatedAt time.Time
UpdatedAt time.Time
// Quotas define resource limits for this tenant
Quotas *Quotas
// Metadata for custom tenant properties
Metadata map[string]string
// Status indicates if tenant is active, suspended, etc.
Status TenantStatus
}
Tenant represents a multi-tenant namespace in StreamBus
type TenantStats ¶
TenantStats returns summary statistics for a tenant
type TenantStatus ¶
type TenantStatus string
TenantStatus represents the operational status of a tenant
const ( TenantStatusActive TenantStatus = "ACTIVE" TenantStatusSuspended TenantStatus = "SUSPENDED" TenantStatusDeleted TenantStatus = "DELETED" )
type TenantStore ¶
type TenantStore struct {
// contains filtered or unexported fields
}
TenantStore manages tenants in the system
func (*TenantStore) ActivateTenant ¶
func (s *TenantStore) ActivateTenant(id TenantID) error
ActivateTenant activates a suspended tenant
func (*TenantStore) CreateTenant ¶
CreateTenant creates a new tenant
func (*TenantStore) DeleteTenant ¶
func (s *TenantStore) DeleteTenant(id TenantID) error
DeleteTenant deletes a tenant
func (*TenantStore) GetTenant ¶
func (s *TenantStore) GetTenant(id TenantID) (*Tenant, error)
GetTenant retrieves a tenant by ID
func (*TenantStore) ListTenants ¶
func (s *TenantStore) ListTenants() []*Tenant
ListTenants returns all tenants
func (*TenantStore) SuspendTenant ¶
func (s *TenantStore) SuspendTenant(id TenantID) error
SuspendTenant suspends a tenant
func (*TenantStore) UpdateTenant ¶
func (s *TenantStore) UpdateTenant(id TenantID, name string, quotas *Quotas) error
UpdateTenant updates a tenant's configuration