Skip to content

Commit

Permalink
Fix health, peers and metrics (#99)
Browse files Browse the repository at this point in the history
* Fix path in dockerfile

* Fix node healthy indicator

* Fix peer interactions in dashboard

* Fix peer and database size metrics
  • Loading branch information
muXxer committed Apr 22, 2024
1 parent 815a1a5 commit 00d9739
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN go mod download
RUN go mod verify

# Build the binary
RUN go build -o /app/inx-dashboard -ldflags="-w -s -X=github.com/iotaledger/inx-api-core-v0/components/app.Version=${BUILD_VERSION}"
RUN go build -o /app/inx-dashboard -ldflags="-w -s -X=github.com/iotaledger/inx-dashboard/components/app.Version=${BUILD_VERSION}"

# Copy the assets
COPY ./config_defaults.json /app/config.json
Expand Down
2 changes: 0 additions & 2 deletions pkg/dashboard/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,13 @@ func (d *Dashboard) apiMiddlewares() []echo.MiddlewareFunc {
// the HTTP REST routes which can be called without authorization.
// Wildcards using * are allowed
publicRoutes := []string{
"/api/routes",
"/api/core/v3/info",
}

// the HTTP REST routes which need to be called with authorization.
// Wildcards using * are allowed
protectedRoutes := []string{
"/api/management/v1/peers*",
"/api/*",
}

publicRoutesRegEx := compileRoutesAsRegexes(publicRoutes)
Expand Down
6 changes: 3 additions & 3 deletions pkg/dashboard/frontend/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/dashboard/static/css/main.17d3dd65.css",
"main.js": "/dashboard/static/js/main.43e7aa0c.js",
"main.js": "/dashboard/static/js/main.741b55ba.js",
"static/js/751.7b6352ab.chunk.js": "/dashboard/static/js/751.7b6352ab.chunk.js",
"static/js/626.a6cf14e7.chunk.js": "/dashboard/static/js/626.a6cf14e7.chunk.js",
"static/js/733.f3d21da9.chunk.js": "/dashboard/static/js/733.f3d21da9.chunk.js",
Expand Down Expand Up @@ -54,10 +54,10 @@
"static/media/health-bad.svg": "/dashboard/static/media/health-bad.f6b3a99f588b20aef147dd8cada3356f.svg",
"static/media/health-good.svg": "/dashboard/static/media/health-good.c06d31b2b699112b161f07c13711dc20.svg",
"main.17d3dd65.css.map": "/dashboard/static/css/main.17d3dd65.css.map",
"main.43e7aa0c.js.map": "/dashboard/static/js/main.43e7aa0c.js.map"
"main.741b55ba.js.map": "/dashboard/static/js/main.741b55ba.js.map"
},
"entrypoints": [
"static/css/main.17d3dd65.css",
"static/js/main.43e7aa0c.js"
"static/js/main.741b55ba.js"
]
}
2 changes: 1 addition & 1 deletion pkg/dashboard/frontend/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="msapplication-TileColor" content="#ffffff"><meta name="theme-color" content="#ffffff"><meta name="author" content="Martyn Janes"><link rel="shortcut icon" href="/dashboard/branding/iota-core/favicon/favicon-32x32.png"><link rel="apple-touch-icon" sizes="180x180" href="/dashboard/branding/iota-core/favicon/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/dashboard/branding/iota-core/favicon/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/dashboard/branding/iota-core/favicon/favicon-16x16.png"><link rel="manifest" href="/dashboard/branding/iota-core/favicon/site.webmanifest"><link rel="mask-icon" href="/dashboard/branding/iota-core/favicon/safari-pinned-tab.svg" color="#485776"><title>Node Dashboard</title><meta name="keywords" content="IOTA,Node,Dashboard,iota-core"/><meta name="description" content="IOTA Node Dashboard iota-core"/><script defer="defer" src="/dashboard/static/js/main.43e7aa0c.js"></script><link href="/dashboard/static/css/main.17d3dd65.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"/><meta name="msapplication-TileColor" content="#ffffff"><meta name="theme-color" content="#ffffff"><meta name="author" content="Martyn Janes"><link rel="shortcut icon" href="/dashboard/branding/iota-core/favicon/favicon-32x32.png"><link rel="apple-touch-icon" sizes="180x180" href="/dashboard/branding/iota-core/favicon/apple-touch-icon.png"><link rel="icon" type="image/png" sizes="32x32" href="/dashboard/branding/iota-core/favicon/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/dashboard/branding/iota-core/favicon/favicon-16x16.png"><link rel="manifest" href="/dashboard/branding/iota-core/favicon/site.webmanifest"><link rel="mask-icon" href="/dashboard/branding/iota-core/favicon/safari-pinned-tab.svg" color="#485776"><title>Node Dashboard</title><meta name="keywords" content="IOTA,Node,Dashboard,iota-core"/><meta name="description" content="IOTA Node Dashboard iota-core"/><script defer="defer" src="/dashboard/static/js/main.741b55ba.js"></script><link href="/dashboard/static/css/main.17d3dd65.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion pkg/dashboard/frontend/static/js/main.43e7aa0c.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/dashboard/frontend/static/js/main.741b55ba.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/dashboard/livefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func (d *Dashboard) runGossipMetricsFeed() {
}

func (d *Dashboard) runPeerMetricsFeed() {

if err := d.daemon.BackgroundWorker("PeerMetrics Feed", func(ctx context.Context) {
ticker := timeutil.NewTicker(func() {
// skip if no client is connected
Expand Down
8 changes: 4 additions & 4 deletions pkg/dashboard/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ const (
nodeTimeout = 5 * time.Second
)

func getPublicNodeStatusByNodeInfo(nodeInfo *api.InfoResponse, isAlmostSynced bool) *PublicNodeStatus {
func getPublicNodeStatusByNodeInfo(nodeInfo *api.InfoResponse) *PublicNodeStatus {
return &PublicNodeStatus{
IsNodeHealthy: nodeInfo.Status.IsHealthy,
IsNetworkHealthy: nodeInfo.Status.IsNetworkHealthy,
PruningEpoch: nodeInfo.Status.PruningEpoch,
IsHealthy: nodeInfo.Status.IsHealthy,
IsNetworkHealthy: isAlmostSynced,
}
}

Expand All @@ -33,7 +33,7 @@ func (d *Dashboard) getPublicNodeStatus(ctx context.Context) (*PublicNodeStatus,
return nil, ierrors.Wrap(err, "failed to get node info")
}

publicNodeStatus := getPublicNodeStatusByNodeInfo(nodeInfo, d.nodeBridge.IsNodeHealthy())
publicNodeStatus := getPublicNodeStatusByNodeInfo(nodeInfo)

return publicNodeStatus, nil
}
Expand Down
39 changes: 16 additions & 23 deletions pkg/dashboard/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,36 @@ import (
"strings"

"github.com/labstack/echo/v4"

"github.com/iotaledger/iota.go/v4/api"
)

const (
FeatureCoreAPI = "core/v3"
FeatureManagementAPI = "management/v2"
FeatureCoreAPI = api.CorePluginName
FeatureManagementAPI = api.ManagementPluginName
FeatureDashboardMetrics = "dashboard-metrics/v2"

BasePath = ""
APIBasePath = "/api"
CoreAPIRoute = BasePath + "/" + FeatureCoreAPI
ManagementAPIRoute = APIBasePath + "/" + FeatureManagementAPI
DashboardMetricsRoute = APIBasePath + "/" + FeatureDashboardMetrics
ManagementAPIRoute = BasePath + "/" + FeatureManagementAPI
DashboardMetricsRoute = api.APIRoot + "/" + FeatureDashboardMetrics
)

const (
// ParameterPeerID is used to identify a peer.
ParameterPeerID = "peerID"

// RouteRoutes is the route for getting the routes the node exposes.
// GET returns the routes.
RouteRoutes = BasePath + "/routes"

// RouteCoreInfo is the route for getting the node info.
// GET returns the node info.
RouteCoreInfo = CoreAPIRoute + "/info"

// RouteCorePeer is the route for getting peers by their peerID.
// GET returns the peer
// RouteManagementPeer is the route for getting peers by their peerID.
// DELETE deletes the peer.
RouteCorePeer = CoreAPIRoute + "/peers/:" + ParameterPeerID
RouteManagementPeer = ManagementAPIRoute + "/peers/:" + ParameterPeerID

// RouteCorePeers is the route for getting all peers of the node.
// GET returns a list of all peers.
// RouteManagementPeers is the route for getting all peers of the node.
// POST adds a new peer.
RouteCorePeers = CoreAPIRoute + "/peers"
RouteManagementPeers = ManagementAPIRoute + "/peers"
)

const (
Expand All @@ -60,24 +55,22 @@ const (
)

func (d *Dashboard) setupAPIRoutes(routeGroup *echo.Group) {

routeGroup.GET(RouteRoutes, func(c echo.Context) error {
return d.forwardRequest(c)
})

// core
routeGroup.GET(RouteCoreInfo, func(c echo.Context) error {
return d.forwardRequest(c)
})

routeGroup.DELETE(RouteCorePeer, func(c echo.Context) error {
// management
routeGroup.DELETE(RouteManagementPeer, func(c echo.Context) error {
return d.forwardRequest(c)
})

routeGroup.POST(RouteCorePeers, func(c echo.Context) error {
routeGroup.POST(RouteManagementPeers, func(c echo.Context) error {
return d.forwardRequest(c)
})

// management
// dashboard-metrics
// HINT: those routes are not forwarded, because they are only used directly in the backend
}

func readAndCloseRequestBody(res *http.Request) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (m *WebsocketMsg) MarshalJSON() ([]byte, error) {

// PublicNodeStatus represents the public node status.
type PublicNodeStatus struct {
IsHealthy bool `serix:""`
IsNodeHealthy bool `serix:""`
IsNetworkHealthy bool `serix:""`
PruningEpoch iotago.EpochIndex `serix:""`
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (d *Dashboard) websocketRoute(ctx echo.Context) error {
_ = client.Send(ctxMsg, d.newWebsocketMsg(
ctxMsg,
MsgTypePublicNodeStatus,
getPublicNodeStatusByNodeInfo(nodeInfo, d.nodeBridge.IsNodeHealthy()),
getPublicNodeStatusByNodeInfo(nodeInfo),
))

case MsgTypeNodeInfoExtended:
Expand Down

0 comments on commit 00d9739

Please sign in to comment.