apache / openwhisk

Apache OpenWhisk is an open source serverless cloud platform
https://openwhisk.apache.org/
Apache License 2.0
6.54k stars 1.17k forks source link

Support for Trigger filters #272

Closed tverilytt closed 7 years ago

tverilytt commented 8 years ago

Hi! In some scenarios it would have been handy and practical to be able to specify a filter for a Trigger. The filter could have been passed on to the Feed creating the Trigger. And then the trigger fires only if the filter condition(s) is satisfied.

In a scenario I am having now, I do many concurrent (bulk) upcerts to a Cloudant ddatabase. My OpenWhisk changes feed fires the Trigger for every single upcert. The Trigger calls an Action for every upcert, and in the Action, I do the filtering on certain value(s) of the received document / payload.

Being able to specify the filtering on the Trigger itself, would make the Action simpler, and also one could create many Triggers (with different filters), all calling the same Action. In my scenario, I have to create a new Action (and Rule associating the Action with the Trigger) for every different filter I want to have.

With best regards -jo2

tverilytt commented 8 years ago

Maybe the CouchDB / Cloudant Design filter function for change feed can be utilized to specify desired filter function. Filter function can also take query parameter(s), which makes it easier to do more dynamic filtering "on demand"...

Filter functions

https://docs.cloudant.com/design_documents.html#filter-functions

Query parameters: https://docs.cloudant.com/cloudant_query.html#query-parameters

Filter function with query parameter:

GET /$DATABASE/_changes?filter=$DESIGN_ID/$FILTER_FUNCTION&status=new

Filter function described in CouchDB The Definitive Guide

http://guide.couchdb.org/draft/notifications.html

CouchDB on filter functions with query parameter sample:

http://couchdb.readthedocs.io/en/latest/couchapp/ddocs.html#filterfun

So e.g. when creating OpenWhisk trigger, a "filter" parameter could specify the filter function:

wsk -v trigger create myTrigger --feed /org_space/cloudantPackage/changes --param dbname mydb --param includeDoc true --params filter mailbox/by_status&status=new

markusthoemmes commented 8 years ago

Ou, that looks very promising. Many thanks for digging that out @tverilytt . We should definitly look into integrating that.

rabbah commented 7 years ago

@johnsolm @dubeejw move to cloudant package repo?

johnsolm commented 7 years ago

@rabbah yeah. I could see this being a must have for very large databases. moving it to open.

johnsolm commented 7 years ago

closing this issue as a duplicate of: https://github.com/openwhisk/openwhisk-package-cloudant/issues/55

johnsolm commented 7 years ago

@rabbah please close this one. I don't seem to be able to do that. I also wanted to label it as a duplicate...