]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add date_us sample
authorEtienne Carriere <etienne.carriere@datadome.co>
Wed, 17 Jan 2018 12:43:24 +0000 (13:43 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 21 Jan 2018 06:56:42 +0000 (07:56 +0100)
Add date_us sample that returns the microsecond part of the timeval
structure representing the date of the structure. The "second" part of
the timeval can already be fetched by the "date" sample

doc/configuration.txt
src/sample.c

index c93af518e6e7de2948bc78b5c1313d056468b468..6f6c1bc34342a8971afb6f914cc10fa72fb9ddf6 100644 (file)
@@ -13503,6 +13503,11 @@ date([<offset>]) : integer
      # set an expires header to now+1 hour in every response
      http-response set-header Expires %[date(3600),http_date]
 
+date_us : integer
+  Return the microseconds part of the date (the "second" part is returned by
+  date sample). This sample is coherent with the date sample as it is comes
+  from the same timeval structure.
+
 distcc_body(<token>[,<occ>]) : binary
   Parses a distcc message and returns the body associated to occurrence #<occ>
   of the token <token>. Occurrences start at 1, and when unspecified, any may
index ed2aee01024a8f792b0cee2cd3a6e354afe311c9..442dc70bde24570c2e117386778f41f0ec48cb44 100644 (file)
@@ -2575,6 +2575,17 @@ smp_fetch_date(const struct arg *args, struct sample *smp, const char *kw, void
        return 1;
 }
 
+/* retrieve the current microsecond part of the date  */
+static int
+smp_fetch_date_us(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       smp->data.u.sint = date.tv_usec;
+       smp->data.type = SMP_T_SINT;
+       smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE;
+       return 1;
+}
+
+
 /* returns the hostname */
 static int
 smp_fetch_hostname(const struct arg *args, struct sample *smp, const char *kw, void *private)
@@ -2768,6 +2779,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "always_true",  smp_fetch_true,  0,            NULL, SMP_T_BOOL, SMP_USE_INTRN },
        { "env",          smp_fetch_env,   ARG1(1,STR),  NULL, SMP_T_STR,  SMP_USE_INTRN },
        { "date",         smp_fetch_date,  ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_INTRN },
+       { "date_us",      smp_fetch_date_us,  0,         NULL, SMP_T_SINT, SMP_USE_INTRN },
        { "hostname",     smp_fetch_hostname, 0,         NULL, SMP_T_STR,  SMP_USE_INTRN },
        { "nbproc",       smp_fetch_nbproc,0,            NULL, SMP_T_SINT, SMP_USE_INTRN },
        { "proc",         smp_fetch_proc,  0,            NULL, SMP_T_SINT, SMP_USE_INTRN },