Loading ...
close

Would you like to discuss your environment with a knowledgable engineer?

Preferred communication *

Thank you. We will be in touch with you shortly

Control aicache via programmable plugins

Posted by on November 3rd, 2014

aiScaler Plug-in Support.

Starting with version 6 of aiScaler, you can provide your own logic to execute when requests enter aiScaler. You can have such logic executed for all requests, requests for certain website or requests matching certain patterns.

You code has access to most of request’s information, including URI, body , Agent, Referrer, Cookies, Client IP and other information. Of course, some of these might not be present in every request.

You plugin code, after analyzing the request, can tell aiScaler to:

Drop the request

Redirect the request to a provided location – rewrite the request URL

Rewrite the request body

Modify request’s TTL

Finish execution of plug-ins, so that any other plug-ins that yet to fire, are skipped

Log a certain message as a result of executing plugin code

A good example use of aiScaler plugin functionality could be enforcing access token verification logic – looking for certain “access-token” parameter to be present in certain requests and programmatically validating the value of such “access-token” parameter.

aiScaler allows you to have, for each plugin, a set of three function: init, exec and destroy. Only the exec function is mandatory, the init and destroy functions are optional. In the init function you can allocate a plugin- specific data structure. aiScaler will then pass a pointer to that data structure to plug-n execution function. Same pointer will be passed to plug-in destroy function, if one is provided.

You can specify a number of plugin exec functions to be executed, one after another, in pre-determined order. Unless a prior plugin requests dropping of request, a redirect or specifies a complete response body, all of the plugins will be executed. Another way to break out of the plugin execution early is to return a special flag in plugin response status.

Sample C code, outlining basic plugin functionality, is provided within aiScaler distribution file. We also provide a simple shell scripts that compiles plugin code into a shared module (Linux .so file).

Defining plugins.

As you shall discover, writing plug-ins is a very straightforward exercise, requiring only minimal C coding skills and adhering to a few basic principles.

aiScaler will attempt to locate and initialize plugin init function only when you provide init string, in the plugin declaration directive. These are to be placed in global section of aiScaler configuration file.

Plugin statistics.

aiScaler internally tracks how many times each plugin has been executed. It also tracks other actions taken by plugins, you don’t have to code any such stat gathering logic into your plugin code. The stats are available via Web, CLI and SNMP stats. Here’s a set of counters output in the SNMP stat file (please note that plugin statistics start at sub-index of .1000.) :

As usual, you can configure your SNMP monitoring SW to collect, graph and alert on any of these SNMP counters.

Leave Comment

US (208) 948-9786‬   EU ‭+31 621302365