CBG-5327: Wire up REST API to document channel history compaction#8275
Conversation
There was a problem hiding this comment.
Pull request overview
This PR wires document channel history compaction into the Admin REST API and adds a REST-accessible way to inspect a document’s channel revocation history.
Changes:
- Added Admin REST routes and handlers for getting document channel history and compacting channel history.
- Added
GetDocChannelHistoryplus updated compaction output to deduplicate compacted channel names. - Added REST/API tests and updated OpenAPI path documentation.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
rest/routing.go |
Registers new Admin channel history GET and compaction POST routes. |
rest/doc_api.go |
Adds request/response handling for channel history APIs. |
rest/api_test.go |
Adds REST coverage and updates compaction expectations for deduplicated channels. |
docs/api/paths/admin/keyspace-_history.yaml |
Updates documented GET channel history response schema. |
docs/api/paths/admin/keyspace-_history-compact.yaml |
Updates compaction response description. |
db/crud.go |
Adds channel history retrieval and deduplicates compacted channel results. |
Comments suppressed due to low confidence (2)
docs/api/paths/admin/keyspace-_history.yaml:17
- This description conflicts with the implemented behavior and the new test for a channel that is revoked and then re-added: such a channel is still returned because it has revocation history. Rephrase this to say active channel memberships without any revocation history are not included, rather than implying all currently assigned channels are excluded.
names to the sequences at which the document was removed from each channel. Only channels
that have been revoked at least once are included; channels the document is currently
assigned to are excluded.
docs/api/paths/admin/keyspace-_history.yaml:34
- This map response is missing the repository’s OpenAPI convention of naming additionalProperties keys with
x-additionalPropertiesName(for example,docs/api/paths/admin/keyspace-_history-compact.yaml:59-61uses it for doc IDs). Add an appropriate key name such aschannel_nameto keep generated docs consistent.
additionalProperties:
type: array
| '/{keyspace}/_channel_history/{docid}': | ||
| $ref: './paths/admin/keyspace-_history.yaml' | ||
| '/{keyspace}/_history/compact': | ||
| '/{keyspace}/_channel_history/compact': |
| if err != nil && !base.IsDocNotFoundError(err) { | ||
| return err |
| additionalProperties: | ||
| type: array | ||
| items: | ||
| type: integer | ||
| format: int64 | ||
| minimum: 0 | ||
| description: Sequences at which the document was removed from this channel. |
| func (h *handler) handleGetDocChannelHistory() error { | ||
| h.assertAdminOnly() | ||
|
|
||
| if !h.collection.UseXattrs() { | ||
| return fmt.Errorf("xattrs not enabled") | ||
| } |
adamcfraser
left a comment
There was a problem hiding this comment.
Posted text cleanup from our discussion - final review pending decisions on discussion items.
- added route for get request and the handler - created a get channel history function and added test coverage
- add route and handler to handle http request - add test coverage for http request - use set instead of array to store compacted channels
- add docstrings to all functions - updated api spec
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Comments suppressed due to low confidence (4)
docs/api/paths/admin/keyspace-_channel_history-compact.yaml:56
- The documented 200 response schema doesn’t match the actual handler output. The code returns an object with a
compacted_channelsproperty (array of strings), but this spec currently describes an object withadditionalProperties(and an unrelatedx-additionalPropertiesName: doc_id). Update the schema to definecompacted_channelsas a property and remove theadditionalPropertiesmapping.
docs/api/paths/admin/keyspace-_channel_history-compact.yaml:37 - The request schema allows
seqwithminimum: 0, but the handler currently returns 400 whenseq==0. Either allow0(treat as a valid no-op) or update the OpenAPI schema/description to requireseq >= 1so the contract matches runtime behavior.
docs/api/paths/admin/keyspace-_channel_history-compact.yaml:59 - The description has a grammar typo: “A array of all the compacted channels” should be “An array of all the compacted channels”.
docs/api/paths/admin/keyspace-_channel_history-compact.yaml:67 operationIdin this file still references the old_historyendpoint name (post_keyspace-_history-compact), but the path is now/_channel_history/{docid}/compact. Update the operationId to match the new endpoint naming to avoid collisions/confusion in generated clients.
| err := h.readJSONInto(&req) | ||
| if err != nil { | ||
| return base.HTTPErrorf(http.StatusBadRequest, "invalid JSON: %v", err) | ||
| } | ||
|
|
||
| if req.Seq == 0 { | ||
| return base.HTTPErrorf(http.StatusBadRequest, "missing seq") | ||
| } |
There was a problem hiding this comment.
changing the open api spec
| schema: | ||
| type: object | ||
| additionalProperties: | ||
| type: array | ||
| items: | ||
| type: integer | ||
| format: int64 | ||
| minimum: 0 | ||
| description: Sequences at which the document was removed from this channel. | ||
| description: Map of channel names to their revocation sequences. |
adamcfraser
left a comment
There was a problem hiding this comment.
Generally looks good, one naming suggestion and then some comments about response ordering.
- rename a few functions - refactor the format of the response being sent for get channel history
| }) | ||
|
|
||
| chanHistoryMap := make(map[string][]uint64) | ||
| for _, entry := range chanHistoryEntries { |
There was a problem hiding this comment.
Once you convert this to a map, we're going to lose the ordering from chanHistoryEntries. The map itself will be unordered, and then JSON serialization of a map is going to order by keys.
So if we want the output to be ordered by sequence, we'd need to change it from a map of channel names to a slice of structs. Let's not make that change in this PR, and revisit the question of sorting by sequence.
adamcfraser
left a comment
There was a problem hiding this comment.
Generally looks good, I think copilot suggestion to sort channels by name for the compact response is correct.
CBG-5327
Describe your PR here...
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Upstream PR: CBG-5326: Function to handle document channel history compaction #8218Integration Tests