-
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
More Packetbeat cleanups #2972
More Packetbeat cleanups #2972
Conversation
urso
commented
Nov 9, 2016
- unexport private symbols in protocol analyzer and some other modules in packetbeat
- remove some unused transaction fields in protocols analyzers
@urso Can you check the test failure before I start reviewing? |
- remove unused structure fields - don't export plugin itself - rename plugin implementation to amqpPlugin
- rename HTTP to httpPlugin - unexport all symbols not used by any other package
- rename Mysql to mysqlPlugin - remove some unused structure fields - remove some unecessary conversions
- rename Pgsql to pgsqlPlugin - remove some unused structure fields - unexport private symbols
- unexport private symbols - rename 'Redis' to 'redisPlugin'
- rename Mongodb to mongodbPlugin - remove some unused structure fields - unexport private symbols
- rename Thrift to thriftPlugin - unexport private symbols - remove some unused struct fields
- rename DNS to dnsPlugin - unexport private symbols
- rename ICMP to icmpPlugin - unexport private symbols
5350b12
to
85f27e8
Compare
jenkins, test it |
jenkins, test it |
3 similar comments
jenkins, test it |
jenkins, test it |
jenkins, test it |
test from build-eu-00 |
jenkins, test it |
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 went through the changes from top to bottom and mainly tried to spot functional changes. I left comments where I was not 100% sure about the change without going deeper into the code to figure out where these changes come from. As most of the changes I commented appeared several times it seemed like all of these were intentional and I stopped comment even though they appeared more often.
This changes makes most of the varialbes which are not used outside the package private. I'm not 100% sure I agree with this change. The reasoning is that I see packetbeat not only as a "tool" but also as a library. For example if someone builds a new protocol but could use some methods from Http, that was possible before but now because they are private he can't. To change it a contribution is necessary which normally leads to people just copy code over. I'm ok with the changes but I think we should be careful here and think more specific which methods should be exposed.
Is there a specific reasons you renamed MongoDb to MongodbPlugin etc? Was there an issue with the previous naming? Not sure if this addition is needed in the name.
I would appreciate to have one PR per commit in the future which makes the review easier on my eyes ;-)
Pub *publish.PacketbeatPublisher | ||
Sniff *sniffer.SnifferSetup | ||
type packetbeat struct { | ||
config config.Config |
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.
Not sure about this change as Packetbeat can also be used as Library and it would be nice to at least have access tot he Config options. I sometimes have that problem with Golang libraries that most things are private and cannot be directly access which leads to coping code.
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.
Well, packetbeat can be used as framework, not as a library. The New function for creating an instances is still available. The packetbeat internals are internal now, so no one messes with them when using packetbeat as framework.
Insteadt of using type beater.Packetbeat, one uses the type beat.Beater as returned by New method.
} | ||
|
||
trans.ts = client.Ts | ||
trans.Ts = client.Ts.UnixNano() / 1000 |
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.
What happened to this and the following line? Already part of client.ts?
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.
The fields removed have never been read from. They are not part of the event being published or anything => save some bytes and drop unused structure fields.
} | ||
|
||
trans.ts = server.Ts | ||
trans.Ts = server.Ts.UnixNano() / 1000 |
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.
See above
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.
same. Remove unused fields.
@@ -83,8 +83,7 @@ func readFrameHeader(data []byte) (ret *AmqpFrame, err bool) { | |||
logp.Warn("Missing frame end octet in frame, discarding it") | |||
return nil, true | |||
} | |||
frame.Type = data[0] | |||
frame.channel = binary.BigEndian.Uint16(data[1:3]) |
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.
What happened to this 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.
same, remove unused fields.
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.
gotta check removal of frame.Type
though.
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.
double checking, frame.Type was not remove. Got confused by diff.
channel uint16 | ||
type amqpFrame struct { | ||
Type frameType | ||
// channel uint16 (frame channel is currently ignored) |
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.
Should we remove it then?
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 commented it out because: a) it indirectly reflects the wire format. b) maybe in future this will be exposed?
trans.event = requ.event | ||
trans.method = requ.method | ||
|
||
trans.cmdline = requ.CmdlineTuple | ||
trans.ts = requ.Ts | ||
trans.Ts = int64(trans.ts.UnixNano() / 1000) // transactions have microseconds resolution |
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.
As this becomes a pattern, I'm quite sure it is set as a default somewhere ;-)
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.
these fields have been set, but never been included in the event being generated (otherwise compilation would fail).
} | ||
|
||
// fill response | ||
if resp != nil { | ||
if requ == nil { |
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.
Not needed anymore?
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.
the value being set has been remove from trans, as field trans.tuple was unused.
@@ -489,34 +484,33 @@ func (mysql *Mysql) Parse(pkt *protos.Packet, tcptuple *common.TCPTuple, | |||
} | |||
} | |||
|
|||
if priv.Data[dir] == nil { | |||
priv.Data[dir] = &MysqlStream{ | |||
tcptuple: tcptuple, |
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 also becomes a pattern :-)
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.
yep, unused field
mysql.transactions.Put(tuple.Hashable(), trans) | ||
} | ||
|
||
trans.ts = msg.Ts | ||
trans.Ts = int64(trans.ts.UnixNano() / 1000) // transactions have microseconds resolution |
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.
pattern again
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 fields
Src common.Endpoint | ||
Dst common.Endpoint | ||
ResponseTime int32 | ||
Ts int64 |
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.
One more pattern
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 fields
No logic has been changed in this PR. PR did rename a load of structures/fields/methods unexporting mostly private symbols. Plus only unused fields in protocol analyzer plugins have been removed (saves some bytes + I don't have to wonder about 3 timestamp values anymore). Often these fields have been initialised, but once initialized never be used again. No reads have had to be fixed after removing fields. Before removing I also double-checked with guru for all potential references to removed fields.
I see packetbeat more as a framework than a library. As I already noted, packetbeat can still be used this way. Also the sniffer, decoder and process watcher are still re-usable. The public API has just been restricted to the most essential use (for good I think). About the HTTP example, I think it's good it discourages people from importing internals from http plugin. If required, I'd rather see common parser support being extracted/made available in general using a third package instead of importing symbols from/between other plugins.
renamed it for dealing with naming clashes |