Skip to content
Snippets Groups Projects
Unverified Commit 954b4bb6 authored by Acha Bill's avatar Acha Bill Committed by GitHub
Browse files

add healthz endpoint (#455)

* add healthz endpoint

* fix comment
parent dd6fbd4e
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/webapi/autopeering" "github.com/iotaledger/goshimmer/plugins/webapi/autopeering"
"github.com/iotaledger/goshimmer/plugins/webapi/data" "github.com/iotaledger/goshimmer/plugins/webapi/data"
"github.com/iotaledger/goshimmer/plugins/webapi/drng" "github.com/iotaledger/goshimmer/plugins/webapi/drng"
"github.com/iotaledger/goshimmer/plugins/webapi/healthz"
"github.com/iotaledger/goshimmer/plugins/webapi/info" "github.com/iotaledger/goshimmer/plugins/webapi/info"
"github.com/iotaledger/goshimmer/plugins/webapi/message" "github.com/iotaledger/goshimmer/plugins/webapi/message"
"github.com/iotaledger/goshimmer/plugins/webapi/spammer" "github.com/iotaledger/goshimmer/plugins/webapi/spammer"
...@@ -19,6 +20,7 @@ var PLUGINS = node.Plugins( ...@@ -19,6 +20,7 @@ var PLUGINS = node.Plugins(
spammer.Plugin, spammer.Plugin,
data.Plugin, data.Plugin,
drng.Plugin, drng.Plugin,
healthz.Plugin,
message.Plugin, message.Plugin,
autopeering.Plugin, autopeering.Plugin,
info.Plugin, info.Plugin,
......
package healthz
import (
"net/http"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/sync"
"github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/node"
"github.com/labstack/echo"
)
// PluginName is the name of the web API healthz endpoint plugin.
const PluginName = "WebAPI healthz Endpoint"
// Plugin is the plugin instance of the web API info endpoint plugin.
var Plugin = node.NewPlugin(PluginName, node.Enabled, configure)
func configure(_ *node.Plugin) {
webapi.Server.GET("healthz", getHealthz)
}
func getHealthz(c echo.Context) error {
if !IsNodeHealthy() {
return c.NoContent(http.StatusServiceUnavailable)
}
return c.NoContent(http.StatusOK)
}
// IsNodeHealthy returns whether the node is synced, has active neighbors.
func IsNodeHealthy() bool {
// Synced
if !sync.Synced() {
return false
}
// Has connected neighbors
if len(gossip.Manager().AllNeighbors()) == 0 {
return false
}
return true
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment