Skip to content
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

Merged
merged 1 commit into from
Apr 27, 2018

Conversation

wenjiaswe
Copy link
Contributor

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

Copy link
Contributor

@gyuho gyuho left a 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!

var r etcdserverpb.Request
if err := r.Unmarshal(entry.Data); err == nil {
fmt.Printf("%4d\t%10d\tnorm", entry.Term, entry.Index)
//cnt ++
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@gyuho
Copy link
Contributor

gyuho commented Apr 25, 2018

I tried this, and very useful. Would be great if we can add Compaction, LeaseGrant, and LeaseRevoke since we've recently hit quite a few issues around lease.

Thanks!

@wenjiaswe
Copy link
Contributor Author

@gyuho Thanks for your prompt review! I will apply your comments now.

@wenjiaswe
Copy link
Contributor Author

@gyuho Are these (Compaction, LeaseGrant, and LeaseRevoke) recorded in WAL log?

@gyuho
Copy link
Contributor

gyuho commented Apr 25, 2018

@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.

@wenjiaswe
Copy link
Contributor Author

@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)
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Fatalf?

Copy link
Contributor Author

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

t.Fatalf?

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@gyuho
Copy link
Contributor

gyuho commented Apr 26, 2018

@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
Copy link
Contributor

Choose a reason for hiding this comment

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

new line.

Copy link
Contributor

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

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)
Copy link
Contributor

@gyuho gyuho Apr 26, 2018

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!

Copy link
Contributor Author

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.

if !fileutil.Exist(dumpLogsBinary) {
t.Skipf("%q does not exist", dumpLogsBinary)
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

@wenjiaswe wenjiaswe left a 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"},
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gyuho

  1. 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.

  2. I added filters for compaction, leasegrant and leaserevoke types and added tests for those.

{ID: 27, AuthRoleGrantPermission: irrauthrolegrantpermission},
{ID: 28, AuthRoleRevokePermission: irrauthrolerevokepermission},
}

Copy link
Contributor Author

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)
}
Copy link
Contributor Author

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"
}

Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Codecov Report

Merging #9628 into master will increase coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
etcdserver/api/v3rpc/util.go 69.56% <0%> (-8.7%) ⬇️
clientv3/namespace/watch.go 72.72% <0%> (-6.07%) ⬇️
raft/node.go 90.83% <0%> (-1.6%) ⬇️
pkg/transport/listener_tls.go 65.56% <0%> (-0.67%) ⬇️
clientv3/watch.go 96.56% <0%> (-0.25%) ⬇️
etcdserver/server.go 71.3% <0%> (+0.37%) ⬆️
etcdserver/api/v2http/client.go 90.78% <0%> (+0.44%) ⬆️
etcdserver/v3_server.go 77.51% <0%> (+0.47%) ⬆️
clientv3/balancer/grpc1.7-health.go 88.08% <0%> (+0.58%) ⬆️
lease/lessor.go 87.22% <0%> (+0.63%) ⬆️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 02e2e3d...5533257. Read the comment docs.

@gyuho
Copy link
Contributor

gyuho commented Apr 27, 2018

Great. I've tried it again, and confirmed that it fixes the issue that we mentioned.

Could you add

### Tooling

- Add [`etcd-dump-logs -entry-type`](https://github.com/coreos/etcd/pull/9628) flag to support WAL log filtering by entry type.

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!

wenjiaswe added a commit to wenjiaswe/etcd that referenced this pull request Apr 27, 2018
@wenjiaswe
Copy link
Contributor Author

@gyuho Thanks for review, I have updated changelog in #9650

Copy link
Contributor

@gyuho gyuho left a comment

Choose a reason for hiding this comment

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

lgtm thanks!

gyuho added a commit that referenced this pull request Apr 27, 2018
@jpbetz
Copy link
Contributor

jpbetz commented Apr 27, 2018

lgtm

Thanks @wenjiaswe !

@gyuho gyuho merged commit 7582a28 into etcd-io:master Apr 27, 2018
@wenjiaswe wenjiaswe deleted the new1 branch June 19, 2018 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants