Skip to content

feat[Go]: implement delete/ rebuild/ listlog api for connector#15300

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:main
May 28, 2026
Merged

feat[Go]: implement delete/ rebuild/ listlog api for connector#15300
JinHai-CN merged 2 commits into
infiniflow:mainfrom
Haruko386:main

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

implement delete, rebuild api for connector

Type of change

  • New Feature (non-breaking change which adds functionality)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 27, 2026
@Haruko386 Haruko386 added ci Continue Integration and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 27, 2026
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds SyncLogs task_type, DAO methods to cancel/list/rebuild connector logs and documents, service helpers and workflows for delete/rebuild (including engine chunk deletion), handler endpoints for list/delete/rebuild with tests, and route registrations.

Changes

Connector Delete and Rebuild Lifecycle Operations

Layer / File(s) Summary
Data Model: SyncLogs TaskType Field
internal/entity/connector.go
Adds TaskType to persisted SyncLogs and the ConnectorSyncLog API projection; updates JSON serialization to include task_type.
Data Access: Connector Rebuild and Cancellation
internal/dao/connector.go
Imports time. Adds CancelRunningOrScheduledLogs, ListDocumentsByKBAndSourceType, transactional RebuildConnector (delete logs/tasks/file2document/files?, documents, update KB counters, set connector scheduled), task-type constants, createRebuildSyncLog, and ListLogsByConnectorID with pagination.
Service Layer: Authorization and Error Handling
internal/service/connector.go
Imports document engine accessor, adds Rebuild() placeholder, canAccessConnector and cancelConnectorTasks helpers, and updates GetConnector signature/error handling.
Service Layer: Delete and Rebuild Workflows
internal/service/connector.go
Implements DeleteConnector (validate, authorize, cancel tasks, delete connector) and RebuildConnector (validate, authorize, list documents, best-effort delete chunks via engine, delegate to DAO). Adds ListLog implementation with pagination and auth.
Handler Layer: Endpoints and Service Contract
internal/handler/connector.go
Updates connectorService interface signatures, adds ListLogs, DeleteConnector, and RebuildConnector handlers; parses/validates pagination and kb_id, extracts user, calls service, returns standardized JSON.
Routing: REST Endpoint Registration
internal/router/router.go
Registers GET /:connector_id/logs, DELETE /:connector_id, POST /:connector_id/rebuild under /api/v1/connectors and GET /:connector_id, POST /:connector_id/rebuild under /v1/connector.
Tests: Handler Test Coverage
internal/handler/connector_test.go
Extends fake connector service with logs/total and stubs for ListLog, DeleteConnector, RebuildConnector; updates TestConnectorHandlerListLogs; adds TestConnectorHandlerDeleteConnector.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Handler
  participant Service
  participant ConnectorDAO
  participant Engine

  Client->>Handler: POST /connectors/:id/rebuild { kb_id }
  Handler->>Service: RebuildConnector(connectorID, userID, kbID)
  Service->>ConnectorDAO: ListDocumentsByKBAndSourceType(kbID, sourceType)
  ConnectorDAO-->>Service: documents[]
  Service->>Engine: DeleteChunks(ragflow_<tenantID>, documents) 
  Engine-->>Service: (ignored errors)
  Service->>ConnectorDAO: RebuildConnector(connector, kbID, documents)
  ConnectorDAO-->>Service: success
  Service-->>Handler: (true, CodeSuccess, nil)
  Handler-->>Client: 200 { code, data: true }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • infiniflow/ragflow#15259: Both PRs modify the connector "get" flow by adjusting GetConnector(connectorID, userID) signatures and tenant-based access control behavior across handler, service, and routing layers.

Suggested labels

size:L

Poem

🐰 A rabbit hops through connectors with glee,
Cancels logs, rebuilds KBs with a spree,
Tasks renamed, chunks swept from the yard,
Sync logs queued and counters trimmed hard—
Reindex complete, the search springs free!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description addresses the problem and specifies the type of change, but it omits the ListLog API implementation mentioned in commit messages and PR objectives. Consider updating the description to mention the ListLog API implementation in addition to delete and rebuild, ensuring complete representation of all new features.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: implementing delete, rebuild, and listlog APIs for connectors, which matches the core functionality added across all modified files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@Haruko386 Haruko386 added the size:L This PR changes 100-499 lines, ignoring generated files. label May 27, 2026
@Haruko386 Haruko386 marked this pull request as draft May 27, 2026 10:02
@Haruko386 Haruko386 marked this pull request as ready for review May 27, 2026 10:02

