-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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()}) | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||
}() | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
for { | ||||||||||||||||||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||
if c.clients[conn] == nil { | ||||||||||||||||||||||||||||||
c.clients[conn] = make(map[string]bool) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
submissionData, err := ApiController.getLatestSubmissionData(c.Context()) | ||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if !strings.Contains(symbol, "test") { | ||||||||||||||||||||||||||||||
symbol = strings.ToUpper(symbol) | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
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.
Committable suggestion