You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Daniel Ruggeri <DR...@primary.net> on 2013/10/25 15:07:56 UTC

Exposing more loggable data from the proxy

As I stand up a simple IPv6 test proxy that supports both AF_INET and
AF_INET6 addresses, I was looking for a way to log what addr family (and
maybe the IP address) mod_proxy settled on for each request in the
access_log. I'm not seeing a way to do that (but correct me if I'm
missing something) and was poking through the code and got to thinking
that there are all kinds of data bits that'd be interesting to have
available in the ENV.

I'm thinking it'd be worth adding a directive (ProxyAddEnvironment?)
that adds these ENV entries to each r->subprocess_env:
 * Host header sent to backend (useful when dynamic targets are used)
 * Target DNS name if set
 * Target IP address
 * Target Address family
 * Target port
 * Target connection protocol
 * Flag for SSL enabled

All of the data is readily available once a connection is acquired in
ap_proxy_acquire_connection sans the HTTP Host header.
Aside from logging, exporting these as ENV entries to the request allows
us to do all sorts of stuff in other modules, too....

Any thoughts? Is there something I should include or exclude before I begin?

--
Daniel Ruggeri


Re: Exposing more loggable data from the proxy

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Oct 25, 2013 at 9:16 AM, Jeff Trawick <tr...@gmail.com> wrote:

> On Fri, Oct 25, 2013 at 9:07 AM, Daniel Ruggeri <DR...@primary.net>wrote:
>
>> As I stand up a simple IPv6 test proxy that supports both AF_INET and
>> AF_INET6 addresses, I was looking for a way to log what addr family (and
>> maybe the IP address) mod_proxy settled on for each request in the
>> access_log. I'm not seeing a way to do that (but correct me if I'm
>> missing something) and was poking through the code and got to thinking
>> that there are all kinds of data bits that'd be interesting to have
>> available in the ENV.
>>
>> I'm thinking it'd be worth adding a directive (ProxyAddEnvironment?)
>> that adds these ENV entries to each r->subprocess_env:
>>  * Host header sent to backend (useful when dynamic targets are used)
>>  * Target DNS name if set
>>  * Target IP address
>>  * Target Address family
>>  * Target port
>>  * Target connection protocol
>>  * Flag for SSL enabled
>>
>> All of the data is readily available once a connection is acquired in
>> ap_proxy_acquire_connection sans the HTTP Host header.
>> Aside from logging, exporting these as ENV entries to the request allows
>> us to do all sorts of stuff in other modules, too....
>>
>> Any thoughts? Is there something I should include or exclude before I
>> begin?
>>
>> --
>> Daniel Ruggeri
>>
>>
> (unrefined, right out of my ...  head)
>
> useful to have a convention (if not API) for how this info is made
> available for logging, etc., so that other modules can play the same game
> (e.g., mod_jk, FastCGI, whatever)
>
> what about a plugin with optional functions that has APIs for recording
> backend state that is meaningful across variety of "gateway" modules?  for
> now maybe it is just for logging, but it could save in shared memory for
> extraction in mod_status or other reports
>
> maybe that solution is a bit farfetched, but I guess the theme is that
> creating a proxy-specific solution can be a wasted effort given the same
> need for any number of other "gateway" modules
>
> --
> Born in Roswell... married an alien...
> http://emptyhammock.com/
>


A little more refined...  (see attached .h file)

It wouldn't take too many lines of code to provide logging (custom access
log format with various format strings).  A "few" more and it is in shared
memory for a scoreboard display so you can see where your requests are
getting stalled when talking to LDAP servers or app servers or whatever...

Having a callable API for modules will help with consistency of
representation and largely eliminate questions of what can/should be
represented.

-- 
Born in Roswell... married an alien...
http://emptyhammock.com/

Re: Exposing more loggable data from the proxy

Posted by Jeff Trawick <tr...@gmail.com>.
On Fri, Oct 25, 2013 at 9:07 AM, Daniel Ruggeri <DR...@primary.net>wrote:

> As I stand up a simple IPv6 test proxy that supports both AF_INET and
> AF_INET6 addresses, I was looking for a way to log what addr family (and
> maybe the IP address) mod_proxy settled on for each request in the
> access_log. I'm not seeing a way to do that (but correct me if I'm
> missing something) and was poking through the code and got to thinking
> that there are all kinds of data bits that'd be interesting to have
> available in the ENV.
>
> I'm thinking it'd be worth adding a directive (ProxyAddEnvironment?)
> that adds these ENV entries to each r->subprocess_env:
>  * Host header sent to backend (useful when dynamic targets are used)
>  * Target DNS name if set
>  * Target IP address
>  * Target Address family
>  * Target port
>  * Target connection protocol
>  * Flag for SSL enabled
>
> All of the data is readily available once a connection is acquired in
> ap_proxy_acquire_connection sans the HTTP Host header.
> Aside from logging, exporting these as ENV entries to the request allows
> us to do all sorts of stuff in other modules, too....
>
> Any thoughts? Is there something I should include or exclude before I
> begin?
>
> --
> Daniel Ruggeri
>
>
(unrefined, right out of my ...  head)

useful to have a convention (if not API) for how this info is made
available for logging, etc., so that other modules can play the same game
(e.g., mod_jk, FastCGI, whatever)

what about a plugin with optional functions that has APIs for recording
backend state that is meaningful across variety of "gateway" modules?  for
now maybe it is just for logging, but it could save in shared memory for
extraction in mod_status or other reports

maybe that solution is a bit farfetched, but I guess the theme is that
creating a proxy-specific solution can be a wasted effort given the same
need for any number of other "gateway" modules

