analytics

package
v0.0.0-...-6c99467 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagDuration = "duration"
	TagName     = "name"
	TagUser     = "user"
	TagMachine  = "machine"
)

keys for request to stats server

Variables

View Source
var Choices = map[Opt]string{
	OptDefault: "default",
	OptOut:     "opt-out",
	OptIn:      "opt-in",
}

Functions

func NewCommand

func NewCommand() *cobra.Command

func NewRemoteAnalytics

func NewRemoteAnalytics(appName string, options ...Option) (*remoteAnalytics, error)

Create a remote analytics object with Windmill-specific defaults for the HTTPClient, report URL, user ID, and opt-in status. All of these defaults can be overridden with appropriate options.

func SetOpt

func SetOpt(c Opt) error

Types

type Analytics

type Analytics interface {
	Count(name string, tags map[string]string, n int)
	Incr(name string, tags map[string]string)
	Timer(name string, dur time.Duration, tags map[string]string)
	Flush(timeout time.Duration)
	GlobalTag(name string) (string, bool)

	// Returns a new analytics that doesn't report any of the global tags.
	// Useful for anonymous reporting.
	WithoutGlobalTags() Analytics
}

type CountEvent

type CountEvent struct {
	Name string
	Tags map[string]string
	N    int
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type MemoryAnalytics

type MemoryAnalytics struct {
	Counts []CountEvent
	Timers []TimeEvent
}

func NewMemoryAnalytics

func NewMemoryAnalytics() *MemoryAnalytics

func (*MemoryAnalytics) Count

func (a *MemoryAnalytics) Count(name string, tags map[string]string, n int)

func (*MemoryAnalytics) Flush

func (a *MemoryAnalytics) Flush(timeout time.Duration)

func (*MemoryAnalytics) GlobalTag

func (a *MemoryAnalytics) GlobalTag(name string) (string, bool)

func (*MemoryAnalytics) Incr

func (a *MemoryAnalytics) Incr(name string, tags map[string]string)

func (*MemoryAnalytics) Timer

func (a *MemoryAnalytics) Timer(name string, dur time.Duration, tags map[string]string)

func (*MemoryAnalytics) WithoutGlobalTags

func (a *MemoryAnalytics) WithoutGlobalTags() Analytics

type Opt

type Opt int
const (
	OptDefault Opt = iota
	OptOut
	OptIn
)

func OptStatus

func OptStatus() (Opt, error)

func ParseOpt

func ParseOpt(s string) (Opt, error)

func SetOptStr

func SetOptStr(s string) (Opt, error)

SetOptStr converts the given string into an Opt enum, and records that choice as the users analytics decision, returning the Opt set (and any errors).

func (Opt) String

func (o Opt) String() string

type Option

type Option func(a *remoteAnalytics)

func WithEnabled

func WithEnabled(enabled bool) Option

Sets whether the analytics client is enabled. Defaults to checking the users' opt-in setting in ~/.windmill

func WithGlobalTags

func WithGlobalTags(tags map[string]string) Option

Sets global tags for every report.

func WithHTTPClient

func WithHTTPClient(client HTTPClient) Option

Sets the HTTP client. Defaults to golang http client.

func WithLogger

func WithLogger(logger Logger) Option

Sets the logger where errors are printed. Defaults to printing to the default logger with the prefix "analytics ".

func WithMachineID

func WithMachineID(machineID string) Option

func WithReportURL

func WithReportURL(url string) Option

Sets the URL to report to. Defaults to https://events.windmill.build/report

func WithUserID

func WithUserID(userID string) Option

Sets the UserID. Defaults to a user ID based on a hash of a machine identifier.

type TimeEvent

type TimeEvent struct {
	Name string
	Tags map[string]string
	Dur  time.Duration
}

Jump to

Keyboard shortcuts

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