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

rename symbols and logging changes for readabillity and monitoring #4

Merged
merged 6 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/datamanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (dm *DataManager) ReadLastTimestamp(namespace string) (time.Time, error) {
"operation": operation,
"namespace": namespace,
"Timestamp": ns.Timestamp,
}).Info("ReadLastTimestamps successfully")
}).Debug("ReadLastTimestamps successfully")

return ns.Timestamp, nil //returning copy
}
Expand All @@ -173,7 +173,7 @@ func (dm *DataManager) ReadLeader(namespace string) (LeaderController, error) {
"operation": operation,
"namespace": namespace,
"leader": ns.Leader,
}).Info("ReadLeader successfully")
}).Debug("ReadLeader successfully")

return ns.Leader, nil //returning copy
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func (dm *DataManager) UpdateLeader(namespace string, leader LeaderController) e
"namespace": namespace,
"leader": ns.Leader,
"time": ns.Timestamp,
}).Info("UpdateLeader data finished successfully")
}).Debug("UpdateLeader data finished successfully")
return nil
}

Expand All @@ -229,7 +229,7 @@ func (dm *DataManager) ReadApps(namespace string) (map[string]App, error) {
"operation": operation,
"namespace": namespace,
"apps": ns.Apps,
}).Info("ReadApp successfully")
}).Debug("ReadApp successfully")

return ns.Apps, nil //returning copy
}
Expand Down Expand Up @@ -259,7 +259,7 @@ func (dm *DataManager) UpdateApps(namespace string, apps map[string]App) error {
"namespace": namespace,
"apps": dm.namespaces[namespace].Apps,
"time": dm.namespaces[namespace].Timestamp,
}).Info("UpdateApps finished successfully")
}).Debug("UpdateApps finished successfully")
return nil
}

Expand All @@ -285,7 +285,7 @@ func (dm *DataManager) ReadKnownVhosts(namespace string) (Vhosts, error) {
"operation": operation,
"namespace": namespace,
"knownVHosts": ns.KnownVHosts,
}).Info("ReadKnownVhosts successfully")
}).Debug("ReadKnownVhosts successfully")

return ns.KnownVHosts, nil //returning copy
}
Expand All @@ -308,7 +308,7 @@ func (dm *DataManager) ReadAllKnownVhosts() Vhosts {
logger.WithFields(logrus.Fields{
"operation": operation,
"allApps": allKnownVhosts,
}).Info("ReadAllKnownVhosts successfully")
}).Debug("ReadAllKnownVhosts successfully")

return allKnownVhosts //returning copy
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (dm *DataManager) UpdateKnownVhosts(namespace string, KnownVHosts Vhosts) e
"namespace": namespace,
"knownHosts": dm.namespaces[namespace].KnownVHosts,
"time": dm.namespaces[namespace].Timestamp,
}).Info("UpdateKnownVhosts finished successfully")
}).Debug("UpdateKnownVhosts finished successfully")
return nil
}

Expand All @@ -351,7 +351,7 @@ func (dm *DataManager) ReadLastReloadTimestamp() time.Time {
logger.WithFields(logrus.Fields{
"operation": operation,
"LastReloadTimestamp": dm.LastReloadTimestamp,
}).Info("ReadLoadedTime successfully")
}).Debug("ReadLoadedTime successfully")

return dm.LastReloadTimestamp //returning copy
}
Expand All @@ -365,7 +365,7 @@ func (dm *DataManager) ReadLastKnownVhosts() Vhosts {
logger.WithFields(logrus.Fields{
"operation": operation,
"LastKnownVhosts": dm.LastKnownVhosts,
}).Info("LastKnownVhosts successfully")
}).Debug("LastKnownVhosts successfully")

return dm.LastKnownVhosts //returning copy
}
Expand All @@ -381,7 +381,7 @@ func (dm *DataManager) UpdateLastKnownVhosts(inLastKnownVhosts Vhosts) error {
logger.WithFields(logrus.Fields{
"operation": operation,
"LastKnownVhosts": dm.LastKnownVhosts,
}).Info("UpdateLastKnownVhosts finished successfully")
}).Debug("UpdateLastKnownVhosts finished successfully")
return nil
}

Expand All @@ -393,7 +393,7 @@ func (dm *DataManager) ReadAllNamespace() map[string]NamespaceData {
// Start the operation log
logger.WithFields(logrus.Fields{
"operation": operation,
}).Info("ReadAllNamespace data successfully")
}).Debug("ReadAllNamespace data successfully")

return dm.namespaces //returning copy
}
Expand All @@ -408,7 +408,7 @@ func (dm *DataManager) ReadStaticData() StaticConfig {
logger.WithFields(logrus.Fields{
"operation": operation,
"staticData": dm.StaticData,
}).Info("ReadStaticData successfully")
}).Debug("ReadStaticData successfully")

