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

More Packetbeat cleanups #2972

Merged
merged 21 commits into from
Nov 14, 2016
Merged

More Packetbeat cleanups #2972

merged 21 commits into from
Nov 14, 2016

Conversation

urso
Copy link

@urso 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 urso added the review label Nov 9, 2016
@ruflin
Copy link
Member

ruflin commented Nov 10, 2016

@urso Can you check the test failure before I start reviewing?

urso added 19 commits November 10, 2016 14:31
- 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
@tsg
Copy link
Contributor

tsg commented Nov 10, 2016

jenkins, test it

@dliappis
Copy link
Contributor

jenkins, test it

3 similar comments
@dliappis
Copy link
Contributor

jenkins, test it

@dliappis
Copy link
Contributor

jenkins, test it

@dliappis
Copy link
Contributor

jenkins, test it

@elasticsearch-release
Copy link

test from build-eu-00

@dliappis
Copy link
Contributor

jenkins, test it

Copy link
Member

@ruflin ruflin left a 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
Copy link
Member

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.

Copy link
Author

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

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?

Copy link
Author

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

Choose a reason for hiding this comment

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

See above

Copy link
Author

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])
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

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

same, remove unused fields.

Copy link
Author

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.

Copy link
Author

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

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?

Copy link
Author

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

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 ;-)

Copy link
Author

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 {
Copy link
Member

Choose a reason for hiding this comment

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

Not needed anymore?

Copy link
Author

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,
Copy link
Member

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 :-)

Copy link
Author

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

Choose a reason for hiding this comment

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

pattern again

Copy link
Author

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

Choose a reason for hiding this comment

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

One more pattern

Copy link
Author

Choose a reason for hiding this comment

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

unused fields

@urso
Copy link
Author

urso commented Nov 11, 2016

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.

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.

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.

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.

renamed it for dealing with naming clashes

@ruflin ruflin merged commit ad0781c into elastic:master Nov 14, 2016
@urso urso deleted the packetbeat-clean-exports branch February 19, 2019 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants