-
Notifications
You must be signed in to change notification settings - Fork 138
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
CBG-3727: Diagnostic API: Get all doc channels #6701
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
352f6b3
Add handling and test for get all doc channels
mohammed-madi 4423426
Fix lint
mohammed-madi 2e9fac9
Add licensing
mohammed-madi 09557de
Address comments
mohammed-madi 696c11e
Add docs
mohammed-madi 0ec77e4
fix yamllint
mohammed-madi 54e8d00
Add DocumentHistoryMaxEntriesPerChannel test case and fix docs
mohammed-madi c2e51e0
Denote compacted sequence pairs with ~
mohammed-madi 2cea1f4
Fix goimports
mohammed-madi 9d008c3
Fix comment
mohammed-madi fda8bfe
Fix comment
mohammed-madi e27372e
Add unmarshalJSON handlign for compacted sequence pair
mohammed-madi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
docs/api/paths/diagnostic/keyspace-docid-_all_channels.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2022-Present Couchbase, Inc. | ||
# | ||
# Use of this software is governed by the Business Source License included | ||
# in the file licenses/BSL-Couchbase.txt. As of the Change Date specified | ||
# in that file, in accordance with the Business Source License, use of this | ||
# software will be governed by the Apache License, Version 2.0, included in | ||
# the file licenses/APL2.txt. | ||
parameters: | ||
- $ref: ../../components/parameters.yaml#/keyspace | ||
- $ref: ../../components/parameters.yaml#/docid | ||
get: | ||
summary: Get channel history for a document | ||
description: |- | ||
Retrieve all doc channels and the sequence spans showing when the doc was added to a channel and when it was removed. | ||
Required Sync Gateway RBAC roles: | ||
* Sync Gateway Application Read Only | ||
responses: | ||
'200': | ||
description: Document found successfully | ||
content: | ||
application/json: | ||
schema: | ||
additionalProperties: | ||
x-additionalPropertiesName: channel | ||
description: The channels the document has been in. | ||
type: array | ||
items: | ||
sequences: | ||
description: The sequence number that document was added to the channel. | ||
type: string | ||
example: "28-48" | ||
|
||
'404': | ||
$ref: ../../components/responses.yaml#/Not-found | ||
tags: | ||
- Document | ||
operationId: get_keyspace-docid-_all_channels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2024-Present Couchbase, Inc. | ||
|
||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"github.com/couchbase/sync_gateway/auth" | ||
"github.com/couchbase/sync_gateway/db" | ||
) | ||
|
||
// HTTP handler for a GET of a document | ||
func (h *handler) handleGetDocChannels() error { | ||
docid := h.PathVar("docid") | ||
|
||
doc, err := h.collection.GetDocument(h.ctx(), docid, db.DocUnmarshalSync) | ||
if err != nil { | ||
return err | ||
} | ||
if doc == nil { | ||
return kNotFoundError | ||
} | ||
resp := make(map[string][]auth.GrantHistorySequencePair, len(doc.Channels)) | ||
|
||
for _, chanSetInfo := range doc.SyncData.ChannelSet { | ||
resp[chanSetInfo.Name] = append(resp[chanSetInfo.Name], auth.GrantHistorySequencePair{StartSeq: chanSetInfo.Start, EndSeq: chanSetInfo.End}) | ||
} | ||
for _, hist := range doc.SyncData.ChannelSetHistory { | ||
resp[hist.Name] = append(resp[hist.Name], auth.GrantHistorySequencePair{StartSeq: hist.Start, EndSeq: hist.End, Compacted: hist.Compacted}) | ||
continue | ||
} | ||
|
||
h.writeJSON(resp) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright 2024-Present Couchbase, Inc. | ||
|
||
Use of this software is governed by the Business Source License included in | ||
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that | ||
file, in accordance with the Business Source License, use of this software will | ||
be governed by the Apache License, Version 2.0, included in the file | ||
licenses/APL2.txt. | ||
*/ | ||
|
||
package rest | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/couchbase/sync_gateway/db" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetAlldocChannels(t *testing.T) { | ||
rt := NewRestTester(t, &RestTesterConfig{SyncFn: `function(doc) {channel(doc.channel);}`}) | ||
defer rt.Close() | ||
|
||
version := rt.PutDoc("doc", `{"channel":["CHAN1"]}`) | ||
updatedVersion := rt.UpdateDoc("doc", version, `{"channel":["CHAN2"]}`) | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{"channel":["CHAN1"]}`) | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{"channel":["CHAN1", "CHAN2"]}`) | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{"channel":["CHAN3"]}`) | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{"channel":["CHAN1"]}`) | ||
|
||
response := rt.SendDiagnosticRequest("GET", "/{{.keyspace}}/doc/_all_channels", "") | ||
RequireStatus(t, response, http.StatusOK) | ||
|
||
var channelMap map[string][]string | ||
err := json.Unmarshal(response.BodyBytes(), &channelMap) | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, channelMap["CHAN1"], []string{"6-0", "1-2", "3-5"}) | ||
assert.ElementsMatch(t, channelMap["CHAN2"], []string{"4-5", "2-3"}) | ||
assert.ElementsMatch(t, channelMap["CHAN3"], []string{"5-6"}) | ||
|
||
for i := 1; i <= 10; i++ { | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{}`) | ||
updatedVersion = rt.UpdateDoc("doc", updatedVersion, `{"channel":["CHAN3"]}`) | ||
} | ||
response = rt.SendAdminRequest("GET", "/{{.keyspace}}/doc", "") | ||
RequireStatus(t, response, http.StatusOK) | ||
response = rt.SendDiagnosticRequest("GET", "/{{.keyspace}}/doc/_all_channels", "") | ||
RequireStatus(t, response, http.StatusOK) | ||
|
||
err = json.Unmarshal(response.BodyBytes(), &channelMap) | ||
assert.NoError(t, err) | ||
|
||
// If the channel is still in channel_set, then the total will be 5 entries in history and 1 in channel_set | ||
assert.Equal(t, len(channelMap["CHAN3"]), db.DocumentHistoryMaxEntriesPerChannel+1) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we're doing this text representation in
MarshalJSON
, an equivalent should be put inUnmarshalJSON
.Right now the two aren't compatible, and will error when running the
splitPair := strings.Split(stringPair, "-")
step.