db

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// default event type
	EventDefault = iota

	// event type for online and offline events
	EventState
)
View Source
const (
	RetryCounter                = "retry_count"
	ConnectionStatusGauge       = "connection_status"
	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"
	SQLQueryRetryCounter        = "sql_query_retry_count"
	SQLDeletedRowsCounter       = "sql_deleted_rows_count"
)

Variables

This section is empty.

Functions

func MarshalEvent added in v0.2.0

func MarshalEvent(event int) string

func Metrics added in v0.2.0

func Metrics() []xmetrics.Metric

Metrics returns the Metrics relevant to this package

func UnmarshalEvent added in v0.2.0

func UnmarshalEvent(event string) int

Types

type Config added in v0.2.0

type Config struct {
	Server         string
	Username       string
	Database       string
	SSLRootCert    string
	SSLKey         string
	SSLCert        string
	NumRetries     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 db connection.

type Connection added in v0.1.1

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

Connection contains the tools to edit the database.

func CreateDbConnection added in v0.2.0

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

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

func (*Connection) Close added in v0.2.0

func (db *Connection) Close() error

func (*Connection) GetRecords added in v0.2.0

func (db *Connection) GetRecords(deviceID string) ([]Record, error)

GetRecords returns a list of records for a given device

func (*Connection) GetRecordsOfType added in v0.2.0

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

GetRecords returns a list of records for a given device

func (*Connection) InsertRecords added in v0.2.1

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

InsertEvent adds a record to the table.

func (*Connection) Ping added in v0.2.0

func (db *Connection) Ping() error

func (*Connection) PruneRecords added in v0.2.0

func (db *Connection) PruneRecords(t int64) error

PruneRecords removes records past their deathdate.

func (*Connection) RemoveAll added in v0.1.1

func (db *Connection) RemoveAll() error

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

type Event

type Event struct {
	// The id for the event.
	//
	// required: true
	// example: 425808997514969090
	ID int `json:"id"`

	// The time this event was found.
	//
	// required: true
	// example: 1549969802
	Time int64 `json:"time"`

	// The source of this event.
	//
	// required: true
	// example: dns:talaria-1234
	Source string `json:"src"`

	// The destination of this event.
	//
	// required: true
	// example: device-status/5/offline
	Destination string `json:"dest"`

	// The partners related to this device.
	//
	// required: true
	// example: ["hello","world"]
	PartnerIDs []string `json:"partner_ids"`

	// The transaction id for this event.
	//
	// required: true
	// example: AgICJpZCI6ICJtYWM6NDhmN2MwZDc5MDI0Iiw
	TransactionUUID string `json:"transaction_uuid,omitempty"`

	// list of bytes received from the source.
	// If the device destination matches "device-status/.*", this is a base64
	// encoded json map that contains the key "ts", denoting the time the event
	// was created.
	//
	// required: false
	// example: eyJpZCI6IjUiLCJ0cyI6IjIwMTktMDItMTJUMTE6MTA6MDIuNjE0MTkxNzM1WiIsImJ5dGVzLXNlbnQiOjAsIm1lc3NhZ2VzLXNlbnQiOjEsImJ5dGVzLXJlY2VpdmVkIjowLCJtZXNzYWdlcy1yZWNlaXZlZCI6MH0=
	Payload []byte `json:"payload,omitempty"`

	// Other metadata and details related to this state.
	//
	// required: true
	// example: {"/boot-time":1542834188,"/last-reconnect-reason":"spanish inquisition"}
	Details map[string]interface{} `json:"details"`
}

Event represents the event information in the database. It has no TTL.

swagger:model Event

type Inserter added in v0.2.0

type Inserter interface {
	InsertRecords(records ...Record) error
}

type Measures added in v0.2.0

type Measures struct {
	Retry                xmetrics.Incrementer
	ConnectionStatus     metrics.Gauge
	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
	SQLQueryRetryCount   metrics.Counter
	SQLDeletedRows       metrics.Counter
}

func NewMeasures added in v0.2.0

func NewMeasures(p provider.Provider) Measures

type Pruner added in v0.2.0

type Pruner interface {
	PruneRecords(t int64) error
}

type Record added in v0.2.0

type Record struct {
	ID        int    `json:"id" gorm:"AUTO_INCREMENT"`
	Type      int    `json:"type"`
	DeviceID  string `json:"deviceid" gorm:"not null;index"`
	BirthDate int64  `json:"birthdate" gorm:"not null;index"`
	DeathDate int64  `json:"deathdate" gorm:"not null;index"`
	Data      []byte `json:"data" gorm:"not null"`
}

func (Record) TableName added in v0.2.0

func (Record) TableName() string

set Record's table name to be `events`

type RecordGetter added in v0.2.0

type RecordGetter interface {
	GetRecords(deviceID string) ([]Record, error)
	GetRecordsOfType(deviceID string, eventType int) ([]Record, error)
}

type RetryInsertService added in v0.2.0

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

func CreateRetryInsertService added in v0.2.0

func CreateRetryInsertService(inserter Inserter, retries int, interval time.Duration, provider provider.Provider) RetryInsertService

func (RetryInsertService) InsertRecords added in v0.2.1

func (ri RetryInsertService) InsertRecords(records ...Record) error

type RetryRGService added in v0.2.0

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

func CreateRetryRGService added in v0.2.0

func CreateRetryRGService(recordGetter RecordGetter, retries int, interval time.Duration, provider provider.Provider) RetryRGService

func (RetryRGService) GetRecords added in v0.2.0

func (rtg RetryRGService) GetRecords(deviceID string) ([]Record, error)

func (RetryRGService) GetRecordsOfType added in v0.2.0

func (rtg RetryRGService) GetRecordsOfType(deviceID string, eventType int) ([]Record, error)

type RetryUpdateService added in v0.2.0

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

func CreateRetryUpdateService added in v0.2.0

func CreateRetryUpdateService(pruner Pruner, retries int, interval time.Duration, provider provider.Provider) RetryUpdateService

func (RetryUpdateService) PruneRecords added in v0.2.0

func (ru RetryUpdateService) PruneRecords(t int64) error

Jump to

Keyboard shortcuts

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