return dm.StaticData //returning copy
}
42 changes: 21 additions & 21 deletions src/drove.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func refreshLeaderData(namespace string) bool {
}).Info("New leader being set")
return true
} else {
logrus.Warn("Leade struct generation failed")
logrus.Error("Leader struct generation failed")
}
}
return false
Expand All @@ -202,7 +202,7 @@ func newDroveClient(name string) *DroveClient {
}
}

func pollingHandler(droveClient *DroveClient, reloadChannel chan<- bool, waitGroup *sync.WaitGroup) {
func pollingHandler(droveClient *DroveClient, appsConfigUpdateChannel chan<- bool, waitGroup *sync.WaitGroup) {
defer waitGroup.Done()
appsRefreshed := false
namespace := droveClient.namespace
Expand All @@ -228,14 +228,14 @@ func pollingHandler(droveClient *DroveClient, reloadChannel chan<- bool, waitGro
"namespace": namespace,
"localTime": time.Now(),
}).Info("Events received")
reloadNeeded := false
appsConfigUpdateNeeded := false
if _, ok := eventSummary.EventsCount["APP_STATE_CHANGE"]; ok {
reloadNeeded = true
appsConfigUpdateNeeded = true
}
if _, ok := eventSummary.EventsCount["INSTANCE_STATE_CHANGE"]; ok {
reloadNeeded = true
appsConfigUpdateNeeded = true
}
if reloadNeeded || leaderShifted {
if appsConfigUpdateNeeded || leaderShifted {
appsRefreshed = refreshApps(droveClient.httpClient, namespace, leaderShifted)
} else {
logger.Debug("Irrelevant events ignored")
Expand All @@ -247,34 +247,34 @@ func pollingHandler(droveClient *DroveClient, reloadChannel chan<- bool, waitGro
}).Debug("New Events received")
}
}
reloadChannel <- appsRefreshed
appsConfigUpdateChannel <- appsRefreshed
}

func pollingEvents() {
var waitGroup sync.WaitGroup
reloadChannel := make(chan bool, len(droveClients))
appsConfigUpdateChannel := make(chan bool, len(droveClients))

for _, droveClient := range droveClients {
waitGroup.Add(1)
go pollingHandler(droveClient, reloadChannel, &waitGroup)
go pollingHandler(droveClient, appsConfigUpdateChannel, &waitGroup)
}

waitGroup.Wait()
close(reloadChannel)
close(appsConfigUpdateChannel)

reloadConfig := false
for result := range reloadChannel {
appsUpdated := false
for result := range appsConfigUpdateChannel {
if result {
reloadConfig = true
appsUpdated = true
break
}
}
logger.WithFields(logrus.Fields{
"reloadConfig": reloadConfig,
"appsUpdated": appsUpdated,
}).Info("Drove poll event result")

if reloadConfig {
reloadSignalQueue <- true
if appsUpdated {
appsConfigUpdateSignalQueue <- true
}

}
Expand All @@ -287,7 +287,7 @@ func schedulePollDroveEvents() {
case <-ticker.C:
logger.Info("Refreshing drove events as per schedule")
pollingEvents()
case <-refreshSignalQueue:
case <-eventRefreshSignalQueue:
logger.Info("Refreshing drove events due to force referesh")
pollingEvents()
}
Expand Down Expand Up @@ -464,7 +464,7 @@ func syncAppsAndVhosts(droveConfig DroveConfig, jsonapps *DroveApps, vhosts *Vho
"tag": droveConfig.RoutingTag,
"vhost": newapp.Vhost,
"value": tagValue,
}).Info("routing tag found")
}).Debug("routing tag found")
groupName = tagValue
} else {

Expand Down Expand Up @@ -563,20 +563,20 @@ func refreshApps(httpClient *http.Client, namespace string, leaderShifted bool)
}
equal := syncAppsAndVhosts(droveConfig, &jsonapps, &vhosts)
if equal && !leaderShifted {
logger.Debug("no config changes")
logger.Debug("no relevant App Data changes")
return false
}

logger.WithFields(logrus.Fields{
"namespace": namespace,
"leaderShifted": leaderShifted,
"appsChanged": !equal,
}).Info("Config reload required") //logging exact reason of reload
}).Debug("Apps Data change required because of") //logging exact reason of potential reload

elapsed := time.Since(start)
go observeAppRefreshTimeMetric(namespace, elapsed)
logger.WithFields(logrus.Fields{
"took": elapsed,
}).Info("Apps updated")
}).Debug("Apps update")
return true
}
10 changes: 5 additions & 5 deletions src/nixy.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func setloglevel() {
case "error":
logLevel = logrus.ErrorLevel
default:
logger.Error("unknown loglevel")
logger.Error("unknown loglevel. Defaulting to info")
logLevel = logrus.InfoLevel
}

Expand All @@ -171,8 +171,8 @@ func setupDataManager() {
}

// Reload signal with buffer of two, because we dont really need more.
var reloadSignalQueue = make(chan bool, 2)
var refreshSignalQueue = make(chan bool, 2)
var appsConfigUpdateSignalQueue = make(chan bool, 2)
var eventRefreshSignalQueue = make(chan bool, 2)

