Skip to content

[3.3.3 backport] CBG-5116: Diagnostic API Improvements#7999

Merged
bbrks merged 15 commits intorelease/3.3.3from
CBG-5116
Jan 26, 2026
Merged

[3.3.3 backport] CBG-5116: Diagnostic API Improvements#7999
bbrks merged 15 commits intorelease/3.3.3from
CBG-5116

Conversation

@RIT3shSapata
Copy link
Contributor

CBG-5116

Describe your PR here...

  • This PR contains all the commits of Diagnostic API

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 requested a review from bbrks January 21, 2026 15:39
Copilot AI review requested due to automatic review settings January 21, 2026 15:39
@github-actions
Copy link

github-actions bot commented Jan 21, 2026

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 backports diagnostic API improvements to version 3.3.3, changing the HTTP methods for sync function and import filter dry-run endpoints from GET to POST, and enhancing their functionality with support for custom functions, user context, metadata, and improved logging.

Changes:

  • Changed HTTP methods from GET to POST for _sync and _import_filter diagnostic endpoints
  • Enhanced dry-run endpoints to accept custom sync functions and import filters in request bodies
  • Added support for user context, user xattrs, and logging capture during dry-run operations

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
rest/routing.go Updated HTTP methods from GET to POST for diagnostic endpoints
rest/handler.go Added audit event handling for diagnostic server requests
rest/diagnostic_doc_api_test.go Removed old test and added comprehensive new tests for sync function and import filter dry-run functionality
rest/diagnostic_doc_api.go Refactored handlers to accept POST requests with enhanced payload structures and logging support
rest/audit_test.go Added test case for diagnostic request auditing
docs/api/paths/diagnostic/keyspace-sync.yaml Updated API documentation to reflect POST method and new request body structure
docs/api/paths/diagnostic/keyspace-import_filter.yaml Updated API documentation to reflect POST method and new request body structure
docs/api/diagnostic.yaml Fixed incorrect endpoint paths in API documentation
docs/api/components/schemas.yaml Added new schema definitions for diagnostic function exception and logging
db/revision_test.go Updated benchmark to use renamed exported function
db/revision.go Exported StripInternalProperties function (renamed from stripInternalProperties)
db/import_test.go Updated test calls to match refactored EvaluateFunction signature
db/import_listener.go Updated calls to use renamed UserXattrKey method
db/import.go Refactored import filter evaluation to support custom functions and logging
db/document.go Updated call to use renamed UserXattrKey method
db/database_collection.go Exported UserXattrKey method (renamed from userXattrKey)
db/database.go Updated calls to use renamed methods
db/crud.go Refactored sync function dry-run to accept custom functions and support logging
db/change_cache.go Updated calls to use renamed UserXattrKey method
channels/sync_runner.go Added NewSyncRunnerWithLogging to support custom logging functions
base/error.go Added custom error types for sync function and import filter dry-run errors
base/audit_events.go Added new audit event ID for diagnostic HTTP API requests

ShouldImport bool `json:"shouldImport"`
Error string `json:"error"`
ShouldImport bool `json:"shouldImport"`
Exception string `json:"exception"`
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The Exception field in ImportFilterDryRun should have the omitempty JSON tag for consistency with the SyncFnDryRun struct where Exception is marked as omitempty (line 33). This ensures the field is omitted from JSON responses when empty.

Suggested change
Exception string `json:"exception"`
Exception string `json:"exception,omitempty"`

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +61
description: |-
Optional XATTR values to include during evaluation.

To provide the user XATTR, include a property whose name exactly matches the configured `user_xattr_key`.
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The description spans multiple lines inconsistently. The continuation should be part of a single description field or properly formatted with line continuation indicators in YAML.

Suggested change
description: |-
Optional XATTR values to include during evaluation.
To provide the user XATTR, include a property whose name exactly matches the configured `user_xattr_key`.
description: Optional XATTR values to include during evaluation. To provide the user XATTR, include a property whose name exactly matches the configured `user_xattr_key`.

Copilot uses AI. Check for mistakes.
var docid string

id, _ := syncDryRunPayload.Doc[db.BodyId].(string)
docid = cmp.Or(bucketDocID, id, SYNC_FN_DIAGNOSTIC_DOCID)
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The use of cmp.Or to select the first non-empty string from multiple sources works correctly, but the logic would be clearer with explicit conditional checks given the significance of docid selection in this context. Consider using an explicit if-else chain to make the precedence order more apparent.

Copilot uses AI. Check for mistakes.
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.

Looks fine but I have a few questions (that may also affect main/4.0.3)

result, err := i.Call(ctx, doc)
if err != nil {
if !dryRun {
base.WarnfCtx(ctx, "Unexpected error invoking import filter for document %s - processing aborted, document will not be imported. Error: %v", base.UD(doc), err)
Copy link
Member

Choose a reason for hiding this comment

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

I've just noticed we're removing this warning logging and relying on the caller which only logs at info. Was this intentional? It seems like customers may miss this message at info level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do return the error back to the handler, which will send then return this error as part of exception in the response body

Copy link
Member

Choose a reason for hiding this comment

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

As discussed - there is no request here to get back to a user. An import is sourced from a doc coming over the DCP feed to Sync Gateway. Warnings are the only way of communicating this error back.

return boolResult, nil
default:
if !dryRun {
base.WarnfCtx(ctx, "Import filter function returned non-boolean result %v Type: %T", result, result)
Copy link
Member

Choose a reason for hiding this comment

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

Likewise, this warning going means that customers won't see this since the caller logs errors at info level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, the error will be sent back to the user as a exception in the response

}
bodyBytes, err := json.Marshal(request)
require.NoError(t, err)
RequireStatus(t, rt.SendDiagnosticRequest(http.MethodPost, "/{{.keyspace}}/_sync", string(bodyBytes)), http.StatusOK)
Copy link
Member

Choose a reason for hiding this comment

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

Just needs the extra auth test commit pulled into this PR branch from #8006

@RIT3shSapata RIT3shSapata requested a review from bbrks January 22, 2026 16:29
@bbrks
Copy link
Member

bbrks commented Jan 23, 2026

See #8017 for restoration of warning logs - we can cherry-pick that into this

Edit: I'll follow up with this cherry-pick so you can review independently.

@bbrks bbrks assigned RIT3shSapata and unassigned bbrks Jan 23, 2026
@bbrks bbrks enabled auto-merge (squash) January 26, 2026 12:12
@bbrks bbrks merged commit d8f9e35 into release/3.3.3 Jan 26, 2026
47 checks passed
@bbrks bbrks deleted the CBG-5116 branch January 26, 2026 12:12
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.

2 participants