From: Florian Forster Date: Sat, 26 Nov 2016 17:46:36 +0000 (+0100) Subject: src/utils_format_graphite.[ch]: Implement the GRAPHITE_PRESERVE_SEPARATOR flag. X-Git-Tag: collectd-5.7.0~27^2~1 X-Git-Url: https://git.tokkee.org/?p=collectd.git;a=commitdiff_plain;h=df3252cafd38f005595e682f4494dd991496140c src/utils_format_graphite.[ch]: Implement the GRAPHITE_PRESERVE_SEPARATOR flag. --- diff --git a/src/utils_format_graphite.c b/src/utils_format_graphite.c index 69c619f4..85f5917c 100644 --- a/src/utils_format_graphite.c +++ b/src/utils_format_graphite.c @@ -83,7 +83,7 @@ static int gr_format_values (char *ret, size_t ret_len, } static void gr_copy_escape_part (char *dst, const char *src, size_t dst_len, - char escape_char) + char escape_char, _Bool preserve_separator) { memset (dst, 0, dst_len); @@ -98,7 +98,7 @@ static void gr_copy_escape_part (char *dst, const char *src, size_t dst_len, break; } - if ((src[i] == '.') + if ((!preserve_separator && (src[i] == '.')) || isspace ((int) src[i]) || iscntrl ((int) src[i])) dst[i] = escape_char; @@ -130,16 +130,18 @@ static int gr_format_name (char *ret, int ret_len, if (postfix == NULL) postfix = ""; + _Bool preserve_separator = (flags & GRAPHITE_PRESERVE_SEPARATOR) ? 1 : 0; + gr_copy_escape_part (n_host, vl->host, - sizeof (n_host), escape_char); + sizeof (n_host), escape_char, preserve_separator); gr_copy_escape_part (n_plugin, vl->plugin, - sizeof (n_plugin), escape_char); + sizeof (n_plugin), escape_char, preserve_separator); gr_copy_escape_part (n_plugin_instance, vl->plugin_instance, - sizeof (n_plugin_instance), escape_char); + sizeof (n_plugin_instance), escape_char, preserve_separator); gr_copy_escape_part (n_type, vl->type, - sizeof (n_type), escape_char); + sizeof (n_type), escape_char, preserve_separator); gr_copy_escape_part (n_type_instance, vl->type_instance, - sizeof (n_type_instance), escape_char); + sizeof (n_type_instance), escape_char, preserve_separator); if (n_plugin_instance[0] != '\0') ssnprintf (tmp_plugin, sizeof (tmp_plugin), "%s%c%s", diff --git a/src/utils_format_graphite.h b/src/utils_format_graphite.h index 5165f9e6..ebc50802 100644 --- a/src/utils_format_graphite.h +++ b/src/utils_format_graphite.h @@ -30,6 +30,7 @@ #define GRAPHITE_SEPARATE_INSTANCES 0x02 #define GRAPHITE_ALWAYS_APPEND_DS 0x04 #define GRAPHITE_DROP_DUPE_FIELDS 0x08 +#define GRAPHITE_PRESERVE_SEPARATOR 0x10 int format_graphite (char *buffer, size_t buffer_size, const data_set_t *ds, diff --git a/src/utils_format_graphite_test.c b/src/utils_format_graphite_test.c index 30cdd7a4..f349db1f 100644 --- a/src/utils_format_graphite_test.c +++ b/src/utils_format_graphite_test.c @@ -96,6 +96,19 @@ DEF_TEST(metric_name) .flags = GRAPHITE_ALWAYS_APPEND_DS, .want_name = "example@com.test-foo.single-bar.value", }, + /* flag GRAPHITE_PRESERVE_SEPARATOR */ + { + .plugin_instance = "f.o.o", + .type_instance = "b.a.r", + .flags = 0, + .want_name = "example@com.test-f@o@o.single-b@a@r", + }, + { + .plugin_instance = "f.o.o", + .type_instance = "b.a.r", + .flags = GRAPHITE_PRESERVE_SEPARATOR, + .want_name = "example.com.test-f.o.o.single-b.a.r", + }, /* prefix and suffix */ { .prefix = "foo.",