MINOR: stats: Add the support of float fields in stats

It is now possible to format stats counters as floats. But the stats applet does
not use it.

This patch is required by the Prometheus exporter to send the time averages in
seconds. If the promex change is backported, this patch must be backported
first.

(cherry picked from commit 88a0db28aeb45e451d36645612e11cd284cc7ef4)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/include/proto/stats.h b/include/proto/stats.h
index 01c96cb..6144d2f 100644
--- a/include/proto/stats.h
+++ b/include/proto/stats.h
@@ -84,6 +84,12 @@
 	return f;
 }
 
+static inline struct field mkf_flt(uint32_t type, double value)
+{
+	struct field f = { .type = FF_FLT | type, .u.flt = value };
+	return f;
+}
+
 extern const char *stat_status_codes[];
 
 /* These two structs contains all field names according with
diff --git a/include/types/stats.h b/include/types/stats.h
index 2a71ff6..0da1400 100644
--- a/include/types/stats.h
+++ b/include/types/stats.h
@@ -195,6 +195,7 @@
 	FF_S64      = 0x00000003,
 	FF_U64      = 0x00000004,
 	FF_STR      = 0x00000005,
+	FF_FLT      = 0x00000006,
 	FF_MASK     = 0x000000FF,
 };
 
@@ -242,6 +243,7 @@
 		uint32_t    u32; /* FF_U32 */
 		int64_t     s64; /* FF_S64 */
 		uint64_t    u64; /* FF_U64 */
+		double      flt; /* FF_FLT */
 		const char *str; /* FF_STR */
 	} u;
 };
diff --git a/src/stats.c b/src/stats.c
index c7cc426..5819f45 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -341,6 +341,7 @@
 	case FF_U32:   return chunk_appendf(out, "%u", f->u.u32);
 	case FF_S64:   return chunk_appendf(out, "%lld", (long long)f->u.s64);
 	case FF_U64:   return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
+	case FF_FLT:   return chunk_appendf(out, "%f", f->u.flt);
 	case FF_STR:   return csv_enc_append(field_str(f, 0), 1, out) != NULL;
 	default:       return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
 	}
@@ -358,6 +359,7 @@
 	case FF_U32:   return chunk_appendf(out, "u32:%u", f->u.u32);
 	case FF_S64:   return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
 	case FF_U64:   return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
+	case FF_FLT:   return chunk_appendf(out, "flt:%f", f->u.flt);
 	case FF_STR:   return chunk_appendf(out, "str:%s", field_str(f, 0));
 	default:       return chunk_appendf(out, "%08x:?", f->type);
 	}
@@ -397,6 +399,8 @@
 		       type = "\"u64\"";
 		       snprintf(buf, sizeof(buf), "%llu",
 				(unsigned long long) f->u.u64);
+	case FF_FLT:   type = "\"flt\"";
+		       snprintf(buf, sizeof(buf), "%f", f->u.flt);
 		       break;
 	case FF_STR:   type = "\"str\"";
 		       value = field_str(f, 0);