Documentation ¶
Overview ¶
Package analytics collects active user metrics and reports them to the cloud dashboard
Index ¶
- func Collect(ctx context.Context, client databroker.DataBrokerServiceClient, ...) error
- func CurrentUsers(ctx context.Context, client databroker.DataBrokerServiceClient) ([]string, error)
- func Metrics(clientProvider func() databroker.DataBrokerServiceClient) []func(m metric.Meter) error
- func ResetDailyUTC(lastReset time.Time, now time.Time) bool
- func ResetMonthlyUTC(lastReset time.Time, now time.Time) bool
- func SaveMetricState(ctx context.Context, client databroker.DataBrokerServiceClient, id string, ...) error
- type ActiveUsersCounter
- type IntervalResetFunc
- type MetricState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
func Collect( ctx context.Context, client databroker.DataBrokerServiceClient, updateInterval time.Duration, ) error
Collect collects metrics and stores them in the databroker
func CurrentUsers ¶
func CurrentUsers( ctx context.Context, client databroker.DataBrokerServiceClient, ) ([]string, error)
CurrentUsers returns a list of users active within the current UTC day
func Metrics ¶
func Metrics( clientProvider func() databroker.DataBrokerServiceClient, ) []func(m metric.Meter) error
Metrics returns a list of metrics to be exported
func ResetDailyUTC ¶
ResetDailyUTC resets the counter on a daily interval
func ResetMonthlyUTC ¶
ResetMonthlyUTC resets the counter on a monthly interval
func SaveMetricState ¶
func SaveMetricState( ctx context.Context, client databroker.DataBrokerServiceClient, id string, data []byte, value uint, lastReset time.Time, ) error
SaveMetricState saves the state of a metric to the databroker
Types ¶
type ActiveUsersCounter ¶
ActiveUsersCounter is a counter that resets on a given interval
func LoadActiveUsersCounter ¶
func LoadActiveUsersCounter(state []byte, lastReset time.Time, resetFn IntervalResetFunc) (*ActiveUsersCounter, error)
LoadActiveUsersCounter loads an active users counter from a binary state
func NewActiveUsersCounter ¶
func NewActiveUsersCounter(needsReset IntervalResetFunc, now time.Time) *ActiveUsersCounter
NewActiveUsersCounter creates a new active users counter
func (*ActiveUsersCounter) GetLastReset ¶
func (c *ActiveUsersCounter) GetLastReset() time.Time
GetLastReset returns the last time the counter was reset
type IntervalResetFunc ¶
IntervalResetFunc is a function that determines if a counter should be reset
type MetricState ¶
MetricState is the persistent state of a metric
func LoadMetricState ¶
func LoadMetricState( ctx context.Context, client databroker.DataBrokerServiceClient, id string, ) (*MetricState, error)
LoadMetricState loads the state of a metric from the databroker
func (*MetricState) FromAny ¶
func (r *MetricState) FromAny(any *anypb.Any) error
FromAny unmarshals an anypb.Any into a MetricState
func (*MetricState) ToAny ¶
func (r *MetricState) ToAny() *anypb.Any
ToAny marshals a MetricState into an anypb.Any