Rename methods and add comments
This commit is contained in:
parent
81368deb78
commit
dbaa19d13a
@ -42,9 +42,9 @@ func (conn *Connection) AddStatistics(stats *runtime.GlobalStats, time time.Time
|
||||
}
|
||||
}
|
||||
|
||||
func (conn *Connection) DeleteNode(deleteAfter time.Duration) {
|
||||
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
||||
for _, item := range conn.list {
|
||||
item.DeleteNode(deleteAfter)
|
||||
item.PruneNodes(deleteAfter)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,24 +8,25 @@ import (
|
||||
|
||||
// Connection interface to use for implementation in e.g. influxdb
|
||||
type Connection interface {
|
||||
// AddNode data for a single node
|
||||
// AddNode stores data of a single node
|
||||
AddNode(nodeID string, node *runtime.Node)
|
||||
|
||||
// AddStatistics stores global statistics
|
||||
AddStatistics(stats *runtime.GlobalStats, time time.Time)
|
||||
|
||||
DeleteNode(deleteAfter time.Duration)
|
||||
// PruneNodes prunes historical per-node data
|
||||
PruneNodes(deleteAfter time.Duration)
|
||||
|
||||
// Close closes the database connection
|
||||
Close()
|
||||
}
|
||||
|
||||
// Connect function with config to get DB connection interface
|
||||
type Connect func(config interface{}) (Connection, error)
|
||||
|
||||
/*
|
||||
* for selfbinding in use of the package all
|
||||
*/
|
||||
|
||||
// Adapters is the list of registered database adapters
|
||||
var Adapters = map[string]Connect{}
|
||||
|
||||
func AddDatabaseType(name string, n Connect) {
|
||||
func RegisterAdapter(name string, n Connect) {
|
||||
Adapters[name] = n
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (c Config) Password() string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AddDatabaseType("influxdb", Connect)
|
||||
database.RegisterAdapter("influxdb", Connect)
|
||||
}
|
||||
func Connect(configuration interface{}) (database.Connection, error) {
|
||||
var config Config
|
||||
@ -80,7 +80,7 @@ func Connect(configuration interface{}) (database.Connection, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
func (conn *Connection) DeleteNode(deleteAfter time.Duration) {
|
||||
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
||||
query := fmt.Sprintf("delete from %s where time < now() - %ds", MeasurementNode, deleteAfter/time.Second)
|
||||
conn.client.Query(client.NewQuery(query, conn.config.Database(), "m"))
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func deleteWorker(conn Connection, deleteInterval time.Duration, deleteAfter tim
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
conn.DeleteNode(deleteAfter)
|
||||
conn.PruneNodes(deleteAfter)
|
||||
case <-quit:
|
||||
ticker.Stop()
|
||||
return
|
||||
|
@ -31,7 +31,7 @@ func (c Config) Path() string {
|
||||
}
|
||||
|
||||
func init() {
|
||||
database.AddDatabaseType("logging", Connect)
|
||||
database.RegisterAdapter("logging", Connect)
|
||||
}
|
||||
|
||||
func Connect(configuration interface{}) (database.Connection, error) {
|
||||
@ -56,8 +56,8 @@ func (conn *Connection) AddStatistics(stats *runtime.GlobalStats, time time.Time
|
||||
conn.log("AddStatistics: [", time.String(), "] nodes: ", stats.Nodes, ", clients: ", stats.Clients, " models: ", len(stats.Models))
|
||||
}
|
||||
|
||||
func (conn *Connection) DeleteNode(deleteAfter time.Duration) {
|
||||
conn.log("DeleteNode")
|
||||
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
|
||||
conn.log("PruneNodes")
|
||||
}
|
||||
|
||||
func (conn *Connection) Close() {
|
||||
|
Loading…
Reference in New Issue
Block a user