From 457d075163bdffe2ee5f14639033a73ebc9730f3 Mon Sep 17 00:00:00 2001 From: nick Date: Thu, 11 Jul 2024 23:02:45 +0900 Subject: [PATCH] fix: store duration in microsecond --- node/pkg/dal/api/controller.go | 3 ++- node/pkg/dal/api/route.go | 11 +---------- node/pkg/dal/utils/stats/stats.go | 6 +++--- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/node/pkg/dal/api/controller.go b/node/pkg/dal/api/controller.go index 405c5d62c..e2be57af0 100644 --- a/node/pkg/dal/api/controller.go +++ b/node/pkg/dal/api/controller.go @@ -103,7 +103,8 @@ func (c *Controller) castSubmissionData(data *dalcommon.OutgoingSubmissionData, } } -func (c *Controller) handleWebsocket(ctx context.Context, conn *websocket.Conn) { +func (c *Controller) handleWebsocket(conn *websocket.Conn) { + ctx := context.Background() c.register <- conn apiKey := conn.Headers("X-Api-Key") if apiKey == "" { diff --git a/node/pkg/dal/api/route.go b/node/pkg/dal/api/route.go index 334a1e4e4..305fcea99 100644 --- a/node/pkg/dal/api/route.go +++ b/node/pkg/dal/api/route.go @@ -1,8 +1,6 @@ package api import ( - "context" - "github.com/gofiber/contrib/websocket" "github.com/gofiber/fiber/v2" ) @@ -13,12 +11,5 @@ func Routes(router fiber.Router) { api.Get("/symbols", getSymbols) api.Get("/latest-data-feeds/all", getLatestFeeds) api.Get("/latest-data-feeds/:symbol", getLatestFeed) - api.Get("/ws", func(c *fiber.Ctx) error { - if websocket.IsWebSocketUpgrade(c) { - return websocket.New(func(conn *websocket.Conn) { - ApiController.handleWebsocket(context.Background(), conn) - })(c) - } - return fiber.ErrUpgradeRequired - }) + api.Get("/ws", websocket.New(ApiController.handleWebsocket)) } diff --git a/node/pkg/dal/utils/stats/stats.go b/node/pkg/dal/utils/stats/stats.go index bddb9f7af..43b4a6d89 100644 --- a/node/pkg/dal/utils/stats/stats.go +++ b/node/pkg/dal/utils/stats/stats.go @@ -38,12 +38,13 @@ type websocketId struct { } func InsertRestCall(ctx context.Context, apiKey string, endpoint string, statusCode int, responseTime time.Duration) error { - responseTimeMilli := int(responseTime.Milliseconds()) + + responseTimeMicro := responseTime.Microseconds() return db.QueryWithoutResult(ctx, INSERT_REST_CALLS, map[string]any{ "api_key": apiKey, "endpoint": endpoint, "status_code": statusCode, - "response_time": responseTimeMilli, + "response_time": responseTimeMicro, }) } @@ -72,7 +73,6 @@ func InsertWebsocketSubscription(ctx context.Context, connectionId int32, topic func StatsMiddleware(c *fiber.Ctx) error { start := time.Now() - if err := c.Next(); err != nil { return err }