metering

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OwnerTypeUser = types.OwnerTypeUser
	OwnerTypeOrg  = types.OwnerTypeOrg
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingOwner

type BillingOwner = types.BillingOwner

type DLQEntry

type DLQEntry struct {
	ID            int64
	Payload       json.RawMessage
	ErrorMessage  string
	RetryCount    int
	FirstFailedAt time.Time
	LastRetriedAt *time.Time
	ResolvedAt    *time.Time
	Resolution    *string
}

type OwnerType

type OwnerType = types.OwnerType

type QuotaStatus

type QuotaStatus = types.QuotaStatus

type Service

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

func New

func New(cfg *config.Config, log pkginterfaces.LoggerInterface, db *sql.DB) (*Service, error)

func (*Service) CheckQuota

func (s *Service) CheckQuota(ctx context.Context, owner BillingOwner, eventType string) (bool, int64, error)

func (*Service) ExportUsage

func (s *Service) ExportUsage(ctx context.Context) (int, error)

func (*Service) GetQuotaStatus

func (s *Service) GetQuotaStatus(ctx context.Context, owner BillingOwner) ([]QuotaStatus, error)

func (*Service) GetUsage

func (s *Service) GetUsage(ctx context.Context, owner BillingOwner, from, to time.Time) (*UsageReport, error)

func (*Service) GetUsageByWorkspace

func (s *Service) GetUsageByWorkspace(ctx context.Context, owner BillingOwner, workspaceID string, from, to time.Time) (*UsageReport, error)

func (*Service) Record

func (s *Service) Record(event UsageEvent)

func (*Service) RecordLifecycleEvent

func (s *Service) RecordLifecycleEvent(ctx context.Context, workspaceID, ownerID string, ownerType OwnerType, fromPhase, toPhase, resourceTier string, eventTime time.Time) error

func (*Service) SetActivePhasesChecker

func (s *Service) SetActivePhasesChecker(fn WorkspacePhaseChecker)

func (*Service) SetBillingProvider

func (s *Service) SetBillingProvider(p WorkspaceBillingProvider)

func (*Service) SetDatabaseService

func (s *Service) SetDatabaseService(dbSvc interfaces.DatabaseService)

func (*Service) SetUsageReporter

func (s *Service) SetUsageReporter(r UsageReporter)

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop() error

type UsageEvent

type UsageEvent = types.UsageEvent

type UsageReport

type UsageReport = types.UsageReport

type UsageReporter

type UsageReporter interface {
	ReportUsage(ctx context.Context, events []billing.UsageExportEvent) ([]int64, error)
}

UsageReporter reports metered usage to an external billing provider (e.g. Stripe). nil means usage is not reported externally (dev/noop mode).

type WorkspaceBillingProvider

type WorkspaceBillingProvider interface {
	ListAllWorkspacesForBilling(ctx context.Context) ([]database.WorkspaceBillingRecord, error)
}

type WorkspaceLifecycleEvent

type WorkspaceLifecycleEvent struct {
	WorkspaceID  string
	OwnerID      string
	OwnerType    OwnerType
	FromPhase    string
	ToPhase      string
	ResourceTier string
	EventTime    time.Time
}

type WorkspacePhaseChecker

type WorkspacePhaseChecker func() map[string]string

Jump to

Keyboard shortcuts

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