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 decoder support #9790

Merged
merged 1 commit into from
May 31, 2018
Merged

Conversation

wenjiaswe
Copy link
Contributor

@wenjiaswe wenjiaswe commented May 30, 2018

etcd-dump-logs: add decoder support

Added "stream-decoder" flag so user could set the decoder and decoder args they want to use to decode each WAL log entries.

Expected behavior of decoder:
The decoder should be able to take hex encoded lines of binary as input (from etcd-dump-logs), process it, output the status and decoded data, preferably in the format of <DECODER_STATUS>|<DECODED_DATA>. (If the output is not in the preferable format, result will be put into decoded data column regardlessly)

Expected behavior of etcd-dump-logs:
When the stream-decoder is specified, etcd-dump-logs will feed the hex encoded lines of WAL LOG binary into the decoder and output the decoder_status and decoded_data for each entry.

Two simple decoders were added for testing and demonstrating purpose:
Both decoders (decoder_correctoutputformat.sh and decoder_wrongoutputformat.sh ) are simply converting 1234567890 to abcdefghij. decoder_correctoutputformat.sh outputs decoder_status and decoded_data in the preferable format as above (<DECODER_STATUS>|<DECODED_DATA>), while decoder_wrongoutputformat.sh does not. The different result from etcd-dump-logs can be found in decoder_correctoutputformat.output and decoder_wrongoutputformat.output.

Combination usage of etcd-dump-logs and Auger:
Other than the two "fake" decoder above, I would like to mention a real usage of this added feature using Auger as decoder. Auger (please refer to Auger link for further details if you are interested) is a very useful tool in kubernetes community to inspect and analyze kubernetes objects stored in etcd. Now with this change, we could use Auger as the decoder to decode kubernetes objects in WAL log and have them output nicely. Here is the example of using etcd-dump-logs and Auger.

$ etcd-dump-logs -stream-decoder "auger decode --output json --batch-process true" datadir
Snapshot:
empty
Start dupmping log entries from snapshot.
WAL metadata:
nodeID=2f7fbfd36802ff7a clusterID=bea638dce5096eef term=2 commitIndex=3358 vote=2f7fbfd36802ff7a
WAL entries:
lastIndex=3358
term index type data decoder_status decoded_data
1 1 conf method=ConfChangeAddNode id=2f7fbfd36802ff7a AUGER_ERROR:error decoding from application/json: Object 'Kind' is missing in '{"id":3422665156528897914,"peerURLs":["https://kubernetes-master:2380"],"name":"etcd-kubernetes-master"}'
2 2 norm AUGER_ERROR:error reading input, does not appear to contain valid JSON or binary data
2 3 norm method=PUT path="/0/members/2f7fbfd36802ff7a/attributes" val="{"name":"etcd-kubernetes-master","clientURLs":["http://127.0.0.1:2379"]}" AUGER_ERROR:error reading input, does not appear to contain valid JSON or binary data
2 4 norm method=PUT path="/0/version" val="3.2.0" AUGER_ERROR:error reading input, does not appear to contain valid JSON or binary data
2 5 norm method=QGET path="" AUGER_ERROR:error reading input, does not appear to contain valid JSON or binary data
2 6 norm method=QGET path="" AUGER_ERROR:error reading input, does not appear to contain valid JSON or binary data
2 7 norm header:<ID:18409135401817889912 > txn:<compare:<target:MOD key:"/registry/ranges/serviceips" mod_revision:0 > success:<request_put:<key:"/registry/ranges/serviceips" value:"k8s\000\n\025\n\002v1\022\017RangeAllocation\022#\n\022\n\000\022\000\032\000"\000*\0002\0008\000B\000z\000\022\01310.0.0.0/16\032\000\032\000"\000" > > failure:<request_range:<key:"/registry/ranges/serviceips" > > > AUGER_OK {"kind":"RangeAllocation","apiVersion":"v1","metadata":{"creationTimestamp":null},"range":"10.0.0.0/16","data":""}
2 8 norm header:<ID:18409135401817889914 > txn:<compare:<target:MOD key:"/registry/ranges/servicenodeports" mod_revision:0 > success:<request_put:<key:"/registry/ranges/servicenodeports" value:"k8s\000\n\025\n\002v1\022\017RangeAllocation\022#\n\022\n\000\022\000\032\000"\000*\0002\0008\000B\000z\000\022\01330000-32767\032\000\032\000"\000" > > failure:<request_range:<key:"/registry/ranges/servicenodeports" > > > AUGER_OK {"kind":"RangeAllocation","apiVersion":"v1","metadata":{"creationTimestamp":null},"range":"30000-32767","data":""}

