Skip to content

Commit

Permalink
fix: store duration in microsecond
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Jul 11, 2024
1 parent 18d830e commit 457d075
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
3 changes: 2 additions & 1 deletion node/pkg/dal/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
11 changes: 1 addition & 10 deletions node/pkg/dal/api/route.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package api

import (
"context"

"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
)
Expand All @@ -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))
}
6 changes: 3 additions & 3 deletions node/pkg/dal/utils/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 457d075

Please sign in to comment.