Documentation
¶
Index ¶
- Constants
- func MarshalEvent(event int) string
- func Metrics() []xmetrics.Metric
- func UnmarshalEvent(event string) int
- type Config
- type Connection
- func (db *Connection) Close() error
- func (db *Connection) GetRecords(deviceID string) ([]Record, error)
- func (db *Connection) GetRecordsOfType(deviceID string, eventType int) ([]Record, error)
- func (db *Connection) InsertRecord(record Record) error
- func (db *Connection) Ping() error
- func (db *Connection) PruneRecords(t time.Time) error
- func (db *Connection) RemoveAll() error
- type Event
- type Inserter
- type Measures
- type Pruner
- type Record
- type RecordGetter
- type RetryInsertService
- type RetryRGService
- type RetryUpdateService
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" )
Variables ¶
This section is empty.
Functions ¶
func MarshalEvent ¶ added in v0.2.0
func UnmarshalEvent ¶ added in v0.2.0
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) InsertRecord ¶ added in v0.2.0
func (db *Connection) InsertRecord(record 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 time.Time) 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"` // payload // // 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 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 }
func NewMeasures ¶ added in v0.2.0
type Record ¶ added in v0.2.0
type Record struct { ID int `json:"id" gorm:"AUTO_INCREMENT"` Type int `json:"type" gorm:"index"` DeviceID string `json:"deviceid" gorm:"not null;index"` BirthDate time.Time `json:"birthdate" gorm:"index"` DeathDate time.Time `json:"deathdate" gorm:"index"` Data []byte `json:"data" gorm:"not null"` }
type RecordGetter ¶ added in v0.2.0
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) RetryInsertService
func (RetryInsertService) InsertRecord ¶ added in v0.2.0
func (ri RetryInsertService) InsertRecord(record 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) 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) RetryUpdateService
func (RetryUpdateService) PruneRecords ¶ added in v0.2.0
func (ru RetryUpdateService) PruneRecords(t time.Time) error
Click to show internal directories.
Click to hide internal directories.