X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Ffrontend%2Fquery.c;h=2a1954abc9a87ebc966dff97e1af47244f76645a;hp=3f33a9914b7bfd342727f73e4ae74134ef9c1b11;hb=HEAD;hpb=5f7e0ee1cf668eaaec097d8f2fa0753b0c089946 diff --git a/src/frontend/query.c b/src/frontend/query.c index 3f33a99..2a1954a 100644 --- a/src/frontend/query.c +++ b/src/frontend/query.c @@ -65,15 +65,23 @@ static int metric_fetcher_metric(sdb_store_metric_t *metric, sdb_object_t *user_data) { metric_store_t *st = SDB_OBJ_WRAPPER(user_data)->data; + sdb_time_t last_update = 0; + size_t idx = 0, i; - if ((! metric->store.type) || (! metric->store.id)) - return 0; - - st->type = strdup(metric->store.type); - st->id = strdup(metric->store.id); - st->last_update = metric->store.last_update; - if ((! st->type) || (! st->id)) + if (! metric->stores_num) return -1; + + /* Find the most up to date data store. + * TODO: Consider merging multiple results? */ + for (i = 0; i < metric->stores_num; ++i) { + if (metric->stores[i].last_update > last_update) { + last_update = metric->stores[i].last_update; + idx = i; + } + } + st->type = strdup(metric->stores[idx].type); + st->id = strdup(metric->stores[idx].id); + st->last_update = metric->stores[idx].last_update; return 0; } /* metric_fetcher_metric */ @@ -128,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); @@ -228,7 +237,7 @@ exec_timeseries(sdb_ast_timeseries_t *ts, sdb_strbuf_t *buf, sdb_strbuf_t *errbu metric_store_t st = { NULL, NULL, 0 }; sdb_object_wrapper_t obj = SDB_OBJECT_WRAPPER_STATIC(&st); sdb_ast_fetch_t fetch = SDB_AST_FETCH_INIT; - sdb_timeseries_opts_t opts = { 0, 0 }; + sdb_timeseries_opts_t opts = { 0, 0, NULL, 0 }; sdb_timeseries_t *series = NULL; int status; @@ -238,11 +247,14 @@ exec_timeseries(sdb_ast_timeseries_t *ts, sdb_strbuf_t *buf, sdb_strbuf_t *errbu fetch.obj_type = SDB_METRIC; fetch.hostname = strdup(ts->hostname); fetch.name = strdup(ts->metric); + opts.data_names = (const char * const *)ts->data_names; + opts.data_names_len = ts->data_names_len; opts.start = ts->start; 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",