* Add the following environment variables to expose the information
* about
the route, the sticky session and the worker used during a request to
other modules:
BALANCER_SESSION_STICKY
BALANCER_SESSION_ROUTE
BALANCER_NAME
BALANCER_WORKER_NAME
BALANCER_WORKER_ROUTE
PR: 39806
Submitted by: Brian <brectanu gmail.com>
Reviewed by: rpluem
fix validation error
* Set the new environment variable BALANCER_ROUTE_CHANGED if a worker with a
route different from the one supplied by the client had been chosen or if
the client supplied no routing information for a balancer with sticky
sessions.
* mod_proxy_balancer: Document BALANCER_ROUTE_CHANGED environment variable.
Submitted by: Brian Rectanus <brectanu gmail.com>
Reviewed by: rpluem
Reviewed by: jim
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@472114
13f79535-47bb-0310-9956-
ffa450edef68
-*- coding: utf-8 -*-
Changes with Apache 2.2.4
+ *) mod_proxy_balancer: Set the new environment variable BALANCER_ROUTE_CHANGED
+ if a worker with a route different from the one supplied by the client
+ had been chosen or if the client supplied no routing information for
+ a balancer with sticky sessions. [Ruediger Pluem]
+
+ *) mod_proxy_balancer: Add information about the route, the sticky session
+ and the worker used during a request as environment variables. PR 39806.
+ [Brian <brectanu gmail.com>]
+
*) mod_proxy: Don't try to use dead backend connection. PR 37770.
[Olivier BOEL <ob dorrboel.com>]
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]
- * mod_proxy_balancer: Implement new environment variables
- BALANCER_NAME
- BALANCER_WORKER_NAME
- BALANCER_WORKER_ROUTE
- BALANCER_SESSION_STICKY
- BALANCER_SESSION_ROUTE
- BALANCER_ROUTE_CHANGED
- Trunk versions of patch:
- http://svn.apache.org/viewvc?view=rev&revision=417238 (including docs)
- http://svn.apache.org/viewvc?view=rev&revision=437773 (docs)
- http://svn.apache.org/viewvc?view=rev&revision=446929
- http://svn.apache.org/viewvc?view=rev&revision=453630 (docs)
- 2.2.x version of patch:
- Trunk version works
- +1: rpluem, mturk, jim
-
PATCHES PROPOSED TO BACKPORT FROM TRUNK:
* mpm_winnt: Fix return values from wait_for_many_objects.
</section>
+<section id="environment">
+ <title>Exported Environment Variables</title>
+ <p>At present there are 6 environment variables exported:</p>
+
+ <dl>
+ <!-- ============= BALANCER_SESSION_STICKY =============== -->
+ <dt><var><a name="balancer_session_sticky" id="balancer_session_sticky">BALANCER_SESSION_STICKY</a></var></dt>
+ <dd>
+ <p>This is assigned the <var>stickysession</var> value used in the current
+ request. It is the cookie or parameter name used for sticky sessions</p>
+ </dd>
+
+ <!-- ============= BALANCER_SESSION_ROUTE ================ -->
+ <dt><var><a name="balancer_session_route" id="balancer_session_route">BALANCER_SESSION_ROUTE</a></var></dt>
+ <dd>
+ <p>This is assigned the <var>route</var> parsed from the current
+ request.</p>
+ </dd>
+
+ <!-- ============= BALANCER_NAME ========================= -->
+ <dt><var><a name="balancer_name" id="balancer_name">BALANCER_NAME</a></var></dt>
+ <dd>
+ <p>This is assigned the name of the balancer used for the current
+ request. The value is something like <code>balancer://foo</code>.</p>
+ </dd>
+
+ <!-- ============= BALANCER_WORKER_NAME ================== -->
+ <dt><var><a name="balancer_worker_name" id="balancer_worker_name">BALANCER_WORKER_NAME</a></var></dt>
+ <dd>
+ <p>This is assigned the name of the worker used for the current request.
+ The value is something like <code>http://hostA:1234</code>.</p>
+ </dd>
+
+ <!-- ============= BALANCER_WORKER_ROUTE ================= -->
+ <dt><var><a name="balancer_worker_route" id="balancer_worker_route">BALANCER_WORKER_ROUTE</a></var></dt>
+ <dd>
+ <p>This is assigned the <var>route</var> of the worker that will be
+ used for the current request.</p>
+ </dd>
+
+ <!-- ============= BALANCER_ROUTE_CHANGED ================= -->
+ <dt><var><a name="balancer_route_changed" id="balancer_route_changed">BALANCER_ROUTE_CHANGED</a></var></dt>
+ <dd>
+ <p>This is set to 1 if the session route does not match the
+ worker route (BALANCER_SESSION_ROUTE != BALANCER_WORKER_ROUTE) or the
+ session does not yet have an established route. This can be used to
+ determine when/if the client needs to be sent an updated route
+ when sticky sessions are used.</p>
+ </dd>
+ </dl>
+
+</section>
+
<section id="enable">
<title>Enabling Balancer Manager Support</title>
<p>This module <em>requires</em> the service of
* Find the worker that has this route defined.
*/
worker = find_route_worker(balancer, *route, r);
+ if (worker && strcmp(*route, worker->s->route)) {
+ /*
+ * Notice that the route of the worker chosen is different from
+ * the route supplied by the client.
+ */
+ apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: BALANCER: Route changed from %s to %s",
+ *route, worker->s->route);
+ }
return worker;
}
else
return HTTP_SERVICE_UNAVAILABLE;
}
+ if ((*balancer)->sticky && runtime) {
+ /*
+ * This balancer has sticky sessions and the client either has not
+ * supplied any routing information or all workers for this route
+ * including possible redirect and hotstandby workers are in error
+ * state, but we have found another working worker for this
+ * balancer where we can send the request. Thus notice that we have
+ * changed the route to the backend.
+ */
+ apr_table_setn(r->subprocess_env, "BALANCER_ROUTE_CHANGED", "1");
+ }
*worker = runtime;
}
+ /* Add balancer/worker info to env. */
+ apr_table_setn(r->subprocess_env,
+ "BALANCER_NAME", (*balancer)->name);
+ apr_table_setn(r->subprocess_env,
+ "BALANCER_WORKER_NAME", (*worker)->name);
+ apr_table_setn(r->subprocess_env,
+ "BALANCER_WORKER_ROUTE", (*worker)->s->route);
+
/* Rewrite the url from 'balancer://url'
* to the 'worker_scheme://worker_hostname[:worker_port]/url'
* This replaces the balancers fictional name with the
if (route) {
apr_table_setn(r->notes, "session-sticky", (*balancer)->sticky);
apr_table_setn(r->notes, "session-route", route);
+
+ /* Add session info to env. */
+ apr_table_setn(r->subprocess_env,
+ "BALANCER_SESSION_STICKY", (*balancer)->sticky);
+ apr_table_setn(r->subprocess_env,
+ "BALANCER_SESSION_ROUTE", route);
}
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"proxy: BALANCER (%s) worker (%s) rewritten to %s",