Tim.

On 31.05.21 23:23, Tim Düsterhus wrote:
Aleks,

On 5/31/21 9:35 PM, Aleksandar Lazic wrote:
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

The backporting information should be part of the commit message. But I don't 
think it's going to be backported that far.

Further comments inline.

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.
-

Good catch, but please split moving this around into a dedicated patch (DOC).

Done.

 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.
+

This explanation is not useful to the reader (even I don't understand it).

Hm. Well it fetches the uniq_id from the stream struct.

http://git.haproxy.org/?p=haproxy.git;a=blob;f=include/haproxy/stream-t.h;h=9499e94d77feea0dad787eb3bd7b6b0375ca0148;hb=HEAD#l120
120         unsigned int uniq_id;           /* unique ID used for the traces */

This is shown on the SPOE log line as sid and therefore I think it should be
possible to get the same ID also within HAProxy as fetch method.

```
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
```

In the log is this the variable "%rt" when a stream is available, when no stream
is available then is this the "global.req_count".

http://git.haproxy.org/?p=haproxy.git;a=blob;f=src/log.c;h=7dabe16f8fa54631f6eab815eb73f77d058d0368;hb=HEAD#l2178

In the doc is it described as request_counter which is only true when no stream
is available, when a stream is available then is that %rt the uniq id.

http://git.haproxy.org/?p=haproxy.git;a=blob;f=doc/configuration.txt;h=11c38945c29d2d28c9afb13afed60b30a97069cb;hb=HEAD#l20576
20576   |   | %rt  | request_counter (HTTP req or TCP session)     | numeric    
 |

So, yes I agree it's difficult to describe it in the doc for the normal user.

How about this wording.

```
This fetch method returns the internal Stream ID, if a stream is available. The
internal Stream ID is used in several places in HAProxy to trace the Stream
inside HAProxy. It is also uses in SPOE as "sid" value.
```


 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/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)

I believe the 'static int' should go on the same line.

Well I copied from "smp_fetch_cpu_calls" but yes most of the other fetches are
in the same line so I will put it in the same line.

+{
+    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 },
+

I believe 'SMP_USE_INTRN' is not correct. I believe you need 'SMP_SRC_L4CLI', 
but don't quote me on that.

Well I don't know.
To all what's the right Value to be used there?


     { /* END */ },
 }};

--
2.25.1

Best regards
Tim Düsterhus

Regards
Alex

Reply via email to