Code

Don't fetch timeseries info when fetching the interval.
authorSebastian Harl <sh@tokkee.org>
Sun, 11 Sep 2016 14:09:12 +0000 (10:09 -0400)
committerSebastian Harl <sh@tokkee.org>
Sun, 11 Sep 2016 14:09:12 +0000 (10:09 -0400)
For this purpose, add query options to fine-tune the behavior. These are
passed in to sdb_plugin_query.

src/core/plugin.c
src/frontend/query.c
src/include/core/plugin.h

index ecd84b5f9c5f5f525017872ecdf54fe234a6267f..67f9dfea05259610299d5838623b863f820fc87f 100644 (file)
@@ -276,8 +276,13 @@ typedef struct {
        sdb_object_t super;
        sdb_store_writer_t *w;
        sdb_object_t *ud;
        sdb_object_t super;
        sdb_store_writer_t *w;
        sdb_object_t *ud;
+       sdb_query_opts_t opts;
 } query_writer_t;
 } query_writer_t;
-#define QUERY_WRITER_INIT(w, ud) { SDB_OBJECT_INIT, (w), (ud) }
+#define QUERY_WRITER_INIT(w, ud) { \
+       SDB_OBJECT_INIT, \
+       (w), (ud), \
+       SDB_DEFAULT_QUERY_OPTS \
+}
 #define QUERY_WRITER(obj) ((query_writer_t *)(obj))
 
 static int
 #define QUERY_WRITER(obj) ((query_writer_t *)(obj))
 
 static int
@@ -305,8 +310,11 @@ query_store_metric(sdb_store_metric_t *metric, sdb_object_t *user_data)
        int status;
        size_t i;
 
        int status;
        size_t i;
 
