From: Sebastian Harl Date: Sun, 11 Sep 2016 14:09:12 +0000 (-0400) Subject: Don't fetch timeseries info when fetching the interval. X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=daf9e92a1a3bf86a5cdbb2f3cc7d9c37f050174d Don't fetch timeseries info when fetching the interval. For this purpose, add query options to fine-tune the behavior. These are passed in to sdb_plugin_query. --- diff --git a/src/core/plugin.c b/src/core/plugin.c index ecd84b5..67f9dfe 100644 --- a/src/core/plugin.c +++ b/src/core/plugin.c @@ -276,8 +276,13 @@ typedef struct { sdb_object_t super; sdb_store_writer_t *w; sdb_object_t *ud; + sdb_query_opts_t opts; } 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 @@ -305,8 +310,11 @@ query_store_metric(sdb_store_metric_t *metric, sdb_object_t *user_data) 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++) { - /* 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); @@ -875,7 +883,7 @@ get_interval(int obj_type, const char *hostname, 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; @@ -1649,7 +1657,8 @@ sdb_plugin_describe_timeseries(const char *type, const char *id) 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; @@ -1661,6 +1670,9 @@ sdb_plugin_query(sdb_ast_node_t *ast, 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)) { diff --git a/src/frontend/query.c b/src/frontend/query.c index 302c586..af0aa54 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -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)); - 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); @@ -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), - &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", diff --git a/src/include/core/plugin.h b/src/include/core/plugin.h index 6574330..5c299dd 100644 --- a/src/include/core/plugin.h +++ b/src/include/core/plugin.h @@ -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_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 - * 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 @@ -459,7 +470,8 @@ sdb_plugin_describe_timeseries(const char *type, const char *id); */ 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,