-
Notifications
You must be signed in to change notification settings - Fork 141
CBG-5089: Add support for user defined metadata in diagnostic api #7954
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
Conversation
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 support for user-defined metadata (xattrs) in the Sync Function Diagnostic API, allowing users to test sync functions with custom xattr values. The changes enable passing user xattrs through the API request payload or reading them from existing documents in the database.
Changes:
- Added
Metafield toSyncFnDryRunPayloadto accept user-defined xattrs in API requests - Updated
SyncFnDryrunmethod signature to accept and process user metadata - Changed
userXattrKey()from private to publicUserXattrKey()method across multiple files - Added comprehensive test coverage for user xattr scenarios in diagnostic API
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| rest/diagnostic_doc_api.go | Added Meta field to payload struct and validation logic for user xattrs |
| rest/diagnostic_doc_api_test.go | Added test cases for user xattr handling and updated test setup for xattr support |
| db/crud.go | Updated SyncFnDryrun signature to accept userMeta parameter and apply it when provided |
| db/database_collection.go | Changed userXattrKey() to public UserXattrKey() method |
| db/database.go | Updated userXattrKey() call to UserXattrKey() |
| db/import.go | Updated userXattrKey() calls to UserXattrKey() |
| db/import_listener.go | Updated userXattrKey() calls to UserXattrKey() |
| db/change_cache.go | Updated userXattrKey() calls to UserXattrKey() |
| db/background_mgr_attachment_migration.go | Updated userXattrKey() call to UserXattrKey() |
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.
Probably move the user xattr test cases to a test that is testing that specific sub-feature, so all the other tests can still run in CE mode.
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.
Need a bit more validation around the meta object being passed into the request really. See inline.
rest/diagnostic_doc_api.go
Outdated
| } | ||
|
|
||
| // checking user defined metadata | ||
| if syncDryRunPayload.Meta != nil { |
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.
This isn't ensuring there's nothing else set in the map (e.g. meta.foo)
I think that's mostly why I prefer the struct approach, though it also makes access easier since there's less type assertions too:
Meta *SyncFnDryRunMeta `json:"meta,omitempty"`
}
type SyncFnDryRunMeta struct {
Xattrs map[string]any `json:"xattrs,omitempty"`
}We'd also need to length-check the Xattrs map to ensure only exactly 1 (matching) key is present as well - it's too easy to unintentionally pass extra data into the sync function otherwise that wouldn't be available in the real one.
e.g.
meta.xattrs[my_user_xattr_key]={"my_xattr_data":true}
meta.xattrs[bar]="buzz"
dry run could technically still be able to access meta.xattrs.bar despite not being available in a real sync function.
02d8ddc to
9a517d4
Compare
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
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
rest/diagnostic_doc_api.go
Outdated
| } | ||
|
|
||
| type SyncFnDryRunMetaMap struct { | ||
| Xatrrs map[string]any `json:"xatrrs"` |
Copilot
AI
Jan 16, 2026
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.
Typo in field name: 'Xatrrs' should be 'Xattrs'.
| Xatrrs map[string]any `json:"xatrrs"` | |
| Xattrs map[string]any `json:"xattrs"` |
rest/diagnostic_doc_api_test.go
Outdated
| Doc: db.Body{ | ||
| "foo": "bar", | ||
| }, | ||
| Meta: SyncFnDryRunMetaMap{Xatrrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}}, |
Copilot
AI
Jan 16, 2026
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.
Typo in field name: 'Xatrrs' should be 'Xattrs'.
| Meta: SyncFnDryRunMetaMap{Xatrrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}}, | |
| Meta: SyncFnDryRunMetaMap{Xattrs: map[string]any{"channelXattr": []string{"channel1", "channel3", "useradmin"}}}, |
CBG-5089
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/221/