Skip to content

Conversation

@RIT3shSapata
Copy link
Contributor

@RIT3shSapata RIT3shSapata commented Dec 19, 2025

CBG-4412

Describe your PR here...

  • Upstream PR for CBG-4411
  • Adds ability to pass custom import filter into diagnostic API
  • Refactor unit tests

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

@RIT3shSapata RIT3shSapata self-assigned this Dec 19, 2025
@RIT3shSapata RIT3shSapata marked this pull request as ready for review December 23, 2025 12:15
@RIT3shSapata RIT3shSapata requested a review from bbrks December 23, 2025 12:15
@RIT3shSapata RIT3shSapata assigned bbrks and unassigned RIT3shSapata Dec 23, 2025
Copy link
Member

@bbrks bbrks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good 👍

@RIT3shSapata RIT3shSapata requested a review from bbrks December 24, 2025 07:46
Base automatically changed from CBG-4411 to main December 24, 2025 10:38
Copilot AI review requested due to automatic review settings December 24, 2025 11:27
@github-actions
Copy link

github-actions bot commented Dec 24, 2025

Redocly previews

Copy link
Contributor

Copilot AI left a 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_filter endpoint 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: "}
Copy link

Copilot AI Dec 24, 2025

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

Suggested change
ErrImportDryRun = &sgError{"Error occured during import dry run: "}
ErrImportDryRun = &sgError{"Error occurred during import dry run: "}

Copilot uses AI. Check for mistakes.
db/import.go Outdated
Comment on lines 566 to 567
importOuput, err := importRunner.Call(ctx, doc)
switch result := importOuput.(type) {
Copy link

Copilot AI Dec 24, 2025

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

Suggested change
importOuput, err := importRunner.Call(ctx, doc)
switch result := importOuput.(type) {
importOutput, err := importRunner.Call(ctx, doc)
switch result := importOutput.(type) {

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

db/import.go Outdated
Comment on lines 570 to 577
break
case string:
boolResult, err := strconv.ParseBool(result)
if err != nil {
return false, err
}
} else {
return false, err
shouldImport = boolResult
break
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

db/import.go Outdated
Comment on lines 570 to 577
break
case string:
boolResult, err := strconv.ParseBool(result)
if err != nil {
return false, err
}
} else {
return false, err
shouldImport = boolResult
break
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
db/import.go Outdated
shouldImport = boolResult
break
default:
return false, &base.ImportFilterDryRunError{Err: err}
Copy link

Copilot AI Dec 24, 2025

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.

Suggested change
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}

Copilot uses AI. Check for mistakes.
db/import.go Outdated
Comment on lines 570 to 577
break
case string:
boolResult, err := strconv.ParseBool(result)
if err != nil {
return false, err
}
} else {
return false, err
shouldImport = boolResult
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

db/import.go Outdated
Comment on lines 566 to 567
importOuput, err := importRunner.Call(ctx, doc)
switch result := importOuput.(type) {
Copy link
Member

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
Copy link
Member

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.

@RIT3shSapata RIT3shSapata requested a review from bbrks December 29, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants