summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55f6919)
raw | patch | inline | side by side (parent: 55f6919)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 11 Sep 2016 14:09:12 +0000 (10:09 -0400) | ||
committer | Sebastian 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.
passed in to sdb_plugin_query.
src/core/plugin.c | patch | blob | history | |
src/frontend/query.c | patch | blob | history | |
src/include/core/plugin.h | patch | blob | history |
diff --git a/src/core/plugin.c b/src/core/plugin.c
index ecd84b5f9c5f5f525017872ecdf54fe234a6267f..67f9dfea05259610299d5838623b863f820fc87f 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
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
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);
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;
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;
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 302c586a6c227de98b7e3ae035f58224a135a7de..af0aa5424eb7eee46af1fb5561dcb27170275f09 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
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",
index 6574330412417dee9de23b98715fc9ba4882eafe..5c299ddc13193ba0df9073d8b006dcaeab88b975 100644 (file)
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
*/
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,