MINOR: contrib/prometheus-exporter: export build_info

commit c55a626217a7e676e1cc ("MINOR: contrib/prometheus-exporter: Add
missing global and per-server metrics") is renaming two metrics between
v2.2 and v2.3:
  server_idle_connections_current
  server_idle_connections_limit

It is breaking some tools which are making use of those metrics while
supporting several haproxy versions. This build_info will permit tools
which make use of metrics to be able to match the haproxy version and
change the list of expected metrics. This was possible using the haproxy
stats socket but not with prometheus export.

This patch follows prometheus best pratices to export specific software
informations. It is adding a new field `build_info` so we can extend it
to other parameters if needed in the future.

example output:
  # HELP haproxy_process_build_info HAProxy build info.
  # TYPE haproxy_process_build_info gauge
  haproxy_process_build_info{version="2.4-dev5-2e1a3f-5"} 1

Even though it is not a bugfix, this patch will make more sense when
backported up to >= 2.0

Signed-off-by: William Dauchy <wdauchy@gmail.com>
(cherry picked from commit 5a982a71656ce885be4b1d4b90b8db31204788a1)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit d97162cc94eafff8bd0e67f69ad5f75f59ceaf97)
[wt: context in stats-t.h]
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit ce3e98eb1f9240b7633c5de6855dd115e61708ae)
[wt: adjusted include file names (version.h is in common)]
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit ab210b6efde62f4e22f5a000faf9858ae3b72982)
[wt: adjusted context in stats.h -- no INF_DEBUG_COMMANDS_ISSUED there]
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c
index 9852206..fb50db2 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -20,6 +20,7 @@
 #include <common/initcall.h>
 #include <common/memory.h>
 #include <common/mini-clist.h>
+#include <common/version.h>
 
 #include <types/global.h>
 
@@ -83,12 +84,17 @@
  */
 #define PROMEX_MAX_METRIC_LENGTH 512
 
+/* Some labels for build_info */
+#define PROMEX_VERSION_LABEL "version=\"" HAPROXY_VERSION "\""
+#define PROMEX_BUILDINFO_LABEL PROMEX_VERSION_LABEL
+
 /* Matrix used to dump global metrics. Each metric points to the next one to be
  * processed or 0 to stop the dump. */
 const int promex_global_metrics[INF_TOTAL_FIELDS] = {
-	[INF_NAME]                           = INF_NBTHREAD,
+	[INF_NAME]                           = INF_BUILD_INFO,
 	[INF_VERSION]                        = 0,
 	[INF_RELEASE_DATE]                   = 0,
+	[INF_BUILD_INFO]                     = INF_NBTHREAD,
 	[INF_NBTHREAD]                       = INF_NBPROC,
 	[INF_NBPROC]                         = INF_PROCESS_NUM,
 	[INF_PROCESS_NUM]                    = INF_UPTIME_SEC,
@@ -450,6 +456,7 @@
 	[INF_NAME]                           = IST("name"),
 	[INF_VERSION]                        = IST("version"),
 	[INF_RELEASE_DATE]                   = IST("release_date"),
+	[INF_BUILD_INFO]                     = IST("build_info"),
 	[INF_NBTHREAD]                       = IST("nbthread"),
 	[INF_NBPROC]                         = IST("nbproc"),
 	[INF_PROCESS_NUM]                    = IST("relative_process_id"),
@@ -611,7 +618,8 @@
 const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
 	[INF_NAME]                           = IST("Product name."),
 	[INF_VERSION]                        = IST("HAProxy version."),
-	[INF_RELEASE_DATE]                   = IST("HAProxy realease date."),
+	[INF_RELEASE_DATE]                   = IST("HAProxy release date."),
+	[INF_BUILD_INFO]                     = IST("HAProxy build info."),
 	[INF_NBTHREAD]                       = IST("Configured number of threads."),
 	[INF_NBPROC]                         = IST("Configured number of processes."),
 	[INF_PROCESS_NUM]                    = IST("Relative process id, starting at 1."),
@@ -774,6 +782,7 @@
 	[INF_NAME]                           = IST(""),
 	[INF_VERSION]                        = IST(""),
 	[INF_RELEASE_DATE]                   = IST(""),
+	[INF_BUILD_INFO]                     = IST(PROMEX_BUILDINFO_LABEL),
 	[INF_NBTHREAD]                       = IST(""),
 	[INF_NBPROC]                         = IST(""),
 	[INF_PROCESS_NUM]                    = IST(""),
@@ -930,6 +939,7 @@
 	[INF_NAME]                           = IST("untyped"),
 	[INF_VERSION]                        = IST("untyped"),
 	[INF_RELEASE_DATE]                   = IST("untyped"),
+	[INF_BUILD_INFO]                     = IST("gauge"),
 	[INF_NBTHREAD]                       = IST("gauge"),
 	[INF_NBPROC]                         = IST("gauge"),
 	[INF_PROCESS_NUM]                    = IST("gauge"),
@@ -1269,6 +1279,9 @@
 #endif
 	while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
 		switch (appctx->st2) {
+			case INF_BUILD_INFO:
+				metric = mkf_u32(FN_GAUGE, 1);
+				break;
 			case INF_NBTHREAD:
 				metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
 				break;
diff --git a/include/types/stats.h b/include/types/stats.h
index d1a0004..f184263 100644
--- a/include/types/stats.h
+++ b/include/types/stats.h
@@ -317,6 +317,7 @@
 	INF_FAILED_RESOLUTIONS,
 	INF_TOTAL_BYTES_OUT,
 	INF_BYTES_OUT_RATE,
+	INF_BUILD_INFO,
 
 	/* must always be the last one */
 	INF_TOTAL_FIELDS