@cryptotaxi247 / netdata-1 / commits / 2ff68fbc7

do not allow duplicate chart names; #2654

Costa Tsaousis (ktsaou) committed Oct 7, 2017 at 01:32 UTC 2ff68fbc7fb40d98d0b3e5ab14661fab4321f7d5
2 files changed +17 -6
src/rrd.h
+1 -1
@@ -578,7 +578,7 @@ extern void __rrd_check_wrlock(const char *file, const char *function, const uns
578 // ----------------------------------------------------------------------------
579 // RRDSET functions
580
581 -extern void rrdset_set_name(RRDSET *st, const char *name);
581 +extern int rrdset_set_name(RRDSET *st, const char *name);
582
583 extern RRDSET *rrdset_create_custom(RRDHOST *host
584 , const char *type
src/rrdset.c
+16 -5
@@ -135,11 +135,11 @@ char *rrdset_strncpyz_name(char *to, const char *from, size_t length) {
135 return to;
136 }
137
138 -void rrdset_set_name(RRDSET *st, const char *name) {
138 +int rrdset_set_name(RRDSET *st, const char *name) {
139 if(unlikely(st->name && !strcmp(st->name, name)))
140 - return;
140 + return 1;
141
142 - debug(D_RRD_CALLS, "rrdset_set_name() old: %s, new: %s", st->name, name);
142 + debug(D_RRD_CALLS, "rrdset_set_name() old: '%s', new: '%s'", st->name?st->name:"", name);
143
144 char b[CONFIG_MAX_VALUE + 1];
145 char n[RRD_ID_LENGTH_MAX + 1];
@@ -147,6 +147,11 @@ void rrdset_set_name(RRDSET *st, const char *name) {
147 snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
148 rrdset_strncpyz_name(b, n, CONFIG_MAX_VALUE);
149
150 + if(rrdset_index_find_name(st->rrdhost, b, 0)) {
151 + error("RRDSET: chart name '%s' on host '%s' already exists.", b, st->rrdhost->hostname);
152 + return 0;
153 + }
154 +
155 if(st->name) {
156 rrdset_index_del_name(st->rrdhost, st);
157 st->name = config_set_default(st->config_section, "name", b);
@@ -166,6 +171,8 @@ void rrdset_set_name(RRDSET *st, const char *name) {
171
172 if(unlikely(rrdset_index_add_name(st->rrdhost, st) != st))
173 error("RRDSET: INTERNAL ERROR: attempted to index duplicate chart name '%s'", st->name);
174 +
175 + return 1;
176 }
177
178 inline void rrdset_is_obsolete(RRDSET *st) {
@@ -628,8 +635,12 @@ RRDSET *rrdset_create_custom(
635
636 netdata_rwlock_init(&st->rrdset_rwlock);
637
631 - if(name && *name) rrdset_set_name(st, name);
632 - else rrdset_set_name(st, id);
638 + if(name && *name && rrdset_set_name(st, name))
639 + // we did set the name
640 + ;
641 + else
642 + // could not use the name, use the id
643 + rrdset_set_name(st, id);
644
645 st->title = config_get(st->config_section, "title", title);
646 json_fix_string(st->title);