GitHub user nickwallen opened a pull request:

    https://github.com/apache/metron/pull/705

    METRON-1118 Ignore Profile with Bad 'onlyif' or 'foreach' Expressions

    The Profiler needs to gracefully ignore profiles that have a bad 'onlyif' 
or 'foreach' expression.  Under certain conditions a message may not be applied 
to all valid profiles, due to a single bad profile.
    
    If the Profiler is running with multiple profiles defined and one of those 
profiles has a Stellar expression that throws an exception for either the 
'foreach' or 'onlyif', the current logic will not continue to attempt to apply 
the message to the remaining valid profiles.  Only valid profiles executed 
before the bad profile will have the message applied.
    
    ## Testing
    
    Unit tests have been added to check for these conditions.  This can be 
manually tested with either a live Profiler running in a cluster or using the 
Profiler debugging functions.  
    
    Create two profiles; one that is valid and another that is invalid, like 
the following.  Ensure that all test messages that are sent through the 
Profiler, reach the `good-profile` despite the `bad-profile`.
    
    ```
     {
       "profiles": [
          {
            "profile": "bad-profile",
            "foreach": "2 / 0",
            "init":   { "x": "0" },
            "update": { "x": "x + 1" },
            "result": "x"
          },
          {
            "profile": "good-profile",
            "foreach": "ip_src_addr",
            "init":   { "x": "0" },
            "update": { "x": "x + 1" },
            "result": "x"
          }
       ]
     }
    ```
    
    Here are instructions for how to test using the Profiler debugging 
functions in the REPL. Create a Profiler with the above definition.  Copy and 
paste the definition above into the editor.
    ```
    [Stellar]>>> conf := SHELL_EDIT()
    [Stellar]>>> conf
    {
       "profiles": [
          {
            "profile": "bad-profile",
            "foreach": "2 / 0",
            "init":   { "x": "0" },
            "update": { "x": "x + 1" },
            "result": "x"
          },
          {
            "profile": "good-profile",
            "foreach": "ip_src_addr",
            "init":   { "x": "0" },
            "update": { "x": "x + 1" },
            "result": "x"
          }
       ]
     }
    [Stellar]>>> p := PROFILER_INIT(conf)
    ```
    
    Create a message.  Almost any message will do.
    ```
    [Stellar]>>> msg := SHELL_EDIT()
    [Stellar]>>> msg
    {
      "ip_src_addr": "10.0.0.1"
    }
    ```
    
    Apply the message to the profiler.  If the patch is successful it will 
look-like the following.
    ```
    [Stellar]>>> PROFILER_APPLY(msg, p)
    2017-08-17 23:39:42,605 ERROR [AeshProcess: 4] 
profiler.DefaultMessageRouter: error encountered while executing profile; 
profile='bad-profile', error='/ by zero'
    org.apache.metron.profiler.StandAloneProfiler@67ea50dd
    ```
    
    Prior to this patch this would trigger the bug and the same would look-like 
this.
    ```
    [Stellar]>>> PROFILER_APPLY( msg, p)
    [!] / by zero
    java.lang.ArithmeticException: / by zero
        at 
org.apache.metron.stellar.common.evaluators.ArithmeticEvaluator$ArithmeticEvaluatorFunctions.lambda$division$3(ArithmeticEvaluator.java:98)
        at 
org.apache.metron.stellar.common.evaluators.ArithmeticEvaluator.evaluate(ArithmeticEvaluator.java:39)
        at 
org.apache.metron.stellar.common.StellarCompiler.lambda$exitArithExpr_div$2(StellarCompiler.java:281)
        at 
org.apache.metron.stellar.common.StellarCompiler$Expression.apply(StellarCompiler.java:160)
        at 
org.apache.metron.stellar.common.BaseStellarProcessor.parse(BaseStellarProcessor.java:152)
        at 
org.apache.metron.stellar.common.DefaultStellarStatefulExecutor.execute(DefaultStellarStatefulExecutor.java:160)
        at 
org.apache.metron.stellar.common.DefaultStellarStatefulExecutor.execute(DefaultStellarStatefulExecutor.java:123)
        at 
org.apache.metron.profiler.DefaultMessageRouter.route(DefaultMessageRouter.java:75)
        at 
org.apache.metron.profiler.StandAloneProfiler.apply(StandAloneProfiler.java:71)
        at 
org.apache.metron.profiler.client.stellar.ProfilerFunctions$ProfilerApply.apply(ProfilerFunctions.java:150)
        at 
org.apache.metron.stellar.common.StellarCompiler.lambda$exitTransformationFunc$13(StellarCompiler.java:556)
        at 
org.apache.metron.stellar.common.StellarCompiler$Expression.apply(StellarCompiler.java:160)
        at 
org.apache.metron.stellar.common.BaseStellarProcessor.parse(BaseStellarProcessor.java:152)
        at 
org.apache.metron.stellar.common.shell.StellarExecutor.execute(StellarExecutor.java:287)
        at 
org.apache.metron.stellar.common.shell.StellarShell.executeStellar(StellarShell.java:364)
        at 
org.apache.metron.stellar.common.shell.StellarShell.handleStellar(StellarShell.java:267)
        at 
org.apache.metron.stellar.common.shell.StellarShell.execute(StellarShell.java:403)
        at org.jboss.aesh.console.AeshProcess.run(AeshProcess.java:53)
        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    ```
    
    ## Pull Request Checklist
    
    - [ ] Is there a JIRA ticket associated with this PR? If not one needs to 
be created at [Metron 
Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
 
    - [ ] 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)?
    - [ ] 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:
    - [ ] 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](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] Have you verified the basic functionality of the build by building 
and running locally with Vagrant full-dev environment or the equivalent?
    - [ ] 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`:


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nickwallen/metron METRON-1118

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metron/pull/705.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #705
    
----
commit f6ee7b182fa04f0566e97de9073780981207b4de
Author: Nick Allen <n...@nickallen.org>
Date:   2017-08-17T23:29:20Z

    METRON-1118 Ignore Profile with Bad 'onlyif' or 'foreach' Expressions

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to