Skip to content
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

Merged
merged 1 commit into from
Apr 10, 2017
Merged

[TASK] Make yanic more modular #33

merged 1 commit into from
Apr 10, 2017

Conversation

genofire
Copy link
Member

@genofire genofire commented Mar 7, 2017

restructure of yanic to make it more modular.

On this way other timeserial-databases by other community are possible.

@genofire genofire force-pushed the cleanup-package branch 6 times, most recently from d136516 to 627262b Compare March 7, 2017 20:52
@genofire genofire requested a review from corny March 7, 2017 20:58
Copy link
Member

@corny corny left a 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?

if DEBUGDATABASE_BOOTSTRAP && config.Debug.Enable {
db = debugdatabase.New(config)
defer db.Close()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leerzeile entfernen

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)
Copy link
Member

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

@@ -0,0 +1,49 @@
package debugdatabase
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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"`
}
Copy link
Member

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

const (
INFLUXDB_BOOTSTRAP = true
DEBUGDATABASE_BOOTSTRAP = true
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dokumentation fehlt 👎

const (
INFLUXDB_BOOTSTRAP = true
DEBUGDATABASE_BOOTSTRAP = false
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dokumentation fehlt 👎

@genofire genofire force-pushed the cleanup-package branch 2 times, most recently from a0d5ba9 to 27d5f43 Compare March 13, 2017 17:39
@genofire genofire added review and removed wip labels Mar 14, 2017
@genofire genofire force-pushed the cleanup-package branch 2 times, most recently from 73afb72 to aed177f Compare March 15, 2017 22:37
DeleteInterval Duration // Delete stats of nodes every n minutes
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
Connection map[string]interface{}
Copy link
Member Author

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)

Copy link
Member

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]
# ...

@genofire genofire changed the title Make yanic more modular [TASK] Make yanic more modular Mar 16, 2017
if config.Database.Enable {
db = connectDB(config)
}
defer database.Close(db)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db can be nil

@@ -0,0 +1,55 @@
package exampledatabase
Copy link
Member

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 ?

address = "http://localhost:8086"
database = "ffhb"
username = ""
password = ""
Copy link
Member

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.

DeleteInterval Duration // Delete stats of nodes every n minutes
DeleteAfter Duration // Delete stats of nodes till now-deletetill n minutes
Connection map[string]interface{}
Copy link
Member

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,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

)

// 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
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

@genofire genofire Mar 18, 2017

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

}
if config.Database.Logging.Enable {
dbs = append(dbs, logging.New(config))
}
Copy link
Member

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

@genofire genofire added review and removed wip labels Mar 29, 2017
return &DB{config: config, dbs: dbs}
}
func (this *DB) AddNode(nodeID string, node *runtime.Node) {
for _, db := range this.dbs {
Copy link
Member

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"

type ConfigDatabaseLogging struct {
Enable bool
Path string
}
Copy link
Member

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.

timer.Stop()
db.wg.Done()
func AddConnection(n New) {
DBConnections = append(DBConnections, n)
Copy link
Member

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.

}
}
// DB interface to use for implementation in e.g. influxdb
type DB interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besser: Adapter

}

func init() {
database.AddConnection(func(config *runtime.Config) database.DB {
Copy link
Member

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).

Copy link
Member

@corny corny left a 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.

@genofire
Copy link
Member Author

genofire commented Apr 1, 2017

Ja da er noch nicht richtig dei Config einliest:
überleg ein toml fork auf zu machen, toml:"-" funktioniert nicht richtig und hidden entries im struct werden dennoch versucht zu befüllen.
Für die angefangene implementation bräuchte ich viele hidden Funktion aus den toml package.

Hast du eine besser idee, wollte mich noch ein bisschen in reflection einlesen ... find die aktuelle angefange implentation für die Config schrecklich

@genofire
Copy link
Member Author

genofire commented Apr 1, 2017

Darfst gern weitermachen, komme vor montag nicht dazu

database.AddConnect("logging", Connect)
}

func Connect(configuration interface{}) database.Connection {
Copy link
Member

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.

// write batch now?
if bp != nil && (writeNow || closed || len(bp.Points()) >= batchMaxSize) {
log.Println("saving", len(bp.Points()), "points")
var Connects = map[string]Connect{}
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is DatabaseTypes also okay?

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@genofire genofire added the wip label Apr 2, 2017
@genofire
Copy link
Member Author

genofire commented Apr 2, 2017

Add both labels, because .... - This PR is in main develop, and had to switch so often the labels

@genofire
Copy link
Member Author

genofire commented Apr 4, 2017

Soll ich schon mal vor squashen?

if !config.Enable() {
return nil, errors.New("connection disabled")
}
log.Println("init database: influxdb")
Copy link
Member

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

if !config.Enable() {
return nil, errors.New("connection disabled")
}
log.Println("init database: logging")
Copy link
Member

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

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())
Copy link
Member

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

list []database.Connection
}

func Connect(configuration interface{}) database.Connection {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crash

return &Connection{list: list}
if len(list) <= 0 {
return nil, errors.New("it was not possible to create any database connection")
}
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

egal, wurde dort ausgenommen

@genofire
Copy link
Member Author

genofire commented Apr 7, 2017

@corny wie schaut es aus?

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{}
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keine Gute Idee?

# 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
Copy link
Member Author

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.

}
database.Start(db, config)
defer database.Close(db)
db, err = all.Connect(config.Database.Connection)
Copy link
Member

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.

@genofire genofire force-pushed the cleanup-package branch 2 times, most recently from b4570a3 to fed58a4 Compare April 10, 2017 16:39
@genofire genofire merged commit f135249 into master Apr 10, 2017
@genofire genofire deleted the cleanup-package branch April 10, 2017 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants