From b8689a5ea928d8f42b9dc393cc5f943e1b9422df Mon Sep 17 00:00:00 2001 From: muXxer Date: Fri, 19 Apr 2024 18:19:08 +0200 Subject: [PATCH] Fix dashboard metrics types --- components/dashboard_metrics/component.go | 10 +++++--- components/dashboard_metrics/types.go | 28 +++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/dashboard_metrics/component.go b/components/dashboard_metrics/component.go index 38deedc28..03ef46e55 100644 --- a/components/dashboard_metrics/component.go +++ b/components/dashboard_metrics/component.go @@ -75,15 +75,15 @@ func configure() error { routeGroup := deps.RestRouteManager.AddRoute("dashboard-metrics/v2") routeGroup.GET(RouteNodeInfoExtended, func(c echo.Context) error { - return httpserver.JSONResponse(c, http.StatusOK, nodeInfoExtended()) + return responseByHeader(c, nodeInfoExtended(), http.StatusOK) }) routeGroup.GET(RouteDatabaseSizes, func(c echo.Context) error { - return httpserver.JSONResponse(c, http.StatusOK, databaseSizesMetrics()) + return responseByHeader(c, databaseSizesMetrics(), http.StatusOK) }) routeGroup.GET(RouteGossipMetrics, func(c echo.Context) error { - return httpserver.JSONResponse(c, http.StatusOK, gossipMetrics()) + return responseByHeader(c, gossipMetrics(), http.StatusOK) }) return nil @@ -101,3 +101,7 @@ func run() error { return nil } + +func responseByHeader(c echo.Context, obj any, httpStatusCode ...int) error { + return httpserver.SendResponseByHeader(c, deps.Protocol.Engines.Main.Get().CommittedAPI(), obj, httpStatusCode...) +} diff --git a/components/dashboard_metrics/types.go b/components/dashboard_metrics/types.go index 9fcf07ef0..aacd49adf 100644 --- a/components/dashboard_metrics/types.go +++ b/components/dashboard_metrics/types.go @@ -2,26 +2,26 @@ package dashboardmetrics // NodeInfoExtended represents extended information about the node. type NodeInfoExtended struct { - Version string `json:"version"` - LatestVersion string `json:"latestVersion"` - Uptime int64 `json:"uptime"` - NodeID string `json:"nodeId"` - NodeAlias string `json:"nodeAlias"` - MemoryUsage int64 `json:"memUsage"` + Version string `serix:",lenPrefix=uint8"` + LatestVersion string `serix:",lenPrefix=uint8"` + Uptime int64 `serix:""` + NodeID string `serix:",lenPrefix=uint8"` + NodeAlias string `serix:",lenPrefix=uint8"` + MemoryUsage int64 `serix:""` } // DatabaseSizesMetric represents database size metrics. type DatabaseSizesMetric struct { - Permanent int64 `json:"permanent"` - Prunable int64 `json:"prunable"` - TxRetainer int64 `json:"txRetainer"` - Total int64 `json:"total"` - Time int64 `json:"ts"` + Permanent int64 `serix:""` + Prunable int64 `serix:""` + TxRetainer int64 `serix:""` + Total int64 `serix:""` + Time int64 `serix:""` } // GossipMetrics represents the metrics for blocks per second. type GossipMetrics struct { - Incoming uint32 `json:"incoming"` - New uint32 `json:"new"` - Outgoing uint32 `json:"outgoing"` + Incoming uint32 `serix:""` + New uint32 `serix:""` + Outgoing uint32 `serix:""` }