-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
etcd-dump-logs: add entry-type flag to list entries of specific types… #9628
Conversation
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.
Some minor nits. Otherwise, LGTM.
Defer to @jpbetz
Thanks!
tools/etcd-dump-logs/main.go
Outdated
var r etcdserverpb.Request | ||
if err := r.Unmarshal(entry.Data); err == nil { | ||
fmt.Printf("%4d\t%10d\tnorm", entry.Term, entry.Index) | ||
//cnt ++ |
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.
unused comment?
"go.uber.org/zap" | ||
) | ||
|
||
func TestEtcdDumpLogEntryType(t *testing.T) { |
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.
Check at the beginning of tests, if etcd-dump-logs
exists?
I tried this, and very useful. Would be great if we can add Thanks! |
@gyuho Thanks for your prompt review! I will apply your comments now. |
@gyuho Are these (Compaction, LeaseGrant, and LeaseRevoke) recorded in WAL log? |
@wenjiaswe Lease has a separate storage layer. I was confused with dump db tool, so never mind. Update: lease grants are recorded in WAL since they are processed by Raft layer. But we can add this later. |
@gyuho just make sure I didn't miss anything here:) db might be another area we will would like to analyse anyway. I am willing to fix that in etcd-dump-db later as well. For this PR, I have fixed the other two comments you had. Does that mean this is ready for merge once all the test passed? |
cmd := exec.Command(dumpLogsBinary, argtest.args...) | ||
actual, err := cmd.CombinedOutput() | ||
if err != nil { | ||
t.Fatal("%v", err) |
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.
t.Fatalf
?
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.
Good catch, fixed.
} | ||
expected, err := ioutil.ReadFile(path.Join(binDir, argtest.fileExpected)) | ||
if err != nil { | ||
t.Fatal("%v", err) |
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.
t.Fatalf
?
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.
Or just t.Fatal(err)
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.
Fixed.
@wenjiaswe Yeah let's improve dump db tool later. Just a few minor nits, and should be ready to merge. Thanks. |
6 12 norm ID:7 delete_range:<key:"0" range_end:"9" prev_kv:true > | ||
7 13 norm ID:8 txn:<success:<request_delete_range:<key:"a" range_end:"b" > > failure:<request_delete_range:<key:"a" range_end:"b" > > > | ||
|
||
Entry types () count is : 13 |
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.
new line.
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.
hmm... ignore this. just noticed that this is testing output data.
6 12 norm ID:7 delete_range:<key:"0" range_end:"9" prev_kv:true > | ||
7 13 norm ID:8 txn:<success:<request_delete_range:<key:"a" range_end:"b" > > failure:<request_delete_range:<key:"a" range_end:"b" > > > | ||
|
||
Entry types (Normal) count is : 9 |
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.
new line
|
||
// listEntriesType filters and prints entries based on the entry-type flag, | ||
func listEntriesType(entrytype string, ents []raftpb.Entry) { | ||
entryFilters := evaluateEntrytypeFlag(entrytype) |
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.
Can evaluateEntrytypeFlag
handle entrytype == ""
?
I double-checked our code, and lease grant does get recorded in WAL. And etcd-dump-logs ./data-dir
with no --entry-type
flag would omit those entries, while current master branch etcd-dump-logs
tool prints them out. If --entry-type
is empty, it should prints out all entries by default (e.g. lease grant, revoke, etc.).
Thanks!
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.
Yes, you are right! Thanks for the catch! I have fixed that and commented in place.
65d6233
to
8a2b347
Compare
if !fileutil.Exist(dumpLogsBinary) { | ||
t.Skipf("%q does not exist", dumpLogsBinary) | ||
} | ||
|
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.
@gyuho Here I added the check to see if etcd-dump-logs exists.
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.
@gyuho I have addressed the review comments. Thanks!
{"lease grant entry-type", []string{"-entry-type", "IRRLeaseGrant", p}, "expectedoutput/listIRRLeaseGrant.output"}, | ||
{"lease revoke entry-type", []string{"-entry-type", "IRRLeaseRevoke", p}, "expectedoutput/listIRRLeaseRevoke.output"}, | ||
{"confchange and txn entry-type", []string{"-entry-type", "ConfigChange,IRRCompaction", p}, "expectedoutput/listConfigChangeIRRCompaction.output"}, | ||
} |
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.
-
Thank you for catching the regression that when no entry-type is defined, the tool did not list all the entries. Now I have fixed that and added all types of InternalRaftRequest and made sure that no entries are missing in cases like: 1. no entry-type defined, 2. -entry-type Normal, 3. -entry-type InternalRaftRequest.
-
I added filters for compaction, leasegrant and leaserevoke types and added tests for those.
{ID: 27, AuthRoleGrantPermission: irrauthrolegrantpermission}, | ||
{ID: 28, AuthRoleRevokePermission: irrauthrolerevokepermission}, | ||
} | ||
|
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.
Here I added all internalraftrequest types for testing.
currentry.Type = raftpb.EntryNormal | ||
currentry.Data = []byte("?") | ||
*ents = append(*ents, currentry) | ||
} |
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.
I added the check to make sure unknown normal entries are listed as well, like the behavior of the tool before my change.
var rr etcdserverpb.InternalRaftRequest | ||
return entry.Type == raftpb.EntryNormal && rr.Unmarshal(entry.Data) == nil && rr.LeaseRevoke != nil, "InternalRaftRequest" | ||
} | ||
|
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.
Here I added filters for Compaction, LeaseGrant, and LeaseRevoke. More could be added in future if needed.
|
||
// listEntriesType filters and prints entries based on the entry-type flag, | ||
func listEntriesType(entrytype string, ents []raftpb.Entry) { | ||
entryFilters := evaluateEntrytypeFlag(entrytype) |
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.
Yes, you are right! Thanks for the catch! I have fixed that and commented in place.
Codecov Report
@@ Coverage Diff @@
## master #9628 +/- ##
==========================================
+ Coverage 69.03% 69.22% +0.19%
==========================================
Files 373 373
Lines 34048 34048
==========================================
+ Hits 23506 23571 +65
+ Misses 8816 8765 -51
+ Partials 1726 1712 -14
Continue to review full report at Codecov.
|
Great. I've tried it again, and confirmed that it fixes the issue that we mentioned. Could you add
around https://github.com/coreos/etcd/blob/master/CHANGELOG-3.4.md#go so people know who worked on it? A separate commit is fine. Then this should be good to merge. Thanks! |
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.
lgtm thanks!
lgtm Thanks @wenjiaswe ! |
etcd-dump-logs: add entry-type flag to list entries of specific types and add test
Added "entry-type" flag so user could use the tool to just list and count one or more types of interested entries. If not set, all entries are listed.
Added test as well.
Fixes #9295
@jpbetz @gyuho