]> git.ipfire.org Git - oddments/collecty.git/commitdiff
source: Migrate RRDs if we have lost fields
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Oct 2025 19:46:04 +0000 (19:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 22 Oct 2025 19:46:04 +0000 (19:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/source.c
src/daemon/string.h

index 002aa4988a5da79fbf6bf0ec2751408e6d452d81..a116c68a4aa95fd854d1134085107784f8dffbca 100644 (file)
@@ -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;
index c9610fe862ff4d35f8814f8a42b5a5bb2fa302a2..c3b41fb3df687b2030ec2f3cd751fadf12a44a84 100644 (file)
@@ -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;