Go API Documentation

github.com/titpetric/microservice/server/stats

No package summary is available.

Package

Files: 7. Third party imports: 3. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

Vars

IncomingFields are all the field names in the DB table

IncomingPrimaryFields are the primary key fields in the DB table

IncomingProcFields are all the field names in the DB table

IncomingProcPrimaryFields are the primary key fields in the DB table

MigrationsFields are all the field names in the DB table

MigrationsPrimaryFields are the primary key fields in the DB table

Keep returning a single object to avoid allocations

Types

Flusher

Flusher is a context-driven background data flush job

Field name Field type Comment

context.Context

No comment on field.
finish

func()

No comment on field.
enabled

*atomic.Bool

No comment on field.
queueIndex

*atomic.Uint32

queueIndex is a key for []queues

queueMask

uint32

queueMask is a masking value for queueIndex -> key

queues

[]*Queue

queues hold a set of writable queues

db

*sqlx.DB

No comment on field.

Incoming

Incoming generated for db table incoming

Incoming stats log, writes only

Field name Field type Comment
ID

uint64

Tracking ID

Property

string

Property name (human readable, a-z)

PropertySection

uint32

Property Section ID

PropertyID

uint32

Property Item ID

RemoteIP

string

Remote IP from user making request

Stamp

*time.Time

Timestamp of request

IncomingProc

IncomingProc generated for db table incoming_proc

Incoming stats log, writes only

Field name Field type Comment
ID

uint64

Tracking ID

Property

string

Property name (human readable, a-z)

PropertySection

uint32

Property Section ID

PropertyID

uint32

Property Item ID

RemoteIP

string

Remote IP from user making request

Stamp

*time.Time

Timestamp of request

Migrations

Migrations generated for db table migrations

Field name Field type Comment
Project

string

Microservice or project name

Filename

string

yyyy-mm-dd-HHMMSS.sql

StatementIndex

int32

Statement number from SQL file

Status

string

ok or full error message

Queue

Queue provides a queuing structure for Incoming{}

Field name Field type Comment

sync.RWMutex

No comment on field.
values

[]*Incoming

No comment on field.

Server

Server implements stats.StatsService

Field name Field type Comment
db

*sqlx.DB

No comment on field.
sonyflake

*sonyflake.Sonyflake

No comment on field.
flusher

*Flusher

No comment on field.

Functions

func New

Uses: db.Connect, inject.Sonyflake.

func NewFlusher

NewFlusher creates a *Flusher

Uses: atomic.NewBool, atomic.NewUint32, context.Background, context.WithCancel.

func NewQueue

NewQueue creates a new *Queue instance

func NewQueues

NewQueues creates a slice of *Queue instances

func (*Flusher) Push

Push spreads queue writes evenly across all queues

func (*Incoming) SetStamp

SetStamp sets Stamp which requires a *time.Time

func (*IncomingProc) SetStamp

SetStamp sets Stamp which requires a *time.Time

func (*Queue) Clear

Clear returns current queue items and clears it

func (*Queue) Length

Length returns the current queue size

func (*Queue) Push

Push adds a new item to the queue

func (*Server) Push

Push a record to the incoming log table

Uses: errors.New, time.Now.

func (*Server) Shutdown

Shutdown is a cleanup hook after SIGTERM

Private functions

func flush

References: fmt.Sprintf, log.Println, strings.Join.

func run

References: log.Println, time.NewTicker, time.Second.


Tests

Files: 1. Third party imports: 0. Imports from organisation: 0. Tests: 1. Benchmarks: 0.

Test functions

TestQueue