-- 
Born in Roswell... married an alien...
http://emptyhammock.com/

Re: Exposing more loggable data from the proxy

Posted by Daniel Ruggeri <DR...@primary.net>.
On 10/25/2013 8:16 AM, Jeff Trawick wrote:
> (unrefined, right out of my ...  head)

:-)


> useful to have a convention (if not API) for how this info is made
> available for logging, etc., so that other modules can play the same
> game (e.g., mod_jk, FastCGI, whatever)

I think what I'd be proposing is to follow in the footsteps that mod_ssl
set but MAKE it the general convention. A lot of env variables are
available so you can do all sorts of stuff. The *other* convention could
simply be the notes mechanism but I think there's better ways. In any
event, there should be some good documentation to let server admins know
what's available - that's the main reason I even suggested adding a
directive (so the list of ENV entries are exposed like mod_ssl has
documented)


> what about a plugin with optional functions that has APIs for
> recording backend state that is meaningful across variety of "gateway"
> modules?  for now maybe it is just for logging, but it could save in
> shared memory for extraction in mod_status or other reports
>
> maybe that solution is a bit farfetched, but I guess the theme is that
> creating a proxy-specific solution can be a wasted effort given the
> same need for any number of other "gateway" modules

The main reason I lean toward env is because a few modules already use
env variables in meaningful ways today (big use-cases for me are log,
rewrite, headers, expr).
So... in that case, I think unrefined kinda works in our favor.



On 10/25/2013 9:10 AM, Yann Ylavic wrote:
> How about setting backend->r to r->backend (when applyable)?

At a cursory look, that'd probably suffice if I wanted to log FROM
mod_proxy. I wasn't clear, but my initial goal was to just add a
%{proxy_addr_family}e chunk in the access log format so the request and
target info is handy on a single line. As mentioned to Jeff, I'd also
like a little more utility from the work involved. Plus, as you say, I
haven't looked to see how well those lifecycles mesh.



On 10/25/2013 9:21 AM, Eric Covener wrote:
> I think the how simple the data is compared to that underlying
> structure, I would rather see it in a flat table that other proxy-like
> things could emulate.  Similar to SSL variables.

That was kind of the idea... the stuff I'm looking for is pretty basic
but I wanted to shoot an email along the lines of, "Anyone else want a
beer while I'm in the fridge?" to see if there were some other
attributes that are worth gathering. And yes, SSL led me to the suggestion.

--
Daniel Ruggeri



Re: Exposing more loggable data from the proxy

Posted by Eric Covener <co...@gmail.com>.
On Fri, Oct 25, 2013 at 10:10 AM, Yann Ylavic <yl...@gmail.com> wrote:
> How about setting backend->r to r->backend (when applyable)?
>
> For now backend->r is pooled to backend's connection, and has a different
> lifetime than r but maybe it worth having it destroyed with r (setting
> things related to the origin's connection to NULL, when released, to avoid
> invalid accesses)...
>
> Hence r->backend->useragent_addr/useragent_ip (useragent is the origin here)
> are accessible everywhere, and so are backend->r->headers_* and everything
> related to the request/response send/received to/from the backend.
>
> I may be missing lot of things with backend->r's lifetime, since it is now
> attached to origin->pool, surely for good reasons...
> Also, not all proxy modules use backend->r, but maybe these can create a
> fake request too with everything NULL except sockaddr (and other relevant
> things, if any).

I think the how simple the data is compared to that underlying
structure, I would rather see it in a flat table that other proxy-like
things could emulate.  Similar to SSL variables.

Re: Exposing more loggable data from the proxy

Posted by Yann Ylavic <yl...@gmail.com>.
How about setting backend->r to r->backend (when applyable)?

For now backend->r is pooled to backend's connection, and has a different
lifetime than r but maybe it worth having it destroyed with r (setting
things related to the origin's connection to NULL, when released, to avoid
invalid accesses)...

Hence r->backend->useragent_addr/useragent_ip (useragent is the origin
here) are accessible everywhere, and so are backend->r->headers_* and
everything related to the request/response send/received to/from the
backend.

I may be missing lot of things with backend->r's lifetime, since it is now
attached to origin->pool, surely for good reasons...
Also, not all proxy modules use backend->r, but maybe these can create a
fake request too with everything NULL except sockaddr (and other relevant
things, if any).



On Fri, Oct 25, 2013 at 3:07 PM, Daniel Ruggeri <DR...@primary.net>wrote:

> As I stand up a simple IPv6 test proxy that supports both AF_INET and
> AF_INET6 addresses, I was looking for a way to log what addr family (and
> maybe the IP address) mod_proxy settled on for each request in the
> access_log. I'm not seeing a way to do that (but correct me if I'm
> missing something) and was poking through the code and got to thinking
> that there are all kinds of data bits that'd be interesting to have
> available in the ENV.
>
> I'm thinking it'd be worth adding a directive (ProxyAddEnvironment?)
> that adds these ENV entries to each r->subprocess_env:
>  * Host header sent to backend (useful when dynamic targets are used)
>  * Target DNS name if set
>  * Target IP address
>  * Target Address family
>  * Target port
>  * Target connection protocol
>  * Flag for SSL enabled
>
> All of the data is readily available once a connection is acquired in
> ap_proxy_acquire_connection sans the HTTP Host header.
> Aside from logging, exporting these as ENV entries to the request allows
> us to do all sorts of stuff in other modules, too....
>
> Any thoughts? Is there something I should include or exclude before I
> begin?
>
> --
> Daniel Ruggeri
>
>