Skip to content

Commit

Permalink
Merge pull request #11 from kubescape/liveness
Browse files Browse the repository at this point in the history
adding liveness probe
  • Loading branch information
matthyx authored Nov 20, 2023
2 parents 6fb0ed4 + a92fbce commit 9d427c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func main() {
// synchronizer server URL using service discovery
if services, err := config.LoadServiceURLs("/etc/config/services.json"); err != nil {
logger.L().Warning("failed discovering urls", helpers.Error(err))
} else {
logger.L().Debug("synchronizer server URL", helpers.String("synchronizer", services.GetSynchronizerUrl()))
cfg.InCluster.ServerUrl = services.GetSynchronizerUrl()
} else if serverUrl := services.GetSynchronizerUrl(); serverUrl != "" {
logger.L().Debug("synchronizer server URL", helpers.String("synchronizer", serverUrl))
cfg.InCluster.ServerUrl = serverUrl
}

cfg.InCluster.ValidateConfig()
Expand Down Expand Up @@ -89,6 +89,9 @@ func main() {
}),
}

// start liveness probe
utils.StartLivenessProbe()

for {
if err := start(ctx, cfg.InCluster, adapter, dialer); err != nil {
d := 5 * time.Second // TODO: use exponential backoff for retries
Expand Down
4 changes: 4 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gobwas/ws"
pulsarconnector "github.com/kubescape/messaging/pulsar/connector"
"github.com/kubescape/synchronizer/utils"

"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
Expand Down Expand Up @@ -63,6 +64,9 @@ func main() {
adapter = adapters.NewMockAdapter(false)
}

// start liveness probe
utils.StartLivenessProbe()

// websocket server
_ = http.ListenAndServe(":8080",
authentication.AuthenticationServerMiddleware(cfg.Backend.AuthenticationServer,
Expand Down
12 changes: 12 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"flag"
"fmt"
"net/http"
"path/filepath"
"reflect"
"strconv"
Expand Down Expand Up @@ -186,3 +187,14 @@ func PulsarMessageIDtoString(msgID pulsar.MessageID) string {
msgIDstr := msgID.String() + ":" + batchStr
return msgIDstr
}

func StartLivenessProbe() {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
go func() {
if err := http.ListenAndServe(":7888", nil); err != nil {
logger.L().Error("failed to start liveness probe", helpers.Error(err))
}
}()
}

0 comments on commit 9d427c8

Please sign in to comment.