README.md is added.
As etcd-dump-logs is getting more powerful and complicated, I think it's easier to have a README.md to explain the usage.

@gyuho @xiang90 @jpbetz

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 formatting issue. Can we also rebase from current master branch? We've bumped up the base test image to use Go 1.10.2.

Will try this new patch as well.

Lists all the interested entries from WAL log.

```

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this unneeded blank line at 39?

Entry types () count is : 4
```

[decoder_correctoutputformat.sh]: https://github.com/wenjiaswe/etcd/blob/decoder-support/tools/etcd-dump-logs/testdecoder/decoder_correctoutputformat.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

[decoder_correctoutputformat.sh]: ./testdecoder/decoder_correctoutputformat.sh?

@@ -45,6 +45,9 @@ func TestEtcdDumpLogEntryType(t *testing.T) {
t.Skipf("%q does not exist", dumpLogsBinary)
}

decoder_correctoutputformat := path.Join(binDir + "/testdecoder/decoder_correctoutputformat.sh")
Copy link
Contributor

Choose a reason for hiding this comment

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

filepath.Join(binDir, "/testdecoder/decoder_correctoutputformat.sh")?

@@ -45,6 +45,9 @@ func TestEtcdDumpLogEntryType(t *testing.T) {
t.Skipf("%q does not exist", dumpLogsBinary)
}

decoder_correctoutputformat := path.Join(binDir + "/testdecoder/decoder_correctoutputformat.sh")
decoder_wrongoutputformat := path.Join(binDir + "/testdecoder/decoder_wrongoutputformat.sh")
Copy link
Contributor

Choose a reason for hiding this comment

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

filepath.Join(binDir, "/testdecoder/decoder_wrongoutputformat.sh")?

@@ -31,6 +35,8 @@ import (
"github.com/coreos/etcd/wal/walpb"

"go.uber.org/zap"
"bytes"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move "bytes" and "os" at the same level as "encoding/hex"? Just minor gofmt issue.

etcd-dump-logs inspects etcd db files.

```

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary blank line at 6?

@wenjiaswe wenjiaswe force-pushed the decoder-support branch 5 times, most recently from c0a49a3 to 3ef3cff Compare May 30, 2018 22:40
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 Thank you very much for your review, I have addressed all your comments and rebased from the latest master branch, I have reran the unit tests and they all passed:

$ PASSES=unit PKG=./tools/etcd-dump-logs TESTCASE="\bTestEtcdDumpLogEntryType\b" ./test
Running with TEST_CPUS: 1,2,4
Starting 'unit' pass at Wed May 30 15:44:58 PDT 2018
Running unit tests...

if err != nil {
log.Panic(err)
}
os.Stderr.WriteString("decoder stderr: " + stderr.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

if stderr.String() != "" {
  os.Stderr.WriteString("decoder stderr: " + stderr.String())
}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Fixed!

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.

I manually tried it and works great. Thanks a lot!
Just minor nits on decoder stderr: output. And lgtm.

9 6 norm ID:10 lease_grant:<TTL:1 ID:1 > decoder output format is not right, print output anyway jhjadbjdjhjaajja
12 7 norm ID:13 auth_enable:<> decoder output format is not right, print output anyway jhjdcbcejj
27 8 norm ??? decoder output format is not right, print output anyway cf
decoder stderr:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?

9 6 norm ID:10 lease_grant:<TTL:1 ID:1 > ERROR jhjadbjdjhjaajja
12 7 norm ID:13 auth_enable:<> ERROR jhjdcbcejj
27 8 norm ??? ERROR cf
decoder stderr:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this?

@gyuho
Copy link
Contributor

gyuho commented May 31, 2018

Manually addressed README.md typos. Merging. Thanks.

@gyuho gyuho merged commit cc50a70 into etcd-io:master May 31, 2018
@wenjiaswe
Copy link
Contributor Author

Thanks, @gyuho !

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.

2 participants