From: Michael Tremer Date: Wed, 29 Oct 2025 15:44:08 +0000 (+0000) Subject: bus: Parse timestamps X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=622c03e5969673330962018e8f5d7febf6db8a0b;p=telemetry.git bus: Parse timestamps Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph-bus.c b/src/daemon/graph-bus.c index b93b332..3d7e75c 100644 --- a/src/daemon/graph-bus.c +++ b/src/daemon/graph-bus.c @@ -25,6 +25,7 @@ #include "graph.h" #include "graph-bus.h" #include "string.h" +#include "time.h" static int td_graph_node_enumerator(sd_bus* bus, const char* path, void* data, char*** nodes, sd_bus_error* error) { @@ -106,6 +107,10 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro size_t length = 0; int r; + // Intervals + const char* since = NULL; + const char* until = NULL; + // Open the options array r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "{sv}"); if (r < 0) @@ -148,6 +153,34 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro r = sd_bus_message_read(m, "v", "t", &options.dimensions.w); if (r < 0) goto ERROR; + + // Parse "since" + } else if (td_string_equals(key, "since")) { + r = sd_bus_message_read(m, "v", "s", &since); + if (r < 0) + goto ERROR; + + // Parse the timestamp + r = time_parse(&options.interval.t_start, since); + if (r < 0) { + r = sd_bus_error_setf(error, + SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", since); + goto ERROR; + } + + // Parse until + } else if (td_string_equals(key, "until")) { + r = sd_bus_message_read(m, "v", "s", &until); + if (r < 0) + goto ERROR; + + // Parse the timestamp + r = time_parse(&options.interval.t_end, until); + if (r < 0) { + r = sd_bus_error_setf(error, + SD_BUS_ERROR_INVALID_ARGS, "Failed to time '%s'", until); + goto ERROR; + } } // Leave the container @@ -161,6 +194,19 @@ static int td_graph_bus_render(sd_bus_message* m, void* data, sd_bus_error* erro if (r < 0) goto ERROR; + // Check the timestamps + if (options.interval.t_start && options.interval.t_end + && options.interval.t_start > options.interval.t_end) { + r = sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, + "Graph start time is after the end time"); + if (r < 0) + goto ERROR; + + // Abort + r = -ERANGE; + goto ERROR; + } + // Render the graph r = td_graph_render(graph, object, &options, &buffer, &length); if (r < 0)