This adds a new 'FULL' status to the Prometheus metric 'srv_state'. It helps
identify servers that have exceeded their maxconn limit and cannot accept new
connections.
Rename server_has_room to !server_is_full to matches what's used at a few
places in the doc in association with servers or backends being "full".
---
addons/promex/service-prometheus.c | 7 +++++++
include/haproxy/queue.h | 6 +++---
src/backend.c | 2 +-
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/addons/promex/service-prometheus.c
b/addons/promex/service-prometheus.c
index 7b6081fab..40ec00085 100644
--- a/addons/promex/service-prometheus.c
+++ b/addons/promex/service-prometheus.c
@@ -380,6 +380,7 @@ enum promex_srv_state {
PROMEX_SRV_STATE_UP,
PROMEX_SRV_STATE_MAINT,
PROMEX_SRV_STATE_DRAIN,
+ PROMEX_SRV_STATE_FULL,
PROMEX_SRV_STATE_NOLB,
PROMEX_SRV_STATE_COUNT /* must be last */
@@ -390,10 +391,13 @@ const struct ist promex_srv_st[PROMEX_SRV_STATE_COUNT] = {
[PROMEX_SRV_STATE_UP] = IST("UP"),
[PROMEX_SRV_STATE_MAINT] = IST("MAINT"),
[PROMEX_SRV_STATE_DRAIN] = IST("DRAIN"),
+ [PROMEX_SRV_STATE_FULL] = IST("FULL"),
[PROMEX_SRV_STATE_NOLB] = IST("NOLB"),
};
/* Return the server status. */
+
+
enum promex_srv_state promex_srv_status(struct server *sv)
{
int state = PROMEX_SRV_STATE_DOWN;
@@ -402,6 +406,9 @@ enum promex_srv_state promex_srv_status(struct server *sv)
state = PROMEX_SRV_STATE_UP;
if (sv->cur_admin & SRV_ADMF_DRAIN)
state = PROMEX_SRV_STATE_DRAIN;
+ if (server_is_full(sv))
+ state = PROMEX_SRV_STATE_FULL;
+
}
else if (sv->cur_state == SRV_ST_STOPPING)
state = PROMEX_SRV_STATE_NOLB;
diff --git a/include/haproxy/queue.h b/include/haproxy/queue.h
index e77370cdd..2817b6c8b 100644
--- a/include/haproxy/queue.h
+++ b/include/haproxy/queue.h
@@ -77,9 +77,9 @@ static inline void pendconn_free(struct stream *s)
}
}
-/* Returns 0 if all slots are full on a server, or 1 if there are slots
available. */
-static inline int server_has_room(const struct server *s) {
- return !s->maxconn || s->cur_sess < srv_dynamic_maxconn(s);
+/* Returns 1 if all slots are full on a server, or 0 if there are slots
available. */
+static inline int server_is_full(const struct server *s) {
+ return s->maxconn && s->cur_sess >= srv_dynamic_maxconn(s);
}
/* returns 0 if nothing has to be done for server <s> regarding queued
connections,
diff --git a/src/backend.c b/src/backend.c
index 2f9da87ab..9b9e63649 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -658,7 +658,7 @@ int assign_server(struct stream *s)
if (tmpsrv && tmpsrv->proxy == s->be &&
((s->sess->flags & SESS_FL_PREFER_LAST) ||
(!s->be->max_ka_queue ||
- server_has_room(tmpsrv) || (
+ !server_is_full(tmpsrv) || (
tmpsrv->queue.length + 1 < s->be->max_ka_queue)))
&&
srv_currently_usable(tmpsrv)) {
list_for_each_entry(conn, &srv_list->conn_list,
session_list) {
--
2.25.1