mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-02 10:12:03 +00:00
MINOR: stats: use stricter naming stats/field/line
Several unique names were used for different purposes under statistics implementation. This caused the code to be difficult to understand. * stat/stats name is removed when a more specific name could be used * restrict field usage to purely refer to <struct field> which represents a raw stat value. * use "line" naming to represent an array of <struct field>
This commit is contained in:
parent
8dbb74542f
commit
e97375dcab
@ -659,7 +659,7 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
|
||||
if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
|
||||
goto next_px;
|
||||
|
||||
if (!stats_fill_fe_stats(px, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
if (!stats_fill_fe_line(px, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
return -1;
|
||||
|
||||
switch (ctx->field_num) {
|
||||
@ -856,8 +856,8 @@ static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx)
|
||||
labels[1].name = ist("listener");
|
||||
labels[1].value = ist2(li->name, strlen(li->name));
|
||||
|
||||
if (!stats_fill_li_stats(px, li, 0, stats,
|
||||
ST_I_PX_MAX, &(ctx->field_num)))
|
||||
if (!stats_fill_li_line(px, li, 0, stats,
|
||||
ST_I_PX_MAX, &(ctx->field_num)))
|
||||
return -1;
|
||||
|
||||
switch (ctx->field_num) {
|
||||
@ -1037,7 +1037,7 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
|
||||
if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
|
||||
goto next_px;
|
||||
|
||||
if (!stats_fill_be_stats(px, 0, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
if (!stats_fill_be_line(px, 0, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
return -1;
|
||||
|
||||
switch (ctx->field_num) {
|
||||
@ -1307,7 +1307,7 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
|
||||
labels[1].name = ist("server");
|
||||
labels[1].value = ist2(sv->id, strlen(sv->id));
|
||||
|
||||
if (!stats_fill_sv_stats(px, sv, 0, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
if (!stats_fill_sv_line(px, sv, 0, stats, ST_I_PX_MAX, &(ctx->field_num)))
|
||||
return -1;
|
||||
|
||||
if ((ctx->flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
|
||||
|
@ -39,7 +39,7 @@
|
||||
#define STAT_SHNODE 0x00000200 /* conf: show node name */
|
||||
#define STAT_SHDESC 0x00000400 /* conf: show description */
|
||||
#define STAT_SHLGNDS 0x00000800 /* conf: show legends */
|
||||
#define STAT_SHOW_FDESC 0x00001000 /* show the field descriptions when possible */
|
||||
#define STAT_SHOW_FDESC 0x00001000 /* show the column descriptions when possible */
|
||||
#define STAT_SHMODULES 0x00002000 /* conf: show modules */
|
||||
#define STAT_HIDE_MAINT 0x00004000 /* hide maint/disabled servers */
|
||||
#define STAT_CONVDONE 0x00008000 /* conf: rules conversion done */
|
||||
@ -250,12 +250,12 @@ enum field_scope {
|
||||
FS_MASK = 0xFF000000,
|
||||
};
|
||||
|
||||
/* Show info fields for CLI output. For any field added here, please add the
|
||||
/* Show info columns for CLI output. For any column added here, please add the
|
||||
* text representation in the metrics_info array. Please only append at the end,
|
||||
* before the ST_I_INF_MAX entry, and never insert anything in the middle
|
||||
* nor at the beginning.
|
||||
*/
|
||||
enum info_field {
|
||||
enum stat_idx_info {
|
||||
ST_I_INF_NAME,
|
||||
ST_I_INF_VERSION,
|
||||
ST_I_INF_RELEASE_DATE,
|
||||
@ -338,14 +338,14 @@ enum info_field {
|
||||
};
|
||||
|
||||
|
||||
/* Stats fields for CSV output. For any field added here, please add the text
|
||||
/* Stats columns for CSV output. For any column added here, please add the text
|
||||
* representation in the metrics_px array. Please only append at the end,
|
||||
* before the ST_I_PX_MAX entry, and never insert anything in the middle
|
||||
* nor at the beginning.When adding an entry here, one must always add a
|
||||
* corresponding one in metrics_px[] otherwise Lua's get_stats() will break,
|
||||
* and "show stats" will show a null.
|
||||
*/
|
||||
enum stat_field {
|
||||
enum stat_idx_px {
|
||||
ST_I_PX_PXNAME,
|
||||
ST_I_PX_SVNAME,
|
||||
ST_I_PX_QCUR,
|
||||
@ -464,10 +464,6 @@ enum stat_field {
|
||||
ST_I_PX_MAX
|
||||
};
|
||||
|
||||
/* Please consider updating stats_dump_fields_*(),
|
||||
* stats_dump_.*_info_fields() and stats_*_schema()
|
||||
* when modifying struct field or related enums.
|
||||
*/
|
||||
struct field {
|
||||
uint32_t type;
|
||||
union {
|
||||
|
@ -35,8 +35,8 @@ struct appctx;
|
||||
struct htx;
|
||||
struct stconn;
|
||||
|
||||
/* These two structs contains all field names and descriptions according to
|
||||
* the the number of entries in "enum stat_field" and "enum info_field"
|
||||
/* These two structs contains all column names and descriptions according to
|
||||
* the the number of entries in "enum stat_idx_px" and "enum stat_idx_info"
|
||||
*/
|
||||
extern const struct name_desc metrics_px[];
|
||||
extern const struct name_desc metrics_info[];
|
||||
@ -52,17 +52,17 @@ int stats_putchk(struct appctx *appctx, struct buffer *buf, struct htx *htx);
|
||||
|
||||
const char *stats_scope_ptr(struct appctx *appctx);
|
||||
|
||||
int stats_dump_one_line(const struct field *stats, size_t stats_count, struct appctx *appctx);
|
||||
int stats_dump_one_line(const struct field *line, size_t stats_count, struct appctx *appctx);
|
||||
|
||||
int stats_fill_info(struct field *info, int len, uint flags);
|
||||
int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len,
|
||||
enum stat_field *selected_field);
|
||||
int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
|
||||
struct field *stats, int len, enum stat_field *selected_field);
|
||||
int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
|
||||
struct field *stats, int len, enum stat_field *selected_field);
|
||||
int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len,
|
||||
enum stat_field *selected_field);
|
||||
int stats_fill_fe_line(struct proxy *px, struct field *line, int len,
|
||||
enum stat_idx_px *index);
|
||||
int stats_fill_li_line(struct proxy *px, struct listener *l, int flags,
|
||||
struct field *line, int len, enum stat_idx_px *index);
|
||||
int stats_fill_sv_line(struct proxy *px, struct server *sv, int flags,
|
||||
struct field *line, int len, enum stat_idx_px *index);
|
||||
int stats_fill_be_line(struct proxy *px, int flags, struct field *line, int len,
|
||||
enum stat_idx_px *index);
|
||||
|
||||
int stats_dump_stat_to_buffer(struct stconn *sc, struct buffer *buf, struct htx *htx);
|
||||
|
||||
|
@ -1158,8 +1158,8 @@ int hlua_listener_get_stats(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
stats_fill_li_stats(li->bind_conf->frontend, li, STAT_SHLGNDS, stats,
|
||||
STATS_LEN, NULL);
|
||||
stats_fill_li_line(li->bind_conf->frontend, li, STAT_SHLGNDS, stats,
|
||||
STATS_LEN, NULL);
|
||||
|
||||
lua_newtable(L);
|
||||
for (i=0; i<ST_I_PX_MAX; i++) {
|
||||
@ -1204,8 +1204,8 @@ int hlua_server_get_stats(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
stats_fill_sv_stats(srv->proxy, srv, STAT_SHLGNDS, stats,
|
||||
STATS_LEN, NULL);
|
||||
stats_fill_sv_line(srv->proxy, srv, STAT_SHLGNDS, stats,
|
||||
STATS_LEN, NULL);
|
||||
|
||||
lua_newtable(L);
|
||||
for (i=0; i<ST_I_PX_MAX; i++) {
|
||||
@ -2052,9 +2052,9 @@ int hlua_proxy_get_stats(lua_State *L)
|
||||
|
||||
px = hlua_check_proxy(L, 1);
|
||||
if (px->cap & PR_CAP_BE)
|
||||
stats_fill_be_stats(px, STAT_SHLGNDS, stats, STATS_LEN, NULL);
|
||||
stats_fill_be_line(px, STAT_SHLGNDS, stats, STATS_LEN, NULL);
|
||||
else
|
||||
stats_fill_fe_stats(px, stats, STATS_LEN, NULL);
|
||||
stats_fill_fe_line(px, stats, STATS_LEN, NULL);
|
||||
lua_newtable(L);
|
||||
for (i=0; i<ST_I_PX_MAX; i++) {
|
||||
lua_pushstring(L, metrics_px[i].name);
|
||||
|
@ -160,9 +160,9 @@ void stats_dump_json_header(struct buffer *out)
|
||||
chunk_strcat(out, "[");
|
||||
}
|
||||
|
||||
/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
|
||||
/* Dump all fields from <line> into <out> using a typed "field:desc:type:value" format */
|
||||
int stats_dump_fields_json(struct buffer *out,
|
||||
const struct field *stats, size_t stats_count,
|
||||
const struct field *line, size_t stats_count,
|
||||
struct show_stat_ctx *ctx)
|
||||
{
|
||||
int flags = ctx->flags;
|
||||
@ -177,9 +177,9 @@ int stats_dump_fields_json(struct buffer *out,
|
||||
|
||||
for (; ctx->field < stats_count; ctx->field++) {
|
||||
int old_len;
|
||||
int field = ctx->field;
|
||||
int i = ctx->field;
|
||||
|
||||
if (!stats[field].type)
|
||||
if (!line[i].type)
|
||||
continue;
|
||||
|
||||
if (started && !chunk_strcat(out, ","))
|
||||
@ -188,26 +188,26 @@ int stats_dump_fields_json(struct buffer *out,
|
||||
|
||||
old_len = out->data;
|
||||
if (domain == STATS_DOMAIN_PROXY) {
|
||||
stats_print_proxy_field_json(out, &stats[field],
|
||||
metrics[domain][field].name,
|
||||
field,
|
||||
stats[ST_I_PX_TYPE].u.u32,
|
||||
stats[ST_I_PX_IID].u.u32,
|
||||
stats[ST_I_PX_SID].u.u32,
|
||||
stats[ST_I_PX_PID].u.u32);
|
||||
stats_print_proxy_field_json(out, &line[i],
|
||||
metrics[domain][i].name,
|
||||
i,
|
||||
line[ST_I_PX_TYPE].u.u32,
|
||||
line[ST_I_PX_IID].u.u32,
|
||||
line[ST_I_PX_SID].u.u32,
|
||||
line[ST_I_PX_PID].u.u32);
|
||||
} else if (domain == STATS_DOMAIN_RESOLVERS) {
|
||||
stats_print_rslv_field_json(out, &stats[field],
|
||||
metrics[domain][field].name,
|
||||
field);
|
||||
stats_print_rslv_field_json(out, &line[i],
|
||||
metrics[domain][i].name,
|
||||
i);
|
||||
}
|
||||
|
||||
if (old_len == out->data)
|
||||
goto err;
|
||||
|
||||
if (!stats_emit_json_field_tags(out, &stats[field]))
|
||||
if (!stats_emit_json_field_tags(out, &line[i]))
|
||||
goto err;
|
||||
|
||||
if (!stats_emit_json_data_field(out, &stats[field]))
|
||||
if (!stats_emit_json_data_field(out, &line[i]))
|
||||
goto err;
|
||||
|
||||
if (!chunk_strcat(out, "}"))
|
||||
@ -256,9 +256,9 @@ int stats_dump_json_info_fields(struct buffer *out,
|
||||
|
||||
for (; ctx->field < ST_I_INF_MAX; ctx->field++) {
|
||||
int old_len;
|
||||
int field = ctx->field;
|
||||
int i = ctx->field;
|
||||
|
||||
if (!field_format(info, field))
|
||||
if (!field_format(info, i))
|
||||
continue;
|
||||
|
||||
if (started && !chunk_strcat(out, ","))
|
||||
@ -269,15 +269,15 @@ int stats_dump_json_info_fields(struct buffer *out,
|
||||
chunk_appendf(out,
|
||||
"{\"field\":{\"pos\":%d,\"name\":\"%s\"},"
|
||||
"\"processNum\":%u,",
|
||||
field, metrics_info[field].name,
|
||||
i, metrics_info[i].name,
|
||||
info[ST_I_INF_PROCESS_NUM].u.u32);
|
||||
if (old_len == out->data)
|
||||
goto err;
|
||||
|
||||
if (!stats_emit_json_field_tags(out, &info[field]))
|
||||
if (!stats_emit_json_field_tags(out, &info[i]))
|
||||
goto err;
|
||||
|
||||
if (!stats_emit_json_data_field(out, &info[field]))
|
||||
if (!stats_emit_json_data_field(out, &info[i]))
|
||||
goto err;
|
||||
|
||||
if (!chunk_strcat(out, "}"))
|
||||
|
902
src/stats.c
902
src/stats.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user