Rainer,

On 5/26/22 17:25, Rainer Jung wrote:
Hi Chris,

Am 26.05.2022 um 21:49 schrieb Christopher Schultz:
On 5/16/22 13:48, Christopher Schultz wrote:

I see the place in the code where the error is generated, but I'm not familiar enough with the code to know how to add that kind of thing. The function in question (ajp_process_callback) has a pointer to a jk_ws_service_t structure. Is it as simple as also logging like this?

   /* convert start-time to a string */
   char[32] timestamp;
   apr_strftime(timestamp, NULL, 32, "%Y-%m-%d %H:%M:%S", r->r->request_time);
   /* emit a detailed log message */
   jk_log(l, JK_LOG_INFO,
          "(%s) Request to (%s %s) started at %s,%ld",
          ae->worker->name, r->method, r->req_uri, timestamp, r->r->request_time.tm_usec);

Does anyone think this might be generally useful?

It looks like I needed a few more things in order to get this to work:

   {
     char *timestamp = malloc(32);
     apr_time_exp_t *timerec = malloc(sizeof(apr_time_exp_t));
     apache_private_data_t *ap = (apache_private_data_t*)r->ws_private;
     apr_time_exp_gmt(timerec, ap->r->request_time);
     apr_strftime(timestamp, NULL, 32, "%Y-%m-%d %H:%M:%S", timerec);
     /* emit a detailed log message */
     jk_log(l, JK_LOG_INFO,
            "(%s) Request to (%s %s) started at %s",
            ae->worker->name, r->method, r->req_uri, timestamp);
     free(timerec);
     free(timestamp);
   }

The compiler wouldn't let me use an automatically-allocated char[32] so I had to malloc it. I also had to convert from long to apr_time_exp_t which required another structure/malloc as well.

Finally, I had to cast the r->ws_private to apache_private_data_t* which required me to copy/paste the definition of apache_private_data_t from mod_jk.h into jk_ajp_common.c -- just as a test for now.

Obviously, this works only for Apache httpd.

I have it running on one of my web servers for now -- hoping to catch an error and see this additional logging to see if it's helpful to me. (LOL just segfaulted; time to go back and look.)

What would be the best way to get the "start time" of the request in a platform-independent way? Maybe just expand the jk_ws_service structure to include it?

Apart from the info chuck send via PM, I think it would be better to try to add a unique request ID as a correlation ID. Apache can already generate them using mod_unique_id and you can add them there to the access log.

Would you prefer to use mod_unique_id + unique-id-logging in mod_jk over just adding more request-level information to the mod_jk.log? I'm kind of okay either way, but for my current purposes it seems more convenient to have all relevant information in a single place (the mod_jk.log file).

Now how could we make that ID accessible from mod_jk?

We could either add it as a new item to jk_ws_service and I think it would be a good fit. Any server not yet providing it, eg. if we find no way adding it in IIS, would have a null value there (or some constant we init it to). We are free to add things, because we do not really provide a public API used elsewhere which we need to keep stable.

When we do logging in mod_jk, we use jk_log(jk_logger_t *l, ...) where the remaining arguments are just standard log arguments. We could add a new jk_request_log(jk_logger_t *l, jk_ws_service_t *s, ...) and that function retrieves the request ID from s and adds it to the log line.

It seems, typically where we want to log something that would benefit from a request ID, we have the jk_ws_service_t at hand, so could add it to the log call.

WDYT?

I'm okay adding either or both of these "features" to the JK portion of the code. If we are considering "enhancing" this kind of logging in the JK portion, I would recommend that we add request_start_time to the jk_ws_service; I don't see a good way to determine the nature of the host web server from within the JK code and it's better-done from the outside-in rather than the inside-out.

Unrelated: I believe the segfaults I'm seeing have to do with me simply updating the .so file on the disk before restarting the httpd process. As soon as I copy the .so file over the existing module binary, I start getting a string of segfaults in the log file. When I don't try to "hot-update" the module binary, I don't see any of that happening. (I also don't see any possible segfaults in my code at this point, either.) I have httpd set up to dump cores but I think my file permissions are wrong so I'm not actually getting anything in there (yet).

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to