aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-11-09 10:52:19 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-11-09 10:52:19 +0100
commit916423ef9585c7042730fdb17f55afc376565d32 (patch)
treee85bb297c99781fdea4cd61b39bf3e645a2f12ba
parent834819471a024a98cf6062f1e20c75a9b9e26f88 (diff)
stats: Fix name prefix handling
Currently the having an unset prefix leads to an abort() in the statsd reporter due to an fprintf format string error. In addition the prefix cannot be reset to its initial state (NULL) by using 'no prefix', which just sets the prefix to the empty string, causing a single leading dot to appear in front of the name. This commit changes the implemenation to consistly use NULL for the unset name prefix ('no prefix') and to handle this case correctly in the statsd reporter. Sponsored-by: On-Waves ehf
-rw-r--r--src/stats.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/stats.c b/src/stats.c
index a0723702..fa56f50a 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -278,7 +278,8 @@ int osmo_stats_set_interval(int interval)
int osmo_stats_reporter_set_name_prefix(struct osmo_stats_reporter *srep, const char *prefix)
{
talloc_free(srep->name_prefix);
- srep->name_prefix = prefix ? talloc_strdup(srep, prefix) : NULL;
+ srep->name_prefix = prefix && strlen(prefix) > 0 ?
+ talloc_strdup(srep, prefix) : NULL;
return update_srep_config(srep);
}
@@ -468,18 +469,29 @@ static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,
int buf_size;
int nchars, rc = 0;
char *fmt = NULL;
+ char *prefix = srep->name_prefix;
int old_len = msgb_length(srep->buffer);
- if (name1) {
- if (index1 != 0)
- fmt = "%1$s.%2$s.%6$u.%3$s:%4$d|%5$s";
- else
- fmt = "%1$s.%2$s.%3$s:%4$d|%5$s";
+ if (prefix) {
+ if (name1) {
+ if (index1 != 0)
+ fmt = "%1$s.%2$s.%6$u.%3$s:%4$d|%5$s";
+ else
+ fmt = "%1$s.%2$s.%3$s:%4$d|%5$s";
+ } else {
+ fmt = "%1$s.%2$0.0s%3$s:%4$d|%5$s";
+ }
} else {
- fmt = "%1$s.%2$0.0s%3$s:%4$d|%5$s";
+ prefix = "";
+ if (name1) {
+ if (index1 != 0)
+ fmt = "%1$s%2$s.%6$u.%3$s:%4$d|%5$s";
+ else
+ fmt = "%1$s%2$s.%3$s:%4$d|%5$s";
+ } else {
+ fmt = "%1$s%2$0.0s%3$s:%4$d|%5$s";
+ }
}
- if (!srep->name_prefix)
- fmt += 5; /* skip prefix part */
if (srep->agg_enabled) {
if (msgb_length(srep->buffer) > 0 &&
@@ -493,7 +505,7 @@ static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,
buf_size = msgb_tailroom(srep->buffer);
nchars = snprintf(buf, buf_size, fmt,
- srep->name_prefix, name1, name2,
+ prefix, name1, name2,
value, unit, index1);
if (nchars >= buf_size) {
@@ -508,7 +520,7 @@ static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,
buf_size = msgb_tailroom(srep->buffer);
nchars = snprintf(buf, buf_size, fmt,
- srep->name_prefix, name1, name2,
+ prefix, name1, name2,
value, unit, index1);
if (nchars >= buf_size)