@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: 6

🧹 Nitpick comments (1)
internal/handler/connector_test.go (1)

115-171: ⚡ Quick win

Add handler coverage for RebuildConnector too.

The rebuild endpoint introduces its own JSON binding and validation branches, but this file only exercises delete. A small table test for success, missing kb_id, blank kb_id, and service failure would catch most regressions 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/handler/connector_test.go` around lines 115 - 171, Add table-driven
tests in the same test file to cover ConnectorHandler.RebuildConnector: create
tests for success, missing kb_id (no kb_id field in JSON), blank kb_id (empty
string), and service failure (fakeConnectorService returning an error/code). For
each case instantiate ConnectorHandler with the appropriate
fakeConnectorService, register a route that sets the user context and calls
h.RebuildConnector, send a request with the JSON body per case (including
content-type), assert HTTP 200 and then unmarshal the response JSON and verify
the "code", "data" and "message" fields match expected values for each scenario;
reuse the existing test patterns (resp recorder, json.Unmarshal and comparisons)
used in TestConnectorHandlerDeleteConnector to keep style consistent.
🤖 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 `@internal/handler/connector_test.go`:
- Around line 24-27: The fakeConnectorService currently implements Rebuild()
which causes a mismatch because ConnectorHandler.connectorService expects
RebuildConnector; replace or add the correct stub by implementing a
RebuildConnector method on fakeConnectorService with the same signature expected
by the real interface (match parameters/return types used by ConnectorHandler),
and remove or deprecate the Rebuild method; ensure tt.service (used in tests) is
the fakeConnectorService so ConnectorHandler{connectorService: tt.service}
compiles.

In `@internal/handler/connector.go`:
- Around line 180-213: Add or correct the Swagger `@Router` annotations so they
match the real registered routes: add an `@Router` entry for DeleteConnector using
the route template (e.g. "/connector/{connector_id} [delete]") and update
RebuildConnector's `@Router` to use the same template style (e.g.
"/connector/{connector_id}/rebuild [post]"); edit the annotations above the
functions DeleteConnector and RebuildConnector to replace the incorrect or
missing `@Router` lines so generated docs reflect the actual endpoints.

In `@internal/router/router.go`:
- Around line 414-419: The legacy connector route group
(authorized.Group("/v1/connector")) is missing the DELETE route for connector
deletion; add a DELETE route mapping "/:connector_id" to the existing handler
method (r.connectorHandler.DeleteConnector) so the legacy namespace exposes the
same delete API as the newer namespace alongside ListConnectors, GetConnector
and RebuildConnector.

In `@internal/service/connector.go`:
- Around line 221-249: The RebuildConnector flow currently only authorizes
access to the connector but never ensures the supplied kbID is actually linked
to that connector; add a validation after loading connector (and after
canAccessConnector) that the kbID belongs to the connector (e.g., call a DAO
method such as connectorDAO.HasConnectorKBLink(connector.ID, kbID) or
connectorDAO.GetConnectorKBLink/connector2kb lookup) and also verify the KB's
tenant/owner matches connector.TenantID if applicable; if the kbID is not linked
or tenant mismatches, return false with common.CodeAuthenticationError (or
CodeDataError) and a clear error so connectorDAO.RebuildConnector and
connectorDAO.ListDocumentsByKBAndSourceType cannot operate on unrelated KBs.
- Around line 247-264: deleteConnectorDocumentChunks currently removes search
chunks out-of-band (called before the DB transaction), uses
context.Background(), ignores errors and can leave index/db inconsistent if the
DB operation fails; change the flow so chunk deletion is coordinated with the DB
transaction: instead of calling deleteConnectorDocumentChunks before
s.connectorDAO.RebuildConnector, either move the chunk deletion into the same
transactional operation (e.g., add chunk removal to
connectorDAO.RebuildConnector) or have deleteConnectorDocumentChunks return an
error and be invoked after a successful DB commit; also stop using
context.Background() — accept/passthrough the caller context (or create a
cancellable context tied to the request), check engine.Get() != nil and
propagate and handle DeleteChunks errors so failures cause the overall operation
to rollback/return an error rather than silently dropping chunks.
- Around line 44-47: The exported ConnectorService.Rebuild method currently
panics; either remove it if unused or implement it to perform the service-level
rebuild without panicking: locate ConnectorService.Rebuild and replace the panic
with the actual rebuild sequence (e.g., call the underlying components such as
s.repo.Rebuild(), s.store.Rebuild() or s.cache.Clear()/Reload() as appropriate),
handle and log errors via s.logger (or return them if you change the signature),
and ensure the method is safe for concurrent use and does not call panic. Use
the existing service fields (e.g., s.repo, s.store, s.cache, s.logger) to
perform the work and return gracefully or surface errors rather than panicking.

---

Nitpick comments:
In `@internal/handler/connector_test.go`:
- Around line 115-171: Add table-driven tests in the same test file to cover
ConnectorHandler.RebuildConnector: create tests for success, missing kb_id (no
kb_id field in JSON), blank kb_id (empty string), and service failure
(fakeConnectorService returning an error/code). For each case instantiate
ConnectorHandler with the appropriate fakeConnectorService, register a route
that sets the user context and calls h.RebuildConnector, send a request with the
JSON body per case (including content-type), assert HTTP 200 and then unmarshal
the response JSON and verify the "code", "data" and "message" fields match
expected values for each scenario; reuse the existing test patterns (resp
recorder, json.Unmarshal and comparisons) used in
TestConnectorHandlerDeleteConnector to keep style consistent.
🪄 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: bfb738c0-6ef1-4973-b8e4-5e017189b887

📥 Commits

Reviewing files that changed from the base of the PR and between 129e1e3 and aa724a3.

📒 Files selected for processing (6)
  • internal/dao/connector.go
  • internal/entity/connector.go
  • internal/handler/connector.go
  • internal/handler/connector_test.go
  • internal/router/router.go
  • internal/service/connector.go

Comment thread internal/handler/connector_test.go Outdated
Comment on lines +180 to +213
// DeleteConnector delete connector
// @Description Detele Connector
// @Tags connector
// @Accept json
// @Produce json
func (h *ConnectorHandler) DeleteConnector(c *gin.Context) {
user, errorCode, errorMessage := GetUser(c)
if errorCode != common.CodeSuccess {
jsonError(c, errorCode, errorMessage)
return
}

ok, code, err := h.connectorService.DeleteConnector(c.Param("connector_id"), user.ID)
if err != nil {
jsonError(c, code, err.Error())
return
}

c.JSON(http.StatusOK, gin.H{
"code": common.CodeSuccess,
"data": ok,
"message": "success",
})
}

// RebuildConnector rebuild connector
// @Summary Rebuild Connector
// @Description Trigger a rebuild for an accessible connector and knowledge base
// @Tags connector
// @Accept json
// @Produce json
// @Success 200 {object} map[string]interface{}
// @Router /connector/:connector_id/rebuild [post]
func (h *ConnectorHandler) RebuildConnector(c *gin.Context) {

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the Swagger annotations for the new endpoints.

DeleteConnector is missing an @Router entry, and RebuildConnector documents /connector/:connector_id/rebuild instead of the registered route template. The generated API docs won't match the real endpoints.

🤖 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/handler/connector.go` around lines 180 - 213, Add or correct the
Swagger `@Router` annotations so they match the real registered routes: add an
`@Router` entry for DeleteConnector using the route template (e.g.
"/connector/{connector_id} [delete]") and update RebuildConnector's `@Router` to
use the same template style (e.g. "/connector/{connector_id}/rebuild [post]");
edit the annotations above the functions DeleteConnector and RebuildConnector to
replace the incorrect or missing `@Router` lines so generated docs reflect the
actual endpoints.

