You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by cestella <gi...@git.apache.org> on 2018/06/27 14:40:10 UTC

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

GitHub user cestella opened a pull request:

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

    METRON-1643: Create a REGEX_ROUTING field transformation

    ## Contributor Comments
    A relatively common pattern is to choose the value of a field based on if another field matches a set of regexes.  This can be done via stellar with match, but if the list of possible regexes are large, that can be unwieldy.  To ease that burden, we should have a REGEX_ROUTING field transformation.
    
    
    ## Pull Request Checklist
    
    Thank you for submitting a contribution to Apache Metron.  
    Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.  
    Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) 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:
    - [x] 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).
    - [x] 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.
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    
    ### For code changes:
    - [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
    - [x] Have you included steps or a guide to how the change may be verified and tested manually?
    - [x] 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 
      ```
    
    - [x] Have you written or updated unit tests and or integration tests to verify your changes?
    - [x] 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)?
    - [x] 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:
    - [x] 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](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.


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

    $ git pull https://github.com/cestella/incubator-metron regex_routing

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

    https://github.com/apache/metron/pull/1083.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 #1083
    
----
commit 5030d00f9eb13ff662716f1c05a731938a66cb52
Author: cstella <ce...@...>
Date:   2018-06-05T19:05:59Z

    Regex based message router transformer.

commit 7c2723bc243996a2a0606e07def5e3b5c1736e59
Author: cstella <ce...@...>
Date:   2018-06-06T14:35:25Z

    updating test

commit 4a5461a8a7b4cd34d6541c0449470901d6ef3ed5
Author: cstella <ce...@...>
Date:   2018-06-08T02:56:50Z

    Merge branch 'master' into regex_routing

commit f1bda7478824e716d60a28cab8680e303a9e28a7
Author: cstella <ce...@...>
Date:   2018-06-08T03:03:34Z

    regex routing docs

commit ba862789e43f9e5d8e648d86378d89ec98d30d5b
Author: cstella <ce...@...>
Date:   2018-06-27T14:19:42Z

    Merge branch 'master' into regex_routing

----


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    @ottobackwards Yeah, my history of really crappy naming continues.  How about `REGEX_SELECT` or `REGEX_SWITCH`?


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    " Ultimately, I consider this a stop-gap."
    
    Yes.  What we are basically doing is writing a meta language on top of stellar.  In this case we are using that to make up for the meta language itself not supporting multi-line input ( and stellar's support for that as well )
    
    A question would be, why would this transform not just be transformed into a match statement instead of adding a new function?
    
    How much of this pain is from not using the UI for editing?  Would a ui editor that let you put in a multi line match make this pain better?



---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r198530993
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_ROUTING` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This has functional overlap with Stellar match statements, but the syntax is more bearable for large sets of conditionals.
    --- End diff --
    
    Yeah, that was wrong of me.  I had a bad night, when I wrote that.  My bad.  Will correct right away.  `match` is and continues to be awesome. :)


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r198536558
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_ROUTING` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This has functional overlap with Stellar match statements, but the syntax is more bearable for large sets of conditionals.
    --- End diff --
    
    I don't take it as an indictment on match, but more on stellar and the requirement for a meta programming mode through the transformation construct.  So... don't be so tough on yourself.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    A big thumbs up to not embedding Stellar directly in JSON.  I think that would solve a number of problems.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    I am not sure ROUTING is a good name for this.  This is more like a SELECT.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    @ottobackwards Makes sense; I made the change and percolated it to METRON-1644 aka #1084 


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    Can you provide a "routing in Stellar" versus "routing with REGEX_ROUTING" example that highlights the benefits of this approach?  
    
    This go against our current trajectory of "do everything in Stellar" and I want to make sure I understand the benefits.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    Sure, so the difference in the parser chaining example would be between the following
    # Stellar
    ```
    "fieldTransformations" : [
        {
         "transformation" : "STELLAR"
        ,"input" :  "pix_type"
        ,"output" :  "logical_source_type"
        ,"config" : {
          "logical_source_type" : "match{REGEXP_MATCH(pix_type, '^6-302.*') => 'cisco-6-302', REGEXP_MATCH(pix_type, '^5-304.*') => 'cisco-5-304', default => NULL}",
                    }
        }
                               ]
    ```
    
    # `REGEX_SELECT`
    ```
    "fieldTransformations" : [
        {
         "transformation" : "REGEX_SELECT"
        ,"input" :  "pix_type"
        ,"output" :  "logical_source_type"
        ,"config" : {
          "cisco-6-302" : "^6-302.*",
          "cisco-5-304" : "^5-304.*"
                    }
        }
                               ]
    ```
    
    It bears mentioning that things get worse in stellar when:
    1. You want to match on one of a set of regexs (e.g. `match { REGEXP_MATCH(pix_type, 'regex1') or REGEXP_MATCH(pix_type, 'regex2') => 'foo', ...`)
    2. The set of target kafka topics grows.  In this example there are 2, but if there were 5, they'd all have to fit in a long line of stellar.
    
    I think it's not that stellar isn't equipped to handle it theoretically, it's just that for these kinds of use-cases, it's more readable to create something a bit more specific until we get multi-line Stellar available.  Ultimately, I consider this a stop-gap.


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r200672238
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_SELECT` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This transformation is useful when the number or conditions are large enough to make a stellar language match statement unwieldy.
    + 
    +The following config will set the field `my_output` to one of the
    +following, dependent upon the value of the `my_input` field:
    +* `awesome` if `my_input` starts with `metron` or `mortron`
    +* `boo` if `my_input` starts with `scary`
    +```
    +{
    +...
    +    "fieldTransformations" : [
    +          {
    +            "transformation" : "REGEX_SELECT"
    +          , "input" : "my_input"
    +          , "output" : "my_output"
    +          , "config" : {
    +            "awesome" : [ "^metron.*", "^mortron.*" ],
    --- End diff --
    
    A little nit.  It makes it harder to grok the docs when you use non-sensical phrases like 'boo', 'scary', etc in the primary example.  Is there an actual use case that we could show here instead?  


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    I think a decent UI that would make this a hell of a lot easier, but also not embedding stellar in JSON would help a lot.  Something like:
    ```
    match {
      REGEXP_MATCH(pix_type, '^6-302.*') => 'cisco-6-302', 
      REGEXP_MATCH(pix_type, '^5-304.*') => 'cisco-5-304', 
      default => NULL
    }
    ```
    is a lot easier to read and deal with.  Also, enabling REGEXP_MATCH to take multiple regexes via a list in the 2nd arg would make things easier.


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r200675612
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_SELECT` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This transformation is useful when the number or conditions are large enough to make a stellar language match statement unwieldy.
    + 
    +The following config will set the field `my_output` to one of the
    +following, dependent upon the value of the `my_input` field:
    +* `awesome` if `my_input` starts with `metron` or `mortron`
    +* `boo` if `my_input` starts with `scary`
    +```
    +{
    +...
    +    "fieldTransformations" : [
    +          {
    +            "transformation" : "REGEX_SELECT"
    +          , "input" : "my_input"
    +          , "output" : "my_output"
    +          , "config" : {
    +            "awesome" : [ "^metron.*", "^mortron.*" ],
    --- End diff --
    
    I changed the parsers docs to reflect the use-case that I wrote up for the next PR.  That should fold in well together and be a real use-case.  Thanks for the feedback.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    Ok, I updated with manual testing plan and I think I've made the changes requested.  Let me know what you guys think.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    You got it [METRON-1655](https://issues.apache.org/jira/browse/METRON-1655)


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r198530068
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_ROUTING` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This has functional overlap with Stellar match statements, but the syntax is more bearable for large sets of conditionals.
    --- End diff --
    
    I don't think we need to editorialize so much about the match statements here.
    "This transformation is useful when the number or conditions are large enough to make a stellar language match statement unwieldy" would be better.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    +1 to SELECT
    What you are saying is SET FIELD to X if SELECT.
    It would be SWITCH if it were a different X per matching regex


---

[GitHub] metron pull request #1083: METRON-1643: Create a REGEX_ROUTING field transfo...

Posted by nickwallen <gi...@git.apache.org>.
Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1083#discussion_r200672433
  
    --- Diff: metron-platform/metron-parsers/README.md ---
    @@ -337,6 +337,28 @@ The following config will rename the fields `old_field` and `different_old_field
                           ]
     }
     ```
    +* `REGEX_SELECT` : This transformation lets users set an output field to one of a set of possibilities based on matching regexes. This transformation is useful when the number or conditions are large enough to make a stellar language match statement unwieldy.
    + 
    +The following config will set the field `my_output` to one of the
    +following, dependent upon the value of the `my_input` field:
    +* `awesome` if `my_input` starts with `metron` or `mortron`
    +* `boo` if `my_input` starts with `scary`
    +```
    +{
    +...
    +    "fieldTransformations" : [
    +          {
    +            "transformation" : "REGEX_SELECT"
    +          , "input" : "my_input"
    +          , "output" : "my_output"
    +          , "config" : {
    +            "awesome" : [ "^metron.*", "^mortron.*" ],
    --- End diff --
    
    Same goes for the test cases, IMO, but I am not going to hold up the PR for that.


---

[GitHub] metron issue #1083: METRON-1643: Create a REGEX_ROUTING field transformation

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/1083
  
    Why don't you create a jira for the REGEXP_MATCH 


---