]> git.ipfire.org Git - collecty.git/commitdiff
queue: Store the timestamp with the sample
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 16:58:51 +0000 (16:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 16:58:51 +0000 (16:58 +0000)
We can no longer store it this way because we are storing multiple
samples in a single object now.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/queue.c

index 162d2ee6dabd77f8272491674d49caba35575311..d032ec0ceeed7292670dcc6cf3cc7120f7161ee4 100644 (file)
@@ -19,6 +19,7 @@
 #############################################################################*/
 
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/queue.h>
@@ -39,9 +40,6 @@ struct collecty_queue_object {
        // Object
        char* object;
 
-       // Timestamp
-       struct timeval t;
-
        // Samples
        char** samples;
        unsigned int num_samples;
@@ -216,17 +214,24 @@ static struct collecty_queue_object* collecty_queue_find_object(
 
 static int collecty_queue_object_append_sample(collecty_queue* self, collecty_module* module,
                const char* object, struct collecty_queue_object* o, const char* sample) {
+       struct timeval t = {};
        char** samples = NULL;
        char* s = NULL;
+       int r;
+
+       // Fetch the current timestamp
+       r = gettimeofday(&t, NULL);
+       if (r < 0)
+               return -errno;
 
        // Increase the size of the array
        samples = reallocarray(o->samples, o->num_samples + 1, sizeof(*o->samples));
        if (!samples)
                return -errno;
 
-       // Copy the sample to the heap
-       s = strdup(sample);
-       if (!s)
+       // Prepend the timestamp to the sample
+       r = asprintf(&s, "%ld:%s", t.tv_sec, sample);
+       if (r < 0)
                return -errno;
 
        // Assign the sample
@@ -263,13 +268,6 @@ int collecty_queue_submit(collecty_queue* self,
        // Reference the module
        o->module = collecty_module_ref(module);
 
-       // Fetch the current timestamp
-       r = gettimeofday(&o->t, NULL);
-       if (r < 0) {
-               r = -errno;
-               goto ERROR;
-       }
-
        // Store the object
        if (o->object) {
                o->object = strdup(object);