// Global http transport for connection reuse
var tr = &http.Transport{MaxIdleConnsPerHost: 10, TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
Expand Down Expand Up @@ -224,10 +224,10 @@ func validateConfig() error {
func nixyReload(w http.ResponseWriter, r *http.Request) {
logger.WithFields(logrus.Fields{
"client": r.RemoteAddr,
}).Info("Reload triggered")
}).Info("Reload triggered via /v1/reload")
queued := true
select {
case refreshSignalQueue <- true: // Add referesh to our signal channel, unless it is full of course.
case eventRefreshSignalQueue <- true: // Add referesh to our signal channel, unless it is full of course.
default:
queued = false
}
Expand Down
35 changes: 19 additions & 16 deletions src/reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ func reload() error {
} else {
//Nginx plus is enabled
if config.NginxReloadDisabled {
logger.Warn("Template reload has been disabled")
logger.Debug("Template reload has been disabled")
} else {
vhosts := db.ReadAllKnownVhosts()
lastKnownVhosts := db.ReadLastKnownVhosts()
if !reflect.DeepEqual(vhosts, lastKnownVhosts) {
logger.Info("Need to reload config")
logger.Info("Vhost changes detected. Need to reload config")
err = updateAndReloadConfig(&data)
if err != nil {
logger.WithFields(logrus.Fields{
Expand All @@ -86,7 +86,7 @@ func reload() error {
elapsed := time.Since(start)
logger.WithFields(logrus.Fields{
"took": elapsed,
}).Info("config reloaded successfully")
}).Debug("reload worker completed")
return nil

}
Expand Down Expand Up @@ -116,7 +116,7 @@ func updateAndReloadConfig(data *RenderingData) error {
elapsed := time.Since(start)
logger.WithFields(logrus.Fields{
"took": elapsed,
}).Info("config updated successfully")
}).Debug("config updated and reloaded successfully")
go statsCount("reload.success", 1)
go statsTiming("reload.time", elapsed)
go countSuccessfulReloads.Inc()
Expand Down Expand Up @@ -197,7 +197,7 @@ func createRenderingData(data *RenderingData) {
data.Apps = allApps
logger.WithFields(logrus.Fields{
"data": data,
}).Info("Rendering data generated")
}).Debug("Rendering data generated")
return
}

Expand Down Expand Up @@ -227,6 +227,9 @@ func writeConf(data *RenderingData) error {
logger.Error("Error in config generated")
return err
}
logger.WithFields(logrus.Fields{
"file": config.NginxConfig,
}).Info("Writing new config")
err = os.Rename(tmpFile.Name(), config.NginxConfig)
if err != nil {
return err
Expand Down Expand Up @@ -261,7 +264,7 @@ func nginxPlus(data *RenderingData) error {
return error
}

logger.WithFields(logrus.Fields{"apps": data.Apps}).Info("Updating upstreams for the whitelisted drove tags")
logger.WithFields(logrus.Fields{"apps": data.Apps}).Debug("Updating upstreams for the whitelisted drove vhosts")
for _, app := range data.Apps {
var newFormattedServers []string
for _, t := range app.Hosts {
Expand All @@ -282,15 +285,11 @@ func nginxPlus(data *RenderingData) error {

logger.WithFields(logrus.Fields{
"vhost": app.Vhost,
}).Info("app.vhost")
}).Debug("app.vhost")

logger.WithFields(logrus.Fields{
"upstreams": newFormattedServers,
}).Info("nginx upstreams")

logger.WithFields(logrus.Fields{
"nginx": config.Nginxplusapiaddr,
}).Info("endpoint")
}).Debug("nginx upstreams")

upstreamtocheck := app.Vhost
var finalformattedServers []nplus.UpstreamServer
Expand Down Expand Up @@ -335,21 +334,25 @@ func nginxPlus(data *RenderingData) error {

if added != nil {
logger.WithFields(logrus.Fields{
"nginx upstreams added": added,
"vhost": upstreamtocheck,
"upstreams added": added,
}).Info("nginx upstreams added")
}
if deleted != nil {
logger.WithFields(logrus.Fields{
"nginx upstreams deleted": deleted,
"vhost": upstreamtocheck,
"upstreams deleted": deleted,
}).Info("nginx upstreams deleted")
}
if updated != nil {
logger.WithFields(logrus.Fields{
"nginx upsteams updated": updated,
"vhost": upstreamtocheck,
"upstreams updated": updated,
}).Info("nginx upstreams updated")
}
if error != nil {
logger.WithFields(logrus.Fields{
"vhost": upstreamtocheck,
"error": error,
}).Error("unable to update nginx upstreams")
return error
Expand Down Expand Up @@ -446,7 +449,7 @@ func reloadWorker() {
for {
select {
case <-ticker.C:
<-reloadSignalQueue
<-appsConfigUpdateSignalQueue
reload()
}
}
Expand Down