Version: v0.10.0 Latest Latest

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 16 Imported by: 0



package postgresql provides a way to connect to a postgresql database to keep track of device events.



View Source
const (
	RetryCounter                = "retry_count"
	PoolOpenConnectionsGauge    = "pool_open_connections"
	PoolInUseConnectionsGauge   = "pool_in_use_connections"
	PoolIdleConnectionsGauge    = "pool_idle_connections"
	SQLWaitCounter              = "sql_wait_count"
	SQLWaitDurationCounter      = "sql_wait_duration_seconds"
	SQLMaxIdleClosedCounter     = "sql_max_idle_closed"
	SQLMaxLifetimeClosedCounter = "sql_max_lifetime_closed"
	SQLQuerySuccessCounter      = "sql_query_success_count"
	SQLQueryFailureCounter      = "sql_query_failure_count"
	SQLInsertedRecordsCounter   = "sql_inserted_rows_count"
	SQLReadRecordsCounter       = "sql_read_rows_count"
	SQLDeletedRecordsCounter    = "sql_deleted_rows_count"


This section is empty.


func Metrics

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package


type Config

type Config struct {
	Server         string
	Username       string
	Database       string
	SSLRootCert    string
	SSLKey         string
	SSLCert        string
	NumRetries     int
	PruneLimit     int
	WaitTimeMult   time.Duration
	ConnectTimeout time.Duration
	OpTimeout      time.Duration

	// MaxIdleConns sets the max idle connections, the min value is 2
	MaxIdleConns int

	// MaxOpenConns sets the max open connections, to specify unlimited set to 0
	MaxOpenConns int

	PingInterval time.Duration

Config contains the initial configuration information needed to create a postgresql db connection.

type Connection

type Connection struct {
	// contains filtered or unexported fields

Connection manages the connection to the postgresql database, and maintains a health check on the database connection.

func CreateDbConnection

func CreateDbConnection(config Config, provider provider.Provider, health *health.Health) (*Connection, error)

CreateDbConnection creates db connection and returns the struct to the consumer.

func (*Connection) Close

func (c *Connection) Close() error

Close closes the database connection.

func (*Connection) DeleteRecord added in v0.8.0

func (c *Connection) DeleteRecord(shard int, deathDate int64, recordID int64) error

DeleteRecord removes a record.

func (*Connection) GetBlacklist

func (c *Connection) GetBlacklist() (list []blacklist.BlackListedItem, err error)

GetBlacklist returns a list of blacklisted devices.

func (*Connection) GetDeviceList added in v0.8.0

func (c *Connection) GetDeviceList(offset string, limit int) ([]string, error)

GetDeviceList returns a list of device ids where the device id is greater than the offset device id.

func (*Connection) GetRecords

func (c *Connection) GetRecords(deviceID string, limit int) ([]db.Record, error)

GetRecords returns a list of records for a given device.

func (*Connection) GetRecordsOfType

func (c *Connection) GetRecordsOfType(deviceID string, limit int, eventType db.EventType) ([]db.Record, error)

GetRecords returns a list of records for a given device and event type.

func (*Connection) GetRecordsToDelete added in v0.8.0

func (c *Connection) GetRecordsToDelete(shard int, limit int, deathDate int64) ([]db.RecordToDelete, error)

GetRecordsToDelete returns a list of record ids and deathdates not past a given date.

func (*Connection) InsertRecords

func (c *Connection) InsertRecords(records ...db.Record) error

InsertEvent adds a list of records to the table.

func (*Connection) Ping

func (c *Connection) Ping() error

Ping is for pinging the database to verify that the connection is still good.

func (*Connection) RemoveAll

func (c *Connection) RemoveAll() error

RemoveAll removes everything in the events table. Used for testing.

type Measures

type Measures struct {
	Retry                xmetrics.Incrementer
	PoolOpenConnections  metrics.Gauge
	PoolInUseConnections metrics.Gauge
	PoolIdleConnections  metrics.Gauge

	SQLWaitCount         metrics.Counter
	SQLWaitDuration      metrics.Counter
	SQLMaxIdleClosed     metrics.Counter
	SQLMaxLifetimeClosed metrics.Counter
	SQLQuerySuccessCount metrics.Counter
	SQLQueryFailureCount metrics.Counter
	SQLInsertedRecords   metrics.Counter
	SQLReadRecords       metrics.Counter
	SQLDeletedRecords    metrics.Counter

func NewMeasures

func NewMeasures(p provider.Provider) Measures

Jump to

Keyboard shortcuts

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