-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: implement WebSocket client and server for log transmission #806
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
Conversation
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Failed to generate code suggestions for PR |
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.
Pull Request Overview
This PR adds WebSocket-based logging support by implementing a WebSocket server and client (with tests), improves error propagation in command modules by switching to RunE
and returning errors, and refactors initLogger
/runModule
to handle WebSocket log sinks.
- Introduce
pkg/util/ws
client/server with base64‐encoded message handling and unit tests - Update CLI commands (
bash
,gnutls
,gotls
,mysqld
,nspr
,postgres
,zsh
,tls
) to useRunE
/error returns for better error propagation - Extend
initLogger
incli/cmd/root.go
to detectws://
/wss://
addresses and dial WebSocket clients
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
pkg/util/ws/server_test.go | New tests for WebSocket server message handling |
pkg/util/ws/server.go | WebSocket server implementation decoding base64 messages |
pkg/util/ws/client_test.go | Tests for WebSocket client Dial , Write |
pkg/util/ws/client.go | WebSocket client implementing io.Writer over base64 |
cli/cmd/root.go | Refactor initLogger to support WebSocket addresses |
cli/cmd/bash.go | Switch bash command to RunE and return errors |
cli/cmd/gnutls.go | Switch gnutls command to RunE and return errors |
cli/cmd/gotls.go | Switch gotls command to RunE and return errors |
cli/cmd/mysqld.go | Switch mysqld command to RunE and return errors |
cli/cmd/nspr.go | Switch nspr command to RunE and return errors |
cli/cmd/postgres.go | Switch postgres command to RunE and return errors |
cli/cmd/zsh.go | Switch zsh command to RunE and return errors |
cli/cmd/tls.go | Switch tls command to RunE and return errors |
Comments suppressed due to low confidence (6)
cli/cmd/root.go:205
- After dialing the WebSocket connection, call
modConfig.SetAddrType(loggerTypeWebsocket)
so that downstream components know the address type is WebSocket.
} else if strings.Contains(addr, "ws://") || strings.Contains(addr, "wss://") {
cli/cmd/tls.go:61
- The comment above
openSSLCommandFunc
incorrectly references "bash"; update it to reflect the OpenSSL/TLS command (e.g., "executes the TLS module").
// openSSLCommandFunc executes the "bash" command.
cli/cmd/gnutls.go:58
- The doc comment for
gnuTlsCommandFunc
mentions "bash"; please correct it to describe the GnuTLS command execution.
// gnuTlsCommandFunc executes the "bash" command.
pkg/util/ws/client.go:30
- [nitpick] Consider adding an English version of this comment or making it bilingual to maintain consistency across the codebase.
// Write 实现 io.Writer 接口
pkg/util/ws/client.go:51
- There is no test covering
Close()
, which may hide resource leaks or panics. Add a unit test to verify thatClose
always succeeds (or returns a predictable error).
func (w *Client) Close() error {
pkg/util/ws/server_test.go:64
- Consider adding a test case that sends an invalid base64 message to
handleWebSocket
and verifies the server continues processing subsequent valid messages.
select {
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
…Socket connections Co-authored-by: Hugo <77865234+zenyanle@users.noreply.github.com> Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
This pull request introduces significant improvements to error handling across multiple command modules, adds WebSocket support for logging, and includes a new WebSocket client implementation with tests. The changes enhance the robustness of the codebase and expand functionality for capturing and logging events.
Error Handling Enhancements:
bashCommandFunc
,gnuTlsCommandFunc
,goTLSCommandFunc
,mysqldCommandFunc
,nssCommandFunc
,postgresCommandFunc
,openSSLCommandFunc
,zshCommandFunc
) to return errors instead of using implicit error handling. This improves error propagation and makes debugging easier. [1] [2] [3] [4] [5] [6] [7] [8]WebSocket Support for Logging:
loggerTypeWebsocket
) and modifying theinitLogger
function to handle WebSocket connections. This enables logs to be sent to WebSocket servers. [1] [2] [3] [4]WebSocket Client Implementation:
pkg/util/ws/client.go
with methods for connecting (Dial
), writing (Write
), and closing (Close
) WebSocket connections. This client uses base64 encoding for transmitted data.pkg/util/ws/client_test.go
to verify functionality, including data transmission and error handling during connection.Command Module Updates:
Run
toRunE
) in multiple modules (cli/cmd/bash.go
,cli/cmd/gnutls.go
,cli/cmd/gotls.go
,cli/cmd/mysqld.go
,cli/cmd/nspr.go
,cli/cmd/postgres.go
,cli/cmd/tls.go
,cli/cmd/zsh.go
) to support error handling improvements. [1] [2] [3] [4] [5] [6] [7] [8]Miscellaneous Improvements:
runModule
function (e.g.,url
toupgradeUrl
).runModule
to return errors instead of logging fatal messages, ensuring better control over program flow.