From: Florian Forster Date: Wed, 11 Aug 2010 13:45:01 +0000 (+0200) Subject: src/utils_db_query.[ch]: Remove legacy code. X-Git-Tag: collectd-5.0.0-beta0~51 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=97a1b92446be5e0ebb68d25ec8b94743f2ac12fb src/utils_db_query.[ch]: Remove legacy code. The "legacy mode" supported an old configuration schema of the PostgreSQL plugin. This commit removes it, so only the recommended configuration remains possible. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 01f0f824..936088eb 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3225,11 +3225,6 @@ allowed as long as a single non-empty command has been specified only. The returned lines will be handled separately one after another. -=item B I - -This is a deprecated synonym for B. It will be removed in version 5 -of collectd. - =item B I|I|I|I Specify the parameters which should be passed to the SQL query. The parameters @@ -3305,21 +3300,6 @@ This option is required inside a B block and may be specified multiple times. If multiple B options are specified, the columns are read in the given order. -=item B I [I] - -This is a deprecated alternative to a B block. It will be removed in -version 5 of collectd. It is equivalent to the following B block: - - - Type I - InstancePrefix I - ValuesFrom I - - -The order of the B options defines which columns of the query result -should be used. The first option specifies the data found in the first column, -the second option that of the second column, and so on. - =item B I =item B I @@ -3334,13 +3314,6 @@ The I has to be specified as the concatenation of the major, minor and patch-level versions, each represented as two-decimal-digit numbers. For example, version 8.2.3 will become 80203. -=item B I - -=item B I - -These are deprecated synonyms for B and B -respectively. They will be removed in version 5 of collectd. - =back The following predefined queries are available (the definitions can be found diff --git a/src/dbi.c b/src/dbi.c index 77f393f5..cd9240a6 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -400,7 +400,7 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) udb_query_create (&queries, &queries_num, child, - /* callback = */ NULL, /* legacy mode = */ 0); + /* callback = */ NULL); else if (strcasecmp ("Database", child->key) == 0) cdbi_config_add_database (child); else diff --git a/src/oracle.c b/src/oracle.c index 3fe21254..2f218519 100644 --- a/src/oracle.c +++ b/src/oracle.c @@ -331,7 +331,7 @@ static int o_config (oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp ("Query", child->key) == 0) udb_query_create (&queries, &queries_num, child, - /* callback = */ NULL, /* legacy mode = */ 0); + /* callback = */ NULL); else if (strcasecmp ("Database", child->key) == 0) o_config_add_database (child); else diff --git a/src/postgresql.c b/src/postgresql.c index dd53cb4f..175cc095 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -737,8 +737,7 @@ static int c_psql_config (oconfig_item_t *ci) if (0 == strcasecmp (c->key, "Query")) udb_query_create (&queries, &queries_num, c, - /* callback = */ config_query_callback, - /* legacy mode = */ 1); + /* callback = */ config_query_callback); else if (0 == strcasecmp (c->key, "Database")) c_psql_config_database (c); else diff --git a/src/utils_db_query.c b/src/utils_db_query.c index 7d594d81..78c8052e 100644 --- a/src/utils_db_query.c +++ b/src/utils_db_query.c @@ -39,15 +39,6 @@ struct udb_result_s char **values; size_t values_num; - /* Legacy data */ - int legacy_mode; - size_t legacy_position; - /* When in legacy mode: - * - type/ds hold the format of the data - * - instance_prefix is used as type-instance if non-NULL - * - legacy_position holds the index of the column to use as value. - */ - udb_result_t *next; }; /* }}} */ @@ -57,8 +48,6 @@ struct udb_query_s /* {{{ */ char *statement; void *user_data; - int legacy_mode; - unsigned int min_version; unsigned int max_version; @@ -191,173 +180,6 @@ static int udb_config_set_uint (unsigned int *ret_value, /* {{{ */ } /* }}} int udb_config_set_uint */ /* - * Legacy result private functions - */ -static void udb_legacy_result_finish_result (const udb_result_t const *r, /* {{{ */ - udb_result_preparation_area_t *prep_area) -{ - if ((r == NULL) || (prep_area)) - return; - - assert (r->legacy_mode == 1); - - prep_area->ds = NULL; -} /* }}} void udb_legacy_result_finish_result */ - -static int udb_legacy_result_handle_result (udb_result_t *r, /* {{{ */ - udb_query_preparation_area_t *q_area, - udb_result_preparation_area_t *r_area, - const udb_query_t const *q, char **column_values) -{ - value_list_t vl = VALUE_LIST_INIT; - value_t value; - char *value_str; - - assert (r->legacy_mode == 1); - assert (r_area->ds != NULL); - assert (r_area->ds->ds_num == 1); - - vl.values = &value; - vl.values_len = 1; - - value_str = column_values[r->legacy_position]; - if (0 != parse_value (value_str, &vl.values[0], r_area->ds->ds[0].type)) - { - ERROR ("db query utils: udb_legacy_result_handle_result: " - "Parsing `%s' as %s failed.", value_str, - DS_TYPE_TO_STRING (r_area->ds->ds[0].type)); - errno = EINVAL; - return (-1); - } - - if (q_area->interval > 0) - vl.interval = q_area->interval; - - sstrncpy (vl.host, q_area->host, sizeof (vl.host)); - sstrncpy (vl.plugin, q_area->plugin, sizeof (vl.plugin)); - sstrncpy (vl.plugin_instance, q_area->db_name, sizeof (vl.type_instance)); - sstrncpy (vl.type, r->type, sizeof (vl.type)); - - if (r->instance_prefix != NULL) - sstrncpy (vl.type_instance, r->instance_prefix, - sizeof (vl.type_instance)); - - plugin_dispatch_values (&vl); - - return (0); -} /* }}} int udb_legacy_result_handle_result */ - -static int udb_legacy_result_prepare_result (const udb_result_t const *r, /* {{{ */ - udb_result_preparation_area_t *prep_area, - char **column_names, size_t column_num) -{ - if (r == NULL) - return (-EINVAL); - - assert (r->legacy_mode == 1); - - /* Make sure previous preparations are cleaned up. */ - udb_legacy_result_finish_result (r, prep_area); - - if (r->legacy_position >= column_num) - { - ERROR ("db query utils: The legacy configuration specified (at least) " - "%zu `Column's, but the query returned only %zu columns!", - r->legacy_position + 1, column_num); - return (-ENOENT); - } - - /* Read `ds' and check number of values {{{ */ - prep_area->ds = plugin_get_ds (r->type); - if (prep_area->ds == NULL) - { - ERROR ("db query utils: udb_result_prepare_result: Type `%s' is not " - "known by the daemon. See types.db(5) for details.", - r->type); - return (-1); - } - - if (prep_area->ds->ds_num != 1) - { - ERROR ("db query utils: udb_result_prepare_result: The type `%s' " - "requires exactly %i values, but the legacy configuration " - "requires exactly one!", - r->type, - prep_area->ds->ds_num); - return (-1); - } - /* }}} */ - - return (0); -} /* }}} int udb_legacy_result_prepare_result */ - -static int udb_legacy_result_create (const char *query_name, /* {{{ */ - udb_result_t **r_head, oconfig_item_t *ci, size_t position) -{ - udb_result_t *r; - - if ((ci->values_num < 1) || (ci->values_num > 2) - || (ci->values[0].type != OCONFIG_TYPE_STRING) - || ((ci->values_num == 2) - && (ci->values[1].type != OCONFIG_TYPE_STRING))) - { - WARNING ("db query utils: The `Column' block needs either one or two " - "string arguments."); - return (-1); - } - - r = (udb_result_t *) malloc (sizeof (*r)); - if (r == NULL) - { - ERROR ("db query utils: malloc failed."); - return (-1); - } - memset (r, 0, sizeof (*r)); - - r->legacy_mode = 1; - r->legacy_position = position; - - r->type = strdup (ci->values[0].value.string); - if (r->type == NULL) - { - ERROR ("db query utils: strdup failed."); - free (r); - return (-1); - } - - r->instance_prefix = NULL; - if (ci->values_num == 2) - { - r->instance_prefix = strdup (ci->values[1].value.string); - if (r->instance_prefix == NULL) - { - ERROR ("db query utils: strdup failed."); - free (r->type); - free (r); - return (-1); - } - } - - /* If all went well, add this result to the list of results. */ - if (*r_head == NULL) - { - *r_head = r; - } - else - { - udb_result_t *last; - - last = *r_head; - while (last->next != NULL) - last = last->next; - - last->next = r; - } - - return (0); -} /* }}} int udb_legacy_result_create */ - -/* * Result private functions */ static int udb_result_submit (udb_result_t *r, /* {{{ */ @@ -368,7 +190,6 @@ static int udb_result_submit (udb_result_t *r, /* {{{ */ size_t i; assert (r != NULL); - assert (r->legacy_mode == 0); assert (r_area->ds != NULL); assert (((size_t) r_area->ds->ds_num) == r->values_num); @@ -444,14 +265,6 @@ static void udb_result_finish_result (const udb_result_t const *r, /* {{{ */ if ((r == NULL) || (prep_area == NULL)) return; - if (r->legacy_mode == 1) - { - udb_legacy_result_finish_result (r, prep_area); - return; - } - - assert (r->legacy_mode == 0); - prep_area->ds = NULL; sfree (prep_area->instances_pos); sfree (prep_area->values_pos); @@ -468,12 +281,6 @@ static int udb_result_handle_result (udb_result_t *r, /* {{{ */ assert (r && q_area && r_area); - if (r->legacy_mode == 1) - return (udb_legacy_result_handle_result (r, q_area, r_area, - q, column_values)); - - assert (r->legacy_mode == 0); - for (i = 0; i < r->instances_num; i++) r_area->instances_buffer[i] = column_values[r_area->instances_pos[i]]; @@ -492,12 +299,6 @@ static int udb_result_prepare_result (const udb_result_t const *r, /* {{{ */ if ((r == NULL) || (prep_area == NULL)) return (-EINVAL); - if (r->legacy_mode == 1) - return (udb_legacy_result_prepare_result (r, prep_area, - column_names, column_num)); - - assert (r->legacy_mode == 0); - #define BAIL_OUT(status) \ prep_area->ds = NULL; \ sfree (prep_area->instances_pos); \ @@ -759,7 +560,7 @@ void udb_query_free_one (udb_query_t *q) /* {{{ */ */ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ size_t *ret_query_list_len, oconfig_item_t *ci, - udb_query_create_callback_t cb, int legacy_mode) + udb_query_create_callback_t cb) { udb_query_t **query_list; size_t query_list_len; @@ -768,8 +569,6 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ int status; int i; - size_t legacy_position; - if ((ret_query_list == NULL) || (ret_query_list_len == NULL)) return (-EINVAL); query_list = *ret_query_list; @@ -790,12 +589,9 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ return (-1); } memset (q, 0, sizeof (*q)); - q->legacy_mode = legacy_mode; q->min_version = 0; q->max_version = UINT_MAX; - legacy_position = 0; - status = udb_config_set_string (&q->name, ci); if (status != 0) { @@ -817,42 +613,6 @@ int udb_query_create (udb_query_t ***ret_query_list, /* {{{ */ else if (strcasecmp ("MaxVersion", child->key) == 0) status = udb_config_set_uint (&q->max_version, child); - /* PostgreSQL compatibility code */ - else if ((strcasecmp ("Query", child->key) == 0) - && (q->legacy_mode == 1)) - { - WARNING ("db query utils: Query `%s': The `Query' option is " - "deprecated. Please use `Statement' instead.", - q->name); - status = udb_config_set_string (&q->statement, child); - } - else if ((strcasecmp ("Column", child->key) == 0) - && (q->legacy_mode == 1)) - { - WARNING ("db query utils: Query `%s': The `Column' option is " - "deprecated. Please use the new syntax instead.", - q->name); - status = udb_legacy_result_create (q->name, &q->results, child, - legacy_position); - legacy_position++; - } - else if ((strcasecmp ("MinPGVersion", child->key) == 0) - && (q->legacy_mode == 1)) - { - WARNING ("db query utils: Query `%s': The `MinPGVersion' option is " - "deprecated. Please use `MinVersion' instead.", - q->name); - status = udb_config_set_uint (&q->min_version, child); - } - else if ((strcasecmp ("MaxPGVersion", child->key) == 0) - && (q->legacy_mode == 1)) - { - WARNING ("db query utils: Query `%s': The `MaxPGVersion' option is " - "deprecated. Please use `MaxVersion' instead.", - q->name); - status = udb_config_set_uint (&q->max_version, child); - } - /* Call custom callbacks */ else if (cb != NULL) { diff --git a/src/utils_db_query.h b/src/utils_db_query.h index fa2b2885..846f81c2 100644 --- a/src/utils_db_query.h +++ b/src/utils_db_query.h @@ -41,7 +41,7 @@ typedef int (*udb_query_create_callback_t) (udb_query_t *q, */ int udb_query_create (udb_query_t ***ret_query_list, size_t *ret_query_list_len, oconfig_item_t *ci, - udb_query_create_callback_t cb, int legacy_mode); + udb_query_create_callback_t cb); void udb_query_free (udb_query_t **query_list, size_t query_list_len); int udb_query_pick_from_list_by_name (const char *name,