From: Michael Tremer Date: Wed, 22 Oct 2025 19:46:04 +0000 (+0000) Subject: source: Migrate RRDs if we have lost fields X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe2f5f56dd20e44be95310dc256219233eeba6dc;p=telemetry.git source: Migrate RRDs if we have lost fields Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 002aa49..a116c68 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -836,6 +836,28 @@ static int td_source_check_field_maximum(td_source* self, const char* path, return 1; } +static int td_source_check_num_ds(td_source* self, const char* path, rrd_info_t* info, int index) { + int i = 0; + + for (; info; info = info->next) { + // Skip if the key does not start with "ds[" + if (!td_string_startswith(info->key, "ds[")) + continue; + + // Skip if the key does not end with "].index" + if (!td_string_endswith(info->key, "].index")) + continue; + + // Need to migrate if we have more DS than we should have + if (index <= i++) { + DEBUG(self->ctx, "%s: We have some extra DS and need to migrate\n", path); + return 1; + } + } + + return 0; +} + static int td_source_needs_migration(td_source* self, const char* path, rrd_info_t* info) { unsigned long index = 0; int r; @@ -868,6 +890,11 @@ static int td_source_needs_migration(td_source* self, const char* path, rrd_info return r; } + // Check if we have some extra DSs + r = td_source_check_num_ds(self, path, info, index); + if (r) + return r; + // XXX Check RRAs return 0; diff --git a/src/daemon/string.h b/src/daemon/string.h index c9610fe..c3b41fb 100644 --- a/src/daemon/string.h +++ b/src/daemon/string.h @@ -129,6 +129,14 @@ static inline int td_string_startswith(const char* s, const char* prefix) { return !strncmp(s, prefix, strlen(prefix)); } +static inline int td_string_endswith(const char* s, const char* suffix) { + // Validate input + if (!s || !suffix) + return -EINVAL; + + return !strcmp(s + strlen(s) - strlen(suffix), suffix); +} + static inline void td_string_lstrip(char* s) { if (!s) return;