Hi.
On 31.05.21 14:23, Aleksandar Lazic wrote:
Hi.
While I try to get the stream id from spoa I recognized that there is no fetch
method for the streamID.
Attached a patch which adds the fetch sample for the stream id.
I assume it could be back ported up to version 2.0
Regards
Alex
The discussion is here.
https://github.com/criteo/haproxy-spoe-go/issues/28
That's the sid in filter spoa log output.
SPOE: [agent-on-http-req] <EVENT:on-frontend-http-request> sid=88 st=0
0/0/0/0/0 1/1 0/0 10/33
http://git.haproxy.org/?p=haproxy-2.4.git;a=blob;f=src/flt_spoe.c;h=a68f7b9141025963e8f4ad79c0d1617a4c59774e;hb=HEAD#l2815
```
2815 if (ctx->status_code || !(conf->agent_fe.options2 &
PR_O2_NOLOGNORM))
2816 send_log(&conf->agent_fe, (!ctx->status_code ?
LOG_NOTICE : LOG_WARNING),
2817 "SPOE: [%s] <EVENT:%s> sid=%u st=%u
%ld/%ld/%ld/%ld/%ld %u/%u %u/%u %llu/%llu\n",
2818 agent->id, spoe_event_str[ev], s->uniq_id,
ctx->status_code,
^^^^^^^^^^
2819 ctx->stats.t_request, ctx->stats.t_queue,
ctx->stats.t_waiting,
2820 ctx->stats.t_response,
ctx->stats.t_process,
2821 agent->counters.idles,
agent->counters.applets,
2822 agent->counters.nb_sending,
agent->counters.nb_waiting,
2823 agent->counters.nb_errors,
agent->counters.nb_processed);
```
It looks to me that the %rt log format have the stream id, right?
http://git.haproxy.org/?p=haproxy-2.4.git;a=blob;f=doc/configuration.txt;h=a13a9a77f8a077a6ac798b1dccc8a0f2f3f67396;hb=HEAD#l20576
| | %rt | request_counter (HTTP req or TCP session) | numeric |
http://git.haproxy.org/?p=haproxy-2.4.git;a=blob;f=src/log.c;hb=c5c5bc4e36ce4a6f3bc113c8e16824fdb276c220#l3175
3175 case LOG_FMT_COUNTER: // %rt
http://git.haproxy.org/?p=haproxy-2.4.git;a=blob;f=src/log.c;hb=c5c5bc4e36ce4a6f3bc113c8e16824fdb276c220#l2202
2202 uniq_id = _HA_ATOMIC_FETCH_ADD(&global.req_count, 1);
Regards
Alex
>From 15a2026c495e64d8165a13a3c8a4e5e19ad7e8d6 Mon Sep 17 00:00:00 2001
From: Alexandar Lazic <[email protected]>
Date: Mon, 31 May 2021 21:28:56 +0200
Subject: [PATCH] MINOR: sample: fetch stream_uniq_id
This fetch sample allows to get the current Stream ID for the
current session.
---
doc/configuration.txt | 13 ++++++----
reg-tests/sample_fetches/stream_id.vtc | 33 ++++++++++++++++++++++++++
src/sample.c | 14 +++++++++++
3 files changed, 55 insertions(+), 5 deletions(-)
create mode 100644 reg-tests/sample_fetches/stream_id.vtc
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 11c38945c..7eb7e29cd 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -17433,11 +17433,6 @@ rand([<range>]) : integer
needed to take some routing decisions for example, or just for debugging
purposes. This random must not be used for security purposes.
-uuid([<version>]) : string
- Returns a UUID following the RFC4122 standard. If the version is not
- specified, a UUID version 4 (fully random) is returned.
- Currently, only version 4 is supported.
-
srv_conn([<backend>/]<server>) : integer
Returns an integer value corresponding to the number of currently established
connections on the designated server, possibly including the connection being
@@ -17514,6 +17509,9 @@ stopping : boolean
str(<string>) : string
Returns a string.
+stream_uniq_id : integer
+ Returns the uniq stream id.
+
table_avl([<table>]) : integer
Returns the total number of available entries in the current proxy's
stick-table or in the designated stick-table. See also table_cnt.
@@ -17528,6 +17526,11 @@ thread : integer
the function, between 0 and (global.nbthread-1). This is useful for logging
and debugging purposes.
+uuid([<version>]) : string
+ Returns a UUID following the RFC4122 standard. If the version is not
+ specified, a UUID version 4 (fully random) is returned.
+ Currently, only version 4 is supported.
+
var(<var-name>) : undefined
Returns a variable with the stored type. If the variable is not set, the
sample fetch fails. The name of the variable starts with an indication
diff --git a/reg-tests/sample_fetches/stream_id.vtc b/reg-tests/sample_fetches/stream_id.vtc
new file mode 100644
index 000000000..ec512b198
--- /dev/null
+++ b/reg-tests/sample_fetches/stream_id.vtc
@@ -0,0 +1,33 @@
+varnishtest "stream id sample fetch Test"
+
+#REQUIRE_VERSION=2.0
+
+feature ignore_unknown_macro
+
+server s1 {
+ rxreq
+ txresp
+} -start
+
+haproxy h1 -conf {
+ defaults
+ mode http
+ timeout connect 1s
+ timeout client 1s
+ timeout server 1s
+
+ frontend fe
+ bind "fd@${fe}"
+ http-response set-header stream-id "%[stream_uniq_id]"
+ default_backend be
+
+ backend be
+ server srv1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe_sock} {
+ txreq -url "/"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.stream-id == "0"
+} -run
diff --git a/src/sample.c b/src/sample.c
index 09c272c48..5d3b06b10 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -4210,6 +4210,18 @@ static int smp_fetch_uuid(const struct arg *args, struct sample *smp, const char
return 0;
}
+/* returns the stream uniq_id */
+static int
+smp_fetch_stream_uniq_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+ if (!smp->strm)
+ return 0;
+
+ smp->data.type = SMP_T_SINT;
+ smp->data.u.sint = smp->strm->uniq_id;
+ return 1;
+}
+
/* Note: must not be declared <const> as its list will be overwritten.
* Note: fetches that may return multiple types must be declared as the lowest
* common denominator, the type that can be casted into all other ones. For
@@ -4243,6 +4255,8 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
{ "bin", smp_fetch_const_bin, ARG1(1,STR), smp_check_const_bin , SMP_T_BIN, SMP_USE_CONST },
{ "meth", smp_fetch_const_meth, ARG1(1,STR), smp_check_const_meth, SMP_T_METH, SMP_USE_CONST },
+ { "stream_uniq_id", smp_fetch_stream_uniq_id, 0, NULL, SMP_T_SINT, SMP_USE_INTRN },
+
{ /* END */ },
}};
--
2.25.1