-
Notifications
You must be signed in to change notification settings - Fork 2
keyviz: label sub-ranges in the SPA and document the K tradeoff #1230
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
Open
bootjp
wants to merge
1
commit into
main
Choose a base branch
from
design/keyviz-subrange-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
| package admin | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/bootjp/elastickv/keyviz" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestSubBucketFieldsStayOffTheWireUnlessSubDivided pins that the new | ||
| // fields are inert at the K=1 default. The keyviz response is consumed | ||
| // by an SPA that ships separately from the server, so a field that | ||
| // appeared on every row would change the payload for every existing | ||
| // deployment that never enabled sub-bucketing. | ||
| func TestSubBucketFieldsStayOffTheWireUnlessSubDivided(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| row keyviz.MatrixRow | ||
| }{ | ||
| {name: "K=1 route", row: keyviz.MatrixRow{RouteID: 7, SubBucketCount: 1}}, | ||
| {name: "unset count", row: keyviz.MatrixRow{RouteID: 7}}, | ||
| {name: "aggregate row", row: keyviz.MatrixRow{RouteID: 7, Aggregate: true, SubBucketCount: 4, SubBucket: 2}}, | ||
| } | ||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
| encoded, err := json.Marshal(KeyVizRow{ | ||
| BucketID: bucketIDFor(tc.row), | ||
| SubBucket: subBucketIndexFor(tc.row), | ||
| SubBucketCount: subBucketCountFor(tc.row), | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotContains(t, string(encoded), "sub_bucket", | ||
| "the sub-range fields must not appear for a non-sub-divided row") | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestSubBucketFieldsAgreeWithTheBucketID pins that the fields and the | ||
| // "#i" suffix cannot disagree about whether a row is a sub-range — | ||
| // they share one predicate, so an SPA can trust either. | ||
| func TestSubBucketFieldsAgreeWithTheBucketID(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| subdivided := keyviz.MatrixRow{RouteID: 42, SubBucket: 3, SubBucketCount: 8} | ||
| require.Equal(t, "route:42#3", bucketIDFor(subdivided)) | ||
| require.Equal(t, 3, subBucketIndexFor(subdivided)) | ||
| require.Equal(t, 8, subBucketCountFor(subdivided)) | ||
|
|
||
| encoded, err := json.Marshal(KeyVizRow{ | ||
| BucketID: bucketIDFor(subdivided), | ||
| SubBucket: subBucketIndexFor(subdivided), | ||
| SubBucketCount: subBucketCountFor(subdivided), | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Contains(t, string(encoded), `"sub_bucket_count":8`) | ||
|
|
||
| // Bucket zero of a subdivided route: the index is legitimately 0, | ||
| // so only the count keeps it on the wire — which is why the count | ||
| // is what the SPA must test, not the index. | ||
| first := keyviz.MatrixRow{RouteID: 42, SubBucket: 0, SubBucketCount: 8} | ||
| require.Equal(t, "route:42#0", bucketIDFor(first)) | ||
| require.Equal(t, 8, subBucketCountFor(first)) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
When
--keyvizFanoutNodesyields at least one successful peer,mergeKeyVizMatricestakes its multi-matrix path, butrowMergeAccandresolveRowMergeAccininternal/admin/keyviz_fanout.godo not retain either of these new fields. Every merged response therefore serializes them as omitted, causingsubRangeLabelto returnnulland disabling the new sub-range label and narrowed Start/End captions specifically in the cluster-wide view. Preserve the metadata through the accumulator, preferably accepting a nonzero value from any modern peer for rolling-upgrade compatibility.Useful? React with 👍 / 👎.