Comment thread internal/router/router.go
Comment on lines 414 to 419
connector := authorized.Group("/v1/connector")
{
connector.GET("/list", r.connectorHandler.ListConnectors)
connector.GET("/:connector_id", r.connectorHandler.GetConnector)
connector.POST("/:connector_id/rebuild", r.connectorHandler.RebuildConnector)
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Expose delete on the legacy /v1/connector group too.

GetConnector and RebuildConnector are available on both connector namespaces, but DELETE /v1/connector/:connector_id is missing here. Clients still using the legacy route won't be able to use the new delete API.

Suggested route addition
 		connector.GET("/list", r.connectorHandler.ListConnectors)
 		connector.GET("/:connector_id", r.connectorHandler.GetConnector)
+		connector.DELETE("/:connector_id", r.connectorHandler.DeleteConnector)
 		connector.POST("/:connector_id/rebuild", r.connectorHandler.RebuildConnector)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
connector := authorized.Group("/v1/connector")
{
connector.GET("/list", r.connectorHandler.ListConnectors)
connector.GET("/:connector_id", r.connectorHandler.GetConnector)
connector.POST("/:connector_id/rebuild", r.connectorHandler.RebuildConnector)
}
connector := authorized.Group("/v1/connector")
{
connector.GET("/list", r.connectorHandler.ListConnectors)
connector.GET("/:connector_id", r.connectorHandler.GetConnector)
connector.DELETE("/:connector_id", r.connectorHandler.DeleteConnector)
connector.POST("/:connector_id/rebuild", r.connectorHandler.RebuildConnector)
}
🤖 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/router/router.go` around lines 414 - 419, The legacy connector route
group (authorized.Group("/v1/connector")) is missing the DELETE route for
connector deletion; add a DELETE route mapping "/:connector_id" to the existing
handler method (r.connectorHandler.DeleteConnector) so the legacy namespace
exposes the same delete API as the newer namespace alongside ListConnectors,
GetConnector and RebuildConnector.

Comment on lines +44 to +47
func (s *ConnectorService) Rebuild() {
//TODO implement me
panic("implement me")
}

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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Remove or implement Rebuild() before merge.

This exported method will panic the server on any call path.

Possible fix
-func (s *ConnectorService) Rebuild() {
-	//TODO implement me
-	panic("implement me")
-}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func (s *ConnectorService) Rebuild() {
//TODO implement me
panic("implement me")
}
🤖 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/service/connector.go` around lines 44 - 47, The exported
ConnectorService.Rebuild method currently panics; either remove it if unused or
implement it to perform the service-level rebuild without panicking: locate
ConnectorService.Rebuild and replace the panic with the actual rebuild sequence
(e.g., call the underlying components such as s.repo.Rebuild(),
s.store.Rebuild() or s.cache.Clear()/Reload() as appropriate), handle and log
errors via s.logger (or return them if you change the signature), and ensure the
method is safe for concurrent use and does not call panic. Use the existing
service fields (e.g., s.repo, s.store, s.cache, s.logger) to perform the work
and return gracefully or surface errors rather than panicking.

Comment on lines +221 to +249
func (s *ConnectorService) RebuildConnector(connectorID, userID, kbID string) (bool, common.ErrorCode, error) {
if connectorID == "" {
return false, common.CodeDataError, fmt.Errorf("connector_id is required")
}
if kbID == "" {
return false, common.CodeArgumentError, fmt.Errorf("required argument is missing: kb_id")
}

connector, err := s.connectorDAO.GetByID(connectorID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return false, common.CodeDataError, fmt.Errorf("Can't find this Connector!")
}
return false, common.CodeServerError, err
}

if !s.canAccessConnector(connector, userID) {
return false, common.CodeAuthenticationError, fmt.Errorf("No authorization.")
}

sourceType := fmt.Sprintf("%s/%s", connector.Source, connector.ID)
documents, err := s.connectorDAO.ListDocumentsByKBAndSourceType(kbID, sourceType)
if err != nil {
return false, common.CodeServerError, err
}

s.deleteConnectorDocumentChunks(connector.TenantID, kbID, documents)

if err := s.connectorDAO.RebuildConnector(connector, kbID, documents); err != nil {

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.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Validate that kb_id is actually linked to this connector.

This flow only authorizes the connector. A caller can pass any kb_id, and the DAO then updates knowledgebase by that raw ID and creates rebuild logs for the pair without checking connector2kb or KB ownership. That opens the door to mutating unrelated datasets if an ID is known.

🤖 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/service/connector.go` around lines 221 - 249, The RebuildConnector
flow currently only authorizes access to the connector but never ensures the
supplied kbID is actually linked to that connector; add a validation after
loading connector (and after canAccessConnector) that the kbID belongs to the
connector (e.g., call a DAO method such as
connectorDAO.HasConnectorKBLink(connector.ID, kbID) or
connectorDAO.GetConnectorKBLink/connector2kb lookup) and also verify the KB's
tenant/owner matches connector.TenantID if applicable; if the kbID is not linked
or tenant mismatches, return false with common.CodeAuthenticationError (or
CodeDataError) and a clear error so connectorDAO.RebuildConnector and
connectorDAO.ListDocumentsByKBAndSourceType cannot operate on unrelated KBs.

Comment on lines +247 to +264
s.deleteConnectorDocumentChunks(connector.TenantID, kbID, documents)

if err := s.connectorDAO.RebuildConnector(connector, kbID, documents); err != nil {
return false, common.CodeServerError, err
}
return true, common.CodeSuccess, nil
}

func (s *ConnectorService) deleteConnectorDocumentChunks(tenantID, kbID string, documents []*entity.Document) {
docEngine := engine.Get()
if docEngine == nil {
return
}

indexName := fmt.Sprintf("ragflow_%s", tenantID)
for _, document := range documents {
_, _ = docEngine.DeleteChunks(context.Background(), map[string]interface{}{"doc_id": document.ID}, indexName, kbID)
}

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.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Don't delete search chunks out-of-band and ignore the result.

deleteConnectorDocumentChunks runs before the DB transaction, uses context.Background(), and drops the engine error. If chunk deletion fails, rebuild can still return success; if the later transaction fails, the chunks are already gone. That leaves the search index and database out of sync.

🤖 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/service/connector.go` around lines 247 - 264,
deleteConnectorDocumentChunks currently removes search chunks out-of-band
(called before the DB transaction), uses context.Background(), ignores errors
and can leave index/db inconsistent if the DB operation fails; change the flow
so chunk deletion is coordinated with the DB transaction: instead of calling
deleteConnectorDocumentChunks before s.connectorDAO.RebuildConnector, either
move the chunk deletion into the same transactional operation (e.g., add chunk
removal to connectorDAO.RebuildConnector) or have deleteConnectorDocumentChunks
return an error and be invoked after a successful DB commit; also stop using
context.Background() — accept/passthrough the caller context (or create a
cancellable context tied to the request), check engine.Get() != nil and
propagate and handle DeleteChunks errors so failures cause the overall operation
to rollback/return an error rather than silently dropping chunks.

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (43cbfd4) to head (6dbe5f7).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15300   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 28, 2026
@Haruko386 Haruko386 changed the title feat[Go]: implement delete, rebuild api for connector feat[Go]: implement delete/ rebuild/ listlog api for connector May 28, 2026

@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/handler/connector.go (1)

283-293: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Normalize kb_id before calling service.

You validate trimmed kb_id, but pass the untrimmed value. Leading/trailing whitespace can still leak into DAO queries.

Suggested patch
-	if strings.TrimSpace(req.KbID) == "" {
+	kbID := strings.TrimSpace(req.KbID)
+	if kbID == "" {
 		c.JSON(http.StatusOK, gin.H{
 			"code":    common.CodeDataError,
 			"data":    nil,
 			"message": "kb_id cannot be empty",
 		})
 		return
 	}
 
-	ok, code, err := h.connectorService.RebuildConnector(c.Param("connector_id"), user.ID, req.KbID)
+	ok, code, err := h.connectorService.RebuildConnector(c.Param("connector_id"), user.ID, kbID)
🤖 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/handler/connector.go` around lines 283 - 293, Trim and normalize
req.KbID before using it: after the existing validation that checks
strings.TrimSpace(req.KbID), assign the trimmed value back (e.g., kbID :=
strings.TrimSpace(req.KbID)) and pass that kbID into
h.connectorService.RebuildConnector(c.Param("connector_id"), user.ID, kbID) so
the service/DAO never receives untrimmed whitespace from req.KbID.
♻️ Duplicate comments (1)
internal/handler/connector.go (1)

230-235: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix Swagger route annotations for delete/rebuild endpoints.

DeleteConnector still has no @Router, and RebuildConnector still documents a different path template than the registered route. Generated docs won’t match runtime endpoints.

Suggested patch
 // DeleteConnector delete connector
+// `@Summary` Delete Connector
 // `@Description` Detele Connector
 // `@Tags` connector
 // `@Accept` json
 // `@Produce` json
+// `@Success` 200 {object} map[string]interface{}
+// `@Router` /api/v1/connectors/{connector_id} [delete]
 func (h *ConnectorHandler) DeleteConnector(c *gin.Context) {
@@
 // `@Accept` json
 // `@Produce` json
 // `@Success` 200 {object} map[string]interface{}
-// `@Router` /connector/:connector_id/rebuild [post]
+// `@Router` /api/v1/connectors/{connector_id}/rebuild [post]
 func (h *ConnectorHandler) RebuildConnector(c *gin.Context) {

Also applies to: 255-263

🤖 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/handler/connector.go` around lines 230 - 235, Add or correct the
Swagger `@Router` annotations so generated docs match runtime endpoints: add an
appropriate `@Router` entry to the DeleteConnector function's comment block (so
DeleteConnector has a `@Router` line) and update the RebuildConnector function's
`@Router` annotation to use the exact path template used by the registered route
(fix the path/placeholders to match the actual route). Locate the comment blocks
above the DeleteConnector and RebuildConnector functions in connector.go and
modify their Swagger annotations (`@Router`, HTTP verb and path) to exactly match
the runtime route definitions.
🧹 Nitpick comments (1)
internal/handler/connector_test.go (1)

185-271: ⚡ Quick win

Add handler tests for RebuildConnector paths.

This PR adds a new endpoint, but there’s no corresponding handler test yet. Please add table-driven cases for:

  • success (kb_id present),
  • missing/empty kb_id,
  • service error propagation (e.g., auth/data/server code mapping).
🤖 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/handler/connector_test.go` around lines 185 - 271, Add table-driven
tests in internal/handler/connector_test.go mirroring the style of
TestConnectorHandlerListLogs that exercise ConnectorHandler.RebuildConnector via
the test router; create cases for (1) success when a valid kb_id is provided
(assert response code, message, and any returned data), (2) missing/empty kb_id
(assert appropriate validation error response), and (3) service error
propagation by using fakeConnectorService with different code/err values (e.g.,
common.CodeAuthenticationError and a data/server error) to verify the handler
maps service errors to the correct HTTP response and body. Use the same test
scaffolding: instantiate h := &ConnectorHandler{connectorService: tt.service},
register a route that sets the user in context and calls h.RebuildConnector,
send requests with appropriate query/body parameters, unmarshal the JSON
response, and assert body["code"], body["message"], and any body["data"] fields
as per each case.
🤖 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/handler/connector.go`:
- Around line 283-293: Trim and normalize req.KbID before using it: after the
existing validation that checks strings.TrimSpace(req.KbID), assign the trimmed
value back (e.g., kbID := strings.TrimSpace(req.KbID)) and pass that kbID into
h.connectorService.RebuildConnector(c.Param("connector_id"), user.ID, kbID) so
the service/DAO never receives untrimmed whitespace from req.KbID.

---

Duplicate comments:
In `@internal/handler/connector.go`:
- Around line 230-235: Add or correct the Swagger `@Router` annotations so
generated docs match runtime endpoints: add an appropriate `@Router` entry to the
DeleteConnector function's comment block (so DeleteConnector has a `@Router` line)
and update the RebuildConnector function's `@Router` annotation to use the exact
path template used by the registered route (fix the path/placeholders to match
the actual route). Locate the comment blocks above the DeleteConnector and
RebuildConnector functions in connector.go and modify their Swagger annotations
(`@Router`, HTTP verb and path) to exactly match the runtime route definitions.

---

Nitpick comments:
In `@internal/handler/connector_test.go`:
- Around line 185-271: Add table-driven tests in
internal/handler/connector_test.go mirroring the style of
TestConnectorHandlerListLogs that exercise ConnectorHandler.RebuildConnector via
the test router; create cases for (1) success when a valid kb_id is provided
(assert response code, message, and any returned data), (2) missing/empty kb_id
(assert appropriate validation error response), and (3) service error
propagation by using fakeConnectorService with different code/err values (e.g.,
common.CodeAuthenticationError and a data/server error) to verify the handler
maps service errors to the correct HTTP response and body. Use the same test
scaffolding: instantiate h := &ConnectorHandler{connectorService: tt.service},
register a route that sets the user in context and calls h.RebuildConnector,
send requests with appropriate query/body parameters, unmarshal the JSON
response, and assert body["code"], body["message"], and any body["data"] fields
as per each case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05f23164-1380-442b-b5dd-7296b4e24fbe

📥 Commits

Reviewing files that changed from the base of the PR and between aa724a3 and 6dbe5f7.

📒 Files selected for processing (6)
  • internal/dao/connector.go
  • internal/entity/connector.go
  • internal/handler/connector.go
  • internal/handler/connector_test.go
  • internal/router/router.go
  • internal/service/connector.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/router/router.go
  • internal/service/connector.go

JPette1783 added a commit to JPette1783/ragflow that referenced this pull request May 28, 2026
…ed by infiniflow#15300

Per reviewer request, remove Create, Get, Update, Delete, ListLogs, and Rebuild
connector endpoints (already implemented in infiniflow#15300). Keep only POST
/:connector_id/test which is not covered there.

- handler: remove all methods except ListConnectors and TestConnector; introduce
  connectorServiceIface for testability; update test to cover TestConnector cases
- service: remove CreateConnector, UpdateConnector, DeleteConnector, ListLogs,
  Rebuild, and all scheduling/task helpers; keep accessible and TestConnector
- dao: remove SyncLogsDAO and Connector2KbDAO (no longer used)
- entity: remove ConnectorTaskType and ConnectorInputType constants
- router: remove all connector routes except GET / and POST /:id/test
JinHai-CN pushed a commit that referenced this pull request May 28, 2026
## Summary
- Add Go REST support for `GET /api/v1/system/healthz`.
- Return Python-compatible `ok`/`nok` dependency fields for DB, Redis,
document engine, and storage.
- Return HTTP 200 only when all checks pass; otherwise return HTTP 500
with `_meta` failure details.
- Add focused service coverage for the unhealthy dependency response
when Go dependencies are not initialized.

## Scope
This is a small, isolated slice of #15240. It avoids current open
connector PRs (#15274, #15300, #15265, #15264), tenant/member PRs
(#15295, #15301, #15276), MCP PRs (#15281, #15253, #15254, #15260,
#15261, #15262), and the memory-message PR (#15256).

Refs #15240
@JinHai-CN JinHai-CN merged commit ed87893 into infiniflow:main May 28, 2026
2 of 3 checks passed
JPette1783 added a commit to JPette1783/ragflow that referenced this pull request May 28, 2026
Upstream PR infiniflow#15300 merged the Get/List/Delete/Rebuild/ListLog connector
endpoints and our branch keeps only the Test endpoint, so the merge had
to interleave handlers, tests, services, and DAO additions.

Resolved conflicts by keeping every method from both sides:

- internal/router/router.go: keep upstream's GET/POST/DELETE routes
  plus our POST /:connector_id/test route on the connectors group
- internal/handler/connector.go: union the connectorServiceIface
  methods (ListConnectors, CreateConnector, GetConnector, ListLog,
  DeleteConnector, RebuildConnector, TestConnector); union the
  handler functions; consolidate imports (errors, net/http, strconv,
  strings, common, entity, service)
- internal/handler/connector_test.go: union fakeConnectorService
  fields and methods so it satisfies the wider interface; add the
  missing CreateConnector method; keep both
  TestConnectorHandlerTestConnector and the upstream Delete/ListLogs
  tests
- internal/service/connector.go: keep upstream's CreateConnectorRequest,
  RebuildConnectorRequest, canAccessConnector, cancelConnectorTasks,
  CreateConnector, GetConnector, DeleteConnector, RebuildConnector,
  deleteConnectorDocumentChunks, ListLog AND our accessible +
  TestConnector
- internal/dao/connector.go: keep upstream's CancelRunningOrScheduledLogs,
  ListDocumentsByKBAndSourceType, RebuildConnector,
  createRebuildSyncLog, ListLogsByConnectorID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants