Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook / Event System #690

Closed
nijikokun opened this issue Nov 6, 2015 · 12 comments
Closed

Hook / Event System #690

nijikokun opened this issue Nov 6, 2015 · 12 comments
Labels
task/feature Requests for new features in Kong
Milestone

Comments

@nijikokun
Copy link
Contributor

Would provide an ample and powerful solution to many outstanding issues including #682 and #338 by having hooks / events that plugins can register functions on for listening or actionable purposes.

Hook Examples

  • PLUGIN_ENABLED
  • PLUGIN_DISABLED
  • PLUGIN_DELETED
  • API_CREATED
  • API_DELETED
  • API_UPDATED
  • CONSUMER_...
  • PROVISION
  • etc...

Effectively allowing plugins to do actions throughout kong, without kong being aware of the plugins existence or calling the plugin directly.

Some Use Cases

These are just two, but there are countless more, even the #640 (slack integration) would benefit from hooks.


@thibaultcha thibaultcha added the task/feature Requests for new features in Kong label Nov 7, 2015
@Tieske
Copy link
Member

Tieske commented Nov 7, 2015

this might help; https://github.com/Olivine-Labs/mediator_lua

@thibaultcha
Copy link
Member

I'd say it looks overly complex for the very simple goal we are trying to achieve here. We simply want a hash table with keys being the event ids, and values being arrays containing functions to execute on a given key.

I can see a simple Lua module doing the job here.

@Tieske
Copy link
Member

Tieske commented Nov 7, 2015

I see what you mean. But in my experience, the simple module will quickly get a few feature requests and then ends up being a copy of an existing, fancier, module. It all depends on how confident you are that it stays "simple".

Also; this module is only 160 lines (126 sloc),

@thibaultcha
Copy link
Member

Yes you're right. We should consider it as an implementation. We would need some sort of wrapper around it though.

@nijikokun
Copy link
Contributor Author

I think this needs some clarification that wasn't specified, this is not simply an event bus.

Its Hooking, hooks can modify the result and return it.

Essentially it's a place in code that allows you to tap in to either provide different behavior (invoked callback methods that return the same or different results in sequence) or to react when something happens (this would be the event bus currently in #729).

@Tieske
Copy link
Member

Tieske commented Nov 21, 2015

There are many ways to do roughly the same thing. I think an important distinction here is whether the event handler (or hook) is trusted or not. If it's trusted, pass the full set of data along and let the handler decide whether or not to modify it (usually it will be tables, which are passed by reference anyway).

But if the code is not trusted, only a minimum set of data should be passed (by value, not by reference), and any results should be validated and copied back. Performance wise this is a tough one, considering deep copying of tables etc.

The first approach is far simpler of course... but because it is security related it is a rather fundamental choice.

@nijikokun
Copy link
Contributor Author

I don't think we should waste our time with the minimum set of data / copy mechanism, since the administrator of Kong would most likely only add officially supported by Kong or self-made plugins. I think this was a discussion previously brought up on plugins when separating them out and it is not really our concern.

Obviously if you add a plugin that isn't officially supported you are taking a risk on your behalf, we are not liable for this security wise, it is your own responsibility to verify and vet that before installing said plugin on your instances.


From another angle, let's say it's a medical enterprise business and they want to process their information, I don't think they would enable something that logs to the cloud for their health-care information and should they want to do this, they would split up their apis, or utilize sort of a plugin enabling mechanism that is in discussion (there are many ways to mitigate having that information pipe through such plugins)

@Tieske
Copy link
Member

Tieske commented Nov 24, 2015

It comes down to what your security philosophy is. So I guess it comes down to making a choice (Kong wide), document it, stick with it.

Anyway, my personal opinion is that I would leave it to the admin as to which plugins he/she wants to install. The complexity and performance hit will probably not be worth it.

@Tieske
Copy link
Member

Tieske commented Nov 24, 2015

So far for off-topic. On the event bus itself; the picture just registers callbacks for kong events (single producer, multiple consumer, hardly a bus).

Could it be useful to have any component register its own events (multi producer, multi consumer)? for example; a logger that subscribes to authentication events.

@nijikokun
Copy link
Contributor Author

Anyway, my personal opinion is that I would leave it to the admin as to which plugins he/she wants to install. The complexity and performance hit will probably not be worth it.

👍

Could it be useful to have any component register its own events (multi producer, multi consumer)? for example; a logger that subscribes to authentication events.

If you pass along the hook mechanisms in the new ngx.ctx and kong.core (#709) (attach / create) then I wouldn't see why a plugin couldn't have them (in fact I would expect some to create their own so other plugins could also hook into them -- auditing plugin, etc)

@Tieske
Copy link
Member

Tieske commented Nov 29, 2015

Couldn't the event/hook system also resolve #267? (provided the hook mechanism is passed along to enable multi-producer/multi-consumer setups)

@thibaultcha thibaultcha modified the milestone: Jan 2016 Dec 21, 2015
@thibaultcha
Copy link
Member

In 0.6.0 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task/feature Requests for new features in Kong
Projects
None yet
Development

No branches or pull requests

3 participants