]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: Add lists of frontends and backends
authorThierry FOURNIER <thierry.fournier@ozon.io>
Mon, 24 Jul 2017 11:30:43 +0000 (13:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 25 Jul 2017 16:19:50 +0000 (18:19 +0200)
Adis Nezirovic reports:

   While playing with Lua API I've noticed that core.proxies attribute
   doesn't return all the proxies, more precisely the ones with same names
   (e.g. for frontend and backend with the same name it would only return
   the latter one).

So, this patch fixes this problem without breaking the actual behaviour.
We have two case of proxies with frontend/backend capabilities:

The first case is the listen. This case is not a problem because the
proxy object process these two entities as only one and it is the
expected behavior. With these case the "proxies" list works fine.

The second case is the frontend and backend with the same name. i think
that this case is possible for compatibility with 'listen' declaration.
These two proxes with same name and different capabilities must not
processed with the same object (different statitics, differents orders).
In fact, one the the two object crush the other one whoch is no longer
accessible.

To fix this problem, this patch adds two lists which are "frontends" and
"backends", each of these list contains specialized proxy, but warning
the "listen" proxy are declare in each list.

doc/lua-api/index.rst
src/hlua_fcn.c

index 541d960a5601e220bf70a29373e46ea437dd1fa1..822f8bc978375501c26f7cf6538284f62cdbb64c 100644 (file)
@@ -173,6 +173,40 @@ Core class
   proxy give an access to his list of listeners and servers. Each entry is of
   type :ref:`proxy_class`
 
+  Warning, if you are declared frontend and backend with the same name, only one
+  of these are listed.
+
+  :see: :js:attr:`core.backends`
+  :see: :js:attr:`core.frontends`
+
+.. js:attribute:: core.backends
+
+  **context**: task, action, sample-fetch, converter
+
+  This attribute is an array of declared proxies with backend capability. Each
+  proxy give an access to his list of listeners and servers. Each entry is of
+  type :ref:`proxy_class`
+
+  Warning, if you are declared frontend and backend with the same name, only one
+  of these are listed.
+
+  :see: :js:attr:`core.proxies`
+  :see: :js:attr:`core.frontends`
+
+.. js:attribute:: core.frontends
+
+  **context**: task, action, sample-fetch, converter
+
+  This attribute is an array of declared proxies with frontend capability. Each
+  proxy give an access to his list of listeners and servers. Each entry is of
+  type :ref:`proxy_class`
+
+  Warning, if you are declared frontend and backend with the same name, only one
+  of these are listed.
+
+  :see: :js:attr:`core.proxies`
+  :see: :js:attr:`core.backends`
+
 .. js:function:: core.log(loglevel, msg)
 
   **context**: body, init, task, action, sample-fetch, converter
index a176b34bd7535428181b4d03ec3e76092c5c5b39..6992613292e89487c35689db9bbe23d383cddd67 100644 (file)
@@ -915,6 +915,38 @@ int hlua_fcn_post_init(lua_State *L)
        /* push "proxies" in "core" */
        lua_settable(L, -3);
 
+       /* Create proxies entry. */
+       lua_pushstring(L, "frontends");
+       lua_newtable(L);
+
+       /* List all proxies. */
+       for (px = proxy; px; px = px->next) {
+               if (!(px->cap & PR_CAP_FE))
+                       continue;
+               lua_pushstring(L, px->id);
+               hlua_fcn_new_proxy(L, px);
+               lua_settable(L, -3);
+       }
+
+       /* push "frontends" in "core" */
+       lua_settable(L, -3);
+
+       /* Create proxies entry. */
+       lua_pushstring(L, "backends");
+       lua_newtable(L);
+
+       /* List all proxies. */
+       for (px = proxy; px; px = px->next) {
+               if (!(px->cap & PR_CAP_BE))
+                       continue;
+               lua_pushstring(L, px->id);
+               hlua_fcn_new_proxy(L, px);
+               lua_settable(L, -3);
+       }
+
+       /* push "backend" in "core" */
+       lua_settable(L, -3);
+
        return 1;
 }