Skip to content

Commit

Permalink
Merge pull request #302 from jajik/issue-297
Browse files Browse the repository at this point in the history
Add `UseNocanon` to mod_lbmethod_cluster, fix testsuite to use the right module
  • Loading branch information
jajik authored Nov 19, 2024
2 parents 778b7b7 + a2f7b0a commit 44dd11e
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ jobs:
- name: Setup dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y docker maven git curl iproute2
sudo apt-get install -y docker maven git curl iproute2 wcstools
cd test
sh setup-dependencies.sh
- name: Print network environment
Expand Down
74 changes: 64 additions & 10 deletions native/balancers/mod_lbmethod_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static struct balancer_storage_method *balancer_storage = NULL;
static struct domain_storage_method *domain_storage = NULL;

static int use_alias = 0; /* 1 : Compare Alias with server_name */
static int use_nocanon = 0;
static apr_time_t lbstatus_recalc_time =
apr_time_from_sec(5); /* recalcul the lbstatus based on number of request in the time interval */
static apr_time_t wait_for_remove = apr_time_from_sec(10); /* wait until that before removing a removed node */
Expand Down Expand Up @@ -142,16 +143,18 @@ static int lbmethod_cluster_trans(request_rec *r)
{
const char *balancer;
void *sconf = r->server->module_config;
const char *use_uri = r->uri;
proxy_server_conf *conf = (proxy_server_conf *)ap_get_module_config(sconf, &proxy_module);
proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config, &proxy_module);
proxy_vhost_table *vhost_table = read_vhost_table(r->pool, host_storage, 0);
proxy_context_table *context_table = read_context_table(r->pool, context_storage, 0);
proxy_balancer_table *balancer_table = read_balancer_table(r->pool, balancer_storage, 0);
proxy_node_table *node_table = read_node_table(r->pool, node_storage, 0);

ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server,
"lbmethod_cluster_trans for %d %s %s uri: %s args: %s unparsed_uri: %s", r->proxyreq, r->filename,
"lbmethod_cluster_trans: for %d %s %s uri: %s args: %s unparsed_uri: %s", r->proxyreq, r->filename,
r->handler, r->uri, r->args, r->unparsed_uri);
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans for %d", conf->balancers->nelts);
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans: for %d", conf->balancers->nelts);

apr_table_setn(r->notes, "vhost-table", (char *)vhost_table);
apr_table_setn(r->notes, "context-table", (char *)context_table);
Expand All @@ -163,29 +166,66 @@ static int lbmethod_cluster_trans(request_rec *r)
balancer = get_context_host_balancer(r, vhost_table, context_table, node_table, use_alias);
}


if (balancer) {
int i;
int rv = HTTP_CONTINUE;
struct proxy_alias *ent;
/* short way - this location is reverse proxied? */
if (dconf->alias) {
if ((dconf->alias->flags & PROXYPASS_MAP_ENCODED) == 0) {
rv = ap_proxy_trans_match(r, dconf->alias, dconf);
if (rv != HTTP_CONTINUE) {
ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
"lbmethod_cluster_trans: ap_proxy_trans_match(dconf) matches or reject %s to %s %d",
r->uri, r->filename, rv);
return rv; /* Done */
}
}
}

/* long way - walk the list of aliases, find a match */
for (i = 0; i < conf->aliases->nelts; i++) {
ent = &((struct proxy_alias *)conf->aliases->elts)[i];
if ((ent->flags & PROXYPASS_MAP_ENCODED) == 0) {
rv = ap_proxy_trans_match(r, ent, dconf);
if (rv != HTTP_CONTINUE) {
ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r,
"lbmethod_cluster_trans: ap_proxy_trans_match(conf) matches or reject %s to %s %d",
r->uri, r->filename, rv);
return rv; /* Done */
}
}
}
}

/* Use proxy-nocanon if needed */
if (use_nocanon) {
apr_table_setn(r->notes, "proxy-nocanon", "1");
use_uri = r->unparsed_uri;
}

if (balancer) {
/* It is safer to use r->uri */
if (strncmp(r->uri, BALANCER_PREFIX, BALANCER_PREFIX_LENGTH)) {
r->filename = apr_pstrcat(r->pool, ("proxy:" BALANCER_PREFIX), balancer, r->uri, NULL);
if (strncmp(use_uri, BALANCER_PREFIX, BALANCER_PREFIX_LENGTH)) {
r->filename = apr_pstrcat(r->pool, ("proxy:" BALANCER_PREFIX), balancer, use_uri, NULL);
} else {
r->filename = apr_pstrcat(r->pool, "proxy:", r->uri, NULL);
r->filename = apr_pstrcat(r->pool, "proxy:", use_uri, NULL);
}
r->handler = "proxy-server";
r->proxyreq = PROXYREQ_REVERSE;
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "proxy_cluster_trans using %s uri: %s", balancer,
ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, r->server, "lbmethod_cluster_trans: using %s uri: %s", balancer,
r->filename);
return OK; /* Mod_proxy will process it */
}

ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, r->server,
"proxy_cluster_trans DECLINED (no balancer) uri: %s unparsed_uri: %s", r->filename, r->unparsed_uri);
"lbmethod_cluster_trans: DECLINED (no balancer) uri: %s unparsed_uri: %s", r->filename,
r->unparsed_uri);
return DECLINED;
}

