Re: [PATCH] MINOR: halog: Add -qry parameter allowing to preserve the query string in -uX

2021-10-27 Thread Willy Tarreau
On Mon, Oct 18, 2021 at 12:16:11PM +0200, Tim Düsterhus, WoltLab GmbH wrote:
> From 6095a454dee425487083674ec9d35be7a59f7ef6 Mon Sep 17 00:00:00 2001
> From: Tim Duesterhus 
> Date: Mon, 18 Oct 2021 12:12:02 +0200
> Subject: [PATCH] MINOR: halog: Add -qry parameter allowing to preserve the
>  query string in -uX
> To: haproxy@formilux.org
> Cc: w...@1wt.eu
> 
> Our use-case for this is a dynamic application that performs routing based on
> the query string. Without this option all URLs will just point to the central
> entrypoint of this location, making the output completely useless.
(...)

Applied, thanks Tim!
Willy



[PATCH] MINOR: halog: Add -qry parameter allowing to preserve the query string in -uX

2021-10-18 Thread Tim Düsterhus , WoltLab GmbH

Willy,

please find the patch attached.


Our use-case for this is a dynamic application that performs routing based on
the query string. Without this option all URLs will just point to the central
entrypoint of this location, making the output completely useless.

Best regards
Tim Düsterhus
Developer WoltLab GmbH

--

WoltLab GmbH
Nedlitzer Str. 27B
14469 Potsdam

Tel.: +49 331 96784338

duester...@woltlab.com
www.woltlab.com

Managing director:
Marcel Werk

AG Potsdam HRB 26795 P
>From 6095a454dee425487083674ec9d35be7a59f7ef6 Mon Sep 17 00:00:00 2001
From: Tim Duesterhus 
Date: Mon, 18 Oct 2021 12:12:02 +0200
Subject: [PATCH] MINOR: halog: Add -qry parameter allowing to preserve the
 query string in -uX
To: haproxy@formilux.org
Cc: w...@1wt.eu

Our use-case for this is a dynamic application that performs routing based on
the query string. Without this option all URLs will just point to the central
entrypoint of this location, making the output completely useless.
---
 admin/halog/halog.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/admin/halog/halog.c b/admin/halog/halog.c
index 5d256209b..2d6c17f45 100644
--- a/admin/halog/halog.c
+++ b/admin/halog/halog.c
@@ -117,7 +117,8 @@ struct url_stat {
 #define FILT_COUNT_COOK_CODES 0x4000
 #define FILT_COUNT_IP_COUNT   0x8000
 
-#define FILT2_TIMESTAMP	0x01
+#define FILT2_TIMESTAMP 0x01
+#define FILT2_PRESERVE_QUERY0x02
 
 unsigned int filter = 0;
 unsigned int filter2 = 0;
@@ -147,7 +148,7 @@ void usage(FILE *output, const char *msg)
 		"Usage: halog [-h|--help] for long help\n"
 		"   halog [-q] [-c] [-m ]\n"
 		"   {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt|-ic}\n"
-		"   [-s ] [-e|-E] [-H] [-rt|-RT ] [-ad ] [-ac ]\n"
+		"   [-s ] [-e|-E] [-H] [-rt|-RT ] [-ad ] [-ac ] [-qry]\n"
 		"   [-v] [-Q|-QS] [-tcn|-TCN ] [ -hs|-HS [min][:[max]] ] [ -time [min][:[max]] ] < log\n"
 		"\n",
 		msg ? msg : ""
@@ -196,7 +197,8 @@ void help()
 	   "   -u : by URL, -uc : request count, -ue : error count\n"
 	   "   -ua : average response time, -ut : average total time\n"
 	   "   -uao, -uto: average times computed on valid ('OK') requests\n"
-	   "   -uba, -ubt: average bytes returned, total bytes returned\n",
+	   "   -uba, -ubt: average bytes returned, total bytes returned\n"
+	   " -qry  preserve the query string for per-URL statistics\n",
SOURCE_FIELD,SOURCE_FIELD
 	   );
 	exit(0);
@@ -831,6 +833,8 @@ int main(int argc, char **argv)
 			filter |= FILT_COUNT_URL_BAVG;
 		else if (strcmp(argv[0], "-ubt") == 0)
 			filter |= FILT_COUNT_URL_BTOT;
+		else if (strcmp(argv[0], "-qry") == 0)
+			filter2 |= FILT2_PRESERVE_QUERY;
 		else if (strcmp(argv[0], "-ic") == 0)
 			filter |= FILT_COUNT_IP_COUNT;
 		else if (strcmp(argv[0], "-o") == 0) {
@@ -1576,7 +1580,8 @@ void filter_count_url(const char *accept_field, const char *time_field, struct t
 	/* stop at end of field or first ';' or '?', takes avg 64 ns per line */
 	e = b;
 	do {
-		if (*e == ' ' || *e == '?' || *e == ';') {
+		if (*e == ' '||
+		(!(filter2 & FILT2_PRESERVE_QUERY) && (*e == '?' || *e == ';'))) {
 			*(char *)e = 0;
 			break;
 		}
-- 
2.33.0