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

METRON-1722: PcapCLI should print progress to stdout#1138

Closed
merrimanr wants to merge 6 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1722
Closed

METRON-1722: PcapCLI should print progress to stdout#1138
merrimanr wants to merge 6 commits intoapache:feature/METRON-1554-pcap-query-panelfrom
merrimanr:METRON-1722

Conversation

@merrimanr
Copy link
Copy Markdown
Contributor

Contributor Comments

This PR updates the Pcap CLI to print the status of a running job. I took a fairly simple approach as a first pass:

  • Added a PrintStream member variable to PcapJob
  • Added a reportStatus method that configures that variable
  • Added logic to the PcapJob.get method to print status if the printStream variable is set

This approach keeps us from having to change the Statusable interface. For those reviewing, what do you think of the message? Should we format it differently or include more information?

I am also considering adding a unit test for PcapJob.get in this PR since it doesn't exist and the changes in this PR affect that method.

Let me know what you think. There are several different ways to solve this.

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 metron folder via:

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

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • 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.

@justinleet
Copy link
Copy Markdown
Contributor

Given that this is solving a regression, I'd like a quick update on what the previous state was and how this compares. In particular, I'd like to know how it functions in terms of status and error / exception handling? I believe the old version printed out some of the underlying MR progression along with underlying errors. Do we have a sample of the old output at available?

I'm not sure how concerned we need to be with it being exactly the same (and I think there is definitely a fairly strong argument towards being consistent with the UI because the MR job isn't the only time consuming item there), but we do need to make sure it's at least as informative.

@merrimanr
Copy link
Copy Markdown
Contributor Author

I believe I found the solution. There is a method called monitorAndPrintJob on the org.apache.hadoop.mapreduce.Job class that blocks and prints status just as if you had submitted the job synchronously. I compared the Pcap CLI output in this PR with the output in master and it is exactly the same as far as I can tell.

@mmiklavc
Copy link
Copy Markdown
Contributor

mmiklavc commented Aug 6, 2018

@merrimanr I think this is closer with your recent change. I think it should still use the get() method because you need to wait for the finalizer to complete. Can we add a param for the CLI like PcapOptions.PRINT_JOB_STATUS.put(commonConfig, true)?

@merrimanr
Copy link
Copy Markdown
Contributor Author

@mmiklavc the latest commit includes the changes you suggested. Let me know what you think.

@justinleet
Copy link
Copy Markdown
Contributor

+1 by inspection, assuming @mmiklavc is good.

@merrimanr
Copy link
Copy Markdown
Contributor Author

Are you good @mmiklavc?

@mmiklavc
Copy link
Copy Markdown
Contributor

mmiklavc commented Aug 9, 2018

@merrimanr - That's not quite what I suggested - it's still not using the common config we pass in

Can we add a param for the CLI like PcapOptions.PRINT_JOB_STATUS.put(commonConfig, true)

If that monitorAndPrintJob() is a blocking call, it probably belongs in the get() itself. Rather than creating a one-off custom method invoked by the client, we already have configuration facilities for providing these options that we use for all other options. e.g. this section

Optional<String> jobName = Optional.ofNullable(PcapOptions.JOB_NAME.get(configuration, String.class));

And then it's just using that property like we use the others.

public Pageable<Path> get() throws JobException, InterruptedException {

public Pageable<Path> get() throws JobException, InterruptedException {
    if (PcapOptions.PRINT_JOB_STATUS.get(configuration, Boolean.class)) {
        mrJob.monitorAndPrintJob();
    }
    for (; ; ) {
      JobStatus status = getStatus();
      if (status.getState() == State.SUCCEEDED
          || status.getState() == State.KILLED
          || status.getState() == State.FAILED) {
        return getFinalResults();
      }
      Thread.sleep(completeCheckInterval);
    }
  }

The only reservation I have about the monitorAndPrintJob (versus using the pcapjob's TimerTask method) is that users cannot print status in a non-blocking way. Honestly I don't see a circumstance where you would do that with stdout anyhow. It's through pcapcli, where we want the process to return only after fully completing, so I think this is fine.

@merrimanr
Copy link
Copy Markdown
Contributor Author

Let me know what you think of the latest commit.

Copy link
Copy Markdown
Contributor

@mmiklavc mmiklavc left a comment

Choose a reason for hiding this comment

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

Looks great @merrimanr! One small cleanup for the unused properties in the unit test and I'm +1 via inspection.

PcapOptions.START_TIME_MS.put(config, 500L);
PcapOptions.END_TIME_MS.put(config, 1000L);
PcapOptions.NUM_RECORDS_PER_FILE.put(config, 1000);
PcapOptions.PRINT_JOB_STATUS.put(config, true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably remove these as they're not used anymore by the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This needs to be there since the print status command line argument is set.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see. Missed that with the diff only showing the option line in the latest commit. Full diff shows the extra option in the cli options arg list.

@mmiklavc
Copy link
Copy Markdown
Contributor

mmiklavc commented Aug 9, 2018

+1

@justinleet
Copy link
Copy Markdown
Contributor

I'm still +1

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