analytics

package
v0.25.2 Latest Latest
Warning

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

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

Documentation

Overview

Package analytics collects active user metrics and reports them to the cloud dashboard

Index

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

func ResetDailyUTC(lastReset time.Time, now time.Time) bool

ResetDailyUTC resets the counter on a daily interval

func ResetMonthlyUTC

func ResetMonthlyUTC(lastReset time.Time, now time.Time) bool

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

type ActiveUsersCounter struct {
	*counter.Counter
	// contains filtered or unexported fields
}

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

func (*ActiveUsersCounter) Update

func (c *ActiveUsersCounter) Update(users []string, now time.Time) (current uint, wasReset bool)

Update updates the counter with the current users

type IntervalResetFunc

type IntervalResetFunc func(lastReset time.Time, now time.Time) bool

IntervalResetFunc is a function that determines if a counter should be reset

type MetricState

type MetricState struct {
	Data      []byte
	LastReset time.Time
	Count     uint
}

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

Jump to

Keyboard shortcuts

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