Update On Tue Jul 2 20:34:19 CEST 2024

This commit is contained in:
github-action[bot]
2024-07-02 20:34:19 +02:00
parent 91fe520152
commit 55a38739d4
630 changed files with 55392 additions and 5173 deletions

View File

@@ -26,7 +26,8 @@ jobs:
steps:
- id: set-matrix
run: |
echo '::set-output name=matrix::{"platform":["amd64","arm64"]}'
echo '{"platform": ["amd64", "arm64"]}' > matrix.json
echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
build-bin:
runs-on: ubuntu-latest

View File

@@ -10,5 +10,5 @@ type Reloader interface {
type HealthChecker interface {
// get relay by ID and check the connection health
HealthCheck(ctx context.Context, RelayID string) error
HealthCheck(ctx context.Context, RelayID string) (int64, error)
}

View File

@@ -55,6 +55,10 @@ func (r *Config) GetWSRemoteAddr(baseAddr string) (string, error) {
return addr, nil
}
func (r *Config) GetTCPRemotes() string {
return fmt.Sprintf("%v", r.TCPRemotes)
}
func (r *Config) Validate() error {
if r.Adjust() != nil {
return errors.New("adjust config failed")

View File

@@ -9,10 +9,10 @@ import (
var _ glue.HealthChecker = (*Server)(nil)
func (r *Server) HealthCheck(ctx context.Context, relayID string) error {
func (r *Server) HealthCheck(ctx context.Context, relayID string) (int64, error) {
rs, ok := r.relayM.Load(relayID)
if !ok {
return fmt.Errorf("label for relay: %s not found,can not health check", relayID)
return 0, fmt.Errorf("label for relay: %s not found,can not health check", relayID)
}
inner, _ := rs.(*Relay)
return inner.relayServer.HealthCheck(ctx)

View File

@@ -101,6 +101,7 @@ func (b *baseTransporter) RelayTCPConn(c net.Conn, handshakeF TCPHandShakeF) err
return relayConn.Transport(remote.Label)
}
func (b *baseTransporter) HealthCheck(ctx context.Context) error {
return b.relayer.HealthCheck(ctx, b.GetRemote().Clone())
func (b *baseTransporter) HealthCheck(ctx context.Context) (int64, error) {
remote := b.GetRemote().Clone()
return remote.HandShakeDuration.Milliseconds(), b.relayer.HealthCheck(ctx, remote)
}

View File

@@ -40,7 +40,7 @@ func newRelayClient(cfg *conf.Config) (RelayClient, error) {
type RelayServer interface {
ListenAndServe() error
Close() error
HealthCheck(ctx context.Context) error
HealthCheck(ctx context.Context) (int64, error) // latency in ms
}
func NewRelayServer(cfg *conf.Config, cmgr cmgr.Cmgr) (RelayServer, error) {

View File

@@ -103,11 +103,12 @@ func (s *Server) HandleHealthCheck(c echo.Context) error {
if relayLabel == "" {
return echo.NewHTTPError(http.StatusBadRequest, "relay_label is required")
}
if err := s.HealthCheck(c.Request().Context(), relayLabel); err != nil {
res := CommonResp{Message: err.Error()}
latency, err := s.HealthCheck(c.Request().Context(), relayLabel)
if err != nil {
res := HealthCheckResp{Message: err.Error(), ErrorCode: -1}
return c.JSON(http.StatusBadRequest, res)
}
return c.JSON(http.StatusOK, CommonResp{Message: "connect success"})
return c.JSON(http.StatusOK, HealthCheckResp{Message: "connect success", Latency: latency})
}
func (s *Server) CurrentConfig(c echo.Context) error {
@@ -158,3 +159,9 @@ func (s *Server) ListConnections(c echo.Context) error {
"AllCount": s.connMgr.CountConnection("active") + s.connMgr.CountConnection("closed"),
})
}
func (s *Server) ListRules(c echo.Context) error {
return c.Render(http.StatusOK, "rule_list.html", map[string]interface{}{
"Configs": s.cfg.RelayConfigs,
})
}

View File

@@ -102,6 +102,7 @@ func NewServer(
e.GET("/", s.index)
e.GET("/connections/", s.ListConnections)
e.GET("/rules/", s.ListRules)
e.GET("/clash_proxy_provider/", s.HandleClashProxyProvider)
// api group

View File

@@ -70,6 +70,13 @@
>Connections</a
>
</li>
<li>
<a
href="/rules/"
class="button is-info is-light"
>Rule List</a
>
</li>
<li>
<a
href="/api/v1/config/"

View File

@@ -0,0 +1,86 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="ehco web" />
<meta name="keywords" content="ehco-relay" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.1/css/bulma.min.css"
/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Rules</title>
</head>
<body>
<section class="section">
<div class="container">
<h1 class="title">Rules</h1>
<table class="table is-striped is-fullwidth">
<thead>
<tr>
<th>Label</th>
<th>Listen</th>
<th>Listen Type</th>
<th>Transport Type</th>
<th>Remote</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{range .Configs}}
<tr>
<td>{{.Label}}</td>
<td>{{.Listen}}</td>
<td>{{.ListenType}}</td>
<td>{{.TransportType}}</td>
<td>{{.GetTCPRemotes}}</td>
<td>
<button
class="button is-small is-primary health-check"
data-label="{{.Label}}"
onclick="checkHealth('{{.Label}}')"
>
Check Health
</button>
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</section>
<script>
function checkHealth(label) {
$.ajax({
url: "/api/v1/health_check/?relay_label=" + label,
method: "GET",
success: function (response) {
// Check if the response includes an error code
if (response.error_code === 0) {
// If no error, show success message with latency
alert(
"Health Check for " +
label +
": " +
response.msg + // Use 'msg' as per Go struct
" (Latency: " +
response.latency + // Ensure this matches the Go struct field name
"ms)"
);
} else {
// If error code is not 0, show error message
alert("Error for " + label + ": " + response.msg);
}
},
error: function (xhr) {
// Parse the response JSON in case of HTTP error
var response = JSON.parse(xhr.responseText);
alert("Error: " + response.msg); // Use 'msg' as per Go struct
},
});
}
</script>
</body>
</html>

View File

@@ -1,5 +1,7 @@
package web
type CommonResp struct {
Message string `json:"msg"`
type HealthCheckResp struct {
ErrorCode int `json:"error_code"` // code = 0 means success
Message string `json:"msg"`
Latency int64 `json:"latency"`
}