Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(DAL) basic implementation to store logs #1751

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions node/pkg/dal/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,18 @@ func (c *Controller) castSubmissionData(data *dalcommon.OutgoingSubmissionData,

func (c *Controller) handleWebsocket(conn *websocket.Conn) {
c.register <- conn
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket connected from " + conn.IP()})

Comment on lines +108 to +112
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from logging.

Ignoring errors from logging operations might hide underlying issues. Consider logging the errors or handling them appropriately.

-  _ = db.QueryWithoutResult(
+  if err := db.QueryWithoutResult(
      context.Background(),
      "INSERT INTO logs (message) VALUES (@message);",
-     map[string]any{"message": "websocket connected from " + conn.IP()})
+     map[string]any{"message": "websocket connected from " + conn.IP()}); err != nil {
+     log.Error().Err(err).Msg("failed to log websocket connection")
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket connected from " + conn.IP()})
if err := db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket connected from " + conn.IP()}); err != nil {
log.Error().Err(err).Msg("failed to log websocket connection")
}

defer func() {
c.unregister <- conn
conn.Close()
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket disconnected from " + conn.IP()})
Comment on lines +116 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from logging.

Ignoring errors from logging operations might hide underlying issues. Consider logging the errors or handling them appropriately.

-  _ = db.QueryWithoutResult(
+  if err := db.QueryWithoutResult(
      context.Background(),
      "INSERT INTO logs (message) VALUES (@message);",
-     map[string]any{"message": "websocket disconnected from " + conn.IP()})
+     map[string]any{"message": "websocket disconnected from " + conn.IP()}); err != nil {
+     log.Error().Err(err).Msg("failed to log websocket disconnection")
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket disconnected from " + conn.IP()})
if err := db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket disconnected from " + conn.IP()}); err != nil {
log.Error().Err(err).Msg("failed to log websocket disconnection")
}

}()

for {
Expand All @@ -118,6 +127,11 @@ func (c *Controller) handleWebsocket(conn *websocket.Conn) {
}

if msg.Method == "SUBSCRIBE" {
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()},
)
Comment on lines +130 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from logging.

Ignoring errors from logging operations might hide underlying issues. Consider logging the errors or handling them appropriately.

-  _ = db.QueryWithoutResult(
+  if err := db.QueryWithoutResult(
      context.Background(),
      "INSERT INTO logs (message) VALUES (@message);",
-     map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()},
-  )
+     map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()}); err != nil {
+     log.Error().Err(err).Msg("failed to log websocket subscription")
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_ = db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()},
)
if err := db.QueryWithoutResult(
context.Background(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()}); err != nil {
log.Error().Err(err).Msg("failed to log websocket subscription")
}

if c.clients[conn] == nil {
c.clients[conn] = make(map[string]bool)
}
Expand Down Expand Up @@ -197,6 +211,13 @@ func (c *Controller) getLatestSubmissionDataSingle(ctx context.Context, symbol s
}

func getLatestFeeds(c *fiber.Ctx) error {
defer func() {
_ = db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeeds called from " + c.IP()})
}()
Comment on lines +214 to +219
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from logging.

Ignoring errors from logging operations might hide underlying issues. Consider logging the errors or handling them appropriately.

-  _ = db.QueryWithoutResult(
+  if err := db.QueryWithoutResult(
      c.Context(),
      "INSERT INTO logs (message) VALUES (@message);",
-     map[string]any{"message": "getLatestFeeds called from " + c.IP()})
+     map[string]any{"message": "getLatestFeeds called from " + c.IP()}); err != nil {
+     log.Error().Err(err).Msg("failed to log getLatestFeeds call")
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defer func() {
_ = db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeeds called from " + c.IP()})
}()
defer func() {
if err := db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeeds called from " + c.IP()}); err != nil {
log.Error().Err(err).Msg("failed to log getLatestFeeds call")
}
}()


submissionData, err := ApiController.getLatestSubmissionData(c.Context())
if err != nil {
return err
Expand Down Expand Up @@ -224,6 +245,13 @@ func getLatestFeed(c *fiber.Ctx) error {
return errors.New("symbol should be in {BASE}-{QUOTE} format")
}

defer func() {
_ = db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()})
}()
Comment on lines +248 to +253
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from logging.

Ignoring errors from logging operations might hide underlying issues. Consider logging the errors or handling them appropriately.

-  _ = db.QueryWithoutResult(
+  if err := db.QueryWithoutResult(
      c.Context(),
      "INSERT INTO logs (message) VALUES (@message);",
-     map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()})
+     map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()}); err != nil {
+     log.Error().Err(err).Msg("failed to log getLatestFeed call")
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
defer func() {
_ = db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()})
}()
defer func() {
if err := db.QueryWithoutResult(
c.Context(),
"INSERT INTO logs (message) VALUES (@message);",
map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()}); err != nil {
log.Error().Err(err).Msg("failed to log getLatestFeed call")
}
}()


if !strings.Contains(symbol, "test") {
symbol = strings.ToUpper(symbol)
}
Expand Down
Loading