{"action":"created","issue":{"url":"https://api.github.com/repos/Jeffail/benthos/issues/84","repository_url":"https://api.github.com/repos/Jeffail/benthos","labels_url":"https://api.github.com/repos/Jeffail/benthos/issues/84/labels{/name}","comments_url":"https://api.github.com/repos/Jeffail/benthos/issues/84/comments","events_url":"https://api.github.com/repos/Jeffail/benthos/issues/84/events","html_url":"https://github.com/Jeffail/benthos/issues/84","id":356560274,"node_id":"MDU6SXNzdWUzNTY1NjAyNzQ=","number":84,"title":"proposal: refactor conditions to support operator configuration","user":{"login":"cludden","id":4565917,"node_id":"MDQ6VXNlcjQ1NjU5MTc=","avatar_url":"https://avatars1.githubusercontent.com/u/4565917?v=4","gravatar_id":"","url":"https://api.github.com/users/cludden","html_url":"https://github.com/cludden","followers_url":"https://api.github.com/users/cludden/followers","following_url":"https://api.github.com/users/cludden/following{/other_user}","gists_url":"https://api.github.com/users/cludden/gists{/gist_id}","starred_url":"https://api.github.com/users/cludden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cludden/subscriptions","organizations_url":"https://api.github.com/users/cludden/orgs","repos_url":"https://api.github.com/users/cludden/repos","events_url":"https://api.github.com/users/cludden/events{/privacy}","received_events_url":"https://api.github.com/users/cludden/received_events","type":"User","site_admin":false},"labels":[{"id":1030058058,"node_id":"MDU6TGFiZWwxMDMwMDU4MDU4","url":"https://api.github.com/repos/Jeffail/benthos/labels/conditions","name":"conditions","color":"f29a57","default":false},{"id":345436756,"node_id":"MDU6TGFiZWwzNDU0MzY3NTY=","url":"https://api.github.com/repos/Jeffail/benthos/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-09-03T16:29:57Z","updated_at":"2018-09-03T19:41:00Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I am working on adding additonal operators to both the `metadata` and `jmespath` (which currently does not support operators) conditions. One of my use cases is to match against a long list of enumerations (to go along with the switch output). It currently feels awkward to force config for an `enum` operator into the string `arg` field. I'm proposing changing the way condition configuration is currently implemented to mirror the configuration structure of other benthos components (namely inputs, outputs, and processors). Below is an example to illustrate the proposal:\r\n\r\nchange this:\r\n```yaml\r\ncondition:\r\n  type: metadata\r\n  metadata:\r\n    operator: less_than\r\n    key: foo\r\n    part: 0\r\n    arg: \"3\"\r\n```\r\n\r\nto this:\r\n```yaml\r\ncondition:\r\n  type: metadata\r\n  metadata:\r\n    operator: less_than\r\n    key: foo\r\n    part: 0\r\n    less_than: 3\r\n```\r\n\r\nThe difference may seem subtle, but is better illustrated with more complex (hypothetical) operators:\r\n\r\n```yaml\r\ncondition:\r\n  type: metadata\r\n  metadata:\r\n    operator: enum\r\n    key: foo\r\n    part: 0\r\n    enum:\r\n      - \"a\"\r\n      - \"very, long\"\r\n      - \"list\"\r\n      - \"of\"\r\n      - \"values!\"\r\n```\r\n\r\nor\r\n\r\n```yaml\r\ncondition:\r\n  type: jmespath\r\n  jmespath:\r\n    operator: json_schema\r\n    query: foo\r\n    part: 0\r\n    json_schema:\r\n      type: object\r\n      properties:\r\n        bar:\r\n          type: string\r\n          pattern: date-time\r\n        baz:\r\n          type: integer\r\n          minimum: 5\r\n          exclusiveMinimum: true\r\n        qux:\r\n          type: array\r\n          uniqueItems: true\r\n          items:\r\n            type: string\r\n            enum: [\"quux\",\"quz\",\"corge\"]\r\n      required:\r\n        - bar\r\n        - baz\r\n```\r\n\r\nWe could maintain backwards compatibility by continuing to support the `arg` field for existing operators. @Jeffail what are your thoughts?"},"comment":{"url":"https://api.github.com/repos/Jeffail/benthos/issues/comments/418183077","html_url":"https://github.com/Jeffail/benthos/issues/84#issuecomment-418183077","issue_url":"https://api.github.com/repos/Jeffail/benthos/issues/84","id":418183077,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODE4MzA3Nw==","user":{"login":"cludden","id":4565917,"node_id":"MDQ6VXNlcjQ1NjU5MTc=","avatar_url":"https://avatars1.githubusercontent.com/u/4565917?v=4","gravatar_id":"","url":"https://api.github.com/users/cludden","html_url":"https://github.com/cludden","followers_url":"https://api.github.com/users/cludden/followers","following_url":"https://api.github.com/users/cludden/following{/other_user}","gists_url":"https://api.github.com/users/cludden/gists{/gist_id}","starred_url":"https://api.github.com/users/cludden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cludden/subscriptions","organizations_url":"https://api.github.com/users/cludden/orgs","repos_url":"https://api.github.com/users/cludden/repos","events_url":"https://api.github.com/users/cludden/events{/privacy}","received_events_url":"https://api.github.com/users/cludden/received_events","type":"User","site_admin":false},"created_at":"2018-09-03T19:41:00Z","updated_at":"2018-09-03T19:41:00Z","author_association":"CONTRIBUTOR","body":"that seems reasonable. I think my only concern with the `interface{}` approach is the lack of built in documentation for operator configuration and the addition of a lot of type coercion / reflection in each of the operator factories which may clutter the code base unnecessarily. are you imaging something like the `json` processor's `value` field?\r\n\r\nand the `json_schema` operator was a made up example. at the moment I really only need enum support for both metadata and json payloads, and was hoping to avoid building gigantic configurations by combining an `or` condition with a long list of subconditions. I do however really like the idea of a `check_field` condition. Also, what are your thoughts on adding `operator` support to the `jmespath` condition? currently it acts as a `bool` operator (`foo == 'bar'`), but I think it could be useful to allow some other common operators (`regexp_partial`, `regexp_exact`, `less_than`, `greater_than`, `enum`)"}}
{"actor":{"display_login":"cludden"}}