Documentation ¶
Index ¶
- Variables
- func ComputeResetTime(now time.Time, period config.UsageLimitPeriod) time.Time
- func ErrUsageLimitExceeded(name LimitName) error
- type CountCollector
- func (c *CountCollector) CollectDailyActiveUser(ctx context.Context, startTime *time.Time) (int, error)
- func (c *CountCollector) CollectDailyEmailSent(ctx context.Context, startTime *time.Time) (int, error)
- func (c *CountCollector) CollectDailySMSSent(ctx context.Context, startTime *time.Time) (int, error)
- func (c *CountCollector) CollectDailyWhatsappSent(ctx context.Context, startTime *time.Time) (int, error)
- func (c *CountCollector) CollectMonthlyActiveUser(ctx context.Context, startTime *time.Time) (int, error)
- func (c *CountCollector) CollectWeeklyActiveUser(ctx context.Context, startTime *time.Time) (int, error)
- type GlobalDBStore
- func (s *GlobalDBStore) FetchUploadedUsageRecords(ctx context.Context, appID string, recordName RecordName, ...) ([]*UsageRecord, error)
- func (s *GlobalDBStore) FetchUsageRecords(ctx context.Context, appID string, recordName RecordName, ...) ([]*UsageRecord, error)
- func (s *GlobalDBStore) FetchUsageRecordsInRange(ctx context.Context, appID string, recordName RecordName, ...) ([]*UsageRecord, error)
- func (s *GlobalDBStore) GetAppIDs(ctx context.Context) (appIDs []string, err error)
- func (s *GlobalDBStore) UpsertUsageRecords(ctx context.Context, usageRecords []*UsageRecord) error
- type LimitName
- type Limiter
- func (l *Limiter) Cancel(ctx context.Context, r *Reservation)
- func (l *Limiter) Reserve(ctx context.Context, name LimitName, config *config.UsageLimitConfig) (*Reservation, error)
- func (l *Limiter) ReserveN(ctx context.Context, name LimitName, n int, config *config.UsageLimitConfig) (*Reservation, error)
- type Logger
- type MeterAuditDBStore
- type ReadCounterStore
- type RecordName
- type RecordType
- type Reservation
- type UsageRecord
Constants ¶
This section is empty.
Variables ¶
View Source
var DependencySet = wire.NewSet( NewLogger, wire.Struct(new(GlobalDBStore), "*"), wire.Struct(new(CountCollector), "*"), wire.Struct(new(Limiter), "*"), )
View Source
var UsageLimitExceeded = apierrors.TooManyRequest.WithReason("UsageLimitExceeded")
Functions ¶
func ComputeResetTime ¶
func ErrUsageLimitExceeded ¶
Types ¶
type CountCollector ¶
type CountCollector struct { GlobalHandle *globaldb.Handle GlobalDBStore *GlobalDBStore ReadCounter ReadCounterStore AuditHandle *auditdb.ReadHandle Meters MeterAuditDBStore }
func (*CountCollector) CollectDailyActiveUser ¶
func (*CountCollector) CollectDailyEmailSent ¶
func (*CountCollector) CollectDailySMSSent ¶
func (*CountCollector) CollectDailyWhatsappSent ¶
func (*CountCollector) CollectMonthlyActiveUser ¶
func (*CountCollector) CollectWeeklyActiveUser ¶
type GlobalDBStore ¶
type GlobalDBStore struct { SQLBuilder *globaldb.SQLBuilder SQLExecutor *globaldb.SQLExecutor }
func (*GlobalDBStore) FetchUploadedUsageRecords ¶
func (s *GlobalDBStore) FetchUploadedUsageRecords( ctx context.Context, appID string, recordName RecordName, period periodical.Type, stripeStart time.Time, stripeEnd time.Time, ) ([]*UsageRecord, error)
func (*GlobalDBStore) FetchUsageRecords ¶
func (s *GlobalDBStore) FetchUsageRecords( ctx context.Context, appID string, recordName RecordName, period periodical.Type, startTime time.Time, ) ([]*UsageRecord, error)
func (*GlobalDBStore) FetchUsageRecordsInRange ¶
func (s *GlobalDBStore) FetchUsageRecordsInRange( ctx context.Context, appID string, recordName RecordName, period periodical.Type, fromStartTime time.Time, toEndTime time.Time, ) ([]*UsageRecord, error)
func (*GlobalDBStore) GetAppIDs ¶
func (s *GlobalDBStore) GetAppIDs(ctx context.Context) (appIDs []string, err error)
func (*GlobalDBStore) UpsertUsageRecords ¶
func (s *GlobalDBStore) UpsertUsageRecords(ctx context.Context, usageRecords []*UsageRecord) error
UpsertUsageRecords upsert usage record in batches
type Limiter ¶
func (*Limiter) Reserve ¶
func (l *Limiter) Reserve(ctx context.Context, name LimitName, config *config.UsageLimitConfig) (*Reservation, error)
type MeterAuditDBStore ¶
type MeterAuditDBStore interface { QueryPage(ctx context.Context, appID string, opts audit.QueryPageOptions, pageArgs graphqlutil.PageArgs) ([]*audit.Log, uint64, error) GetCountByActivityType(ctx context.Context, appID string, activityType string, rangeFrom *time.Time, rangeTo *time.Time) (int, error) }
type ReadCounterStore ¶
type ReadCounterStore interface { GetDailyActiveUserCount(ctx context.Context, appID config.AppID, date *time.Time) (count int, redisKey string, err error) GetWeeklyActiveUserCount(ctx context.Context, appID config.AppID, year int, week int) (count int, redisKey string, err error) GetMonthlyActiveUserCount(ctx context.Context, 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
Click to show internal directories.
Click to hide internal directories.