-
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
Conversation
WalkthroughWalkthroughThe recent changes introduce logging mechanisms for tracking websocket connections, disconnections, and API calls for fetching the latest feeds and a specific feed by symbol. These updates enhance monitoring capabilities by recording relevant events into a database. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant DB
Client->>+Server: Establish WebSocket Connection
Server->>+DB: Log "websocket connected from IP"
DB-->>-Server: Log Confirmation
Note over Server, Client: WebSocket Communication
Client->>+Server: Close WebSocket Connection
Server->>+DB: Log "websocket disconnected from IP"
DB-->>-Server: Log Confirmation
Client->>+Server: GET /api/feeds/latest
Server->>+DB: Log "getLatestFeeds called from IP"
DB-->>-Server: Log Confirmation
Server-->>Client: Latest Feeds
Client->>+Server: GET /api/feed/{symbol}
Server->>+DB: Log "getLatestFeed(symbol) called from IP"
DB-->>-Server: Log Confirmation
Server-->>Client: Feed for {symbol}
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
_ = db.QueryWithoutResult( | ||
context.Background(), | ||
"INSERT INTO logs (message) VALUES (@message);", | ||
map[string]any{"message": "websocket subscribed(" + strings.Join(msg.Params, ",") + ") from " + conn.IP()}, | ||
) |
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.
- _ = 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.
_ = 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") | |
} |
defer func() { | ||
_ = db.QueryWithoutResult( | ||
c.Context(), | ||
"INSERT INTO logs (message) VALUES (@message);", | ||
map[string]any{"message": "getLatestFeeds called from " + c.IP()}) | ||
}() |
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.
- _ = 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.
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") | |
} | |
}() |
defer func() { | ||
_ = db.QueryWithoutResult( | ||
c.Context(), | ||
"INSERT INTO logs (message) VALUES (@message);", | ||
map[string]any{"message": "getLatestFeed(" + symbol + ") called from " + c.IP()}) | ||
}() |
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.
- _ = 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.
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") | |
} | |
}() |
_ = db.QueryWithoutResult( | ||
context.Background(), | ||
"INSERT INTO logs (message) VALUES (@message);", | ||
map[string]any{"message": "websocket connected from " + conn.IP()}) | ||
|
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.
- _ = 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.
_ = 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") | |
} |
_ = db.QueryWithoutResult( | ||
context.Background(), | ||
"INSERT INTO logs (message) VALUES (@message);", | ||
map[string]any{"message": "websocket disconnected from " + conn.IP()}) |
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.
- _ = 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.
_ = 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") | |
} |
Description
Later will be improved with per api keys and more measurements
Type of change
Please delete options that are not relevant.
Checklist before requesting a review
Deployment