-
Notifications
You must be signed in to change notification settings - Fork 140
CBG-4412: Add ability to pass custom import filter into diagnostic API #7935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
bbrks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good 👍
ee1f2a9 to
bbc67b1
Compare
Redocly previews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the ability to pass a custom import filter function to the diagnostic API's /_import_filter endpoint, allowing users to test import filter behavior with different filter implementations without modifying the database configuration.
Key changes:
- Changed the HTTP method from GET to POST for the
/_import_filterendpoint to support request body - Added support for custom import filter functions via the request body
- Refactored and expanded unit tests to cover various scenarios with and without custom import filters
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| rest/routing.go | Changed HTTP method from GET to POST for the /_import_filter endpoint |
| rest/diagnostic_doc_api_test.go | Removed old test function and added comprehensive table-driven tests for import filter dry run |
| rest/diagnostic_doc_api.go | Refactored handler to accept custom import filter in request body and improved error handling |
| docs/api/paths/diagnostic/keyspace-import_filter.yaml | Updated API specification to reflect POST method and document new request body parameters |
| db/import.go | Modified ImportFilterDryRun to accept custom import filter function and handle both default and custom filters |
| base/error.go | Added new error type ImportFilterDryRunError for import filter dry run errors |
base/error.go
Outdated
| // ErrInvalidJSON is returned when the JSON being unmarshalled cannot be parsed. | ||
| ErrInvalidJSON = HTTPErrorf(http.StatusBadRequest, "Invalid JSON") | ||
|
|
||
| ErrImportDryRun = &sgError{"Error occured during import dry run: "} |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'occured' to 'occurred'.
| ErrImportDryRun = &sgError{"Error occured during import dry run: "} | |
| ErrImportDryRun = &sgError{"Error occurred during import dry run: "} |
db/import.go
Outdated
| importOuput, err := importRunner.Call(ctx, doc) | ||
| switch result := importOuput.(type) { |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'importOuput' to 'importOutput'.
| importOuput, err := importRunner.Call(ctx, doc) | |
| switch result := importOuput.(type) { | |
| importOutput, err := importRunner.Call(ctx, doc) | |
| switch result := importOutput.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
db/import.go
Outdated
| break | ||
| case string: | ||
| boolResult, err := strconv.ParseBool(result) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| } else { | ||
| return false, err | ||
| shouldImport = boolResult | ||
| break |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break statements are unnecessary in a switch statement in Go. The break is implicit at the end of each case unless a fallthrough is explicitly used.
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| } else { | |
| return false, err | |
| shouldImport = boolResult | |
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| shouldImport = boolResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
db/import.go
Outdated
| break | ||
| case string: | ||
| boolResult, err := strconv.ParseBool(result) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| } else { | ||
| return false, err | ||
| shouldImport = boolResult | ||
| break |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break statements are unnecessary in a switch statement in Go. The break is implicit at the end of each case unless a fallthrough is explicitly used.
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| } else { | |
| return false, err | |
| shouldImport = boolResult | |
| break | |
| case string: | |
| boolResult, err := strconv.ParseBool(result) | |
| if err != nil { | |
| return false, err | |
| } | |
| shouldImport = boolResult |
db/import.go
Outdated
| shouldImport = boolResult | ||
| break | ||
| default: | ||
| return false, &base.ImportFilterDryRunError{Err: err} |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error err may be nil at this point since it's only assigned in the string case. This would result in wrapping a nil error. Consider returning an explicit error message indicating that the import filter returned a non-boolean value.
| return false, &base.ImportFilterDryRunError{Err: err} | |
| wrappedErr := err | |
| if wrappedErr == nil { | |
| wrappedErr = errors.New("import filter function returned non-boolean value") | |
| } | |
| return false, &base.ImportFilterDryRunError{Err: wrappedErr} |
db/import.go
Outdated
| break | ||
| case string: | ||
| boolResult, err := strconv.ParseBool(result) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| } else { | ||
| return false, err | ||
| shouldImport = boolResult | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
db/import.go
Outdated
| importOuput, err := importRunner.Call(ctx, doc) | ||
| switch result := importOuput.(type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
db/import.go
Outdated
| if err != nil { | ||
| return false, &base.ImportFilterDryRunError{Err: err} | ||
| } | ||
| shouldImport = output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we return output here, we can avoid the nested } else { block below since we're returning early.
This is more idiomatic Go than writing if else chains and deep nesting.
CBG-4412
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests
GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/208/GSI=true,xattrs=truehttps://jenkins.sgwdev.com/job/SyncGatewayIntegration/211/