From 9345a64b2fa015c30d6b3fcba76211f8d0d7cfd6 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 22 May 2015 00:47:24 +0200 Subject: [PATCH] Replaced sdb_store_ with sdb_plugin_store_. That is, all store updates will now directly go through the plugin API and be distributed to all store-writer plugins from there. --- src/core/store.c | 44 ------ src/core/store_exec.c | 13 +- src/include/core/store.h | 169 +++++++-------------- src/plugins/backend/collectd/unixsock.c | 14 +- src/plugins/backend/facter.cc | 4 +- src/plugins/backend/mk-livestatus.c | 4 +- src/plugins/backend/puppet/store-configs.c | 4 +- t/integration/mock_plugin.c | 8 +- t/unit/core/store_expr_test.c | 13 +- t/unit/core/store_json_test.c | 37 +++-- t/unit/core/store_lookup_test.c | 17 ++- t/unit/core/store_test.c | 141 +++++++++-------- t/unit/frontend/query_test.c | 30 ++-- 13 files changed, 204 insertions(+), 294 deletions(-) diff --git a/src/core/store.c b/src/core/store.c index 1396669..22e965f 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -858,50 +858,6 @@ sdb_store_clear(void) sdb_avltree_clear(global_store->hosts); } /* sdb_store_clear */ -int -sdb_store_host(const char *name, sdb_time_t last_update) -{ - return sdb_plugin_store_host(name, last_update); -} /* sdb_store_host */ - -int -sdb_store_attribute(const char *hostname, - const char *key, const sdb_data_t *value, - sdb_time_t last_update) -{ - return sdb_plugin_store_attribute(hostname, key, value, last_update); -} /* sdb_store_attribute */ - -int -sdb_store_service(const char *hostname, const char *name, - sdb_time_t last_update) -{ - return sdb_plugin_store_service(hostname, name, last_update); -} /* sdb_store_service */ - -int -sdb_store_service_attr(const char *hostname, const char *service, - const char *key, const sdb_data_t *value, sdb_time_t last_update) -{ - return sdb_plugin_store_service_attribute(hostname, service, - key, value, last_update); -} /* sdb_store_service_attr */ - -int -sdb_store_metric(const char *hostname, const char *name, - sdb_metric_store_t *store, sdb_time_t last_update) -{ - return sdb_plugin_store_metric(hostname, name, store, last_update); -} /* sdb_store_metric */ - -int -sdb_store_metric_attr(const char *hostname, const char *metric, - const char *key, const sdb_data_t *value, sdb_time_t last_update) -{ - return sdb_plugin_store_metric_attribute(hostname, metric, - key, value, last_update); -} /* sdb_store_metric_attr */ - bool sdb_store_has_host(const char *name) { diff --git a/src/core/store_exec.c b/src/core/store_exec.c index 6c68dc5..436b36e 100644 --- a/src/core/store_exec.c +++ b/src/core/store_exec.c @@ -26,6 +26,7 @@ */ #include "core/object.h" +#include "core/plugin.h" #include "core/store-private.h" #include "frontend/connection.h" #include "parser/ast.h" @@ -227,19 +228,19 @@ exec_store(sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, sdb_ast_store_t *st) switch (st->obj_type) { case SDB_HOST: strncpy(name, st->name, sizeof(name)); - status = sdb_store_host(st->name, st->last_update); + status = sdb_plugin_store_host(st->name, st->last_update); break; case SDB_SERVICE: snprintf(name, sizeof(name), "%s.%s", st->hostname, st->name); - status = sdb_store_service(st->hostname, st->name, st->last_update); + status = sdb_plugin_store_service(st->hostname, st->name, st->last_update); break; case SDB_METRIC: snprintf(name, sizeof(name), "%s.%s", st->hostname, st->name); metric_store.type = st->store_type; metric_store.id = st->store_id; - status = sdb_store_metric(st->hostname, st->name, + status = sdb_plugin_store_metric(st->hostname, st->name, &metric_store, st->last_update); break; @@ -255,17 +256,17 @@ exec_store(sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, sdb_ast_store_t *st) switch (st->parent_type) { case 0: type |= SDB_HOST; - status = sdb_store_attribute(st->hostname, + status = sdb_plugin_store_attribute(st->hostname, st->name, &st->value, st->last_update); break; case SDB_SERVICE: - status = sdb_store_service_attr(st->hostname, st->parent, + status = sdb_plugin_store_service_attribute(st->hostname, st->parent, st->name, &st->value, st->last_update); break; case SDB_METRIC: - status = sdb_store_metric_attr(st->hostname, st->parent, + status = sdb_plugin_store_metric_attribute(st->hostname, st->parent, st->name, &st->value, st->last_update); break; diff --git a/src/include/core/store.h b/src/include/core/store.h index 4a0960c..15f435f 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -150,21 +150,77 @@ typedef struct sdb_store_json_formatter sdb_store_json_formatter_t; /* * A store writer describes the interface for plugins implementing a store. + * + * Any of the call-back functions shall return: + * - 0 on success + * - a positive value if the new entry is older than the currently stored + * entry (in this case, no update will happen) + * - a negative value on error */ typedef struct { + /* + * store_host: + * Add/update a host in the store. If the host, identified by its + * canonicalized name, already exists, it will be updated according to the + * specified name and timestamp. Else, a new entry will be created in the + * store. + */ int (*store_host)(const char *name, sdb_time_t last_update, sdb_object_t *user_data); + + /* + * store_service: + * Add/update a service in the store. If the service, identified by its + * name, already exists for the specified host, it will be updated + * according to the specified name and timestamp. If the referenced host + * does not exist, an error will be reported. Else, a new entry will be + * created in the store. + */ int (*store_service)(const char *hostname, const char *name, sdb_time_t last_update, sdb_object_t *user_data); + + /* + * store_metric: + * Add/update a metric in the store. If the metric, identified by its + * name, already exists for the specified host, it will be updated + * according to the specified attributes. If the referenced host does not + * exist, an error will be reported. Else, a new entry will be created in + * the store. + */ int (*store_metric)(const char *hostname, const char *name, sdb_metric_store_t *store, sdb_time_t last_update, sdb_object_t *user_data); + + /* + * store_attribute: + * Add/update a host's attribute in the store. If the attribute, + * identified by its key, already exists for the specified host, it will + * be updated to the specified values. If the referenced host does not + * exist, an error will be reported. Else, a new entry will be created in + * the store. + */ int (*store_attribute)(const char *hostname, const char *key, const sdb_data_t *value, sdb_time_t last_update, sdb_object_t *user_data); + + /* + * store_service_attr: + * Add/update a service's attribute in the store. If the attribute, + * identified by its key, already exists for the specified service, it + * will be updated to the specified value. If the references service (for + * the specified host) does not exist, an error will be reported. + */ int (*store_service_attr)(const char *hostname, const char *service, const char *key, const sdb_data_t *value, sdb_time_t last_update, sdb_object_t *user_data); + + /* + * store_metric_attr: + * Add/update a metric's attribute in the store. If the attribute, + * identified by its key, already exists for the specified metric, it will + * be updated to the specified value. If the references metric (for the + * specified host) does not exist, an error will be reported. + */ int (*store_metric_attr)(const char *hostname, const char *metric, const char *key, const sdb_data_t *value, sdb_time_t last_update, sdb_object_t *user_data); @@ -189,23 +245,6 @@ sdb_store_init(void); void sdb_store_clear(void); -/* - * sdb_store_host: - * Add/update a host in the store. If the host, identified by its - * canonicalized name, already exists, it will be updated according to the - * specified name and timestamp. Else, a new entry will be created in the - * store. Any memory required for storing the entry will be allocated an - * managed by the store itself. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_host(const char *name, sdb_time_t last_update); - /* * sdb_store_has_host: * sdb_store_get_host: @@ -220,102 +259,6 @@ sdb_store_has_host(const char *name); sdb_store_obj_t * sdb_store_get_host(const char *name); -/* - * sdb_store_attribute: - * Add/update a host's attribute in the store. If the attribute, identified by - * its key, already exists for the specified host, it will be updated to the - * specified values. If the referenced host does not exist, an error will be - * reported. Else, a new entry will be created in the store. Any memory - * required for storing the entry will be allocated and managed by the store - * itself. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_attribute(const char *hostname, - const char *key, const sdb_data_t *value, - sdb_time_t last_update); - -/* - * sdb_store_service: - * Add/update a service in the store. If the service, identified by its name, - * already exists for the specified host, it will be updated according to the - * specified 'service' object. If the referenced host does not exist, an error - * will be reported. Else, a new entry will be created in the store. Any - * memory required for storing the entry will be allocated an managed by the - * store itself. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_service(const char *hostname, const char *name, - sdb_time_t last_update); - -/* - * sdb_store_service_attr: - * Add/update a service's attribute in the store. If the attribute, identified - * by its key, already exists for the specified service, it will be updated to - * the specified value. If the references service (for the specified host) - * does not exist, an error will be reported. Any memory required for storing - * the entry will be allocated and managed by the store itself. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_service_attr(const char *hostname, const char *service, - const char *key, const sdb_data_t *value, sdb_time_t last_update); - -/* - * sdb_store_metric: - * Add/update a metric in the store. If the metric, identified by its name, - * already exists for the specified host, it will be updated according to the - * specified 'metric' object. If the referenced host does not exist, an error - * will be reported. Else, a new entry will be created in the store. Any - * memory required for storing the entry will be allocated an managed by the - * store itself. - * - * If specified, the metric store describes where to access the metric's data. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_metric(const char *hostname, const char *name, - sdb_metric_store_t *store, sdb_time_t last_update); - -/* - * sdb_store_metric_attr: - * Add/update a metric's attribute in the store. If the attribute, identified - * by its key, already exists for the specified metric, it will be updated to - * the specified value. If the references metric (for the specified host) - * does not exist, an error will be reported. Any memory required for storing - * the entry will be allocated and managed by the store itself. - * - * Returns: - * - 0 on success - * - a positive value if the new entry is older than the currently stored - * entry (in this case, no update will happen) - * - a negative value on error - */ -int -sdb_store_metric_attr(const char *hostname, const char *metric, - const char *key, const sdb_data_t *value, sdb_time_t last_update); - /* * sdb_store_fetch_timeseries: * Fetch the time-series described by the specified host's metric and diff --git a/src/plugins/backend/collectd/unixsock.c b/src/plugins/backend/collectd/unixsock.c index 8af5327..65b0584 100644 --- a/src/plugins/backend/collectd/unixsock.c +++ b/src/plugins/backend/collectd/unixsock.c @@ -125,7 +125,7 @@ store_host(state_t *state, const char *hostname, sdb_time_t last_update) return -1; } - status = sdb_store_host(hostname, last_update); + status = sdb_plugin_store_host(hostname, last_update); if (status < 0) { sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to " @@ -161,10 +161,10 @@ add_metrics(const char *hostname, char *plugin, char *type, if (ud->ts_base) { snprintf(metric_id, sizeof(metric_id), "%s/%s/%s.rrd", ud->ts_base, hostname, name); - status = sdb_store_metric(hostname, name, &store, last_update); + status = sdb_plugin_store_metric(hostname, name, &store, last_update); } else - status = sdb_store_metric(hostname, name, NULL, last_update); + status = sdb_plugin_store_metric(hostname, name, NULL, last_update); if (status < 0) { sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to " "store/update metric '%s/%s'.", hostname, name); @@ -177,7 +177,7 @@ add_metrics(const char *hostname, char *plugin, char *type, ++plugin_instance; data.data.string = plugin_instance; - sdb_store_metric_attr(hostname, name, + sdb_plugin_store_metric_attribute(hostname, name, "plugin_instance", &data, last_update); } @@ -187,14 +187,14 @@ add_metrics(const char *hostname, char *plugin, char *type, ++type_instance; data.data.string = type_instance; - sdb_store_metric_attr(hostname, name, + sdb_plugin_store_metric_attribute(hostname, name, "type_instance", &data, last_update); } data.data.string = plugin; - sdb_store_metric_attr(hostname, name, "plugin", &data, last_update); + sdb_plugin_store_metric_attribute(hostname, name, "plugin", &data, last_update); data.data.string = type; - sdb_store_metric_attr(hostname, name, "type", &data, last_update); + sdb_plugin_store_metric_attribute(hostname, name, "type", &data, last_update); return 0; } /* add_metrics */ diff --git a/src/plugins/backend/facter.cc b/src/plugins/backend/facter.cc index 98f7f57..e556186 100644 --- a/src/plugins/backend/facter.cc +++ b/src/plugins/backend/facter.cc @@ -57,7 +57,7 @@ fact_iter(std::string const &k, facter::facts::value const *v) return true; sdb_data_t value = { SDB_TYPE_STRING, { .string = str } }; - sdb_store_attribute(hostname, k.c_str(), &value, now); + sdb_plugin_store_attribute(hostname, k.c_str(), &value, now); return true; } /* fact_iter */ @@ -83,7 +83,7 @@ extern "C" { std::string s = ss.str(); hostname = s.c_str(); - sdb_store_host(hostname, now); + sdb_plugin_store_host(hostname, now); facts.each(fact_iter); sdb_log(SDB_LOG_DEBUG, "facter backend: Processed %zu facts " "for host '%s'", facts.size(), hostname); diff --git a/src/plugins/backend/mk-livestatus.c b/src/plugins/backend/mk-livestatus.c index 7d9e320..d1126db 100644 --- a/src/plugins/backend/mk-livestatus.c +++ b/src/plugins/backend/mk-livestatus.c @@ -68,7 +68,7 @@ sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client, hostname = data[0].data.string; timestamp = data[1].data.datetime; - status = sdb_store_host(hostname, timestamp); + status = sdb_plugin_store_host(hostname, timestamp); if (status < 0) { sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to " @@ -104,7 +104,7 @@ sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client, svcname = data[1].data.string; timestamp = data[2].data.datetime; - status = sdb_store_service(hostname, svcname, timestamp); + status = sdb_plugin_store_service(hostname, svcname, timestamp); if (status < 0) { sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to " diff --git a/src/plugins/backend/puppet/store-configs.c b/src/plugins/backend/puppet/store-configs.c index 95dd549..800e81b 100644 --- a/src/plugins/backend/puppet/store-configs.c +++ b/src/plugins/backend/puppet/store-configs.c @@ -62,7 +62,7 @@ sdb_puppet_stcfg_get_hosts(sdb_dbi_client_t __attribute__((unused)) *client, hostname = data[0].data.string; timestamp = data[1].data.datetime; - status = sdb_store_host(hostname, timestamp); + status = sdb_plugin_store_host(hostname, timestamp); if (status < 0) { sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to " @@ -100,7 +100,7 @@ sdb_puppet_stcfg_get_attrs(sdb_dbi_client_t __attribute__((unused)) *client, value.data.string = data[2].data.string; last_update = data[3].data.datetime; - status = sdb_store_attribute(hostname, key, &value, last_update); + status = sdb_plugin_store_attribute(hostname, key, &value, last_update); if (status < 0) { sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to " diff --git a/t/integration/mock_plugin.c b/t/integration/mock_plugin.c index 5a9718d..87c86a8 100644 --- a/t/integration/mock_plugin.c +++ b/t/integration/mock_plugin.c @@ -153,14 +153,14 @@ mock_collect(sdb_object_t *user_data) } for (i = 0; i < SDB_STATIC_ARRAY_LEN(hostnames); ++i) { - if ((check = sdb_store_host(hostnames[i], sdb_gettime()))) { + if ((check = sdb_plugin_store_host(hostnames[i], sdb_gettime()))) { sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store host: " "status %d", check); exit(1); } } for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) { - if ((check = sdb_store_metric(metrics[i].hostname, + if ((check = sdb_plugin_store_metric(metrics[i].hostname, metrics[i].metric, &metrics[i].store, sdb_gettime()))) { sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store metric: " @@ -169,7 +169,7 @@ mock_collect(sdb_object_t *user_data) } } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { - if ((check = sdb_store_service(services[i].hostname, + if ((check = sdb_plugin_store_service(services[i].hostname, services[i].service, sdb_gettime()))) { sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store service: " "status %d", check); @@ -180,7 +180,7 @@ mock_collect(sdb_object_t *user_data) sdb_data_t datum = { SDB_TYPE_STRING, { .string = NULL } }; datum.data.string = strdup(attributes[i].value); - if ((check = sdb_store_attribute(attributes[i].hostname, + if ((check = sdb_plugin_store_attribute(attributes[i].hostname, attributes[i].name, &datum, sdb_gettime()))) { sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store attribute: " "status %d", check); diff --git a/t/unit/core/store_expr_test.c b/t/unit/core/store_expr_test.c index b15809a..153e52f 100644 --- a/t/unit/core/store_expr_test.c +++ b/t/unit/core/store_expr_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "core/store-private.h" #include "parser/parser.h" @@ -95,37 +96,37 @@ populate(void) sdb_store_init(); for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) { - int status = sdb_store_host(hosts[i], 1); + int status = sdb_plugin_store_host(hosts[i], 1); ck_assert(status == 0); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) { - int status = sdb_store_metric(metrics[i].host, + int status = sdb_plugin_store_metric(metrics[i].host, metrics[i].metric, /* store */ NULL, 1); ck_assert(status == 0); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { - int status = sdb_store_service(services[i].host, + int status = sdb_plugin_store_service(services[i].host, services[i].service, 1); ck_assert(status == 0); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) { - int status = sdb_store_attribute(attrs[i].host, + int status = sdb_plugin_store_attribute(attrs[i].host, attrs[i].name, &attrs[i].value, 1); ck_assert(status == 0); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(svc_attrs); ++i) { - int status = sdb_store_service_attr(svc_attrs[i].host, + int status = sdb_plugin_store_service_attribute(svc_attrs[i].host, svc_attrs[i].service, svc_attrs[i].name, &svc_attrs[i].value, 1); ck_assert(status == 0); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(metric_attrs); ++i) { - int status = sdb_store_metric_attr(metric_attrs[i].host, + int status = sdb_plugin_store_metric_attribute(metric_attrs[i].host, metric_attrs[i].metric, metric_attrs[i].name, &metric_attrs[i].value, 1); ck_assert(status == 0); diff --git a/t/unit/core/store_json_test.c b/t/unit/core/store_json_test.c index ebb2daf..baecf80 100644 --- a/t/unit/core/store_json_test.c +++ b/t/unit/core/store_json_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "testutils.h" @@ -46,41 +47,45 @@ populate(void) sdb_store_init(); - sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND); - sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND); + sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_STRING; datum.data.string = "v1"; - sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); datum.data.string = "v2"; - sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); datum.data.string = "v3"; - sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); /* make sure that older updates don't overwrite existing values */ datum.data.string = "fail"; - sdb_store_attribute("h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND); - sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); - sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_INTEGER; datum.data.integer = 42; - sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric_attribute("h1", "m1", "k3", + &datum, 2 * SDB_INTERVAL_SECOND); datum.data.integer = 123; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k1", + &datum, 2 * SDB_INTERVAL_SECOND); datum.data.integer = 4711; - sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k2", + &datum, 1 * SDB_INTERVAL_SECOND); /* don't overwrite k1 */ datum.data.integer = 666; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k1", + &datum, 2 * SDB_INTERVAL_SECOND); } /* populate */ static int diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 913e6b7..49f2268 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "core/store-private.h" #include "parser/parser.h" @@ -76,33 +77,33 @@ populate(void) sdb_store_init(); for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) { - int status = sdb_store_host(hosts[i], 1); + int status = sdb_plugin_store_host(hosts[i], 1); fail_unless(status == 0, - "sdb_store_host(%s, 1) = %d; expected: 0", + "sdb_plugin_store_host(%s, 1) = %d; expected: 0", hosts[i], status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) { - int status = sdb_store_metric(metrics[i].host, + int status = sdb_plugin_store_metric(metrics[i].host, metrics[i].metric, /* store */ NULL, 1); fail_unless(status == 0, - "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0", + "sdb_plugin_store_metric(%s, %s, NULL, 1) = %d; expected: 0", metrics[i].host, metrics[i].metric, status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) { - int status = sdb_store_service(services[i].host, + int status = sdb_plugin_store_service(services[i].host, services[i].service, 1); fail_unless(status == 0, - "sdb_store_service(%s, %s, 1) = %d; expected: 0", + "sdb_plugin_store_service(%s, %s, 1) = %d; expected: 0", services[i].host, services[i].service, status); } for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) { - int status = sdb_store_attribute(attrs[i].host, + int status = sdb_plugin_store_attribute(attrs[i].host, attrs[i].name, &attrs[i].value, 1); fail_unless(status == 0, - "sdb_store_attribute(%s, %s, , 1) = %d; expected: 0", + "sdb_plugin_store_attribute(%s, %s, , 1) = %d; expected: 0", attrs[i].host, attrs[i].name, status); } } /* populate */ diff --git a/t/unit/core/store_test.c b/t/unit/core/store_test.c index 8308f33..ed6f5d9 100644 --- a/t/unit/core/store_test.c +++ b/t/unit/core/store_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "core/store.h" #include "core/store-private.h" #include "testutils.h" @@ -48,43 +49,41 @@ populate(void) { sdb_data_t datum; - sdb_store_init(); - - sdb_store_host("h1", 1); - sdb_store_host("h2", 3); + sdb_plugin_store_host("h1", 1); + sdb_plugin_store_host("h2", 3); datum.type = SDB_TYPE_STRING; datum.data.string = "v1"; - sdb_store_attribute("h1", "k1", &datum, 1); + sdb_plugin_store_attribute("h1", "k1", &datum, 1); datum.data.string = "v2"; - sdb_store_attribute("h1", "k2", &datum, 2); + sdb_plugin_store_attribute("h1", "k2", &datum, 2); datum.data.string = "v3"; - sdb_store_attribute("h1", "k3", &datum, 2); + sdb_plugin_store_attribute("h1", "k3", &datum, 2); /* make sure that older updates don't overwrite existing values */ datum.data.string = "fail"; - sdb_store_attribute("h1", "k2", &datum, 1); - sdb_store_attribute("h1", "k3", &datum, 2); + sdb_plugin_store_attribute("h1", "k2", &datum, 1); + sdb_plugin_store_attribute("h1", "k3", &datum, 2); - sdb_store_metric("h1", "m1", /* store */ NULL, 2); - sdb_store_metric("h1", "m2", /* store */ NULL, 1); - sdb_store_metric("h2", "m1", /* store */ NULL, 1); + sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2); + sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1); + sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1); - sdb_store_service("h2", "s1", 1); - sdb_store_service("h2", "s2", 2); + sdb_plugin_store_service("h2", "s1", 1); + sdb_plugin_store_service("h2", "s2", 2); datum.type = SDB_TYPE_INTEGER; datum.data.integer = 42; - sdb_store_metric_attr("h1", "m1", "k3", &datum, 2); + sdb_plugin_store_metric_attribute("h1", "m1", "k3", &datum, 2); datum.data.integer = 123; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2); + sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2); datum.data.integer = 4711; - sdb_store_service_attr("h2", "s2", "k2", &datum, 1); + sdb_plugin_store_service_attribute("h2", "s2", "k2", &datum, 1); /* don't overwrite k1 */ datum.data.integer = 666; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2); + sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2); } /* populate */ START_TEST(test_store_host) @@ -118,10 +117,10 @@ START_TEST(test_store_host) for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { int status; - status = sdb_store_host(golden_data[i].name, + status = sdb_plugin_store_host(golden_data[i].name, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_host(%s, %d) = %d; expected: %d", + "sdb_plugin_store_host(%s, %d) = %d; expected: %d", golden_data[i].name, (int)golden_data[i].last_update, status, golden_data[i].expected); } @@ -144,9 +143,9 @@ START_TEST(test_store_get_host) size_t i; for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) { - int status = sdb_store_host(golden_hosts[i], 1); + int status = sdb_plugin_store_host(golden_hosts[i], 1); fail_unless(status >= 0, - "sdb_store_host(%s) = %d; expected: >=0", + "sdb_plugin_store_host(%s) = %d; expected: >=0", golden_hosts[i], status); } @@ -219,8 +218,8 @@ START_TEST(test_store_attr) size_t i; - sdb_store_host("l", 1); - sdb_store_host("m", 1); + sdb_plugin_store_host("l", 1); + sdb_plugin_store_host("m", 1); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { sdb_data_t datum; int status; @@ -229,11 +228,11 @@ START_TEST(test_store_attr) datum.type = SDB_TYPE_STRING; datum.data.string = golden_data[i].value; - status = sdb_store_attribute(golden_data[i].host, + status = sdb_plugin_store_attribute(golden_data[i].host, golden_data[i].key, &datum, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d", + "sdb_plugin_store_attribute(%s, %s, %s, %d) = %d; expected: %d", golden_data[i].host, golden_data[i].key, golden_data[i].value, golden_data[i].last_update, status, golden_data[i].expected); } @@ -272,16 +271,16 @@ START_TEST(test_store_metric) size_t i; - sdb_store_host("m", 1); - sdb_store_host("l", 1); + sdb_plugin_store_host("m", 1); + sdb_plugin_store_host("l", 1); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { int status; - status = sdb_store_metric(golden_data[i].host, + status = sdb_plugin_store_metric(golden_data[i].host, golden_data[i].metric, golden_data[i].store, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_metric(%s, %s, %p, %d) = %d; expected: %d", + "sdb_plugin_store_metric(%s, %s, %p, %d) = %d; expected: %d", golden_data[i].host, golden_data[i].metric, golden_data[i].store, golden_data[i].last_update, status, golden_data[i].expected); @@ -316,20 +315,20 @@ START_TEST(test_store_metric_attr) size_t i; - sdb_store_host("m", 1); - sdb_store_host("l", 1); - sdb_store_metric("m", "m1", NULL, 1); - sdb_store_metric("l", "m1", NULL, 1); - sdb_store_metric("l", "m2", NULL, 1); + sdb_plugin_store_host("m", 1); + sdb_plugin_store_host("l", 1); + sdb_plugin_store_metric("m", "m1", NULL, 1); + sdb_plugin_store_metric("l", "m1", NULL, 1); + sdb_plugin_store_metric("l", "m2", NULL, 1); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { int status; - status = sdb_store_metric_attr(golden_data[i].host, + status = sdb_plugin_store_metric_attribute(golden_data[i].host, golden_data[i].metric, golden_data[i].attr, &golden_data[i].value, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_metric_attr(%s, %s, %s, %d, %d) = %d; " + "sdb_plugin_store_metric_attribute(%s, %s, %s, %d, %d) = %d; " "expected: %d", golden_data[i].host, golden_data[i].metric, golden_data[i].attr, golden_data[i].value.data.integer, golden_data[i].last_update, status, golden_data[i].expected); @@ -357,15 +356,15 @@ START_TEST(test_store_service) size_t i; - sdb_store_host("m", 1); - sdb_store_host("l", 1); + sdb_plugin_store_host("m", 1); + sdb_plugin_store_host("l", 1); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { int status; - status = sdb_store_service(golden_data[i].host, + status = sdb_plugin_store_service(golden_data[i].host, golden_data[i].svc, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_service(%s, %s, %d) = %d; expected: %d", + "sdb_plugin_store_service(%s, %s, %d) = %d; expected: %d", golden_data[i].host, golden_data[i].svc, golden_data[i].last_update, status, golden_data[i].expected); } @@ -399,20 +398,20 @@ START_TEST(test_store_service_attr) size_t i; - sdb_store_host("m", 1); - sdb_store_host("l", 1); - sdb_store_service("m", "s1", 1); - sdb_store_service("l", "s1", 1); - sdb_store_service("l", "s2", 1); + sdb_plugin_store_host("m", 1); + sdb_plugin_store_host("l", 1); + sdb_plugin_store_service("m", "s1", 1); + sdb_plugin_store_service("l", "s1", 1); + sdb_plugin_store_service("l", "s2", 1); for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) { int status; - status = sdb_store_service_attr(golden_data[i].host, + status = sdb_plugin_store_service_attribute(golden_data[i].host, golden_data[i].svc, golden_data[i].attr, &golden_data[i].value, golden_data[i].last_update); fail_unless(status == golden_data[i].expected, - "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; " + "sdb_plugin_store_service_attribute(%s, %s, %s, %d, %d) = %d; " "expected: %d", golden_data[i].host, golden_data[i].svc, golden_data[i].attr, golden_data[i].value.data.integer, golden_data[i].last_update, status, golden_data[i].expected); @@ -474,10 +473,10 @@ START_TEST(test_get_field) sdb_time_t now = sdb_gettime(); int check; - sdb_store_host("host", 10); - sdb_store_host("host", 20); - sdb_store_attribute("host", "attr", &get_field_data[_i].value, 10); - sdb_store_attribute("host", "attr", &get_field_data[_i].value, 20); + sdb_plugin_store_host("host", 10); + sdb_plugin_store_host("host", 20); + sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 10); + sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 20); if (get_field_data[_i].hostname) { obj = sdb_store_get_host(get_field_data[_i].hostname); @@ -631,51 +630,51 @@ START_TEST(test_interval) sdb_store_obj_t *host; /* 10 us interval */ - sdb_store_host("host", 10); - sdb_store_host("host", 20); - sdb_store_host("host", 30); - sdb_store_host("host", 40); + sdb_plugin_store_host("host", 10); + sdb_plugin_store_host("host", 20); + sdb_plugin_store_host("host", 30); + sdb_plugin_store_host("host", 40); host = sdb_store_get_host("host"); fail_unless(host != NULL, "INTERNAL ERROR: store doesn't have host after adding it"); fail_unless(host->interval == 10, - "sdb_store_host() did not calculate interval correctly: " + "sdb_plugin_store_host() did not calculate interval correctly: " "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10); /* multiple updates for the same timestamp don't modify the interval */ - sdb_store_host("host", 40); - sdb_store_host("host", 40); - sdb_store_host("host", 40); - sdb_store_host("host", 40); + sdb_plugin_store_host("host", 40); + sdb_plugin_store_host("host", 40); + sdb_plugin_store_host("host", 40); + sdb_plugin_store_host("host", 40); fail_unless(host->interval == 10, - "sdb_store_host() changed interval when doing multiple updates " + "sdb_plugin_store_host() changed interval when doing multiple updates " "using the same timestamp; got: %"PRIsdbTIME"; " "expected: %"PRIsdbTIME, host->interval, 10); /* multiple updates using an timestamp don't modify the interval */ - sdb_store_host("host", 20); - sdb_store_host("host", 20); - sdb_store_host("host", 20); - sdb_store_host("host", 20); + sdb_plugin_store_host("host", 20); + sdb_plugin_store_host("host", 20); + sdb_plugin_store_host("host", 20); + sdb_plugin_store_host("host", 20); fail_unless(host->interval == 10, - "sdb_store_host() changed interval when doing multiple updates " + "sdb_plugin_store_host() changed interval when doing multiple updates " "using an old timestamp; got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10); /* new interval: 20 us */ - sdb_store_host("host", 60); + sdb_plugin_store_host("host", 60); fail_unless(host->interval == 11, - "sdb_store_host() did not calculate interval correctly: " + "sdb_plugin_store_host() did not calculate interval correctly: " "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11); /* new interval: 40 us */ - sdb_store_host("host", 100); + sdb_plugin_store_host("host", 100); fail_unless(host->interval == 13, - "sdb_store_host() did not calculate interval correctly: " + "sdb_plugin_store_host() did not calculate interval correctly: " "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11); sdb_object_deref(SDB_OBJ(host)); diff --git a/t/unit/frontend/query_test.c b/t/unit/frontend/query_test.c index d7e5b30..7fb73a4 100644 --- a/t/unit/frontend/query_test.c +++ b/t/unit/frontend/query_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "frontend/connection.h" #include "frontend/connection-private.h" #include "testutils.h" @@ -46,32 +47,35 @@ populate(void) sdb_store_init(); - sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND); - sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND); + sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_STRING; datum.data.string = "v1"; - sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); datum.data.string = "v2"; - sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); datum.data.string = "v3"; - sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); - sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_INTEGER; datum.data.integer = 42; - sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric_attribute("h1", "m1", "k3", + &datum, 2 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); datum.data.integer = 123; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k1", + &datum, 2 * SDB_INTERVAL_SECOND); datum.data.integer = 4711; - sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k2", + &datum, 1 * SDB_INTERVAL_SECOND); } /* populate */ #define HOST_H1 \ -- 2.30.2