-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TASK] Make yanic more modular #33
Conversation
d136516
to
627262b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Package state
unglücklich benannt. Vielleicht runtime
, oder anders nennen?
cmd/yanic/main.go
Outdated
if DEBUGDATABASE_BOOTSTRAP && config.Debug.Enable { | ||
db = debugdatabase.New(config) | ||
defer db.Close() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leerzeile entfernen
respond/collector.go
Outdated
coll.db.AddCounterMap(database.MeasurementModel, stats.Models) | ||
coll.db.AddGlobal(stats, time.Now()) | ||
coll.db.AddCounterMap(database.CounterMeasurementFirmware, stats.Firmwares) | ||
coll.db.AddCounterMap(database.CounterMeasurementModel, stats.Models) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gibt es nur Measurements bei InfluxDB? Dann sollten diese Konstanten hier verschwinden oder anders benannt werden.
→ Separation of Concerns
debugdatabase/file.go
Outdated
@@ -0,0 +1,49 @@ | |||
package debugdatabase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beschreibung für das Package fehlt. Was macht es und wofür ist es gut?
state/config.go
Outdated
} | ||
Debug struct { | ||
Enable bool | ||
File string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was macht eine Debug File
? →Dokumentation!
influxdb/node.go
Outdated
// ToInflux Returns tags and fields for InfluxDB | ||
func (node *Node) ToInflux() (tags imodels.Tags, fields imodels.Fields) { | ||
// NodeToInflux Returns tags and fields for InfluxDB | ||
func NodeToInflux(node *state.Node) (tags models.Tags, fields models.Fields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wird von keinem anderen Package verwendet → nicht exportieren.
@@ -1,8 +1,10 @@ | |||
package models | |||
package meshviewer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sinnvoll 👍
state/node.go
Outdated
type Flags struct { | ||
Online bool `json:"online"` | ||
Gateway bool `json:"gateway"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das flags
struct ist offensichtlich für den MeshViewer? Dann gehört es dahin!
Das Node
struct sollte dann Online
und Gateway
Felder bekommen, die anschließend für Mesh-Viewer kopiert werden.
→ Separation of Concerns
cmd/yanic/build.debug.go
Outdated
const ( | ||
INFLUXDB_BOOTSTRAP = true | ||
DEBUGDATABASE_BOOTSTRAP = true | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dokumentation fehlt 👎
cmd/yanic/build.default.go
Outdated
const ( | ||
INFLUXDB_BOOTSTRAP = true | ||
DEBUGDATABASE_BOOTSTRAP = false | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dokumentation fehlt 👎
a0d5ba9
to
27d5f43
Compare
73afb72
to
aed177f
Compare
runtime/config.go
Outdated
DeleteInterval Duration // Delete stats of nodes every n minutes | ||
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes | ||
Connection map[string]interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corny i do not like to use a map[string]
but toml only allow struct
or map[string]
have you a other idea?
I want a field in Database
which is abstract
und could implemented diffrent by every database type.
Like in https://github.com/FreifunkBremen/yanic/pull/33/files#diff-9eb190bdda93006411f7ae456063a52aR16 (for exampledatabase) and https://github.com/FreifunkBremen/yanic/pull/33/files#diff-d2461a240b36089e7a2f4b124b4b96c9 (for influxdb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just put the database type in the key:
[database.influx]
# ...
[database.logging]
# ...
cmd/yanic/main.go
Outdated
if config.Database.Enable { | ||
db = connectDB(config) | ||
} | ||
defer database.Close(db) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db
can be nil
database/exampledatabase/file.go
Outdated
@@ -0,0 +1,55 @@ | |||
package exampledatabase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about calling it logging
?
config_example.toml
Outdated
address = "http://localhost:8086" | ||
database = "ffhb" | ||
username = "" | ||
password = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which kind of database is database
? How do you select the database kind?
Add a type
or adapter
.
runtime/config.go
Outdated
DeleteInterval Duration // Delete stats of nodes every n minutes | ||
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes | ||
Connection map[string]interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just put the database type in the key:
[database.influx]
# ...
[database.logging]
# ...
Flags: Flags{ | ||
Online: nodeOrigin.Online, | ||
Gateway: nodeOrigin.Gateway, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
respond/collector.go
Outdated
) | ||
|
||
// Collector for a specificle respond messages | ||
type Collector struct { | ||
connection *net.UDPConn // UDP socket | ||
queue chan *Response // received responses | ||
iface string | ||
db *database.DB | ||
nodes *models.Nodes | ||
db database.DB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should support multiple databases at the same time: db []database.DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we? lets talk tomorrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have no added a database called multi
29bb856
to
dbf6a00
Compare
702baf3
to
c22281e
Compare
c22281e
to
12ea186
Compare
database/multi/main.go
Outdated
} | ||
if config.Database.Logging.Enable { | ||
dbs = append(dbs, logging.New(config)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Die datenbank-Packages sollen sich selbst registrieren. Beispiel:
https://github.com/influxdata/telegraf/blob/v0.10.1/plugins/outputs/influxdb/influxdb.go#L158
database/all/internal.go
Outdated
return &DB{config: config, dbs: dbs} | ||
} | ||
func (this *DB) AddNode(nodeID string, node *runtime.Node) { | ||
for _, db := range this.dbs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mein Linter sagt:
receiver name should be a reflection of its identity; don't use generic names such as "this" or "self"
runtime/config.go
Outdated
type ConfigDatabaseLogging struct { | ||
Enable bool | ||
Path string | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separation of concerns ... das gehört in die Packages der Datenbank-Adapter.
database/database.go
Outdated
timer.Stop() | ||
db.wg.Done() | ||
func AddConnection(n New) { | ||
DBConnections = append(DBConnections, n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das sind nicht die DB-Connections, sondern Adapter, die eine DB-Connection erstellen können.
Die Adapter benutzen diese Funktion, um sich zu registrieren.
database/database.go
Outdated
} | ||
} | ||
// DB interface to use for implementation in e.g. influxdb | ||
type DB interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besser: Adapter
database/influxdb/database.go
Outdated
} | ||
|
||
func init() { | ||
database.AddConnection(func(config *runtime.Config) database.DB { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Übergib kein runtime.Config
- der Adapter interessiert sich nur für seine Verbindungsdaten.
Zurückgegeben wird eine eine Instanz des Adapters - also eine Session
oder Verbindung (Connection
) und keine Datenbank (DB
).
a0cc4da
to
57bc520
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Travis-Build schlägt fehlt.
Ja da er noch nicht richtig dei Config einliest: Hast du eine besser idee, wollte mich noch ein bisschen in reflection einlesen ... find die aktuelle angefange implentation für die Config schrecklich |
Darfst gern weitermachen, komme vor montag nicht dazu |
database/logging/file.go
Outdated
database.AddConnect("logging", Connect) | ||
} | ||
|
||
func Connect(configuration interface{}) database.Connection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't ignore errors - return them.
database/database.go
Outdated
// write batch now? | ||
if bp != nil && (writeNow || closed || len(bp.Points()) >= batchMaxSize) { | ||
log.Println("saving", len(bp.Points()), "points") | ||
var Connects = map[string]Connect{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Connects
or Connections
?
I think you mean adapters
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is DatabaseTypes
also okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename it to Adapters
. Does it have to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its needed here: https://github.com/FreifunkBremen/yanic/blob/cleanup-package/database/all/internal.go#L19 - We need a export ...
Add both labels, because .... - This PR is in main develop, and had to switch so often the labels |
82bd068
to
823cae2
Compare
Soll ich schon mal vor squashen? |
database/influxdb/database.go
Outdated
if !config.Enable() { | ||
return nil, errors.New("connection disabled") | ||
} | ||
log.Println("init database: influxdb") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this line to the caller function
database/logging/file.go
Outdated
if !config.Enable() { | ||
return nil, errors.New("connection disabled") | ||
} | ||
log.Println("init database: logging") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this line to the caller function
database/logging/file.go
Outdated
log.Println("init database: logging") | ||
file, err := os.OpenFile(config.Path(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) | ||
if err != nil { | ||
log.Println("File could not opened: ", config.Path()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print errors in the caller function
database/all/internal.go
Outdated
list []database.Connection | ||
} | ||
|
||
func Connect(configuration interface{}) database.Connection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should do something helpful if an unknown adapter is configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?? Stehe auf den schlauch ... was meinst du damit? Connect
soll mit database.Connect equivalent bleiben.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was passiert, wenn man einen unbekannten Adapter und die Konfiguration schreibt und welches Verhalten wünscht man sich als sysadmin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crash
database/all/internal.go
Outdated
return &Connection{list: list} | ||
if len(list) <= 0 { | ||
return nil, errors.New("it was not possible to create any database connection") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ich finde Yanik soll auch ohne Datenbank funktionieren.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jep tut es auch, wenn man es ausschaltet -> f0a6195#diff-690f51ef4035e92812f351daa99158fbR45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
egal, wurde dort ausgenommen
@corny wie schaut es aus? |
04fc994
to
efa2d33
Compare
runtime/config.go
Outdated
Enable bool `toml:"enable"` | ||
DeleteInterval Duration `toml:"delete_interval"` // Delete stats of nodes every n minutes | ||
DeleteAfter Duration `toml:"delete_after"` // Delete stats of nodes till now-deletetill n minutes | ||
Connection map[string][]interface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Das Enable
soll zu einer Datenbankverbindung gehören.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Zeile 35, nein global.
Bei uns/influxdb gibt es noch einmal ein enable (unter Connection)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keine Gute Idee?
config_example.toml
Outdated
# cleaning data of measurement node, | ||
# which are older than 7d | ||
delete_after = "7d" | ||
# how often run the cleaning | ||
delete_interval = "1h" | ||
|
||
[[database.connection.influxdb]] | ||
enable = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Einmal ob generell in datenbanken gespeichert werden soll in Zeile 58
und hier wiederum, ob diese Datenbank benutzt werden soll.
cmd/yanic/main.go
Outdated
} | ||
database.Start(db, config) | ||
defer database.Close(db) | ||
db, err = all.Connect(config.Database.Connection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sind das mehrere Datenbanken? connections
wäre ein besserer Namen für eine Liste von Verbindungen.
b4570a3
to
fed58a4
Compare
fed58a4
to
7da3b13
Compare
restructure of yanic to make it more modular.
On this way other timeserial-databases by other community are possible.