Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

METRON-958: PCAP Query job throws exception when no files returned by time range query#593

Closed
mmiklavc wants to merge 5 commits intoapache:masterfrom
mmiklavc:METRON-958
Closed

METRON-958: PCAP Query job throws exception when no files returned by time range query#593
mmiklavc wants to merge 5 commits intoapache:masterfrom
mmiklavc:METRON-958

Conversation

@mmiklavc
Copy link
Copy Markdown
Contributor

@mmiklavc mmiklavc commented May 17, 2017

https://issues.apache.org/jira/browse/METRON-958

When the PCAP topology is run against a Kafka topic with multiple partitions, there will be at least one file per partition. The current MR job only expects adding a left trailing file for a single partition, so we miss files when performing the filter by timestamp on the filenames and it ends up throwing an exception.

Testing

Part 1

To test this, run a pcap topology against a Kafka topic with multiple partitions, preferably 3 or more. You'll also want to set kafka.pcap.maxTimeMS to something like 5 minutes (300000). You'll need to install pycapa and run it to create some data - https://github.com/apache/metron/tree/master/metron-sensors/pycapa. Let it run for 4-5 minutes. To keep it simple, stop it shy of 5 minutes so there's only 1 large-ish file per partition.

Run pcap inspector on one of the files and make note of the starting and ending time. Pick a time in the middle and run a pcap query using that time, down to the minute, as a filter. e.g.
${METRON_HOME}/bin/pcap_query.sh query -df "yyyyMMddHHmm" -st 201705162000 --query ""

EDIT - also try this with a Kakfa partition name that includes underscores, e.g. pcap_5

Part 2

Run a pcap query with a time outside of the range of times included in the pcap data and verify an exception is not thrown.

https://cwiki.apache.org/confluence/display/METRON/PCAP+CLI+Tool

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root incubating-metron folder via:

    mvn -q clean integration-test install && build_utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

@mmiklavc
Copy link
Copy Markdown
Contributor Author

I also attempted to start using the Google codestyle format in IntelliJ for this PR. It seems a couple things don't match up neatly with the checkstyle plugin using Google's style guide, but I haven't looked into it yet.

@justinleet
Copy link
Copy Markdown
Contributor

@mmiklavc Not everything gets handled by the auto-formatter,. Still do due diligence, because there may be some issue but some things will still get flagged by checkstyle without getting fixed by the autoformatter (e.g. if params are on newlines, it wants the comma with the previous params. Autoformat can't (won't?) do anything about it). My experience was that significantly more checkstyle issues got fixed with the Google profile.

@mmiklavc
Copy link
Copy Markdown
Contributor Author

Added fix for the actual empty result set problem

INFO mr.PcapJob: No files to process with specified date range.
No results returned.

@mmiklavc
Copy link
Copy Markdown
Contributor Author

Here are some instructions for getting pycapa setup

Installing pycapa
====================
env vars
PYCAPA_HOME=/opt/pycapa
PYTHON27_HOME =/opt/rh/python27/root

Install these packages via yum (RHEL, CentOS)
    epel-release
    centos-release-scl
    "@Development tools"
    python27
    python27-scldevel
    python27-python-virtualenv
    libpcap-devel
    libselinux-python

$ yum -y install epel-release centos-release-scl 
$ yum -y install "@Development tools" python27 python27-scldevel python27-python-virtualenv libpcap-devel libselinux-python

Setup directories
$ mkdir $PYCAPA_HOME && chmod 755 $PYCAPA_HOME

Create virtualenv
$ export LD_LIBRARY_PATH="/opt/rh/python27/root/usr/lib64"
$ ${PYTHON27_HOME}/usr/bin/virtualenv pycapa-venv

Install librdkafka
https://gist.github.com/nickwallen/0ed90197c3e45527147c30614d3b4432#pycapa

Copy pycapa
copy incubator-metron/metron-sensors/pycapa from the Metron source tree into $PYCAPA_HOME on the node you would like to install pycapa on.

Build it
$ cd ${PYCAPA_HOME}/pycapa
# activate the virtualenv
$ source ${PYCAPA_HOME}/pycapa-venv/bin/activate
$ pip install -r requirements.txt
$ python setup.py install

Run it
$ cd ${PYCAPA_HOME}/pycapa-venv/bin
$ pycapa --producer --topic pcap -i $ETH_INTERFACE -k $KAFKA_BROKER:6667

@mmiklavc mmiklavc closed this May 19, 2017
@mmiklavc
Copy link
Copy Markdown
Contributor Author

Kick to the Travis

@mmiklavc mmiklavc reopened this May 19, 2017
@merrimanr
Copy link
Copy Markdown
Contributor

+1 worked as advertised. I tested this in full dev using a topic with an '_' character in the name. A query within the time range returned results and a query outside of the time range returned a "No results returned" message and did not throw an exception.

I did notice that when I set the query time range to a different day or month a map reduce job still ran. Is this expected? I would expect the query map reduce job to be smart enough to exclude files in this case. That is outside the scope of this PR but wanted to bring it up.

@mmiklavc
Copy link
Copy Markdown
Contributor Author

Thanks @merrimanr! Good observation on the start/end date. Part of the problem is that we don't know how large the file time ranges are or when they will roll over, so we might still miss some if we try to exclude by day. We might be able to add some clues to help with this though.

@asfgit asfgit closed this in e219731 May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants