[PATCH 9/9] CLEANUP: contrib/prometheus-exporter: align and reorder fields

2021-01-30 Thread William Dauchy
- align safe_idle_connections_current field
  fix minor typo added in commit
  37286a5ac595069a491c3e8a7a7e4faf3d9ea8ad ("MEDIUM:
  contrib/prometheus-exporter: Rework matrices defining Promex metrics")
- reorder info fields to be able to compare them easily
- add missing ignored info fields as comment

Signed-off-by: William Dauchy 
---
 contrib/prometheus-exporter/service-prometheus.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index 98f6fca62..29524cd91 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -108,7 +108,6 @@ const struct promex_metric 
promex_global_metrics[INF_TOTAL_FIELDS] = {
//[INF_NAME]   ignored
//[INF_VERSION],   ignored
//[INF_RELEASE_DATE]   ignored
-   [INF_BUILD_INFO] = { .n = IST("build_info"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
[INF_NBTHREAD]   = { .n = IST("nbthread"),  
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
[INF_NBPROC] = { .n = IST("nbproc"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
[INF_PROCESS_NUM]= { .n = 
IST("relative_process_id"),   .type = PROMEX_MT_GAUGE,   .flags = 
PROMEX_FL_INFO_METRIC },
@@ -116,8 +115,11 @@ const struct promex_metric 
promex_global_metrics[INF_TOTAL_FIELDS] = {
//[INF_UPTIME] ignored
[INF_UPTIME_SEC] = { .n = IST("uptime_seconds"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
[INF_START_TIME_SEC] = { .n = 
IST("start_time_seconds"),.type = PROMEX_MT_GAUGE,   .flags = 
PROMEX_FL_INFO_METRIC },
+   //[INF_MEMMAX_MB]  ignored
[INF_MEMMAX_BYTES]   = { .n = IST("max_memory_bytes"),  
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
+   //[INF_POOL_ALLOC_MB]  ignored
[INF_POOL_ALLOC_BYTES]   = { .n = 
IST("pool_allocated_bytes"),  .type = PROMEX_MT_GAUGE,   .flags = 
PROMEX_FL_INFO_METRIC },
+   //[INF_POOL_USED_MB]   ignored
[INF_POOL_USED_BYTES]= { .n = IST("pool_used_bytes"),   
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
[INF_POOL_FAILED]= { .n = 
IST("pool_failures_total"),   .type = PROMEX_MT_COUNTER, .flags = 
PROMEX_FL_INFO_METRIC },
[INF_ULIMIT_N]   = { .n = IST("max_fds"),   
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
@@ -173,6 +175,7 @@ const struct promex_metric 
promex_global_metrics[INF_TOTAL_FIELDS] = {
[INF_BYTES_OUT_RATE] = { .n = IST("bytes_out_rate"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
//[INF_DEBUG_COMMANDS_ISSUED]  ignored
[INF_CUM_LOG_MSGS]   = { .n = IST("recv_logs_total"),   
.type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC },
+   [INF_BUILD_INFO] = { .n = IST("build_info"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
 };
 
 /* frontend/backend/server fields */
@@ -273,7 +276,7 @@ const struct promex_metric 
promex_st_metrics[ST_F_TOTAL_FIELDS] = {
[ST_F_TT_MAX] = { .n = IST("max_total_time_seconds"),   
.type = PROMEX_MT_GAUGE,.flags = ( 
PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) },
[ST_F_EINT]   = { .n = IST("internal_errors_total"),
.type = PROMEX_MT_COUNTER,  .flags = (PROMEX_FL_FRONT_METRIC | 
PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) },
[ST_F_IDLE_CONN_CUR]  = { .n = IST("unsafe_idle_connections_current"),  
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
-   [ST_F_SAFE_CONN_CUR]=   { .n = IST("safe_idle_connections_current"),
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
+   [ST_F_SAFE_CONN_CUR]  = { .n = IST("safe_idle_connections_current"),
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
[ST_F_USED_CONN_CUR]  = { .n = IST("used_connections_current"), 
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
[ST_F_NEED_CONN_EST]  = { .n = IST("need_connections_current"), 
.type = PROMEX_MT_GAUGE,

[PATCH 7/9] MINOR: contrib/prometheus-exporter: add recv logs_logs_total field

2021-01-30 Thread William Dauchy
this field was added by commit 45c457a62941a7c4a86ce4327d7755edcd4b230e
("MINOR: log: adds counters on received syslog messages.")

Signed-off-by: William Dauchy 
---
 contrib/prometheus-exporter/service-prometheus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index 0db75b6ae..6c5072b16 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -177,6 +177,7 @@ const struct promex_metric 
promex_global_metrics[INF_TOTAL_FIELDS] = {
[INF_TOTAL_SPLICED_BYTES_OUT]= { .n = 
IST("spliced_bytes_out_total"),   .type = PROMEX_MT_COUNTER, .flags = 
PROMEX_FL_INFO_METRIC },
[INF_BYTES_OUT_RATE] = { .n = IST("bytes_out_rate"),
.type = PROMEX_MT_GAUGE,   .flags = PROMEX_FL_INFO_METRIC },
//[INF_DEBUG_COMMANDS_ISSUED]  ignored
+   [INF_CUM_LOG_MSGS]   = { .n = IST("recv_logs_total"),   
.type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC },
 };
 
 /* frontend/backend/server fields */
-- 
2.29.2




[PATCH 8/9] CLEANUP: contrib/prometheus-exporter: remove unused includes

2021-01-30 Thread William Dauchy
unless I'm wrong, those includes are no longer needed.  The only recent
one I remember is ssl-sock include since commit
5d9b8f3c9347a1a10b86f81d70b22c3cab0e6925 ("MINOR:
contrib/prometheus-exporter: use fill_info for process dump") where we
make use of the code from stats.c

Signed-off-by: William Dauchy 
---
 contrib/prometheus-exporter/service-prometheus.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index 6c5072b16..98f6fca62 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -19,8 +19,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
@@ -29,12 +27,9 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
2.29.2




[PATCH 5/9] MINOR: contrib/prometheus-exporter: use stats desc when possible

2021-01-30 Thread William Dauchy
It is a followup work of commit a191b77e54c26a97064cb42ab4927d4f5c95b896
("MINOR: contrib/prometheus-exporter: merge info description from
stats") but for all other stats fields; we however keep a way to
override them when needed (e.g. units, specific cases)

this is another step which will avoid duplicating work between stats.c
and prometheus.

Signed-off-by: William Dauchy 
---
 .../prometheus-exporter/service-prometheus.c  | 107 ++
 1 file changed, 10 insertions(+), 97 deletions(-)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index 8baef82d7..f10e78f49 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -282,107 +282,20 @@ const struct promex_metric 
promex_st_metrics[ST_F_TOTAL_FIELDS] = {
[ST_F_NEED_CONN_EST]  = { .n = IST("need_connections_current"), 
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
 };
 
-/* Description of all stats fields */
+/* Description of overriden stats fields */
 const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
-   [ST_F_PXNAME] = IST("The proxy name."),
-   [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, 
BACKEND for backend, any name for server/listener)."),
-   [ST_F_QCUR]   = IST("Current number of queued requests."),
-   [ST_F_QMAX]   = IST("Maximum observed number of queued 
requests."),
-   [ST_F_SCUR]   = IST("Current number of active sessions."),
-   [ST_F_SMAX]   = IST("Maximum observed number of active 
sessions."),
-   [ST_F_SLIM]   = IST("Configured session limit."),
-   [ST_F_STOT]   = IST("Total number of sessions."),
-   [ST_F_BIN]= IST("Current total of incoming bytes."),
-   [ST_F_BOUT]   = IST("Current total of outgoing bytes."),
-   [ST_F_DREQ]   = IST("Total number of denied requests."),
-   [ST_F_DRESP]  = IST("Total number of denied responses."),
-   [ST_F_EREQ]   = IST("Total number of request errors."),
-   [ST_F_ECON]   = IST("Total number of connection errors."),
-   [ST_F_ERESP]  = IST("Total number of response errors."),
-   [ST_F_WRETR]  = IST("Total number of retry warnings."),
-   [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
[ST_F_STATUS] = IST("Current status of the service (0/1 
depending on current `state` label value)."),
-   [ST_F_WEIGHT] = IST("Service weight."),
-   [ST_F_ACT]= IST("Current number of active servers."),
-   [ST_F_BCK]= IST("Current number of backup servers."),
-   [ST_F_CHKFAIL]= IST("Total number of failed check (Only counts 
checks failed when the server is up)."),
-   [ST_F_CHKDOWN]= IST("Total number of UP->DOWN transitions."),
-   [ST_F_LASTCHG]= IST("Number of seconds since the last UP<->DOWN 
transition."),
-   [ST_F_DOWNTIME]   = IST("Total downtime (in seconds) for the 
service."),
-   [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 
meaning no limit)."),
-   [ST_F_PID]= IST("Process id (0 for first instance, 1 for 
second, ...)"),
-   [ST_F_IID]= IST("Unique proxy id."),
-   [ST_F_SID]= IST("Server id (unique inside a proxy)."),
-   [ST_F_THROTTLE]   = IST("Current throttle percentage for the 
server, when slowstart is active, or no value if not in slowstart."),
-   [ST_F_LBTOT]  = IST("Total number of times a service was 
selected, either for new sessions, or when redispatching."),
-   [ST_F_TRACKED]= IST("Id of proxy/server if tracking is 
enabled."),
-   [ST_F_TYPE]   = IST("Service type (0=frontend, 1=backend, 
2=server, 3=socket/listener)."),
-   [ST_F_RATE]   = IST("Current number of sessions per second over 
last elapsed second."),
-   [ST_F_RATE_LIM]   = IST("Configured limit on new sessions per 
second."),
-   [ST_F_RATE_MAX]   = IST("Maximum observed number of sessions per 
second."),
[ST_F_CHECK_STATUS]   = IST("Status of last health check (0/1 depending 
on current `state` label value)."),
[ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last 
health check."),
[ST_F_CHECK_DURATION] = IST("Total duration of the latest server health 
check, in seconds."),
-   [ST_F_HRSP_1XX]   = IST("Total number of HTTP responses."),
-   [ST_F_HRSP_2XX]   = IST("Total number of HTTP responses."),
-   [ST_F_HRSP_3XX]   = IST("Total number of HTTP responses."),
-   [ST_F_HRSP_4XX]   = IST("Total number of HTTP responses."),
-   [ST_F_HRSP_5XX]   = IST("Total number of HTTP responses."),
-   [ST_F_HRSP_OTHER] = 

[PATCH 6/9] MINOR: contrib/prometheus-exporter: add uweight field

2021-01-30 Thread William Dauchy
this field was added in commit bd7151002437af1a034a9fdbb582b3cbef5a78d1
("MINOR: stats: report server's user-configured weight next to effective
weight")

Signed-off-by: William Dauchy 
---
 contrib/prometheus-exporter/service-prometheus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index f10e78f49..0db75b6ae 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -280,6 +280,7 @@ const struct promex_metric 
promex_st_metrics[ST_F_TOTAL_FIELDS] = {
[ST_F_SAFE_CONN_CUR]=   { .n = IST("safe_idle_connections_current"),
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
[ST_F_USED_CONN_CUR]  = { .n = IST("used_connections_current"), 
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
[ST_F_NEED_CONN_EST]  = { .n = IST("need_connections_current"), 
.type = PROMEX_MT_GAUGE,.flags = (  
   PROMEX_FL_SRV_METRIC) },
+   [ST_F_UWEIGHT]= { .n = IST("uweight"),  
.type = PROMEX_MT_GAUGE,.flags = ( 
PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) },
 };
 
 /* Description of overriden stats fields */
-- 
2.29.2




[PATCH 4/9] MINOR: stats: improve max stats descriptions

2021-01-30 Thread William Dauchy
In order to unify prometheus and stats description, we need to remove
some field reference which are specific to stats implementation:
- `scur` in max current sessions (also reword current session)
- `rate` in max sessions
- `req_rate` in max requests
- `conn_rate` in max connections

Signed-off-by: William Dauchy 
---
 src/stats.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/stats.c b/src/stats.c
index fdb8e9adf..6fa59a9ef 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -160,8 +160,8 @@ const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
[ST_F_SVNAME]= { .name = "svname",  
.desc = "Server name" },
[ST_F_QCUR]  = { .name = "qcur",
.desc = "Number of current queued connections" },
[ST_F_QMAX]  = { .name = "qmax",
.desc = "Highest value of queued connections encountered since process 
started" },
-   [ST_F_SCUR]  = { .name = "scur",
.desc = "Current number of sessions on the frontend, backend or server" 
},
-   [ST_F_SMAX]  = { .name = "smax",
.desc = "Highest value of scur encountered since process started" },
+   [ST_F_SCUR]  = { .name = "scur",
.desc = "Number of current sessions on the frontend, backend or server" 
},
+   [ST_F_SMAX]  = { .name = "smax",
.desc = "Highest value of current sessions encountered since process 
started" },
[ST_F_SLIM]  = { .name = "slim",
.desc = "Frontend/listener/server's maxconn, backend's fullconn" },
[ST_F_STOT]  = { .name = "stot",
.desc = "Total number of sessions since process started" },
[ST_F_BIN]   = { .name = "bin", 
.desc = "Total number of request bytes since process started" },
@@ -191,7 +191,7 @@ const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
[ST_F_TYPE]  = { .name = "type",
.desc = "Type of the object (Listener, Frontend, Backend, Server)" },
[ST_F_RATE]  = { .name = "rate",
.desc = "Total number of sessions processed by this object over the 
last second (sessions for listeners/frontends, requests for backends/servers)" 
},
[ST_F_RATE_LIM]  = { .name = "rate_lim",
.desc = "Limit on the number of sessions accepted in a second (frontend 
only, 'rate-limit sessions' setting)" },
-   [ST_F_RATE_MAX]  = { .name = "rate_max",
.desc = "Highest value of 'rate' observed since the worker process 
started" },
+   [ST_F_RATE_MAX]  = { .name = "rate_max",
.desc = "Highest value of sessions per second observed since the worker 
process started" },
[ST_F_CHECK_STATUS]  = { .name = "check_status",
.desc = "Status report of the server's latest health check, prefixed 
with '*' if a check is currently in progress" },
[ST_F_CHECK_CODE]= { .name = "check_code",  
.desc = "HTTP/SMTP/LDAP status code reported by the latest server 
health check" },
[ST_F_CHECK_DURATION]= { .name = "check_duration",  
.desc = "Total duration of the latest server health check, in 
milliseconds" },
@@ -203,7 +203,7 @@ const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
[ST_F_HRSP_OTHER]= { .name = "hrsp_other",  
.desc = "Total number of HTTP responses with status <100, >599 returned 
by this object since the worker process started (error -1 included)" },
[ST_F_HANAFAIL]  = { .name = "hanafail",
.desc = "Total number of failed checks caused by an 'on-error' 
directive after an 'observe' condition matched" },
[ST_F_REQ_RATE]  = { .name = "req_rate",
.desc = "Number of HTTP requests processed over the last second on this 
object" },
-   [ST_F_REQ_RATE_MAX]  = { .name = "req_rate_max",
.desc = "Highest value of 'req_rate' observed since the worker process 
started" },
+   [ST_F_REQ_RATE_MAX]  = { .name = "req_rate_max",
.desc = "Highest value of http requests observed since the worker 
process started" },
[ST_F_REQ_TOT]   = { .name = "req_tot", 
.desc = "Total number of HTTP requests processed by this object since 
the worker process started" },
[ST_F_CLI_ABRT]  = { .name 

[PATCH 3/9] MINOR: stats: improve pending connections description

2021-01-30 Thread William Dauchy
In order to unify prometheus and stats description, we need to clarify
the description for pending connections.
- remove the BE reference in counters struct, as it is also used in
  servers
- remove reference of `qcur` field in description as it is specific to
  stats implemention
- try to reword cur and max pending connections description

Signed-off-by: William Dauchy 
---
 include/haproxy/counters-t.h | 2 +-
 src/stats.c  | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/haproxy/counters-t.h b/include/haproxy/counters-t.h
index b896c4d36..1ea68dd6c 100644
--- a/include/haproxy/counters-t.h
+++ b/include/haproxy/counters-t.h
@@ -73,7 +73,7 @@ struct be_counters {
 
unsigned int cps_max;   /* maximum of new connections 
received per second */
unsigned int sps_max;   /* maximum of new connections 
accepted per second (sessions) */
-   unsigned int nbpend_max;/* max number of pending 
connections with no server assigned yet (BE only) */
+   unsigned int nbpend_max;/* max number of pending 
connections with no server assigned yet */
unsigned int cur_sess_max;  /* max number of currently 
active sessions */
 
long long bytes_in; /* number of bytes transferred 
from the client to the server */
diff --git a/src/stats.c b/src/stats.c
index 4b8bd89b4..fdb8e9adf 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -158,8 +158,8 @@ const struct name_desc info_fields[INF_TOTAL_FIELDS] = {
 const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
[ST_F_PXNAME]= { .name = "pxname",  
.desc = "Proxy name" },
[ST_F_SVNAME]= { .name = "svname",  
.desc = "Server name" },
-   [ST_F_QCUR]  = { .name = "qcur",
.desc = "Current number of connections waiting in the server of backend 
queue" },
-   [ST_F_QMAX]  = { .name = "qmax",
.desc = "Highest value of qcur encountered since process started" },
+   [ST_F_QCUR]  = { .name = "qcur",
.desc = "Number of current queued connections" },
+   [ST_F_QMAX]  = { .name = "qmax",
.desc = "Highest value of queued connections encountered since process 
started" },
[ST_F_SCUR]  = { .name = "scur",
.desc = "Current number of sessions on the frontend, backend or server" 
},
[ST_F_SMAX]  = { .name = "smax",
.desc = "Highest value of scur encountered since process started" },
[ST_F_SLIM]  = { .name = "slim",
.desc = "Frontend/listener/server's maxconn, backend's fullconn" },
-- 
2.29.2




[PATCH 1/9] MAJOR: contrib/prometheus-exporter: move health check status to labels

2021-01-30 Thread William Dauchy
this patch is a breaking change between v2.3 and v2.4: we move from
using gauge value for health check states to labels values. The diff is
quite small thanks to the preparation work from Christopher to allow
more flexibility in labels, see commit
5a2f938732126f43bbf4cea5482c01552b0d0314 ("MEDIUM:
contrib/prometheus-exporter: Use dynamic labels instead of static ones")

this is a follow up of commit c6464591a365bfcf509b322bdaa4d608c9395d75
("MAJOR: contrib/prometheus-exporter: move ftd/bkd/srv states to
labels"). The main goal being to be better aligned with prometheus use
cases in terms of queries. More specifically to health checks, Pierre C.
mentioned the possible quirks he had to put in place in order to make
use of those metrics through prometheus:

   by(proxy, check_status) (count_values by(proxy,
  instance) ("check_status", haproxy_server_check_status))

I am perfectly aware this introduces a lot more metrics but I don't see
how we can improve the usability without it. The main issue remains in
the cardinality of the states which are > 20. Prometheus recommends to
stay below a cardinality of 10 for a given metric but I consider our
case very specific, because highly linked to the level of precision
haproxy exposes.

Even before this patch I saw several large production setup (a few
hundreds of MB in output) which are making use of the scope parameter to
simply ignore the server metrics, so that the scrapping can be faster,
and memory consumed on client side not too high. So I believe we should
eventually continue in that direction and offer more granularity of
filtering of the output. That being said it is already possible to
filter out the data on prometheus client side.

this is related to github issue #1029

Signed-off-by: William Dauchy 
---
 .../prometheus-exporter/service-prometheus.c| 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index dbf4c7f39..a3141d39d 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -319,7 +320,7 @@ const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = 
{
[ST_F_RATE]   = IST("Current number of sessions per second over 
last elapsed second."),
[ST_F_RATE_LIM]   = IST("Configured limit on new sessions per 
second."),
[ST_F_RATE_MAX]   = IST("Maximum observed number of sessions per 
second."),
-   [ST_F_CHECK_STATUS]   = IST("Status of last health check (HCHK_STATUS_* 
values)."),
+   [ST_F_CHECK_STATUS]   = IST("Status of last health check (0/1 depending 
on current `state` label value)."),
[ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last 
health check."),
[ST_F_CHECK_DURATION] = IST("Total duration of the latest server health 
check, in seconds."),
[ST_F_HRSP_1XX]   = IST("Total number of HTTP responses."),
@@ -886,6 +887,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, 
struct htx *htx)
int ret = 1;
double secs;
enum promex_srv_state state;
+   const char *check_state;
int i;
 
for (;appctx->st2 < ST_F_TOTAL_FIELDS; appctx->st2++) {
@@ -963,8 +965,17 @@ static int promex_dump_srv_metrics(struct appctx *appctx, 
struct htx *htx)
case ST_F_CHECK_STATUS:
if ((sv->check.state & 
(CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
goto next_sv;
-   val = mkf_u32(FN_OUTPUT, 
sv->check.status);
-   break;
+
+   for (i = 0; i < 
HCHK_STATUS_SIZE; i++) {
+   val = 
mkf_u32(FO_STATUS, sv->check.status == i);
+   check_state = 
get_check_status_info(i);
+   labels[2].name = 
ist("state");
+   labels[2].value = 
ist2(check_state, strlen(check_state));
+   if 
(!promex_dump_metric(appctx, htx, prefix, _st_metrics[appctx->st2],
+   
, labels, , max))
+   goto full;
+   }
+   goto next_sv;
case ST_F_CHECK_CODE:
if ((sv->check.state & 
(CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
   

[PATCH 2/9] MINOR: contrib/prometheus-exporter: improve service status description field

2021-01-30 Thread William Dauchy
Since we changed the behaviour of this metric, improve the description
to better explain what is the meaning of the new gauge value; it also
reflects the description we did for health check status.

Signed-off-by: William Dauchy 
---
 contrib/prometheus-exporter/service-prometheus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/prometheus-exporter/service-prometheus.c 
b/contrib/prometheus-exporter/service-prometheus.c
index a3141d39d..8baef82d7 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -301,7 +301,7 @@ const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = 
{
[ST_F_ERESP]  = IST("Total number of response errors."),
[ST_F_WRETR]  = IST("Total number of retry warnings."),
[ST_F_WREDIS] = IST("Total number of redispatch warnings."),
-   [ST_F_STATUS] = IST("Current status of the service."),
+   [ST_F_STATUS] = IST("Current status of the service (0/1 
depending on current `state` label value)."),
[ST_F_WEIGHT] = IST("Service weight."),
[ST_F_ACT]= IST("Current number of active servers."),
[ST_F_BCK]= IST("Current number of backup servers."),
-- 
2.29.2




[PATCH 0/9] prometheus: health check as labels + cleanup

2021-01-30 Thread William Dauchy
Hi Christopher,

Sorry for this long series but I believe this one is fairly easy to
review:
- the major change is for health checks on prometheus side, there are
  more details in the commit message; this is something I wanted early
  so people can start testing it, especially on large setup. I however
  think we will need to improve the `scope` filtering. The good point is
  that after this patch, this metric will be way easier to use; the bad
  point is that it is a breaking change between v2.3 and v2.4. But I
  believe this is acceptable following the previous state changes
  already merged.
- next patch is the continuation of the cleaning work:
 * try to improve descriptions so we can use them in both case
 * merge them when possible, override otherwise
- I finished with a bit of minor cleaning which pointed me a few missing
  fields. I know we probably can improve that to avoid forgetting adding
  those fields in the future, but I assume it is ok for now to simply
  come back with a sane result. The postive point is I did not had to
  add description and implementation, as we make use of stats.c

William Dauchy (9):
  MAJOR: contrib/prometheus-exporter: move health check status to labels
  MINOR: contrib/prometheus-exporter: improve service status description
field
  MINOR: stats: improve pending connections description
  MINOR: stats: improve max stats descriptions
  MINOR: contrib/prometheus-exporter: use stats desc when possible
  MINOR: contrib/prometheus-exporter: add uweight field
  MINOR: contrib/prometheus-exporter: add recv logs_logs_total field
  CLEANUP: contrib/prometheus-exporter: remove unused includes
  CLEANUP: contrib/prometheus-exporter: align and reorder fields

 .../prometheus-exporter/service-prometheus.c  | 140 --
 include/haproxy/counters-t.h  |   2 +-
 src/stats.c   |  14 +-
 3 files changed, 40 insertions(+), 116 deletions(-)

-- 
2.29.2




Re: lua function core.get_info() broken in haproxy 2.2.7

2021-01-30 Thread William Dauchy
Hi James,

On Sat, Jan 30, 2021 at 3:07 AM James Brown  wrote:
> Ah, never mind, I see that this was already fixed in master in 
> 3ddec3ee7d344112b4e4fbde317f8886a20d66a0.

yeah, sorry about that. This will be fixed in v2.2.8 and v2.3.4
-- 
William