Repository navigation
Go: fix 'list services' - #16598
Go: fix 'list services'#16598
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughAdds a ChangesNATS Status Monitoring and Service Discovery
Estimated code review effort: 2 (Simple) | ~15 minutes Suggested labels: 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
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
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 winPreserve the original service id in
ListServices.GetServicestill matches/admin/services/:service_idagainstconfig["id"]fromserver.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 valueCombine identical switch cases.
ServerTypeAPI,ServerTypeIngestion, and the newServerTypeFileSyncercases 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 valueUnused
Stats()call.
n.nc.Stats()'s return value is discarded and has no side effect on connectionStatus(). 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 valueDrop the unused
n.nc.Stats()call.CheckStatus()already returnsn.nc.Status().String(), so theStats()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, nilreturn is overloaded for two different callers.The outer default now returns
nil, nilsoListServicescan skip these entries, butGetServiceDetailsis also called directly by the single-serviceGetServicehandler, which would now silently return a successful response with null data for an unsupportedservice_typeinstead 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
📒 Files selected for processing (5)
internal/admin/service.gointernal/admin/state.gointernal/engine/engine.gointernal/engine/nats/nats.gointernal/server/config.go
### 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]>
### 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]>
Summary