<div dir="ltr"><div dir="ltr">On Thu, Dec 20, 2018 at 12:20 PM <a href="mailto:sduthil@wazo.io">sduthil@wazo.io</a> <<a href="mailto:sduthil@wazo.io">sduthil@wazo.io</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Could you give a use case for the filtering? I can imagine one, but not<br>
sure it is really useful:<br>
<br>
Use case: an application subscribes to all channels, in order to give a<br>
real-time view on all calls currently talking on the server. This<br>
application is only interested in ChannelCreated, ChannelUpdated,<br>
ChannelCallerID and ChannelDestroyed. The events like ChannelVarSet or<br>
ChannelTalkingStarted are just noise wasting CPU time of the application.<br></blockquote><div><br></div><div>Something like this is basically what we had in mind. For now we're just going to focus on filtering the event types, but in the future, if deemed useful, we might eventually add filtering on event type details as well.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
IMO, I would prefer a whitelist approach:<br>
<br>
- In future versions, Asterisk will inevitably add new events. Those new<br>
events may be quite frequent too. The point of the filter is to decrease<br>
the application's event flow, and if the filter is not updated to<br>
account for the new events, then the application's event flow may grow<br>
back. This may have a performance impact on the application side. I<br>
would prefer any Asterisk upgrade to have a minimal potential negative<br>
impact on performance.<br>
- A specific version of an application is interested only in a subset of<br>
events. It knows what events it is interested in, and is able<br>
to give a list of such events. IMO, the application should not have to<br>
know about events it is not interested in, and should even less have to<br>
maintain a list of all events it does not want.<br></blockquote><div><br></div><div>I think you make a good case for having a whitelist. Unless it is a super large headache I will probably go this route now.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Here is another API proposition. Note: I have done no analysis of what<br>
is easier to implement within Asterisk. I'm just stating what I would<br>
like to have for the REST interface, as an application developer:<br>
<br>
I propose to have one event filter per application, and consider the<br>
event filter as a resource that is always present (no POST, no DELETE),<br>
that would by default have no restrictions on events. The filter<br>
resource would look like this:<br>
<br>
GET /applications/{applicationName}/eventFilter<br>
<br>
{<br>
"allow": [<br>
{"type": "StasisStart"},<br>
{"type": "ChannelUserevent",<br>
"eventname": "eventname"}<br>
],<br>
"disallow": null<br>
}<br>
<br>
1. The whitelist and the blacklist can be implemented. The first version<br>
may only support the "blacklist" keyword, if it is easier to implement.<br>
2. Filtering could apply on other fields than the event's "type". The<br>
first version of the event filter may be implemented by only supporting<br>
the event's "type" field.<br>
<br>
So, as a first step, an equivalent to Kevin's proposition would be:<br>
<br>
GET /applications/{applicationName}/eventFilter<br>
<br>
{<br>
"disallow": [<br>
{"type": "eventType"},<br>
{"type": "eventType"},<br>
...<br>
]<br>
}<br>
<br>
Modification of the filter would be done with a PUT:<br>
<br>
PUT /applications/{applicationName}/eventFilter<br>
<br>
{<br>
"allow": [<br>
{"type": "StasisStart"},<br>
{"type": "StasisEnd"},<br>
],<br>
"disallow": null<br>
}<br>
<br>
When the application is created, the event filter is empty and looks<br>
like this:<br>
<br>
GET /applications/{applicationName}/eventFilter<br>
<br>
{<br>
"allow": null,<br>
"disallow": null<br>
}<br>
<br>
allow = null means "no filtering".<br>
allow = [] means "no events allowed", if we keep a strict meaning of the<br>
array as "any event that match at least one filtering directive is<br>
sent". It could also mean "no filtering", since "no events allowed" is<br>
not very useful...</blockquote><div><br></div><div>Joshua Colp also proposed something like this. After seeing it laid out I think I lean toward this approach or something very similar to it. Moving forward, at the very least, we want a flexible way to increase future filtering functionality with little, or preferably no change to the API. Pushing the allow/disallow specification down into the body allows that to happen.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What happens when "allow" and "disallow" are used together and match the<br>
same event? I propose that "disallow" takes precedence.<br></blockquote><div><br></div><div>Yes one would have to take precedence over the other, or make it so the whole operation is rejected and an error is returned. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
A PATCH operation could also be implemented to add or remove filter<br>
directives without having to PUT everything.<br>
<br>
Do you think a "reset" operation would be interesting? Something to<br>
remove all filters? Perhaps a DELETE? But that would be twisting the<br>
semantics of the DELETE, since the eventFilter resource would still be<br>
there. A POST on /applications/.../eventFilter/reset ? Or a POST with<br>
{"allow": null, "disallow": null} ?</blockquote><div><br></div><div>It's probably worthwhile to have some kind of reset or way to clear the filtering. I'm thinking that "no eventFilter" means the application would get all events, so I think a DELETE would work here. By having "no eventFilter" equal "all events" we can maintain the way things currently work (meaning current applications would not have to change). We can also always add this functionality in a subsequent patch too if app developers decide it's needed.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-- <br>
Sébastien Duthil<br>
<br>
---<br></blockquote><div><br></div><div>Many thanks for the detailed feedback!</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Kevin Harwell<div>Digium - A Sangoma Company | Senior Software Developer<div>445 Jan Davis Drive NW - Huntsville, AL 35806 - US</div><div>Check us out at: <a href="https://digium.com" target="_blank">https://digium.com</a> & <a href="https://asterisk.org" target="_blank">https://asterisk.org</a></div></div></div></div></div>