Go: fix nats and go command (#16828)

### Summary
1. update docker compose file to start NATS healthy
2. Add two commands
```
RAGFlow(admin)> live;
SUCCESS
RAGFlow(admin)> health;
+---------------+-------+
| field         | value |
+---------------+-------+
| storage       | ok    |
| message_queue | ok    |
| status        | ok    |
| db            | ok    |
| redis         | ok    |
| doc_engine    | ok    |
+---------------+-------+
```

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-11 19:37:57 +08:00
committed by GitHub
parent 156a11c56b
commit bdef878821
13 changed files with 123 additions and 30 deletions

View File

@@ -87,6 +87,24 @@ func (c *CLI) AdminPingCacheCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, fmt.Sprintf("ping cache"))
}
// AdminLiveServerCommand GET /live
func (c *CLI) AdminLiveServerCommand(cmd *Command) (ResponseIf, error) {
resp, err := c.AdminServerClient.Request("GET", "/live", "none", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show live server: %w", err)
}
return HandleSimpleResponse(resp, fmt.Sprintf("show live server"))
}
// AdminHealthServerCommand GET /healthz
func (c *CLI) AdminHealthServerCommand(cmd *Command) (ResponseIf, error) {
resp, err := c.AdminServerClient.Request("GET", "/healthz", "none", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show health server: %w", err)
}
return HandleCommonDataResponse(resp, fmt.Sprintf("show health server"))
}
// AdminShowVersionCommand show RAGFlow admin version
func (c *CLI) AdminShowVersionCommand(cmd *Command) (ResponseIf, error) {
resp, err := c.AdminServerClient.Request("GET", "/admin/version", "web", nil, nil)

View File

@@ -97,6 +97,18 @@ func (p *Parser) parseAdminPingServer() (*Command, error) {
return cmd, nil
}
func (p *Parser) parseAdminLiveServer() (*Command, error) {
p.nextToken() // consume LIVE
cmd := NewCommand("admin_live_server")
return cmd, nil
}
func (p *Parser) parseAdminHealthServer() (*Command, error) {
p.nextToken() // consume HEALTH
cmd := NewCommand("admin_health_server")
return cmd, nil
}
// endregion
// region LIST commands

View File

@@ -51,6 +51,10 @@ func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
return c.AdminPingCacheCommand(cmd)
case "admin_ping_server":
return c.PingServerByCommand(cmd)
case "admin_live_server":
return c.AdminLiveServerCommand(cmd)
case "admin_health_server":
return c.AdminHealthServerCommand(cmd)
case "benchmark":
return c.RunBenchmark(cmd)
case "admin_list_services":

View File

@@ -67,12 +67,19 @@ func (c *HTTPClient) APIBase() string {
// NonAPIBase returns the non-API base URL
func (c *HTTPClient) NonAPIBase() string {
return fmt.Sprintf("%s:%d/%s", c.Host, c.Port, c.APIVersion)
return fmt.Sprintf("%s:%d", c.Host, c.Port)
}
// BuildURL builds the full URL for a given path
func (c *HTTPClient) BuildURL(path string) string {
base := c.APIBase()
func (c *HTTPClient) BuildURL(path string, authKind string) string {
var base string
if authKind == "none" {
base = c.NonAPIBase()
} else {
base = c.APIBase()
}
if c.VerifySSL {
return fmt.Sprintf("https://%s%s", base, path)
}
@@ -126,7 +133,7 @@ func (c *HTTPClient) Request(method, path string, authKind string, headers map[s
return nil, fmt.Errorf("HTTP Client is nil")
}
url := c.BuildURL(path)
url := c.BuildURL(path, authKind)
mergedHeaders := c.Headers(authKind, headers)
var body io.Reader
@@ -196,7 +203,7 @@ func (c *HTTPClient) RequestWithIterations(method, path string, authKind string,
return response, nil
}
url := c.BuildURL(path)
url := c.BuildURL(path, authKind)
mergedHeaders := c.Headers(authKind, headers)
var body io.Reader
@@ -278,7 +285,7 @@ func (c *HTTPClient) RequestJSON(method, path string, authKind string, headers m
// UploadMultipart uploads data using multipart/form-data
func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Reader) error {
url := c.BuildURL(path)
url := c.BuildURL(path, "api")
req, err := http.NewRequest("POST", url, body)
if err != nil {
@@ -322,7 +329,7 @@ func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Re
// RequestStream makes an HTTP request for SSE streaming and returns the response body reader
func (c *HTTPClient) RequestStream(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (io.ReadCloser, error) {
url := c.BuildURL(path)
url := c.BuildURL(path, authKind)
mergedHeaders := c.Headers(authKind, headers)
var body io.Reader

View File

@@ -227,6 +227,10 @@ func (l *Lexer) lookupIdent(ident string) Token {
return Token{Type: TokenAPI, Value: ident}
case "ADD":
return Token{Type: TokenAdd, Value: ident}
case "LIVE":
return Token{Type: TokenLive, Value: ident}
case "HEALTH":
return Token{Type: TokenHealth, Value: ident}
case "HOST":
return Token{Type: TokenHost, Value: ident}
case "DELETE":

View File

@@ -86,6 +86,10 @@ func (p *Parser) parseAdminCommand() (*Command, error) {
return p.parseAdminLogout()
case TokenPing:
return p.parseAdminPingServer()
case TokenLive:
return p.parseAdminLiveServer()
case TokenHealth:
return p.parseAdminHealthServer()
case TokenList:
return p.parseAdminListCommands()
case TokenShow:

View File

@@ -45,6 +45,8 @@ const (
TokenServer
TokenAPI
TokenAdd
TokenLive
TokenHealth
TokenHost
TokenDelete
TokenPassword