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

Adds readiness and liveness notifications for systemd #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 34 additions & 1 deletion filtra_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"github.com/coreos/go-systemd/daemon"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -177,12 +178,22 @@ func main() {
log.SetLevel(log.DebugLevel)
}

// This is used to send systemd readiness notification
readyToServe := false

// Start go routine that updates values continously in the background
go func() {
for {
log.Info("Updating metrics from Github: %", time.Now())
updatePrometheusMetrics(FetchAllIssues())

// Sending readiness notication to systemd
if !readyToServe {
readyToServe = true
log.Debug("Sending systemd notification: READY=1")
daemon.SdNotify(false, "READY=1")
}

// Sleeping for some time, so that we don't update constantly
// and run into the request limit of Github.
log.Info("Update finished: %", time.Now())
Expand All @@ -191,8 +202,30 @@ func main() {
}
}()

// Start Go routine for systemd watchdog
go func() {
interval, err := daemon.SdWatchdogEnabled(false)
if err != nil || interval == 0 {
log.Debug("systemd watchdog not enabled")
return
}
for {
_, err := http.Get("http://127.0.0.1:8080")
if err == nil {
log.Debug("Sending systemd notification: WATCHDOG=1")
daemon.SdNotify(false, "WATCHDOG=1")
} else {
log.Error("Liveness check failed. Not sending notification for systemd watchdog")
}
time.Sleep(interval / 3)
}
}()

// Start the websever
http.Handle("/metrics", promhttp.Handler())
log.Info("Beginning to serve on port :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Panic(err)
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/brejoc/githubv4 v0.0.0-20190628081146-ff7a0d1c9aa4
github.com/brejoc/graphql v0.0.0-20190628081354-06d07f6a803c // indirect
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a
github.com/prometheus/client_golang v1.0.0
github.com/sirupsen/logrus v1.4.2
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/brejoc/githubv4 v0.0.0-20190628081146-ff7a0d1c9aa4 h1:iVjQgCwcxfMxkeq
github.com/brejoc/githubv4 v0.0.0-20190628081146-ff7a0d1c9aa4/go.mod h1:uGE3ZVEmsyK+I6jG0Zveu92rP5FRoggAErP/uYm0jCA=
github.com/brejoc/graphql v0.0.0-20190628081354-06d07f6a803c h1:tVKvtFD4lhxGQ8er8G48V1SZBN5pncPFq2gppY1NHGo=
github.com/brejoc/graphql v0.0.0-20190628081354-06d07f6a803c/go.mod h1:1suXv94t50OvWZJZNiVJEc3uCE3TmMo0RpE2Z8qLo+4=
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a h1:W8b4lQ4tFF21aspRGoBuCNV6V2fFJBF+pm1J6OY8Lys=
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
191 changes: 191 additions & 0 deletions vendor/github.com/coreos/go-systemd/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/github.com/coreos/go-systemd/NOTICE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions vendor/github.com/coreos/go-systemd/daemon/sdnotify.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading