Skip to content

Go: fix 'list services' - #16598

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix515
Jul 3, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix515

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

Summary

RAGFlow(admin)> list services;
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| extra                                                                       | host      | id | name          | port | service_type  | status    |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| map[database:1 mq_type:redis password:infini_rag_flow]                      | localhost | 0  | redis         | 6379 | message_queue | alive     |
| map[password:infini_rag_flow retrieval_type:elasticsearch username:elastic] | localhost | 1  | elasticsearch | 1200 | retrieval     | alive     |
|                                                                             | 0.0.0.0   | 2  | nats          | 4222 | message_queue | CONNECTED |
| map[meta_type:mysql password:infini_rag_flow username:root]                 | localhost | 3  | mysql         | 3306 | meta_data     | alive     |
| map[password:infini_rag_flow store_type:minio user:rag_flow]                | localhost | 4  | minio         | 9000 | file_store    | alive     |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+

@coderabbitai

coderabbitai Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a CheckStatus() method to the MessageQueue interface and its NATS implementation, integrates NATS status checks into admin service discovery, changes default/error handling for unsupported service types in GetServiceDetails/ListServices, sets service_type for NATS config, and adds file-syncer handling in server state updates.

Changes

NATS Status Monitoring and Service Discovery

Layer / File(s) Summary
MessageQueue CheckStatus interface and NATS implementation
internal/engine/engine.go, internal/engine/nats/nats.go
Adds CheckStatus() string to the MessageQueue interface and implements it in NatsEngine via connection stats/status.
Admin service details and listing use NATS status
internal/admin/service.go
Adds checkNatsAlive, extends GetServiceDetails message_queue handling to support nats, changes default case to return nil, nil, updates ListServices to conditionally append non-nil details and reassign ids in a final pass, and tweaks GenerateUserAPIToken error assignment.
Config and file-syncer state wiring
internal/server/config.go, internal/admin/state.go
Sets service_type to "message_queue" for NATS config entries and adds a ServerTypeFileSyncer case to UpdateServerInfo.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested labels: 🐞 bug

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AdminService
  participant GetServiceDetails
  participant NatsEngine

  Client->>AdminService: ListServices()
  AdminService->>GetServiceDetails: GetServiceDetails(service)
  GetServiceDetails->>NatsEngine: checkNatsAlive() -> CheckStatus()
  NatsEngine-->>GetServiceDetails: status string
  GetServiceDetails-->>AdminService: detail or nil
  AdminService->>AdminService: append if non-nil, reassign ids
  AdminService-->>Client: results list
Loading

Poem

Hop hop, I check the NATS connection tight,
Statuses gathered, ids set just right 🐇
No more phantom entries in the list,
File-syncers stored, none get missed,
A carrot for every service in sight! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title is concise and clearly points to the main 'list services' fix.
Description check ✅ Passed The description includes the required Summary section and shows the intended list-services behavior with an example.

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 3, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 3, 2026 06:48
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 3, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft July 3, 2026 06:49
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 3, 2026 06:50

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/admin/service.go (1)

1027-1069: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve the original service id in ListServices. GetService still matches /admin/services/:service_id against config["id"] from server.GetAllConfigs(), but this loop rewrites every response item to a 0-based slice index after filtering and appending. That makes IDs from the list endpoint point at the wrong service or 404; keep the config id and use a separate list index if needed.

🤖 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/admin/service.go` around lines 1027 - 1069, The ListServices
response is overwriting each service’s original id with a 0-based slice index,
which breaks the id used by GetService and /admin/services/:service_id. In
internal/admin/service.go, keep the existing configDict["id"] from GetAllConfigs
when building results and avoid replacing it in the final loop; if you need a
display order, store that in a separate field instead of mutating id for the
entries appended from serviceDetail and serverList.
🧹 Nitpick comments (4)
internal/admin/state.go (1)

45-61: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Combine identical switch cases.

ServerTypeAPI, ServerTypeIngestion, and the new ServerTypeFileSyncer cases all execute identical logic. Consider merging them into a single case.

♻️ Proposed refactor
 	switch status.ServerType {
-	case common.ServerTypeAPI:
-		s.mu.Lock()
-		defer s.mu.Unlock()
-		s.servers[serverName] = status
-		return
-	case common.ServerTypeIngestion:
-		s.mu.Lock()
-		defer s.mu.Unlock()
-		s.servers[serverName] = status
-		return
-	case common.ServerTypeFileSyncer:
+	case common.ServerTypeAPI, common.ServerTypeIngestion, common.ServerTypeFileSyncer:
 		s.mu.Lock()
 		defer s.mu.Unlock()
 		s.servers[serverName] = status
 		return
 	}
🤖 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/admin/state.go` around lines 45 - 61, The switch in the state update
path handles ServerTypeAPI, ServerTypeIngestion, and ServerTypeFileSyncer with
identical logic, so merge them into a single case in the relevant status update
method in state.go. Keep the existing lock-and-store behavior on the shared
path, and make sure the combined case still updates s.servers[serverName] with
status before returning.
internal/engine/nats/nats.go (2)

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

Unused Stats() call.

n.nc.Stats()'s return value is discarded and has no side effect on connection Status(). This line does nothing useful.

♻️ Proposed cleanup
 func (n *NatsEngine) CheckStatus() string {
-	n.nc.Stats()
 	return n.nc.Status().String()
 }
🤖 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/engine/nats/nats.go` at line 226, The Stats() call in the NATS
connection handling is unused and has no effect, so remove the discarded
n.nc.Stats() invocation from the relevant nats connection code. Keep the
surrounding Status()-based logic intact and only eliminate the no-op call in the
n.nc/Stats path.

225-228: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Drop the unused n.nc.Stats() call. CheckStatus() already returns n.nc.Status().String(), so the Stats() call is dead code here.

🤖 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/engine/nats/nats.go` around lines 225 - 228, Remove the unused stats
call from NatsEngine.CheckStatus, since the method already returns
n.nc.Status().String() and n.nc.Stats() has no effect. Update CheckStatus in the
NatsEngine type to return the status string directly and keep the method focused
on the existing status query.
internal/admin/service.go (1)

1078-1117: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

nil, nil return is overloaded for two different callers.

The outer default now returns nil, nil so ListServices can skip these entries, but GetServiceDetails is also called directly by the single-service GetService handler, which would now silently return a successful response with null data for an unsupported service_type instead of a descriptive status. Consider a dedicated signal (e.g., a sentinel error or boolean) for "not applicable to list" separate from "unsupported service type" so single-service lookups still get an informative response.

🤖 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/admin/service.go` around lines 1078 - 1117, The default nil, nil
return in GetServiceDetails is being used for both “skip in ListServices” and
“unsupported service type” in GetService, which hides the failure. Update
GetServiceDetails in Service to distinguish these cases, using a dedicated
sentinel error or explicit flag for the list-only skip path while keeping
unsupported types informative for single-service lookups. Then adjust the
callers in ListServices and GetService to handle that signal appropriately so
ListServices can omit entries without causing GetService to return a successful
null response.
🤖 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.

Outside diff comments:
In `@internal/admin/service.go`:
- Around line 1027-1069: The ListServices response is overwriting each service’s
original id with a 0-based slice index, which breaks the id used by GetService
and /admin/services/:service_id. In internal/admin/service.go, keep the existing
configDict["id"] from GetAllConfigs when building results and avoid replacing it
in the final loop; if you need a display order, store that in a separate field
instead of mutating id for the entries appended from serviceDetail and
serverList.

---

Nitpick comments:
In `@internal/admin/service.go`:
- Around line 1078-1117: The default nil, nil return in GetServiceDetails is
being used for both “skip in ListServices” and “unsupported service type” in
GetService, which hides the failure. Update GetServiceDetails in Service to
distinguish these cases, using a dedicated sentinel error or explicit flag for
the list-only skip path while keeping unsupported types informative for
single-service lookups. Then adjust the callers in ListServices and GetService
to handle that signal appropriately so ListServices can omit entries without
causing GetService to return a successful null response.

In `@internal/admin/state.go`:
- Around line 45-61: The switch in the state update path handles ServerTypeAPI,
ServerTypeIngestion, and ServerTypeFileSyncer with identical logic, so merge
them into a single case in the relevant status update method in state.go. Keep
the existing lock-and-store behavior on the shared path, and make sure the
combined case still updates s.servers[serverName] with status before returning.

In `@internal/engine/nats/nats.go`:
- Line 226: The Stats() call in the NATS connection handling is unused and has
no effect, so remove the discarded n.nc.Stats() invocation from the relevant
nats connection code. Keep the surrounding Status()-based logic intact and only
eliminate the no-op call in the n.nc/Stats path.
- Around line 225-228: Remove the unused stats call from NatsEngine.CheckStatus,
since the method already returns n.nc.Status().String() and n.nc.Stats() has no
effect. Update CheckStatus in the NatsEngine type to return the status string
directly and keep the method focused on the existing status query.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4a87997-094a-4d01-a1bc-96ad22cd2e2b

📥 Commits

Reviewing files that changed from the base of the PR and between 994b603 and 6e93fb8.

📒 Files selected for processing (5)
  • internal/admin/service.go
  • internal/admin/state.go
  • internal/engine/engine.go
  • internal/engine/nats/nats.go
  • internal/server/config.go

@JinHai-CN
JinHai-CN merged commit a4c370c into infiniflow:main Jul 3, 2026
12 of 15 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
### Summary

```
RAGFlow(admin)> list services;
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| extra                                                                       | host      | id | name          | port | service_type  | status    |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| map[database:1 mq_type:redis password:infini_rag_flow]                      | localhost | 0  | redis         | 6379 | message_queue | alive     |
| map[password:infini_rag_flow retrieval_type:elasticsearch username:elastic] | localhost | 1  | elasticsearch | 1200 | retrieval     | alive     |
|                                                                             | 0.0.0.0   | 2  | nats          | 4222 | message_queue | CONNECTED |
| map[meta_type:mysql password:infini_rag_flow username:root]                 | localhost | 3  | mysql         | 3306 | meta_data     | alive     |
| map[password:infini_rag_flow store_type:minio user:rag_flow]                | localhost | 4  | minio         | 9000 | file_store    | alive     |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+

```

Signed-off-by: Jin Hai <[email protected]>
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
### Summary

```
RAGFlow(admin)> list services;
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| extra                                                                       | host      | id | name          | port | service_type  | status    |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+
| map[database:1 mq_type:redis password:infini_rag_flow]                      | localhost | 0  | redis         | 6379 | message_queue | alive     |
| map[password:infini_rag_flow retrieval_type:elasticsearch username:elastic] | localhost | 1  | elasticsearch | 1200 | retrieval     | alive     |
|                                                                             | 0.0.0.0   | 2  | nats          | 4222 | message_queue | CONNECTED |
| map[meta_type:mysql password:infini_rag_flow username:root]                 | localhost | 3  | mysql         | 3306 | meta_data     | alive     |
| map[password:infini_rag_flow store_type:minio user:rag_flow]                | localhost | 4  | minio         | 9000 | file_store    | alive     |
+-----------------------------------------------------------------------------+-----------+----+---------------+------+---------------+-----------+

```

Signed-off-by: Jin Hai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant