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

Fix parsing of interface options with _ (#4334) #4378

Merged
merged 1 commit into from
May 29, 2017
Merged

Conversation

zecke
Copy link
Contributor

@zecke zecke commented May 23, 2017

In commit 5547060 linting issues
were addresses and variables containing _ were renamed. This broke
the config parsing.

In packetbeat this seems to effect the with_vlans, bpf_filter and
the buffer_size_mb options. Correct it by using a tag in the structure.

@elasticmachine
Copy link
Collaborator

Can one of the admins verify this patch?

@zecke
Copy link
Contributor Author

zecke commented May 23, 2017

Sorry heading out for tonight but wanted to share my findings in regard to issue #4334.

  • There are more variables that might be used in the config file (Src_ip, Dst_ip, proc_prefix)
  • To test one could probably easily have a round-trip test? Parse the config and write what was parsed and check there is no difference?

@elasticmachine
Copy link
Collaborator

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run.

@ruflin
Copy link
Contributor

ruflin commented May 23, 2017

@zecke Thanks a lot for bringing this up. If you are right, it seems that this could affect quite a few more variables.

@ruflin ruflin added in progress Pull request is currently in progress. Packetbeat labels May 23, 2017
@tsg
Copy link
Contributor

tsg commented May 23, 2017

Hmm, yeah, looks like this broke with #2928. :(

@zecke Thanks a lot for finding & fixing this. Can you add config tags to the rest of the InterfaceConfig struct? All the structs in config.go are used in configurations, but only that struct is lacking tags.

Our system tests didn't catch these because they always work on reading from files, rather than opening an interface.

In commit 5547060 linting issues
were addresses and variables containing _ were renamed. This broke
the config parsing.

In packetbeat this seems to effect the with_vlans, bpf_filter and
the buffer_size_mb options. Correct it by adding tags for all
documented variables.
@zecke
Copy link
Contributor Author

zecke commented May 24, 2017

@tsg Shouldn't bpf_filter work for reading from files too? I have not looked at the test setup but setting a filter that should only match a subset of the packets in a file and verifying the number of imported packets should be doable?

I annotated the struct (and aligned the tags to match the longest one). I have left the last options out as they are not documented in the reference file and I didn't know what is being used (top_speed, topspeed, topSpeed)

@clennpillo
Copy link

Thanks for fixing this, this was preventing us from monitoring a busy interface, I guess this PR will be merged soon ?

@tsg tsg added needs_backport PR is waiting to be backported to other branches. v5.5.0 review and removed in progress Pull request is currently in progress. labels May 29, 2017
@tsg
Copy link
Contributor

tsg commented May 29, 2017

@zecke Currently it's not applied on reading from file. We could implement it, but then it would probably be a different setting, because this one applies to "interfaces"?

I'm going to merge it for now like this and improve on the system tests if something like this ever surfaces again. I'll add the Changelog while backporting, thanks a lot for the fix!

@tsg tsg merged commit 813466d into elastic:master May 29, 2017
@tsg tsg removed the needs_backport PR is waiting to be backported to other branches. label May 29, 2017
tsg pushed a commit to tsg/beats that referenced this pull request May 29, 2017
In commit 5547060 linting issues
were addresses and variables containing _ were renamed. This broke
the config parsing.

In packetbeat this seems to effect the with_vlans, bpf_filter and
the buffer_size_mb options. Correct it by adding tags for all
documented variables.
(cherry picked from commit 813466d)
exekias pushed a commit that referenced this pull request May 30, 2017
) (#4411)

* Fix parsing of interface options with _ (#4334) (#4378)

In commit 5547060 linting issues
were addresses and variables containing _ were renamed. This broke
the config parsing.

In packetbeat this seems to effect the with_vlans, bpf_filter and
the buffer_size_mb options. Correct it by adding tags for all
documented variables.
(cherry picked from commit 813466d)
zecke added a commit to zecke/beats that referenced this pull request May 31, 2017
In elastic#4378 we briefly discussed how to test the parsing of config
parameters. The way ucfg works is that the yaml/json is unpacked
into the struct and  with the current approach at least two issues
can occur:

1.) One can have entries in the config file that are not consumed
2.) One can have members in the struct that are not filled

To allow testing proper parsing of a valid configuration file and
help users to show what has been passed I introduce a new config
option.

Instead of forcing this new method for the existing Beater interface,
add a new introspection interface...

TODO: Is this a sound approach? Shall a list of interfaces be returned?
Print them to a file? What about the b.Config? How to add this as a
system test?

TODO: Don't use go-yaml/yaml but the one used by ucfg?
@zecke
Copy link
Contributor Author

zecke commented May 31, 2017

@tsg "interfaces": True, let's not do that then.

In zecke@73e275d I created a new interface (to allow easy porting of the existing beats?!) and played a bit with printing a yaml representation of what has been parsed. It prints something like this...

I think in general it is a nice addition:

  1. It might help users to find typos in their config file (in case something is not picked up?)
  2. We could somehow integrate it into the system tests and just compare text output?

What do you think?

interfaces:
  device: en0
  type: pcap
  file: ""
  withvlans: false
  bpffilter: ""
  snaplen: 65535
  buffersizemb: 0
  topspeed: false
  dumpfile: ""
  oneatatime: false
  loop: 1
flows:
  enabled: false
  timeout: 30s
  period: 10s
protocols:
  amqp: {}
  cassandra: {}
  dns: {}
  http: {}
  icmp: {}
...
runoptions:
  uid: null
  gid: null

@zecke zecke deleted the fix-4334 branch May 31, 2017 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants