usage

package
v0.0.0-...-c4f7e29 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UsageLimitExceeded = apierrors.ServiceUnavailable.WithReason("UsageLimitExceeded")

Functions

func ComputeResetTime

func ComputeResetTime(now time.Time, period config.UsageLimitPeriod) time.Time

func ErrUsageLimitExceeded

func ErrUsageLimitExceeded(name LimitName) error

Types

type CountCollector

type CountCollector struct {
	GlobalHandle  *globaldb.Handle
	GlobalDBStore *GlobalDBStore
	ReadCounter   ReadCounterStore
	AuditHandle   *auditdb.ReadHandle
	Meters        MeterAuditDBStore
}

func (*CountCollector) CollectDailyActiveUser

func (c *CountCollector) CollectDailyActiveUser(startTime *time.Time) (int, error)

func (*CountCollector) CollectDailyEmailSent

func (c *CountCollector) CollectDailyEmailSent(startTime *time.Time) (int, error)

func (*CountCollector) CollectDailySMSSent

func (c *CountCollector) CollectDailySMSSent(startTime *time.Time) (int, error)

func (*CountCollector) CollectDailyWhatsappSent

func (c *CountCollector) CollectDailyWhatsappSent(startTime *time.Time) (int, error)

func (*CountCollector) CollectMonthlyActiveUser

func (c *CountCollector) CollectMonthlyActiveUser(startTime *time.Time) (int, error)

func (*CountCollector) CollectWeeklyActiveUser

func (c *CountCollector) CollectWeeklyActiveUser(startTime *time.Time) (int, error)

type GlobalDBStore

type GlobalDBStore struct {
	SQLBuilder  *globaldb.SQLBuilder
	SQLExecutor *globaldb.SQLExecutor
}

func (*GlobalDBStore) FetchUploadedUsageRecords

func (s *GlobalDBStore) FetchUploadedUsageRecords(
	appID string,
	recordName RecordName,
	period periodical.Type,
	stripeStart time.Time,
	stripeEnd time.Time,
) ([]*UsageRecord, error)

func (*GlobalDBStore) FetchUsageRecords

func (s *GlobalDBStore) FetchUsageRecords(
	appID string,
	recordName RecordName,
	period periodical.Type,
	startTime time.Time,
) ([]*UsageRecord, error)

func (*GlobalDBStore) GetAppIDs

func (s *GlobalDBStore) GetAppIDs() (appIDs []string, err error)

func (*GlobalDBStore) UpsertUsageRecords

func (s *GlobalDBStore) UpsertUsageRecords(usageRecords []*UsageRecord) error

UpsertUsageRecords upsert usage record in batches

type LimitName

type LimitName string

type Limiter

type Limiter struct {
	Logger Logger
	Clock  clock.Clock
	AppID  config.AppID
	Redis  *appredis.Handle
}

func (*Limiter) Cancel

func (l *Limiter) Cancel(r *Reservation)

func (*Limiter) Reserve

func (l *Limiter) Reserve(name LimitName, config *config.UsageLimitConfig) (*Reservation, error)

type Logger

type Logger struct{ *log.Logger }

func NewLogger

func NewLogger(lf *log.Factory) Logger

type MeterAuditDBStore

type MeterAuditDBStore interface {
	QueryPage(appID string, opts audit.QueryPageOptions, pageArgs graphqlutil.PageArgs) ([]*audit.Log, uint64, error)
	GetCountByActivityType(appID string, activityType string, rangeFrom *time.Time, rangeTo *time.Time) (int, error)
}

type ReadCounterStore

type ReadCounterStore interface {
	GetDailyActiveUserCount(appID config.AppID, date *time.Time) (count int, redisKey string, err error)
	GetWeeklyActiveUserCount(appID config.AppID, year int, week int) (count int, redisKey string, err error)
	GetMonthlyActiveUserCount(appID config.AppID, year int, month int) (count int, redisKey string, err error)
}

type RecordName

type RecordName string
const (
	RecordNameActiveUser               RecordName = "active-user"
	RecordNameSMSSentNorthAmerica      RecordName = "sms-sent.north-america"
	RecordNameSMSSentOtherRegions      RecordName = "sms-sent.other-regions"
	RecordNameSMSSentTotal             RecordName = "sms-sent.total"
	RecordNameWhatsappSentNorthAmerica RecordName = "whatsapp-sent.north-america"
	RecordNameWhatsappSentOtherRegions RecordName = "whatsapp-sent.other-regions"
	RecordNameWhatsappSentTotal        RecordName = "whatsapp-sent.total"
	RecordNameEmailSent                RecordName = "email-sent"
	RecordNameWhatsappOTPVerified      RecordName = "whatsapp-otp-verified"
)

type RecordType

type RecordType string
const (
	RecordTypeActiveUser          RecordType = "active-user"
	RecordTypeSMSSent             RecordType = "sms-sent"
	RecordTypeEmailSent           RecordType = "email-sent"
	RecordTypeWhatsappSent        RecordType = "whatsapp-sent"
	RecordTypeWhatsappOTPVerified RecordType = "whatsapp-otp-verified"
)

type Reservation

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

type UsageRecord

type UsageRecord struct {
	ID              string
	AppID           string
	Name            RecordName
	Period          string
	StartTime       time.Time
	EndTime         time.Time
	Count           int
	AlertData       map[string]interface{}
	StripeTimestamp *time.Time
}

nolint:golint

func NewUsageRecord

func NewUsageRecord(appID string, name RecordName, count int, period periodical.Type, startTime time.Time, endTime time.Time) *UsageRecord

Jump to

Keyboard shortcuts

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