+       if (! qw->opts.describe_timeseries)
+               /* nothing further to do */
+               return qw->w->store_metric(metric, qw->ud);
+
        for (i = 0; i < metric->stores_num; i++) {
        for (i = 0; i < metric->stores_num; i++) {
-               /* TODO: Make this optional using query options. */
                sdb_metric_store_t *s = stores + i;
                *s = metric->stores[i];
                infos[i] = sdb_plugin_describe_timeseries(s->type, s->id);
                sdb_metric_store_t *s = stores + i;
                *s = metric->stores[i];
                infos[i] = sdb_plugin_describe_timeseries(s->type, s->id);
@@ -875,7 +883,7 @@ get_interval(int obj_type, const char *hostname,
        fetch.name = n;
 
        status = sdb_plugin_query(SDB_AST_NODE(&fetch),
        fetch.name = n;
 
        status = sdb_plugin_query(SDB_AST_NODE(&fetch),
-                       &interval_fetcher, SDB_OBJ(&obj), NULL);
+                       &interval_fetcher, SDB_OBJ(&obj), NULL, NULL);
        if ((status < 0) || (lu.obj_type != obj_type) || (lu.last_update == 0)) {
                *interval_out = 0;
                return 0;
        if ((status < 0) || (lu.obj_type != obj_type) || (lu.last_update == 0)) {
                *interval_out = 0;
                return 0;
@@ -1649,7 +1657,8 @@ sdb_plugin_describe_timeseries(const char *type, const char *id)
 
 int
 sdb_plugin_query(sdb_ast_node_t *ast,
 
 int
 sdb_plugin_query(sdb_ast_node_t *ast,
-               sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf)
+               sdb_store_writer_t *w, sdb_object_t *wd,
+               sdb_query_opts_t *opts, sdb_strbuf_t *errbuf)
 {
        query_writer_t qw = QUERY_WRITER_INIT(w, wd);
        reader_t *reader;
 {
        query_writer_t qw = QUERY_WRITER_INIT(w, wd);
        reader_t *reader;
@@ -1661,6 +1670,9 @@ sdb_plugin_query(sdb_ast_node_t *ast,
        if (! ast)
                return 0;
 
        if (! ast)
                return 0;
 
+       if (opts)
+               qw.opts = *opts;
+
        if ((ast->type != SDB_AST_TYPE_FETCH)
                        && (ast->type != SDB_AST_TYPE_LIST)
                        && (ast->type != SDB_AST_TYPE_LOOKUP)) {
        if ((ast->type != SDB_AST_TYPE_FETCH)
                        && (ast->type != SDB_AST_TYPE_LIST)
                        && (ast->type != SDB_AST_TYPE_LOOKUP)) {
index 302c586a6c227de98b7e3ae035f58224a135a7de..af0aa5424eb7eee46af1fb5561dcb27170275f09 100644 (file)
@@ -136,7 +136,8 @@ exec_query(sdb_ast_node_t *ast, sdb_strbuf_t *buf, sdb_strbuf_t *errbuf)
 
        f = sdb_store_json_formatter(buf, type, flags);
        sdb_strbuf_memcpy(buf, &res_type, sizeof(res_type));
 
        f = sdb_store_json_formatter(buf, type, flags);
        sdb_strbuf_memcpy(buf, &res_type, sizeof(res_type));
-       status = sdb_plugin_query(ast, &sdb_store_json_writer, SDB_OBJ(f), errbuf);
+       status = sdb_plugin_query(ast, &sdb_store_json_writer, SDB_OBJ(f),
+                       &(sdb_query_opts_t){ true }, errbuf);
        if (status < 0)
                sdb_strbuf_clear(buf);
        sdb_store_json_finish(f);
        if (status < 0)
                sdb_strbuf_clear(buf);
        sdb_store_json_finish(f);
@@ -250,7 +251,8 @@ exec_timeseries(sdb_ast_timeseries_t *ts, sdb_strbuf_t *buf, sdb_strbuf_t *errbu
        opts.end = ts->end;
 
        status = sdb_plugin_query(SDB_AST_NODE(&fetch),
        opts.end = ts->end;
 
        status = sdb_plugin_query(SDB_AST_NODE(&fetch),
-                       &metric_fetcher, SDB_OBJ(&obj), errbuf);
+                       &metric_fetcher, SDB_OBJ(&obj),
+                       &(sdb_query_opts_t){ true }, errbuf);
        if ((status < 0) || (! st.type) || (! st.id)) {
                sdb_log(SDB_LOG_ERR, "frontend: Failed to fetch time-series '%s/%s' "
                                "- no data-store configured for the stored metric",
        if ((status < 0) || (! st.type) || (! st.id)) {
                sdb_log(SDB_LOG_ERR, "frontend: Failed to fetch time-series '%s/%s' "
                                "- no data-store configured for the stored metric",
index 6574330412417dee9de23b98715fc9ba4882eafe..5c299ddc13193ba0df9073d8b006dcaeab88b975 100644 (file)
@@ -448,10 +448,21 @@ sdb_plugin_fetch_timeseries(const char *type, const char *id,
 sdb_timeseries_info_t *
 sdb_plugin_describe_timeseries(const char *type, const char *id);
 
 sdb_timeseries_info_t *
 sdb_plugin_describe_timeseries(const char *type, const char *id);
 
+/*
+ * sdb_query_opts_t:
+ * Options for tuning the behavior of a query.
+ */
+typedef struct {
+       /* If enabled, populate the time-series info field of each metric. */
+       bool describe_timeseries;
+} sdb_query_opts_t;
+#define SDB_DEFAULT_QUERY_OPTS { false }
+
 /*
  * sdb_plugin_query:
  * Query the store using the query specified by 'ast'. The result will be
 /*
  * sdb_plugin_query:
  * Query the store using the query specified by 'ast'. The result will be
- * written to 'buf' and any errors will be written to 'errbuf'.
+ * written to 'buf' and any errors will be written to 'errbuf'. The query
+ * options default to SDB_DEFAULT_QUERY_OPTS.
  *
  * Returns:
  *  - 0 on success
  *
  * Returns:
  *  - 0 on success
@@ -459,7 +470,8 @@ sdb_plugin_describe_timeseries(const char *type, const char *id);
  */
 int
 sdb_plugin_query(sdb_ast_node_t *ast,
  */
 int
 sdb_plugin_query(sdb_ast_node_t *ast,
-               sdb_store_writer_t *w, sdb_object_t *wd, sdb_strbuf_t *errbuf);
+               sdb_store_writer_t *w, sdb_object_t *wd,
+               sdb_query_opts_t *opts, sdb_strbuf_t *errbuf);
 
 /*
  * sdb_plugin_store_host, sdb_plugin_store_service, sdb_plugin_store_metric,
 
 /*
  * sdb_plugin_store_host, sdb_plugin_store_service, sdb_plugin_store_metric,