-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Allow delete and index actions with a document ID #12606
Merged
ycombinator
merged 17 commits into
elastic:master
from
bestpath:feature/allow-index-and-delete-with-id
May 6, 2020
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7ac1280
Add `op_type` meta key for delete and index operations with a documen…
bestpath-gb a054ab5
Add note on why `obj` can be nil.
bestpath-gb e32ca09
Refactor and extract consts.
bestpath-gb 8713bd6
Don't include metadata prefix in key.
bestpath-gb fa44486
Stop appending `nil` else it ends up in the body.
bestpath-gb 1245360
Error when trying to delete with no _id.
bestpath-gb 722dd71
Remove incorrect detail in comment.
bestpath-gb 932f954
Add unit test for new op_type meta key.
bestpath-gb 99c2bf2
No longer required.
bestpath-gb 0ef2a12
Return error to caller.
bestpath-gb dc0a7b1
Fail event if op_type is no string.
bestpath-gb 40a22d9
Use consts in error.
bestpath-gb a541783
Replace assert with require.
bestpath-gb ef3883b
Fail instead of panic.
bestpath-gb 140e74f
Change missed assert calls to require.
bestpath-gb d084e89
Simplify GetMetaStringValue.
bestpath-gb 8ddf373
Ignore err as key may not exist.
bestpath-gb 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
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 |
---|---|---|
|
@@ -318,6 +318,68 @@ func TestBulkEncodeEvents(t *testing.T) { | |
} | ||
} | ||
|
||
func TestBulkEncodeEventsWithOpType(t *testing.T) { | ||
cases := []common.MapStr{ | ||
{"_id": "111", "op_type": "index", "message": "test 1", "bulkIndex": 0}, | ||
{"_id": "112", "op_type": "", "message": "test 2", "bulkIndex": 2}, | ||
{"_id": "", "op_type": "delete", "message": "test 6", "bulkIndex": -1}, // this won't get encoded due to missing _id | ||
{"_id": "", "op_type": "", "message": "test 3", "bulkIndex": 4}, | ||
{"_id": "114", "op_type": "delete", "message": "test 4", "bulkIndex": 6}, | ||
{"_id": "115", "op_type": "index", "message": "test 5", "bulkIndex": 7}, | ||
} | ||
|
||
cfg := common.MustNewConfigFrom(common.MapStr{}) | ||
info := beat.Info{ | ||
IndexPrefix: "test", | ||
Version: version.GetDefaultVersion(), | ||
} | ||
|
||
im, err := idxmgmt.DefaultSupport(nil, info, common.NewConfig()) | ||
require.NoError(t, err) | ||
|
||
index, pipeline, err := buildSelectors(im, info, cfg) | ||
require.NoError(t, err) | ||
|
||
events := make([]publisher.Event, len(cases)) | ||
for i, fields := range cases { | ||
events[i] = publisher.Event{ | ||
Content: beat.Event{ | ||
Meta: common.MapStr{ | ||
"_id": fields["_id"], | ||
"op_type": fields["op_type"], | ||
}, | ||
Fields: common.MapStr{ | ||
"message": fields["message"], | ||
}, | ||
}} | ||
} | ||
|
||
encoded, bulkItems := bulkEncodePublishRequest(logp.L(), *common.MustNewVersion(version.GetDefaultVersion()), index, pipeline, events) | ||
assert.Equal(t, len(events)-1, len(encoded), "all events should have been encoded") | ||
assert.Equal(t, 9, len(bulkItems), "incomplete bulk") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed a couple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh! I've corrected those. |
||
|
||
for i := 0; i < len(cases); i++ { | ||
bulkEventIndex, _ := cases[i]["bulkIndex"].(int) | ||
if bulkEventIndex == -1 { | ||
continue | ||
} | ||
caseOpType, _ := cases[i]["op_type"].(string) | ||
caseMessage, _ := cases[i]["message"].(string) | ||
switch bulkItems[bulkEventIndex].(type) { | ||
case eslegclient.BulkCreateAction: | ||
validOpTypes := []string{opTypeCreate, ""} | ||
require.Contains(t, validOpTypes, caseOpType, caseMessage) | ||
case eslegclient.BulkIndexAction: | ||
require.Equal(t, opTypeIndex, caseOpType, caseMessage) | ||
case eslegclient.BulkDeleteAction: | ||
require.Equal(t, opTypeDelete, caseOpType, caseMessage) | ||
default: | ||
require.FailNow(t, "unknown type") | ||
} | ||
} | ||
|
||
} | ||
|
||
func TestClientWithAPIKey(t *testing.T) { | ||
var headers http.Header | ||
|
||
|
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.
Nit: The function can be simplified to this:
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.
how about (requires no alloc):
All in all I'd prefer to keep the interface of
Event
as small as possible and provide helpers as functions instead of methods.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 is even better. \o/
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.
Thanks for the feedback. I've used the version from @urso . Nice to see this level of attention to detail!