db

package
v0.0.0-...-0b31ed0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DAY_LAYOUT       = "2006-01-02"
	TABLE_DAILY_SUMS = "daily_app_sums"
)

TODO: db package needs some form of unit testing

Variables

This section is empty.

Functions

This section is empty.

Types

type InfluxDBOptions

type InfluxDBOptions struct {
	URL   string
	Token string
	Org   string
	// Bucket to query for previous days counts
	DailyBucket string
	// Bucket to query for today's counts
	CurrentBucket string
}

type PostgresClient

type PostgresClient interface {
	Reporter
	Writer
}

func NewPostgresClient

func NewPostgresClient(options PostgresOptions) (PostgresClient, error)

type PostgresOptions

type PostgresOptions struct {
	Host     string
	User     string
	Password string
	DB       string
}

type Reporter

type Reporter interface {
	// DailyUsage returns saved daily metrics for the specified time period, with each day being an entry in the results map
	DailyUsage(from, to time.Time) (map[time.Time]map[string]api.RelayCounts, error)
	// TodaysUsage returns the metrics for today so far
	TodaysUsage() (map[string]api.RelayCounts, error)
}

Will be implemented by Postgres DB interface

type Source

type Source interface {
	AppRelays(from, to time.Time) (map[string]api.RelayCounts, error)
	DailyCounts(from, to time.Time) (map[time.Time]map[string]api.RelayCounts, error)
	// Returns application metrics for today so far
	TodaysCounts() (map[string]api.RelayCounts, error)
}

func NewInfluxDBSource

func NewInfluxDBSource(options InfluxDBOptions) Source

type Writer

type Writer interface {
	// TODO: rollover of entries
	WriteDailyUsage(counts map[time.Time]map[string]api.RelayCounts) error
	// WriteTodaysUsage writes todays relay counts to the underlying storage.
	WriteTodaysUsage(counts map[string]api.RelayCounts) error
	// Returns oldest and most recent timestamps for stored metrics
	ExistingMetricsTimespan() (time.Time, time.Time, error)
}

Will be implemented by Postgres DB interface

Jump to

Keyboard shortcuts

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