Skip to content

Commit

Permalink
Merge pull request karrieretutor#1 from karrieretutor/fix-external-disco
Browse files Browse the repository at this point in the history
added tcp conn watcher
  • Loading branch information
Kroev authored Sep 5, 2019
2 parents 8bf7424 + 117ef05 commit b938d3c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog
## Unreleased

## [0.0.2] 2019-09-05
### Added
- the prom exporter now watches the tcp conn to the xmpp server (this led to some confusion on k8s), if the connection to the xmpp server is lost, the exporter exits

### Fixed
- Exit the prom-exporter if connection gets closed externally (eg. the XMPP server stops)

## [0.0.1] 2019-08-30
### Added
- initial release
26 changes: 25 additions & 1 deletion exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/tls"
"encoding/xml"
"fmt"
"net"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -53,6 +54,8 @@ var (
connected: false,
}

serverChecker *xmpp.ServerCheck

jvbbrewery string
cm *xmpp.StreamManager

Expand Down Expand Up @@ -120,6 +123,20 @@ func main() {
fmt.Println("internal muc domain not specified")
os.Exit(2)
}

//we need a serverchecker
go func() {
address := xmppServer + ":" + xmppPort
for true {
_, err := net.DialTimeout("tcp", address, 5*time.Second)
if err != nil {
fmt.Printf("Could not connect to server %s: %s\nexiting\n", address, err.Error())
signals <- iExit
}
time.Sleep(10 * time.Second)
}
}()

jvbbrewery = breweryroom + "@" + internalMucDomain

jid := xmppUser + "@" + xmppAuthDomain
Expand Down Expand Up @@ -169,7 +186,8 @@ func main() {
}

func shutdown() {
if cm != nil {
//we get a segfault if connection actually never happened
if cm != nil && cm.Metrics.ConnectTime != 0*time.Second {
cm.Stop()
}
}
Expand Down Expand Up @@ -251,5 +269,11 @@ func connectClient(c xmpp.Config, r *xmpp.Router) {
if err != nil {
fmt.Printf("xmpp connection manager returned with error: %s\n", err.Error())
signals <- iFail
return
}

//connection closed we are done
fmt.Println("XMPP connection closed, exiting.")
signals <- iExit
return
}

0 comments on commit b938d3c

Please sign in to comment.