Skip to content

Commit 517cb1b

Browse files
committed
fix(logger): adjust publish and ttl times to seconds
1 parent 27ea62f commit 517cb1b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

logger/main.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func main() {
5959

6060
go syslogd.Listen(exitChan, cleanupChan, drainChan, fmt.Sprintf("%s:%d", logAddr, logPort))
6161
if enablePublish {
62-
go publishService(exitChan, client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL).Seconds()))
62+
go publishService(exitChan, client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL)*time.Second))
6363
}
6464

6565
// HACK (bacongobbler): poll etcd for changes in the log drain value
@@ -76,7 +76,7 @@ func main() {
7676
if resp != nil && resp.Node != nil {
7777
drainChan <- resp.Node.Value
7878
}
79-
time.Sleep(time.Duration(publishInterval))
79+
time.Sleep(time.Duration(publishInterval) * time.Second)
8080
}
8181
}()
8282

@@ -91,14 +91,21 @@ func main() {
9191
}
9292
}
9393

94-
func publishService(exitChan chan bool, client *etcd.Client, host string, etcdPath string, port string, ttl uint64) {
95-
t := time.NewTicker(time.Duration(publishInterval))
94+
// publishKeys sets relevant etcd keys with a time-to-live.
95+
func publishKeys(client *etcd.Client, host, etcdPath, port string, ttl uint64) {
96+
setEtcd(client, etcdPath+"/host", host, ttl)
97+
setEtcd(client, etcdPath+"/port", port, ttl)
98+
}
9699

100+
// publishServices publishes keys immediately, then every publishInterval seconds until it receives
101+
// something on exitChan.
102+
func publishService(exitChan chan bool, client *etcd.Client, host string, etcdPath string, port string, ttl uint64) {
103+
publishKeys(client, host, etcdPath, port, ttl)
104+
t := time.NewTicker(time.Duration(publishInterval) * time.Second)
97105
for {
98106
select {
99107
case <-t.C:
100-
setEtcd(client, etcdPath+"/host", host, ttl)
101-
setEtcd(client, etcdPath+"/port", port, ttl)
108+
publishKeys(client, host, etcdPath, port, ttl)
102109
case <-exitChan:
103110
return
104111
}

0 commit comments

Comments
 (0)