Change in libosmocore[master]: stats_statsd: sanitize statsd name

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue Jul 24 14:49:13 UTC 2018


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/10133


Change subject: stats_statsd: sanitize statsd name
......................................................................

stats_statsd: sanitize statsd name

The statsd protocol use ':' as seperator between name and value.
It's not allowed to use the seperator in a name. Replace ':' with '.'
before sending the packet to the statsd server.

Change-Id: Ib46d08481e8ca04afd97cb9ae241e4e39c91ad66
---
M src/stats_statsd.c
1 file changed, 22 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/33/10133/1

diff --git a/src/stats_statsd.c b/src/stats_statsd.c
index c11c013..a99aea8 100644
--- a/src/stats_statsd.c
+++ b/src/stats_statsd.c
@@ -68,6 +68,25 @@
 	return srep;
 }
 
+/*! Replace all illegal ':' in the stats name, but not when used as value seperator.
+ *  ':' is used as seperator between the name and the value in the statsd protocol.
+ *  \param[in] buf is a null terminated string containing name, value, unit. */
+static void osmo_stats_reporter_sanitize_name(char *buf)
+{
+	/* e.g. msc.loc_update_type:normal:1|c -> msc.loc_update_type.normal:1|c
+	 * last is the seperator between name and value */
+	char *last = strrchr(buf, ':');
+	char *tmp = strchr(buf, ':');
+
+	if (!last)
+		return;
+
+	while (tmp < last) {
+		*tmp = '.';
+		tmp = strchr(buf, ':');
+	}
+}
+
 static int osmo_stats_reporter_statsd_send(struct osmo_stats_reporter *srep,
 	const char *name1, unsigned int index1, const char *name2, int64_t value,
 	const char *unit)
@@ -134,8 +153,10 @@
 			return -EMSGSIZE;
 	}
 
-	if (nchars > 0)
+	if (nchars > 0) {
+		osmo_stats_reporter_sanitize_name(buf);
 		msgb_trim(srep->buffer, msgb_length(srep->buffer) + nchars);
+	}
 
 	if (!srep->agg_enabled)
 		rc = osmo_stats_reporter_send_buffer(srep);

-- 
To view, visit https://gerrit.osmocom.org/10133
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib46d08481e8ca04afd97cb9ae241e4e39c91ad66
Gerrit-Change-Number: 10133
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180724/e504ee1b/attachment.htm>


More information about the gerrit-log mailing list