picolytics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAdminAPI

func NewAdminAPI(debug bool) *echo.Echo

func SetConfigDefaults

func SetConfigDefaults()

Types

type AsyncEventSaver

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

func NewAsyncEventSaver

func NewAsyncEventSaver(events chan PicolyticsEvent, salter Salter, validEventNames []string, o11y *PicolyticsO11y) *AsyncEventSaver

func (*AsyncEventSaver) SaveEvent

func (es *AsyncEventSaver) SaveEvent(event PicolyticsEvent)

type Config

type Config struct {
	// injected values
	GitCommit, GitBranch, AppVersion string
	// db:
	PgConnString   string `mapstructure:"pgConnString"`
	PgHost         string `mapstructure:"pgHost"`     // required
	PgDatabase     string `mapstructure:"pgDatabase"` // required
	PgUser         string `mapstructure:"pgUser"`     // required
	PgPassword     string `mapstructure:"pgPassword"` // required
	PgPort         int    `mapstructure:"pgPort"`
	PgSslMode      string `mapstructure:"pgSslMode"`
	PgConnAttempts int    `mapstructure:"pgConnAttempts"`
	SkipMigrations bool   `mapstructure:"skipMigrations"`
	// server:
	ListenAddr     string `mapstructure:"listenAddr"`
	AutotlsEnabled bool   `mapstructure:"autotlsEnabled"`
	AutotlsHost    string `mapstructure:"autotlsHost"`
	AutotlsStaging bool   `mapstructure:"autotlsStaging"`
	AdminListen    string `mapstructure:"adminListen"`
	StaticDir      string `mapstructure:"staticDir"`
	RootRedirect   string `mapstructure:"rootRedirect"`
	// proxy:
	IPExtractor    string   `mapstructure:"ipExtractor"`
	TrustedProxies []string `mapstructure:"trustedProxies"`
	// privacy:
	GeoIPFile         string `mapstructure:"geoIpFile"`
	SessionTimeoutMin int    `mapstructure:"sessionTimeoutMin"`
	// tuning:
	QueueSize          int      `mapstructure:"queueSize"`
	BatchMaxSize       int      `mapstructure:"batchMaxSize"`
	BatchMaxMsec       int      `mapstructure:"batchMaxMsec"`
	RequestRateLimit   int      `mapstructure:"requestRateLimit"`
	BodyMaxSize        int64    `mapstructure:"bodyMaxSize"`
	StaticCacheMaxAge  int      `mapstructure:"staticCacheMaxAge"`
	DisableHostMetrics bool     `mapstructure:"disableHostMetrics"`
	LogFormat          string   `mapstructure:"logFormat"`
	PruneDays          int      `mapstructure:"pruneDays"`
	PruneCheckHours    int      `mapstructure:"pruneCheckHours"`
	ValidEventNames    []string `mapstructure:"validEventNames"`
	Debug              bool     `mapstructure:"debug"`

	// internal config
	StaticFiles fs.FS `mapstructure:"-"`
}

type DailySalt

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

func NewDailySalt

func NewDailySalt(pool PgxIface) *DailySalt

type EchoAPI

type EchoAPI struct {
	E *echo.Echo
	// contains filtered or unexported fields
}

func NewEchoAPI

func NewEchoAPI(config *Config, o11y *PicolyticsO11y) (EchoAPI, error)

func (*EchoAPI) HandleStatic

func (e *EchoAPI) HandleStatic(c echo.Context) error

func (EchoAPI) Shutdown

func (api EchoAPI) Shutdown(ctx context.Context) error

func (EchoAPI) Start

func (api EchoAPI) Start(address string, autotls bool) error

type EventDomains

type EventDomains map[string]int32

type EventSaver

type EventSaver interface {
	SaveEvent(event PicolyticsEvent)
}

type EventSessions

type EventSessions map[string]int64

type Metrics

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

type PgxIface

type PgxIface interface {
	Begin(context.Context) (pgx.Tx, error)
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
	Close()
}

type Picolytics

type Picolytics struct {

	// exported
	O11y *PicolyticsO11y
	// contains filtered or unexported fields
}

func New

func New(config *Config, logHandler slog.Handler, pool PgxIface) (Picolytics, error)

func (*Picolytics) HandleShutdown

func (p *Picolytics) HandleShutdown()

func (*Picolytics) Run

func (p *Picolytics) Run()

func (*Picolytics) Shutdown

func (p *Picolytics) Shutdown()

type PicolyticsEvent

type PicolyticsEvent struct {
	// populated by tracker javascript
	Name        string  `json:"n"`
	Location    string  `json:"l"`
	Referrer    string  `json:"r"`
	LoadTime    int32   `json:"lt"`
	TTFB        int32   `json:"fb"`
	ScreenW     int32   `json:"sw"`
	ScreenH     int32   `json:"sh"`
	PixelRatio  float64 `json:"pr"`
	PixelDepth  int32   `json:"pd"`
	Timezone    string  `json:"tz"`
	UtmSource   string  `json:"utm_source"`
	UtmMedium   string  `json:"utm_medium"`
	UtmCampaign string  `json:"utm_campaign"`
	UtmContent  string  `json:"utm_content"`
	UtmTerm     string  `json:"utm_term"`

	// populated by tracker handler
	Lang    string
	Created time.Time

	// populated by tracker handler - DO NOT store in DB
	ClientIpDONOTSTORE string
	UaDONOTSTORE       string

	// populated by parseEvent
	Domain, Path, VisitorID string

	// populated by updateUserAgentDetails
	Browser, BrowserVersion, Os, OsVersion, Platform, DeviceType string

	// populated by enrichEvent
	Longitude, Latitude        float64
	Country, Subdivision, City string
	Bot                        bool
}

type PicolyticsO11y

type PicolyticsO11y struct {
	Metrics *Metrics
	Logger  *slog.Logger
}

type PostgresAutocertCache

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

func NewPostgresCache

func NewPostgresCache(pool PgxIface) *PostgresAutocertCache

func (*PostgresAutocertCache) Delete

func (c *PostgresAutocertCache) Delete(ctx context.Context, key string) error

func (*PostgresAutocertCache) Get

func (c *PostgresAutocertCache) Get(ctx context.Context, key string) ([]byte, error)

func (*PostgresAutocertCache) Put

func (c *PostgresAutocertCache) Put(ctx context.Context, key string, data []byte) error

type Pruner

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

func NewPruner

func NewPruner(config *Config, pool PgxIface, o11y *PicolyticsO11y) (*Pruner, error)

type Salter

type Salter interface {
	// contains filtered or unexported methods
}

type Trackers

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

func NewTrackers

func NewTrackers(eventSaver EventSaver, bodyMaxSize int64) *Trackers

type UsingEmbeddedStaticFiles

type UsingEmbeddedStaticFiles bool

type Worker

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

func NewWorker

func NewWorker(config *Config, pool PgxIface, o11y *PicolyticsO11y) (*Worker, error)

func (*Worker) Shutdown

func (w *Worker) Shutdown()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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