/*
* Remove node that have beeen marked removed for more than 10 seconds.
* Remove node that have been marked removed for more than 10 seconds.
*/
static void remove_removed_node(server_rec *s, apr_pool_t *pool, apr_time_t now, proxy_node_table *node_table)
{
Expand Down Expand Up @@ -370,6 +410,20 @@ static int lbmethod_cluster_post_config(apr_pool_t *p, apr_pool_t *plog, apr_poo
return OK;
}

static const char *cmd_nocanon(cmd_parms *parms, void *mconfig, int on)
{
(void)parms;
(void)mconfig;
use_nocanon = on;

return NULL;
}

static const command_rec lbmethod_cmds[] = {
AP_INIT_FLAG("UseNocanon", cmd_nocanon, NULL, OR_ALL,
"UseNocanon - When no ProxyPass or ProxyMatch for the URL, passes the URL path \"raw\" to the backend "
"(Default: Off)")};

static void register_hooks(apr_pool_t *p)
{
static const char *const aszPre[] = {"mod_manager.c", "mod_rewrite.c", NULL};
Expand All @@ -388,7 +442,7 @@ AP_DECLARE_MODULE(lbmethod_cluster) = {
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
NULL, /* command apr_table_t */
lbmethod_cmds, /* command apr_table_t */
register_hooks, /* register hooks */
AP_MODULE_FLAG_NONE /* flags */
};
43 changes: 43 additions & 0 deletions test/MODCLUSTER-640/mod_lbmethod_cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule manager_module modules/mod_manager.so
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
LoadModule watchdog_module modules/mod_watchdog.so

LogLevel info
ServerName localhost
ProxyPreserveHost On
UseNocanon On

<IfModule manager_module>
Listen 6666
ManagerBalancerName mycluster

EnableWsTunnel
WSUpgradeHeader websocket
<VirtualHost *:6666>
EnableMCMPReceive
<Directory />
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Directory>
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Location>
</VirtualHost>
</IfModule>

<Proxy "balancer://mycluster">
ProxySet growth=10
ProxySet lbmethod=cluster
</Proxy>
9 changes: 6 additions & 3 deletions test/MODCLUSTER-640/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ httpd_remove

# build httpd + mod_proxy_cluster
rm -f nohup.out
MPC_CONF=MODCLUSTER-640/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-640 httpd_start

MPC_CONF=${MPC_CONF:-MODCLUSTER-640/mod_proxy_cluster.conf}
MPC_NAME=MODCLUSTER-640 httpd_start

# wait until httpd is started
httpd_wait_until_ready || exit 1
Expand Down Expand Up @@ -39,7 +41,8 @@ if [ $? -eq 0 ]; then
fi

# Test without UseNocanon On
docker exec MODCLUSTER-640 sh -c "sed -i 's:UseNocanon On::' /usr/local/apache2/conf/mod_proxy_cluster.conf"
docker exec MODCLUSTER-640 sh -c "sed -i 's:UseNocanon On::' /usr/local/apache2/conf/$(filename $MPC_CONF)"

docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart

# wait until the tomcats are back in mod_proxy_cluster tables
Expand All @@ -58,7 +61,7 @@ if [ $? -ne 0 ]; then
fi

# Test for just a proxypass / nocanon
docker exec MODCLUSTER-640 sh -c "echo 'ProxyPass / balancer://mycluster/ nocanon' >> /usr/local/apache2/conf/mod_proxy_cluster.conf"
docker exec MODCLUSTER-640 sh -c "echo 'ProxyPass / balancer://mycluster/ nocanon' >> /usr/local/apache2/conf/$(filename $MPC_CONF)"
docker exec MODCLUSTER-640 /usr/local/apache2/bin/apachectl restart

# wait until the tomcats are back in mod_proxy_cluster tables
Expand Down
5 changes: 4 additions & 1 deletion test/MODCLUSTER-734/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ httpd_remove

# build httpd + mod_proxy_cluster
rm -f nohup.out
MPC_CONF=MODCLUSTER-734/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-734 httpd_start

MPC_CONF=${MPC_CONF:-MODCLUSTER-734/mod_proxy_cluster.conf}
MPC_NAME=MODCLUSTER-734 httpd_start

# wait until httpd is started
httpd_wait_until_ready || exit 1
Expand All @@ -28,6 +30,7 @@ docker cp MODCLUSTER-734/ROOT_OK tomcat2:/usr/local/tomcat/webapps/ROOT
# after a while the health check will get the Under maintenance status.jsp
# and mark the node not OK.
sleep 15

curl -s http://localhost:6666/mod_cluster_manager | grep "Status: NOTOK"
if [ $? -eq 0 ]; then
echo "MODCLUSTER-734 Done!"
Expand Down
1 change: 1 addition & 0 deletions test/MODCLUSTER-736/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

httpd_remove
tomcat_all_remove

MPC_NAME=MODCLUSTER-736 httpd_start

# Start a bunch ($1, or 6 if no argument is given) of tomcat
Expand Down
38 changes: 38 additions & 0 deletions test/MODCLUSTER-755/mod_lbmethod_cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule manager_module modules/mod_manager.so
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
LoadModule watchdog_module modules/mod_watchdog.so

Maxnode 505
Maxhost 1010
Maxcontext 1100
Listen 6666
ManagerBalancerName mycluster
ServerName localhost

<VirtualHost *:6666>
EnableMCMPReceive
<Directory />
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Directory>
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Location>
</VirtualHost>

<Proxy "balancer://mycluster">
ProxySet growth=10
ProxySet lbmethod=cluster
</Proxy>
3 changes: 0 additions & 3 deletions test/MODCLUSTER-755/mod_proxy_cluster.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
LoadModule watchdog_module modules/mod_watchdog.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so

ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}
ModProxyClusterHCTemplate hcmethod=GET hcexpr=in_maint hcuri=/status.jsp

Maxnode 505
Maxhost 1010
Maxcontext 1100
Expand Down
3 changes: 2 additions & 1 deletion test/MODCLUSTER-755/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
httpd_remove
tomcat_all_remove

MPC_CONF=MODCLUSTER-755/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-755 httpd_start
MPC_CONF=${MPC_CONF:-MODCLUSTER-755/mod_proxy_cluster.conf}
MPC_NAME=MODCLUSTER-755 httpd_start

httpd_wait_until_ready

Expand Down
41 changes: 41 additions & 0 deletions test/MODCLUSTER-785/mod_lbmethod_cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule manager_module modules/mod_manager.so
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
LoadModule watchdog_module modules/mod_watchdog.so

Maxnode 505
Maxhost 1010
Maxcontext 1100
Listen 6666
ManagerBalancerName mycluster
ServerName localhost

EnableWsTunnel
WSUpgradeHeader websocket

<VirtualHost *:6666>
EnableMCMPReceive
<Directory />
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Directory>
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Require ip 127.0.0.1
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Location>
</VirtualHost>

<Proxy "balancer://mycluster">
ProxySet growth=10
ProxySet lbmethod=cluster
</Proxy>
4 changes: 3 additions & 1 deletion test/MODCLUSTER-785/testit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ httpd_remove

# build httpd + mod_proxy_cluster
rm -f nohup.out
MPC_CONF=MODCLUSTER-785/mod_proxy_cluster.conf MPC_NAME=MODCLUSTER-785 httpd_start

MPC_CONF=${MPC_CONF:-MODCLUSTER-785/mod_proxy_cluster.conf}
MPC_NAME=MODCLUSTER-785 httpd_start


# start tomcat1 on 8080
Expand Down
42 changes: 42 additions & 0 deletions test/MODCLUSTER-794/mod_lbmethod_cluster.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so

LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule manager_module modules/mod_manager.so
LoadModule lbmethod_cluster_module modules/mod_lbmethod_cluster.so
LoadModule watchdog_module modules/mod_watchdog.so

ProxyPreserveHost On

Listen 6666
ServerName localhost
ManagerBalancerName mycluster
EnableWsTunnel
WSUpgradeHeader websocket

<VirtualHost *:6666>
EnableMCMPReceive
<Directory />
Require ip 127.0.0.
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Directory>
<Location /mod_cluster_manager>
SetHandler mod_cluster-manager
Require ip 127.0.0.
Require ip ::1
# This one is used in GH Actions
Require ip 172.17.
</Location>
</VirtualHost>

<Proxy "balancer://mycluster">
ProxySet growth=20
ProxySet lbmethod=cluster
</Proxy>

# This is the default value, but let's go with the explicit here
Maxnode 20
Loading

0 comments on commit 44dd11e

Please sign in to comment.