Skip to content

Go: fix nats and go command - #16828

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix538
Jul 11, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix538

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

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>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5d9b6e95-7656-4fbd-8d43-ae5758978e5f

📥 Commits

Reviewing files that changed from the base of the PR and between b8b7475 and b33a2e7.

📒 Files selected for processing (2)
  • internal/service/system.go
  • internal/service/system_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/system.go

📝 Walkthrough

Walkthrough

The change adds component-aware health and liveness endpoints, exposes them through new admin CLI commands, updates HTTP URL routing for non-API endpoints, adds system-setting helpers, and improves the NATS container healthcheck.

Changes

Health checks and admin access

Layer / File(s) Summary
Component health aggregation
internal/service/system.go, internal/service/system_test.go, docker/docker-compose-base.yml
Health aggregation now includes message queue status, while NATS uses nats-server --health-check and defaults its port to 4222.
Admin health and liveness endpoints
internal/admin/handler.go, internal/admin/router.go
The admin server replaces /health with /healthz, /, and /live; /healthz reports aggregated status and /live returns success.
Admin CLI command flow
internal/cli/*.go
LIVE and HEALTH commands are lexed, parsed, dispatched, and routed to non-API admin endpoints through auth-aware URL construction.

System setting utilities

Layer / File(s) Summary
System setting formatting and validation
internal/common/system_settings.go
Adds helpers for formatting settings, validating string, integer, boolean, and JSON values, and inferring data types from setting names.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant HTTPClient
  participant AdminServer
  participant HealthzHandler
  participant SystemService
  CLI->>HTTPClient: GET /healthz
  HTTPClient->>AdminServer: Route non-API request
  AdminServer->>HealthzHandler: Invoke Healthz
  HealthzHandler->>SystemService: GetComponentsHealthz
  SystemService-->>HealthzHandler: Component statuses
  HealthzHandler-->>CLI: HTTP 200 or HTTP 500
Loading

Possibly related PRs

Poem

A rabbit checks the queue with care,
Then hops through health routes in the air.
“LIVE!” says the CLI,
“HEALTH!” waves goodbye—
NATS is well, and settings fare!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the change, but it is too vague and underspecified to clearly describe the main update. Use a more specific title like "Improve NATS healthcheck and add admin live/health commands".
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required Summary section and clearly outlines the main changes, with a useful example of the new commands.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 11, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 11, 2026 06:12
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 11, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft July 11, 2026 06:13
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 11, 2026 06:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/common/system_settings.go (1)

27-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Make FormatSystemSetting unexported It’s only used by FormatSystemSettings in this package, so formatSystemSetting would reduce the public surface area.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/common/system_settings.go` around lines 27 - 34, Rename
FormatSystemSetting to formatSystemSetting and update its caller
FormatSystemSettings accordingly, keeping the helper unexported while preserving
its behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker/docker-compose-base.yml`:
- Around line 268-271: Replace the NATS healthcheck command with an HTTP probe
against /healthz, and configure the NATS server to enable monitoring on port
8222 using -m 8222 or --http_port 8222. Update the healthcheck test to verify
http://localhost:8222/healthz while preserving the existing interval, timeout,
and retries settings.

In `@internal/service/system.go`:
- Around line 366-378: The message queue health check dereferences a nil engine
before validating it. In the message queue callback passed to timedHealthCheck,
update the logic to check msgQueueEngine for nil before calling CheckStatus(),
returning the unhealthy error immediately when nil; otherwise evaluate the
connection status as before.

---

Nitpick comments:
In `@internal/common/system_settings.go`:
- Around line 27-34: Rename FormatSystemSetting to formatSystemSetting and
update its caller FormatSystemSettings accordingly, keeping the helper
unexported while preserving its behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4dff3be-d39a-493f-8ab6-f32bdff7f412

📥 Commits

Reviewing files that changed from the base of the PR and between 4060cd1 and b8b7475.

📒 Files selected for processing (12)
  • docker/docker-compose-base.yml
  • internal/admin/handler.go
  • internal/admin/router.go
  • internal/cli/admin_command.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/http_client.go
  • internal/cli/lexer.go
  • internal/cli/parser.go
  • internal/cli/types.go
  • internal/common/system_settings.go
  • internal/service/system.go

Comment on lines +268 to +271
test: ["CMD", "nats-server", "--health-check"]
interval: 10s
timeout: 10s
retries: 120
retries: 30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check NATS Docker image for health-check flag support and monitoring defaults.

# Check if the nats:2.14.2 image is available and inspect its entrypoint/cmd
docker image inspect nats:2.14.2 --format '{{json .Config.Entrypoint}} {{json .Config.Cmd}}' 2>/dev/null || echo "Image not available in sandbox"

# Search the compose file for any monitoring-related NATS flags
rg -n 'monitor|m 8222|health' docker/docker-compose-base.yml

# Check if there are other NATS config files that might enable monitoring
fd -e conf -e cfg -e toml . docker/ | xargs rg -l 'monitor' 2>/dev/null || echo "No monitoring config found"

Repository: infiniflow/ragflow

Length of output: 645


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the compose context around the NATS service.
sed -n '240,280p' docker/docker-compose-base.yml

# Search for any NATS-related port/monitoring exposure in the compose file.
rg -n '8222|monitor|nats-server|js -sd|health-check|healthcheck' docker/docker-compose-base.yml

# Look for repository docs or config that describe the NATS image/tag or healthcheck usage.
rg -n 'nats:2\.14\.2|--health-check|monitoring|8222' .

Repository: infiniflow/ragflow

Length of output: 50379


🌐 Web query:

NATS Server 2.14.2 --health-check command monitoring port 8222 --server --port documentation

💡 Result:

In NATS Server 2.14.2, health monitoring is performed through the /healthz HTTP endpoint, typically accessed via the configured monitoring port (defaulting to 8222) [1][2][3]. Monitoring Configuration To enable the monitoring HTTP server, you use the --http_port flag (or -m) followed by the desired port number [3][4][5]. While you mentioned --server and --port, note that: - The --port (or -p) flag is used to configure the NATS client connection port, which defaults to 4222 [6][5][7]. - There is no standard --server flag for configuring the monitoring port in the nats-server binary; monitoring is controlled via -m/--http_port or configuration files [4][5][7]. Health Check Usage Once the monitoring port is enabled (e.g., nats-server -m 8222), you can perform a health check by sending an HTTP request to the /healthz endpoint [1][3][4]: curl http://localhost:8222/healthz - A successful check returns a 200 OK status with a JSON response: {"status": "ok"} [1][2]. - If the server is unhealthy, it may return a 503 Service Unavailable status (e.g., if JetStream is not ready) [2]. Additional health check options include query parameters: - js-enabled-only=true: Ensures that JetStream is enabled and healthy; returns an error if not [1][3]. - js-server-only=true: Skips health checks for specific accounts, streams, and consumers [1][3]. For more advanced monitoring (including Nagios-compatible checks), the NATS CLI tool provides the nats server check command, which can monitor various aspects of the server, including connections, streams, and consumers [8].

Citations:


🌐 Web query:

nats-server "--health-check" monitoring endpoint standalone command help

💡 Result:

The NATS server provides a dedicated health check endpoint, /healthz, accessible via an HTTP monitoring server [1][2]. It does not have a single standalone command like nats-server --health-check to perform the check directly; instead, you enable the monitoring server and then query the endpoint using standard tools like curl [1][3]. To use the health check: 1. Enable the monitoring server by starting the nats-server with the monitoring port flag (e.g., -m 8222 or --http_port 8222) [1][2][4]. 2. Query the endpoint via HTTP [1][3]: curl http://localhost:8222/healthz The endpoint returns HTTP 200 (OK) if the server is healthy and able to accept connections, or an error code (typically 503) if it is unhealthy [1][2][3]. Advanced health checks can be performed by adding query parameters to the /healthz URL [1][3]: - JetStream readiness: Use js-enabled-only=true to verify JetStream is enabled [1][2]. - Specific resources: You can filter by account, stream, or consumer (e.g., ?stream=ORDERS&account=ORDERS) to check the status of specific JetStream entities [2][3]. If you prefer using a CLI tool specifically designed for NATS administration, the nats CLI provides server management commands that can inspect cluster and JetStream health [5][6]. For example: nats server check meta --expect= nats request jetstream-health --js-enabled [5][6]

Citations:


🌐 Web query:

"nats-server --health-check" nats docker healthcheck compose

💡 Result:

To implement a health check for a NATS server in Docker Compose, you should not use a command-line flag like --health-check, as no such native flag exists in the nats-server binary [1][2]. Instead, you should utilize the HTTP monitoring endpoint, specifically the /healthz path, which returns a 200 OK status when the server is ready to accept connections [1]. To configure this in your docker-compose.yml file, follow these steps: 1. Enable the HTTP monitoring port (default is 8222) in your NATS server configuration or via command-line arguments [1]. You can do this by adding -m 8222 to the NATS command [3]. 2. Add a healthcheck section to your service definition that uses a tool like wget or curl to query the /healthz endpoint [3][4]. Example Docker Compose configuration: services: nats: image: nats:latest command: -m 8222 ports: - "4222:4222" - "8222:8222" healthcheck: test: ["CMD", "wget", "-q", "--spider", "http://localhost:8222/healthz"] interval: 10s timeout: 5s retries: 3 start_period: 3s The /healthz endpoint is the authoritative way to verify readiness for client connections [5]. For more advanced health monitoring, such as checking JetStream status or cluster-wide health, you can use the NATS CLI (nats-io/natscli) command nats server report health or nats server check [6][7][8].

Citations:


🌐 Web query:

site:github.com/nats-io nats-server health-check docker image healthcheck

💡 Result:

To perform a health check on a NATS server running in a Docker container, you should use the /healthz HTTP endpoint, which is specifically designed for liveness and readiness probes [1][2][3]. To enable this, ensure that the NATS server's monitoring service is enabled (typically by exposing or configuring port 8222) [4][5]. Implementation Example: If you are using Docker healthchecks (e.g., in a Dockerfile or compose file), you can use a command like the following: HEALTHCHECK --interval=30s --timeout=5s --start-period=5s CMD curl -f http://localhost:8222/healthz || exit 1 [3] Endpoint Options: The /healthz endpoint supports various query parameters to provide more granular status information [1]: - /healthz: Basic check for server availability [1]. - /healthz?js-server-only=true: Checks only the server's health, excluding the status of JetStream streams and consumers (often useful for startup probes to avoid transient failures) [6]. - /healthz?current-cluster-size=N: Used for verifying cluster quorum readiness [1]. Important Considerations: - Monitoring Port: The /healthz endpoint is served by the NATS monitoring service. Ensure that the monitor port (default 8222) is enabled in your NATS configuration [4][5]. - Readiness vs. Liveness: While /healthz is commonly used for both, use caution when checking complex subsystems like JetStream in a startup probe [2][6]. As noted in NATS community discussions, if your probe includes deep checks (like verifying all JetStream assets), a node with a single "broken" consumer might fail its startup probe indefinitely [6]. Using the js-server-only=true parameter is a recommended strategy to ensure the node becomes ready to accept traffic even if individual streams are still converging [6].

Citations:


Use the NATS HTTP health endpoint instead. nats-server --health-check isn’t a valid probe here; enable monitoring (-m 8222 / --http_port 8222) and point the healthcheck at http://localhost:8222/healthz instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/docker-compose-base.yml` around lines 268 - 271, Replace the NATS
healthcheck command with an HTTP probe against /healthz, and configure the NATS
server to enable monitoring on port 8222 using -m 8222 or --http_port 8222.
Update the healthcheck test to verify http://localhost:8222/healthz while
preserving the existing interval, timeout, and retries settings.

Comment thread internal/service/system.go Resolved
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
@JinHai-CN
JinHai-CN merged commit bdef878 into infiniflow:main Jul 11, 2026
4 checks passed
This was referenced Jul 14, 2026
xugangqiang added a commit to xugangqiang/ragflow that referenced this pull request Sep 17, 2026
…he integration job

- Exclude internal/service/nlp from the job's package list: its DatasetNav
  integration test compiles only against source fixes (Infinity 3013/3052,
  nav available_int, doc_ids_kwd) that are intentionally out of scope for this
  CI-enabling PR. The test file is kept compilable (7-arg NavService.Search
  call fixed) but the package is left out rather than patched.
- Tag system_test.go with //go:build !integration so the pre-existing unit
  test TestSystemServiceHealthzReportsUnhealthyDependencies (added in infiniflow#16828)
  is not built into the integration run, where the doc-engine global is a
  nil-backed interface and GetComponentsHealthz panics. It still runs in the
  unit tier where dependencies are truly uninitialized. This preserves the
  other unit tests and TestWikiKeywordFilter_Integration in the package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant