Skip to content

CBG-5327: Wire up REST API to document channel history compaction#8275

Open
RIT3shSapata wants to merge 11 commits into
mainfrom
CBG-5327
Open

CBG-5327: Wire up REST API to document channel history compaction#8275
RIT3shSapata wants to merge 11 commits into
mainfrom
CBG-5327

Conversation

@RIT3shSapata
Copy link
Copy Markdown
Contributor

@RIT3shSapata RIT3shSapata commented May 15, 2026

CBG-5327

Describe your PR here...

  • Added routes and handlers for get and post requests of document channel history compaction
  • Created a get document channel history function
  • Added test coverage for the http requests
  • Updated the Document Channel history compaction to store the compacted channels as set instead of array
  • Updated Open API spec

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)

Integration Tests

Copy link
Copy Markdown
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 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 GetDocChannelHistory plus 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-61 uses it for doc IDs). Add an appropriate key name such as channel_name to keep generated docs consistent.
            additionalProperties:
              type: array

Comment thread docs/api/paths/admin/keyspace-_channel_history.yaml
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Comment thread rest/doc_api.go
Comment thread db/crud.go Outdated
Comment thread rest/doc_api.go Outdated
Comment thread rest/routing.go
Comment thread rest/doc_api.go Outdated
Copy link
Copy Markdown
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

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

Comment thread docs/api/admin.yaml Outdated
'/{keyspace}/_channel_history/{docid}':
$ref: './paths/admin/keyspace-_history.yaml'
'/{keyspace}/_history/compact':
'/{keyspace}/_channel_history/compact':
Comment thread rest/doc_api.go Outdated
Comment on lines +976 to +977
if err != nil && !base.IsDocNotFoundError(err) {
return err
Comment on lines +33 to +39
additionalProperties:
type: array
items:
type: integer
format: int64
minimum: 0
description: Sequences at which the document was removed from this channel.
Copy link
Copy Markdown
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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Comment thread rest/routing.go Outdated
Comment thread rest/doc_api.go
Comment on lines +934 to +939
func (h *handler) handleGetDocChannelHistory() error {
h.assertAdminOnly()

if !h.collection.UseXattrs() {
return fmt.Errorf("xattrs not enabled")
}
Comment thread rest/doc_api.go Outdated
Comment thread rest/doc_api.go Outdated
Comment thread db/crud.go
Comment thread docs/api/paths/admin/keyspace-_history.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_channel_history-compact.yaml
Comment thread rest/api_test.go
Copy link
Copy Markdown
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

Posted text cleanup from our discussion - final review pending decisions on discussion items.

Comment thread docs/api/paths/admin/keyspace-_history.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Comment thread docs/api/paths/admin/keyspace-_history-compact.yaml Outdated
Base automatically changed from CBG-5326 to main May 26, 2026 14:01
- 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
- fix golang lint
- update the open api spec's path for document channel history and compaction
- add request validation
- fix docstrings
- changed the endpoint for GET and POST requests
- changed the request body and response for POST request
- changed the resposne for the GET request
- updated the OPEN API spec
- renamed the api path fixes
- changed the response of the get request to include multiple sequences
- updated the docstrings and the open api spec
- fixed the permission issue in the route
- handle not found error in the rest handler
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

Redocly previews

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

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_channels property (array of strings), but this spec currently describes an object with additionalProperties (and an unrelated x-additionalPropertiesName: doc_id). Update the schema to define compacted_channels as a property and remove the additionalProperties mapping.
    docs/api/paths/admin/keyspace-_channel_history-compact.yaml:37
  • The request schema allows seq with minimum: 0, but the handler currently returns 400 when seq==0. Either allow 0 (treat as a valid no-op) or update the OpenAPI schema/description to require seq >= 1 so 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
  • operationId in this file still references the old _history endpoint 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.

Comment thread rest/doc_api.go
Comment thread rest/doc_api.go
Comment thread rest/doc_api.go
Comment on lines +971 to +978
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")
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changing the open api spec

Comment thread db/crud.go Outdated
Comment thread db/crud.go
}
_, err = c.dataStore.UpdateXattrs(ctx, key, 0, cas, updatedXattr, opts)
return compactedChannels, err
return compactedChannels.ToArray(), err
Comment thread rest/api_test.go Outdated
Comment on lines +35 to +44
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.
Comment thread db/crud.go
Comment on lines +239 to +242
response[chanName] = make([]uint64, 0)
for seq, _ := range chanEntry {
response[chanName] = append(response[chanName], seq)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree with co-pilot that the individual slices need to be sorted by value.

I would go further, and suggest that the list of channels in the response map should also be sorted by sequence (or sequence[0]), so that callers can easily find the sequence they want to use for the POST operation.

e.g. with this:
"channel1": [10, 4],
"channel2:": [5, 2],
"channel3": [12],
"channel4": [7]
it's harder to see which channels will be compacted for a given sequence value

I think it would be preferable to return sorted by first sequence:
"channel3": [12],
"channel1": [10, 4],
"channel4": [7],
"channel2:": [5, 2]

What do you think?

Copy link
Copy Markdown
Collaborator

@adamcfraser adamcfraser left a comment

Choose a reason for hiding this comment

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

Generally looks good, one naming suggestion and then some comments about response ordering.

Comment thread rest/doc_api.go
Comment thread db/crud.go
Comment on lines +239 to +242
response[chanName] = make([]uint64, 0)
for seq, _ := range chanEntry {
response[chanName] = append(response[chanName], seq)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree with co-pilot that the individual slices need to be sorted by value.

I would go further, and suggest that the list of channels in the response map should also be sorted by sequence (or sequence[0]), so that callers can easily find the sequence they want to use for the POST operation.

e.g. with this:
"channel1": [10, 4],
"channel2:": [5, 2],
"channel3": [12],
"channel4": [7]
it's harder to see which channels will be compacted for a given sequence value

I think it would be preferable to return sorted by first sequence:
"channel3": [12],
"channel1": [10, 4],
"channel4": [7],
"channel2:": [5, 2]

What do you think?

Comment thread db/crud.go

}

type ChannelHistory map[string]map[uint64]bool
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In cases where we're just using a map to store unique keys and don't care about the value, I prefer using empty struct:

Suggested change
type ChannelHistory map[string]map[uint64]bool
type ChannelHistory map[string]map[uint64]struct{}

This has some memory savings (which we don't really care about here), but also makes it self-documenting that we don't care about the map value.

Comment thread db/crud.go
}
}

func (ch ChannelHistory) getChannelHistoryResponse() map[string][]uint64 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this is in the db package, it's better to avoid naming like 'Response', since that implies REST functionality. Maybe just asMap() or asSequenceSlices()?

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