From 1659f75b5a4fa24ec998b7afb6ea179cf40ec211 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 08:59:10 +0100 Subject: [PATCH 1/8] Move functions related to `value_list_t` to a separate package. --- Makefile.am | 4 +- src/daemon/plugin.c | 148 ----------------------- src/daemon/plugin.h | 76 +----------- src/utils/value_list/value_list.c | 189 ++++++++++++++++++++++++++++++ src/utils/value_list/value_list.h | 100 ++++++++++++++++ 5 files changed, 297 insertions(+), 220 deletions(-) create mode 100644 src/utils/value_list/value_list.c create mode 100644 src/utils/value_list/value_list.h diff --git a/Makefile.am b/Makefile.am index 29779a82be..d3fd990962 100644 --- a/Makefile.am +++ b/Makefile.am @@ -259,7 +259,9 @@ collectd_SOURCES = \ src/daemon/utils_threshold.c \ src/daemon/utils_threshold.h \ src/daemon/utils_time.c \ - src/daemon/utils_time.h + src/daemon/utils_time.h \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h collectd_CFLAGS = $(AM_CFLAGS) collectd_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index 90905b950b..a8773b5b2d 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -673,56 +673,6 @@ static void stop_read_threads(void) { read_threads_num = 0; } /* void stop_read_threads */ -static void plugin_value_list_free(value_list_t *vl) /* {{{ */ -{ - if (vl == NULL) - return; - - meta_data_destroy(vl->meta); - sfree(vl->values); - sfree(vl); -} /* }}} void plugin_value_list_free */ - -static value_list_t * -plugin_value_list_clone(value_list_t const *vl_orig) /* {{{ */ -{ - value_list_t *vl; - - if (vl_orig == NULL) - return NULL; - - vl = malloc(sizeof(*vl)); - if (vl == NULL) - return NULL; - memcpy(vl, vl_orig, sizeof(*vl)); - - if (vl->host[0] == 0) - sstrncpy(vl->host, hostname_g, sizeof(vl->host)); - - vl->values = calloc(vl_orig->values_len, sizeof(*vl->values)); - if (vl->values == NULL) { - plugin_value_list_free(vl); - return NULL; - } - memcpy(vl->values, vl_orig->values, - vl_orig->values_len * sizeof(*vl->values)); - - vl->meta = meta_data_clone(vl->meta); - if ((vl_orig->meta != NULL) && (vl->meta == NULL)) { - plugin_value_list_free(vl); - return NULL; - } - - if (vl->time == 0) - vl->time = cdtime(); - - /* Fill in the interval from the thread context, if it is zero. */ - if (vl->interval == 0) - vl->interval = plugin_get_interval(); - - return vl; -} /* }}} value_list_t *plugin_value_list_clone */ - static void write_queue_ref_single(write_queue_elem_t *elem, long dir) { elem->ref_count += dir; @@ -2250,104 +2200,6 @@ EXPORT int plugin_dispatch_metric_family(metric_family_t const *fam) { return status; } -EXPORT int plugin_dispatch_values(value_list_t const *vl) { - data_set_t const *ds = plugin_get_ds(vl->type); - if (ds == NULL) { - return EINVAL; - } - - for (size_t i = 0; i < vl->values_len; i++) { - metric_family_t *fam = plugin_value_list_to_metric_family(vl, ds, i); - if (fam == NULL) { - int status = errno; - ERROR("plugin_dispatch_values: plugin_value_list_to_metric_family " - "failed: %s", - STRERROR(status)); - return status; - } - - int status = plugin_dispatch_metric_family(fam); - metric_family_free(fam); - if (status != 0) { - return status; - } - } - - return 0; -} - -__attribute__((sentinel)) int -plugin_dispatch_multivalue(value_list_t const *template, /* {{{ */ - bool store_percentage, int store_type, ...) { - value_list_t *vl; - int failed = 0; - gauge_t sum = 0.0; - va_list ap; - - assert(template->values_len == 1); - - /* Calculate sum for Gauge to calculate percent if needed */ - if (DS_TYPE_GAUGE == store_type) { - va_start(ap, store_type); - while (42) { - char const *name; - gauge_t value; - - name = va_arg(ap, char const *); - if (name == NULL) - break; - - value = va_arg(ap, gauge_t); - if (!isnan(value)) - sum += value; - } - va_end(ap); - } - - vl = plugin_value_list_clone(template); - /* plugin_value_list_clone makes sure vl->time is set to non-zero. */ - if (store_percentage) - sstrncpy(vl->type, "percent", sizeof(vl->type)); - - va_start(ap, store_type); - while (42) { - char const *name; - int status; - - /* Set the type instance. */ - name = va_arg(ap, char const *); - if (name == NULL) - break; - sstrncpy(vl->type_instance, name, sizeof(vl->type_instance)); - - /* Set the value. */ - switch (store_type) { - case DS_TYPE_GAUGE: - vl->values[0].gauge = va_arg(ap, gauge_t); - if (store_percentage) - vl->values[0].gauge *= sum ? (100.0 / sum) : NAN; - break; - case DS_TYPE_COUNTER: - vl->values[0].counter = va_arg(ap, counter_t); - break; - case DS_TYPE_DERIVE: - vl->values[0].derive = va_arg(ap, derive_t); - break; - default: - ERROR("plugin_dispatch_multivalue: given store_type is incorrect."); - failed++; - } - - status = plugin_dispatch_values(vl); - if (status != 0) - failed++; - } - va_end(ap); - - plugin_value_list_free(vl); - return failed; -} /* }}} int plugin_dispatch_multivalue */ - EXPORT int plugin_dispatch_notification(const notification_t *notif) { llentry_t *le; /* Possible TODO: Add flap detection here */ diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h index 4eb701676e..4f92cb9af7 100644 --- a/src/daemon/plugin.h +++ b/src/daemon/plugin.h @@ -34,6 +34,7 @@ #include "configfile.h" #include "metric.h" #include "utils/metadata/meta_data.h" +#include "utils/value_list/value_list.h" /* for legacy plugins */ #include "utils_time.h" #include @@ -44,10 +45,10 @@ #define DS_TYPE_DERIVE VALUE_TYPE_DERIVE #define DS_TYPE_TO_STRING(t) \ - (t == DS_TYPE_COUNTER) \ - ? "counter" \ - : (t == DS_TYPE_GAUGE) ? "gauge" \ - : (t == DS_TYPE_DERIVE) ? "derive" : "unknown" + (t == DS_TYPE_COUNTER) ? "counter" \ + : (t == DS_TYPE_GAUGE) ? "gauge" \ + : (t == DS_TYPE_DERIVE) ? "derive" \ + : "unknown" #ifndef LOG_ERR #define LOG_ERR 3 @@ -85,23 +86,6 @@ struct identifier_s { }; typedef struct identifier_s identifier_t; -struct value_list_s { - value_t *values; - size_t values_len; - cdtime_t time; - cdtime_t interval; - char host[DATA_MAX_NAME_LEN]; - char plugin[DATA_MAX_NAME_LEN]; - char plugin_instance[DATA_MAX_NAME_LEN]; - char type[DATA_MAX_NAME_LEN]; - char type_instance[DATA_MAX_NAME_LEN]; - meta_data_t *meta; -}; -typedef struct value_list_s value_list_t; - -#define VALUE_LIST_INIT \ - { .values = NULL, .meta = NULL } - struct data_source_s { char name[DATA_MAX_NAME_LEN]; int type; @@ -325,21 +309,6 @@ int plugin_unregister_notification(const char *name); */ void plugin_log_available_writers(void); -/* - * NAME - * plugin_dispatch_values - * - * DESCRIPTION - * This function is called by reading processes with the values they've - * aquired. The function fetches the data-set definition (that has been - * registered using `plugin_register_data_set') and calls _all_ registered - * write-functions. - * - * ARGUMENTS - * `vl' Value list of the values that have been read by a `read' - * function. - */ -int plugin_dispatch_values(value_list_t const *vl); /* * NAME * plugin_dispatch_metric_list @@ -357,41 +326,6 @@ int plugin_dispatch_values(value_list_t const *vl); */ int plugin_dispatch_metric_family(metric_family_t const *fam); -/* - * NAME - * plugin_dispatch_multivalue - * - * SYNOPSIS - * plugin_dispatch_multivalue (vl, true, DS_TYPE_GAUGE, - * "free", 42.0, - * "used", 58.0, - * NULL); - * - * DESCRIPTION - * Takes a list of type instances and values and dispatches that in a batch, - * making sure that all values have the same time stamp. If "store_percentage" - * is set to true, the "type" is set to "percent" and a percentage is - * calculated and dispatched, rather than the absolute values. Values that are - * NaN are dispatched as NaN and will not influence the total. - * - * The variadic arguments is a list of type_instance / type pairs, that are - * interpreted as type "char const *" and type, encoded by their corresponding - * "store_type": - * - * - "gauge_t" when "DS_TYPE_GAUGE" - * - "derive_t" when "DS_TYPE_DERIVE" - * - "counter_t" when "DS_TYPE_COUNTER" - * - * The last argument must be - * a NULL pointer to signal end-of-list. - * - * RETURNS - * The number of values it failed to dispatch (zero on success). - */ -__attribute__((sentinel)) int plugin_dispatch_multivalue(value_list_t const *vl, - bool store_percentage, - int store_type, ...); - int plugin_dispatch_missing(metric_family_t const *fam); void plugin_dispatch_cache_event(enum cache_event_type_e event_type, unsigned long callbacks_mask, const char *name, diff --git a/src/utils/value_list/value_list.c b/src/utils/value_list/value_list.c new file mode 100644 index 0000000000..6ba378fa6a --- /dev/null +++ b/src/utils/value_list/value_list.c @@ -0,0 +1,189 @@ +/** + * collectd - src/utils/value_list/value_list.c + * Copyright (C) 2005-2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + * Sebastian Harl + * Manoj Srivastava + **/ + +#include "collectd.h" +#include "daemon/plugin.h" +#include "utils/value_list/value_list.h" +#include "utils/common/common.h" + +#ifdef WIN32 +#define EXPORT __declspec(dllexport) +#include +#include +#else +#define EXPORT +#endif + +EXPORT int plugin_dispatch_values(value_list_t const *vl) { + data_set_t const *ds = plugin_get_ds(vl->type); + if (ds == NULL) { + return EINVAL; + } + + for (size_t i = 0; i < vl->values_len; i++) { + metric_family_t *fam = plugin_value_list_to_metric_family(vl, ds, i); + if (fam == NULL) { + int status = errno; + ERROR("plugin_dispatch_values: plugin_value_list_to_metric_family " + "failed: %s", + STRERROR(status)); + return status; + } + + int status = plugin_dispatch_metric_family(fam); + metric_family_free(fam); + if (status != 0) { + return status; + } + } + + return 0; +} + +static void plugin_value_list_free(value_list_t *vl) /* {{{ */ +{ + if (vl == NULL) + return; + + meta_data_destroy(vl->meta); + sfree(vl->values); + sfree(vl); +} /* }}} void plugin_value_list_free */ + +static value_list_t * +plugin_value_list_clone(value_list_t const *vl_orig) /* {{{ */ +{ + value_list_t *vl; + + if (vl_orig == NULL) + return NULL; + + vl = malloc(sizeof(*vl)); + if (vl == NULL) + return NULL; + memcpy(vl, vl_orig, sizeof(*vl)); + + if (vl->host[0] == 0) + sstrncpy(vl->host, hostname_g, sizeof(vl->host)); + + vl->values = calloc(vl_orig->values_len, sizeof(*vl->values)); + if (vl->values == NULL) { + plugin_value_list_free(vl); + return NULL; + } + memcpy(vl->values, vl_orig->values, + vl_orig->values_len * sizeof(*vl->values)); + + vl->meta = meta_data_clone(vl->meta); + if ((vl_orig->meta != NULL) && (vl->meta == NULL)) { + plugin_value_list_free(vl); + return NULL; + } + + if (vl->time == 0) + vl->time = cdtime(); + + /* Fill in the interval from the thread context, if it is zero. */ + if (vl->interval == 0) + vl->interval = plugin_get_interval(); + + return vl; +} /* }}} value_list_t *plugin_value_list_clone */ + +__attribute__((sentinel)) int +plugin_dispatch_multivalue(value_list_t const *template, /* {{{ */ + bool store_percentage, int store_type, ...) { + value_list_t *vl; + int failed = 0; + gauge_t sum = 0.0; + va_list ap; + + assert(template->values_len == 1); + + /* Calculate sum for Gauge to calculate percent if needed */ + if (DS_TYPE_GAUGE == store_type) { + va_start(ap, store_type); + while (42) { + char const *name; + gauge_t value; + + name = va_arg(ap, char const *); + if (name == NULL) + break; + + value = va_arg(ap, gauge_t); + if (!isnan(value)) + sum += value; + } + va_end(ap); + } + + vl = plugin_value_list_clone(template); + /* plugin_value_list_clone makes sure vl->time is set to non-zero. */ + if (store_percentage) + sstrncpy(vl->type, "percent", sizeof(vl->type)); + + va_start(ap, store_type); + while (42) { + char const *name; + int status; + + /* Set the type instance. */ + name = va_arg(ap, char const *); + if (name == NULL) + break; + sstrncpy(vl->type_instance, name, sizeof(vl->type_instance)); + + /* Set the value. */ + switch (store_type) { + case DS_TYPE_GAUGE: + vl->values[0].gauge = va_arg(ap, gauge_t); + if (store_percentage) + vl->values[0].gauge *= sum ? (100.0 / sum) : NAN; + break; + case DS_TYPE_COUNTER: + vl->values[0].counter = va_arg(ap, counter_t); + break; + case DS_TYPE_DERIVE: + vl->values[0].derive = va_arg(ap, derive_t); + break; + default: + ERROR("plugin_dispatch_multivalue: given store_type is incorrect."); + failed++; + } + + status = plugin_dispatch_values(vl); + if (status != 0) + failed++; + } + va_end(ap); + + plugin_value_list_free(vl); + return failed; +} /* }}} int plugin_dispatch_multivalue */ + diff --git a/src/utils/value_list/value_list.h b/src/utils/value_list/value_list.h new file mode 100644 index 0000000000..e15a4fd39e --- /dev/null +++ b/src/utils/value_list/value_list.h @@ -0,0 +1,100 @@ +/** + * collectd - src/utils/value_list/value_list.h + * Copyright (C) 2005-2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + * Sebastian Harl + * Manoj Srivastava + **/ + +#ifndef UTILS_VALUE_LIST_H +#define UTILS_VALUE_LIST_H 1 + +struct value_list_s { + value_t *values; + size_t values_len; + cdtime_t time; + cdtime_t interval; + char host[DATA_MAX_NAME_LEN]; + char plugin[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN]; + char type[DATA_MAX_NAME_LEN]; + char type_instance[DATA_MAX_NAME_LEN]; + meta_data_t *meta; +}; +typedef struct value_list_s value_list_t; + +#define VALUE_LIST_INIT \ + { .values = NULL, .meta = NULL } + +/* + * NAME + * plugin_dispatch_values + * + * DESCRIPTION + * This function is called by reading processes with the values they've + * aquired. The function fetches the data-set definition (that has been + * registered using `plugin_register_data_set') and calls _all_ registered + * write-functions. + * + * ARGUMENTS + * `vl' Value list of the values that have been read by a `read' + * function. + */ +int plugin_dispatch_values(value_list_t const *vl); + +/* + * NAME + * plugin_dispatch_multivalue + * + * SYNOPSIS + * plugin_dispatch_multivalue (vl, true, DS_TYPE_GAUGE, + * "free", 42.0, + * "used", 58.0, + * NULL); + * + * DESCRIPTION + * Takes a list of type instances and values and dispatches that in a batch, + * making sure that all values have the same time stamp. If "store_percentage" + * is set to true, the "type" is set to "percent" and a percentage is + * calculated and dispatched, rather than the absolute values. Values that are + * NaN are dispatched as NaN and will not influence the total. + * + * The variadic arguments is a list of type_instance / type pairs, that are + * interpreted as type "char const *" and type, encoded by their corresponding + * "store_type": + * + * - "gauge_t" when "DS_TYPE_GAUGE" + * - "derive_t" when "DS_TYPE_DERIVE" + * - "counter_t" when "DS_TYPE_COUNTER" + * + * The last argument must be + * a NULL pointer to signal end-of-list. + * + * RETURNS + * The number of values it failed to dispatch (zero on success). + */ +__attribute__((sentinel)) int plugin_dispatch_multivalue(value_list_t const *vl, + bool store_percentage, + int store_type, ...); + +#endif From b2f34482e8ee2460603138b91d9b6a507c13fbf5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 09:26:28 +0100 Subject: [PATCH 2/8] daemon: Move `data_set_t` and related functions to its own file. This is part of the legacy support for collectd 5 metrics. Because "data sets" are a global resource, this has to remain within the daemon. --- Makefile.am | 2 + src/daemon/data_set.c | 121 ++++++++++++++++++++++++++++++++++++++++++ src/daemon/data_set.h | 54 +++++++++++++++++++ src/daemon/plugin.c | 84 +---------------------------- src/daemon/plugin.h | 19 ------- 5 files changed, 179 insertions(+), 101 deletions(-) create mode 100644 src/daemon/data_set.c create mode 100644 src/daemon/data_set.h diff --git a/Makefile.am b/Makefile.am index d3fd990962..2fe922908a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -238,6 +238,8 @@ collectd_SOURCES = \ src/daemon/collectd.h \ src/daemon/configfile.c \ src/daemon/configfile.h \ + src/daemon/data_set.c \ + src/daemon/data_set.h \ src/daemon/filter_chain.c \ src/daemon/filter_chain.h \ src/daemon/globals.c \ diff --git a/src/daemon/data_set.c b/src/daemon/data_set.c new file mode 100644 index 0000000000..926ef95918 --- /dev/null +++ b/src/daemon/data_set.c @@ -0,0 +1,121 @@ +/** + * collectd - src/daemon/data_set.c + * Copyright (C) 2005-2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + * Sebastian Harl + * Manoj Srivastava + **/ + +#include "daemon/data_set.h" +#include "daemon/plugin.h" +#include "utils/avltree/avltree.h" +#include "utils/common/common.h" + +#ifdef WIN32 +#define EXPORT __declspec(dllexport) +#include +#include +#else +#define EXPORT +#endif + +static c_avl_tree_t *data_sets; + +EXPORT int plugin_register_data_set(const data_set_t *ds) { + data_set_t *ds_copy; + + if ((data_sets != NULL) && (c_avl_get(data_sets, ds->type, NULL) == 0)) { + NOTICE("Replacing DS `%s' with another version.", ds->type); + plugin_unregister_data_set(ds->type); + } else if (data_sets == NULL) { + data_sets = c_avl_create((int (*)(const void *, const void *))strcmp); + if (data_sets == NULL) + return -1; + } + + ds_copy = malloc(sizeof(*ds_copy)); + if (ds_copy == NULL) + return -1; + memcpy(ds_copy, ds, sizeof(data_set_t)); + + ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num); + if (ds_copy->ds == NULL) { + sfree(ds_copy); + return -1; + } + + for (size_t i = 0; i < ds->ds_num; i++) + memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t)); + + return c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy); +} /* int plugin_register_data_set */ + +EXPORT int plugin_unregister_data_set(const char *name) { + data_set_t *ds; + + if (data_sets == NULL) + return -1; + + if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0) + return -1; + + sfree(ds->ds); + sfree(ds); + + return 0; +} /* int plugin_unregister_data_set */ + +EXPORT const data_set_t *plugin_get_ds(const char *name) { + data_set_t *ds; + + if (data_sets == NULL) { + P_ERROR("plugin_get_ds: No data sets are defined yet."); + return NULL; + } + + if (c_avl_get(data_sets, name, (void *)&ds) != 0) { + DEBUG("No such dataset registered: %s", name); + return NULL; + } + + return ds; +} /* data_set_t *plugin_get_ds */ + +void plugin_free_data_sets(void) { + void *key; + void *value; + + if (data_sets == NULL) + return; + + while (c_avl_pick(data_sets, &key, &value) == 0) { + data_set_t *ds = value; + /* key is a pointer to ds->type */ + + sfree(ds->ds); + sfree(ds); + } + + c_avl_destroy(data_sets); + data_sets = NULL; +} /* void plugin_free_data_sets */ diff --git a/src/daemon/data_set.h b/src/daemon/data_set.h new file mode 100644 index 0000000000..3734bf6f0e --- /dev/null +++ b/src/daemon/data_set.h @@ -0,0 +1,54 @@ +/** + * collectd - src/daemon/data_set.h + * Copyright (C) 2005-2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + * Sebastian Harl + * Manoj Srivastava + **/ + +#ifndef DAEMON_DATA_SET_H +#define DAEMON_DATA_SET_H + +#include "collectd.h" + +struct data_source_s { + char name[DATA_MAX_NAME_LEN]; + int type; + double min; + double max; +}; +typedef struct data_source_s data_source_t; + +struct data_set_s { + char type[DATA_MAX_NAME_LEN]; + size_t ds_num; + data_source_t *ds; +}; +typedef struct data_set_s data_set_t; + +int plugin_register_data_set(const data_set_t *ds); +int plugin_unregister_data_set(const char *name); +const data_set_t *plugin_get_ds(const char *name); +void plugin_free_data_sets(void); + +#endif /* DAEMON_DATA_SET_H */ diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index a8773b5b2d..a4d9f06d01 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -1,5 +1,5 @@ /** - * collectd - src/plugin.c + * collectd - src/daemon/plugin.c * Copyright (C) 2005-2014 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a @@ -32,6 +32,7 @@ #include "collectd.h" #include "configfile.h" +#include "daemon/data_set.h" #include "filter_chain.h" #include "plugin.h" #include "resource.h" @@ -150,8 +151,6 @@ static cache_event_func_t list_cache_event[32]; static fc_chain_t *pre_cache_chain; static fc_chain_t *post_cache_chain; -static c_avl_tree_t *data_sets; - static char *plugindir; #ifndef DEFAULT_MAX_READ_INTERVAL @@ -1409,54 +1408,6 @@ EXPORT int plugin_register_shutdown(const char *name, int (*callback)(void)) { return create_register_callback(&list_shutdown, name, (void *)callback, NULL); } /* int plugin_register_shutdown */ -static void plugin_free_data_sets(void) { - void *key; - void *value; - - if (data_sets == NULL) - return; - - while (c_avl_pick(data_sets, &key, &value) == 0) { - data_set_t *ds = value; - /* key is a pointer to ds->type */ - - sfree(ds->ds); - sfree(ds); - } - - c_avl_destroy(data_sets); - data_sets = NULL; -} /* void plugin_free_data_sets */ - -EXPORT int plugin_register_data_set(const data_set_t *ds) { - data_set_t *ds_copy; - - if ((data_sets != NULL) && (c_avl_get(data_sets, ds->type, NULL) == 0)) { - NOTICE("Replacing DS `%s' with another version.", ds->type); - plugin_unregister_data_set(ds->type); - } else if (data_sets == NULL) { - data_sets = c_avl_create((int (*)(const void *, const void *))strcmp); - if (data_sets == NULL) - return -1; - } - - ds_copy = malloc(sizeof(*ds_copy)); - if (ds_copy == NULL) - return -1; - memcpy(ds_copy, ds, sizeof(data_set_t)); - - ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num); - if (ds_copy->ds == NULL) { - sfree(ds_copy); - return -1; - } - - for (size_t i = 0; i < ds->ds_num; i++) - memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t)); - - return c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy); -} /* int plugin_register_data_set */ - EXPORT int plugin_register_log(const char *name, plugin_log_cb callback, user_data_t const *ud) { return create_register_callback(&list_log, name, (void *)callback, ud); @@ -1733,21 +1684,6 @@ EXPORT int plugin_unregister_shutdown(const char *name) { return plugin_unregister(list_shutdown, name); } -EXPORT int plugin_unregister_data_set(const char *name) { - data_set_t *ds; - - if (data_sets == NULL) - return -1; - - if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0) - return -1; - - sfree(ds->ds); - sfree(ds); - - return 0; -} /* int plugin_unregister_data_set */ - EXPORT int plugin_unregister_log(const char *name) { return plugin_unregister(list_log, name); } @@ -2321,22 +2257,6 @@ EXPORT int parse_notif_severity(const char *severity) { return notif_severity; } /* int parse_notif_severity */ -EXPORT const data_set_t *plugin_get_ds(const char *name) { - data_set_t *ds; - - if (data_sets == NULL) { - P_ERROR("plugin_get_ds: No data sets are defined yet."); - return NULL; - } - - if (c_avl_get(data_sets, name, (void *)&ds) != 0) { - DEBUG("No such dataset registered: %s", name); - return NULL; - } - - return ds; -} /* data_set_t *plugin_get_ds */ - static int plugin_notification_meta_add(notification_t *n, const char *name, enum notification_meta_type_e type, const void *value) { diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h index 4f92cb9af7..e1c54627a6 100644 --- a/src/daemon/plugin.h +++ b/src/daemon/plugin.h @@ -86,21 +86,6 @@ struct identifier_s { }; typedef struct identifier_s identifier_t; -struct data_source_s { - char name[DATA_MAX_NAME_LEN]; - int type; - double min; - double max; -}; -typedef struct data_source_s data_source_t; - -struct data_set_s { - char type[DATA_MAX_NAME_LEN]; - size_t ds_num; - data_source_t *ds; -}; -typedef struct data_set_s data_set_t; - enum notification_meta_type_e { NM_TYPE_STRING, NM_TYPE_SIGNED_INT, @@ -276,7 +261,6 @@ int plugin_register_cache_event(const char *name, plugin_cache_event_cb callback, user_data_t const *ud); int plugin_register_shutdown(const char *name, plugin_shutdown_cb callback); -int plugin_register_data_set(const data_set_t *ds); int plugin_register_log(const char *name, plugin_log_cb callback, user_data_t const *user_data); int plugin_register_notification(const char *name, @@ -293,7 +277,6 @@ int plugin_unregister_flush(const char *name); int plugin_unregister_missing(const char *name); int plugin_unregister_cache_event(const char *name); int plugin_unregister_shutdown(const char *name); -int plugin_unregister_data_set(const char *name); int plugin_unregister_log(const char *name); int plugin_unregister_notification(const char *name); @@ -359,8 +342,6 @@ void daemon_log(int level, const char *format, ...) #define P_NOTICE(...) daemon_log(LOG_NOTICE, __VA_ARGS__) #define P_INFO(...) daemon_log(LOG_INFO, __VA_ARGS__) -const data_set_t *plugin_get_ds(const char *name); - int plugin_notification_meta_add_string(notification_t *n, const char *name, const char *value); int plugin_notification_meta_add_signed_int(notification_t *n, const char *name, From ca313699f199f89564b4186a145208a7db11fd25 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 09:30:25 +0100 Subject: [PATCH 3/8] value_list: Migrate functions related to `value_list_t` out of `common`. --- src/utils/common/common.c | 242 ----------------------------- src/utils/common/common.h | 28 ---- src/utils/value_list/value_list.c | 243 +++++++++++++++++++++++++++++- src/utils/value_list/value_list.h | 31 ++++ 4 files changed, 273 insertions(+), 271 deletions(-) diff --git a/src/utils/common/common.c b/src/utils/common/common.c index 7caa1f51ff..46c4d1179f 100644 --- a/src/utils/common/common.c +++ b/src/utils/common/common.c @@ -948,248 +948,6 @@ int format_values(strbuf_t *buf, metric_t const *m, bool store_rates) { return 0; } /* }}} int format_values */ -int parse_identifier(char *str, char **ret_host, char **ret_plugin, - char **ret_type, char **ret_data_source, - char *default_host) { - char *fields[5]; - size_t fields_num = 0; - - do { - fields[fields_num] = str; - fields_num++; - - char *ptr = strchr(str, '/'); - if (ptr == NULL) { - break; - } - - *ptr = 0; - str = ptr + 1; - } while (fields_num < STATIC_ARRAY_SIZE(fields)); - - switch (fields_num) { - case 4: - *ret_data_source = fields[3]; - /* fall-through */ - case 3: - *ret_type = fields[2]; - *ret_plugin = fields[1]; - *ret_host = fields[0]; - break; - case 2: - if ((default_host == NULL) || (strlen(default_host) == 0)) { - return EINVAL; - } - *ret_type = fields[1]; - *ret_plugin = fields[0]; - *ret_host = default_host; - break; - default: - return EINVAL; - } - - return 0; -} /* int parse_identifier */ - -int parse_identifier_vl(const char *str, value_list_t *vl, - char **ret_data_source) { - if ((str == NULL) || (vl == NULL)) - return EINVAL; - - char str_copy[6 * DATA_MAX_NAME_LEN]; - sstrncpy(str_copy, str, sizeof(str_copy)); - - char *default_host = NULL; - if (strlen(vl->host) != 0) { - default_host = vl->host; - } - - char *host = NULL; - char *plugin = NULL; - char *type = NULL; - char *data_source = NULL; - int status = parse_identifier(str_copy, &host, &plugin, &type, &data_source, - default_host); - if (status != 0) { - return status; - } - - if (data_source != NULL) { - if (ret_data_source == NULL) { - return EINVAL; - } - *ret_data_source = strdup(data_source); - } - - char *plugin_instance = strchr(plugin, '-'); - if (plugin_instance != NULL) { - *plugin_instance = 0; - plugin_instance++; - } - char *type_instance = strchr(type, '-'); - if (type_instance != NULL) { - *type_instance = 0; - type_instance++; - } - - if (host != vl->host) { - sstrncpy(vl->host, host, sizeof(vl->host)); - } - sstrncpy(vl->plugin, plugin, sizeof(vl->plugin)); - if (plugin_instance != NULL) { - sstrncpy(vl->plugin_instance, plugin_instance, sizeof(vl->plugin_instance)); - } - sstrncpy(vl->type, type, sizeof(vl->type)); - if (type_instance != NULL) { - sstrncpy(vl->type_instance, type_instance, sizeof(vl->type_instance)); - } - - return 0; -} /* }}} int parse_identifier_vl */ - -metric_t *parse_legacy_identifier(char const *s) { - value_list_t vl = VALUE_LIST_INIT; - - char *data_source = NULL; - int status = parse_identifier_vl(s, &vl, &data_source); - if (status != 0) { - errno = status; - return NULL; - } - - data_set_t const *ds = plugin_get_ds(vl.type); - if (ds == NULL) { - errno = ENOENT; - return NULL; - } - - if ((ds->ds_num != 1) && (data_source == NULL)) { - DEBUG("parse_legacy_identifier: data set \"%s\" has multiple data sources, " - "but \"%s\" does not specify a data source", - ds->type, s); - errno = EINVAL; - return NULL; - } - - value_t values[ds->ds_num]; - memset(values, 0, sizeof(values)); - vl.values = values; - vl.values_len = ds->ds_num; - - size_t ds_index = 0; - if (data_source != NULL) { - bool found = 0; - for (size_t i = 0; i < ds->ds_num; i++) { - if (strcasecmp(data_source, ds->ds[i].name) == 0) { - ds_index = i; - found = true; - } - } - - if (!found) { - DEBUG("parse_legacy_identifier: data set \"%s\" does not have a \"%s\" " - "data source", - ds->type, data_source); - free(data_source); - errno = EINVAL; - return NULL; - } - } - free(data_source); - data_source = NULL; - - metric_family_t *fam = plugin_value_list_to_metric_family(&vl, ds, ds_index); - if (fam == NULL) { - return NULL; - } - - return fam->metric.ptr; -} - -static int metric_family_name(strbuf_t *buf, value_list_t const *vl, - data_source_t const *dsrc) { - int status = strbuf_print(buf, "collectd"); - - if (strcmp(vl->plugin, vl->type) != 0) { - status = status || strbuf_print(buf, "_"); - status = status || strbuf_print(buf, vl->plugin); - } - - status = status || strbuf_print(buf, "_"); - status = status || strbuf_print(buf, vl->type); - - if (strcmp("value", dsrc->name) != 0) { - status = status || strbuf_print(buf, "_"); - status = status || strbuf_print(buf, dsrc->name); - } - - if ((dsrc->type == DS_TYPE_COUNTER) || (dsrc->type == DS_TYPE_DERIVE)) { - status = status || strbuf_print(buf, "_total"); - } - - return status; -} - -metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl, - data_set_t const *ds, - size_t index) { - if ((vl == NULL) || (ds == NULL)) { - errno = EINVAL; - return NULL; - } - - metric_family_t *fam = calloc(1, sizeof(*fam)); - if (fam == NULL) { - return NULL; - } - - data_source_t const *dsrc = ds->ds + index; - strbuf_t name = STRBUF_CREATE; - int status = metric_family_name(&name, vl, dsrc); - if (status != 0) { - STRBUF_DESTROY(name); - metric_family_free(fam); - errno = status; - return NULL; - } - fam->name = name.ptr; - name = (strbuf_t){0}; - - fam->type = - (dsrc->type == DS_TYPE_GAUGE) ? METRIC_TYPE_GAUGE : METRIC_TYPE_COUNTER; - - metric_t m = { - .family = fam, - .value = vl->values[index], - .time = vl->time, - .interval = vl->interval, - }; - - status = metric_label_set(&m, "instance", - (strlen(vl->host) != 0) ? vl->host : hostname_g); - if (strlen(vl->plugin_instance) != 0) { - status = status || metric_label_set(&m, vl->plugin, vl->plugin_instance); - } - if (strlen(vl->type_instance) != 0) { - char const *name = "type"; - if (strlen(vl->plugin_instance) == 0) { - name = vl->plugin; - } - status = status || metric_label_set(&m, name, vl->type_instance); - } - - status = status || metric_family_metric_append(fam, m); - if (status != 0) { - metric_reset(&m); - metric_family_free(fam); - errno = status; - return NULL; - } - - metric_reset(&m); - return fam; -} - int parse_value(const char *value_orig, value_t *ret_value, int ds_type) { char *value; char *endptr = NULL; diff --git a/src/utils/common/common.h b/src/utils/common/common.h index cc702272d5..6b9f8d79dd 100644 --- a/src/utils/common/common.h +++ b/src/utils/common/common.h @@ -330,34 +330,6 @@ int format_name(char *ret, int ret_len, const char *hostname, (vl)->type, (vl)->type_instance) int format_values(strbuf_t *buf, metric_t const *m, bool store_rates); -int parse_identifier(char *str, char **ret_host, char **ret_plugin, - char **ret_type, char **ret_data_source, - char *default_host); - -/* parse_identifier_vl parses an identifier in the form - * "host/plugin[-inst]/type[-inst]/data_source" and stores the fields in a - * value_list_t. If vl->host is not empty, then it is used as the default value - * if a host name is omitted, i.e. the "plugin/type" format is accepted. If - * ret_data_source is not NULL, a four-part identifier is accepted and a - * pointer to the data source name is (optionally) stored and needs to be freed - * by the caller. If the provided format does not fit the provided arguments, - * e.g. a two-part format but no default host provided, or a four-part format - * but no ret_data_source pointer, then EINVAL is returned. - */ -int parse_identifier_vl(const char *str, value_list_t *vl, - char **ret_data_source); - -/* parse_legacy_identifier parses a legacy identifier in the form - * "host/plugin/type" and converts it to a metric_t. */ -metric_t *parse_legacy_identifier(char const *s); - -/* plugin_value_list_to_metric_family converts a value in a value_list_t to a - * metric_family_t. In case of error, errno is set and NULL is returned. The - * returned pointer must be freed using metric_family_free(). */ -metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl, - data_set_t const *ds, - size_t index); - int parse_value(const char *value, value_t *ret_value, int ds_type); int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds); diff --git a/src/utils/value_list/value_list.c b/src/utils/value_list/value_list.c index 6ba378fa6a..ac49f81c7a 100644 --- a/src/utils/value_list/value_list.c +++ b/src/utils/value_list/value_list.c @@ -28,8 +28,8 @@ #include "collectd.h" #include "daemon/plugin.h" -#include "utils/value_list/value_list.h" #include "utils/common/common.h" +#include "utils/value_list/value_list.h" #ifdef WIN32 #define EXPORT __declspec(dllexport) @@ -187,3 +187,244 @@ plugin_dispatch_multivalue(value_list_t const *template, /* {{{ */ return failed; } /* }}} int plugin_dispatch_multivalue */ +static int metric_family_name(strbuf_t *buf, value_list_t const *vl, + data_source_t const *dsrc) { + int status = strbuf_print(buf, "collectd"); + + if (strcmp(vl->plugin, vl->type) != 0) { + status = status || strbuf_print(buf, "_"); + status = status || strbuf_print(buf, vl->plugin); + } + + status = status || strbuf_print(buf, "_"); + status = status || strbuf_print(buf, vl->type); + + if (strcmp("value", dsrc->name) != 0) { + status = status || strbuf_print(buf, "_"); + status = status || strbuf_print(buf, dsrc->name); + } + + if ((dsrc->type == DS_TYPE_COUNTER) || (dsrc->type == DS_TYPE_DERIVE)) { + status = status || strbuf_print(buf, "_total"); + } + + return status; +} + +int parse_identifier(char *str, char **ret_host, char **ret_plugin, + char **ret_type, char **ret_data_source, + char *default_host) { + char *fields[5]; + size_t fields_num = 0; + + do { + fields[fields_num] = str; + fields_num++; + + char *ptr = strchr(str, '/'); + if (ptr == NULL) { + break; + } + + *ptr = 0; + str = ptr + 1; + } while (fields_num < STATIC_ARRAY_SIZE(fields)); + + switch (fields_num) { + case 4: + *ret_data_source = fields[3]; + /* fall-through */ + case 3: + *ret_type = fields[2]; + *ret_plugin = fields[1]; + *ret_host = fields[0]; + break; + case 2: + if ((default_host == NULL) || (strlen(default_host) == 0)) { + return EINVAL; + } + *ret_type = fields[1]; + *ret_plugin = fields[0]; + *ret_host = default_host; + break; + default: + return EINVAL; + } + + return 0; +} /* int parse_identifier */ + +int parse_identifier_vl(const char *str, value_list_t *vl, + char **ret_data_source) { + if ((str == NULL) || (vl == NULL)) + return EINVAL; + + char str_copy[6 * DATA_MAX_NAME_LEN]; + sstrncpy(str_copy, str, sizeof(str_copy)); + + char *default_host = NULL; + if (strlen(vl->host) != 0) { + default_host = vl->host; + } + + char *host = NULL; + char *plugin = NULL; + char *type = NULL; + char *data_source = NULL; + int status = parse_identifier(str_copy, &host, &plugin, &type, &data_source, + default_host); + if (status != 0) { + return status; + } + + if (data_source != NULL) { + if (ret_data_source == NULL) { + return EINVAL; + } + *ret_data_source = strdup(data_source); + } + + char *plugin_instance = strchr(plugin, '-'); + if (plugin_instance != NULL) { + *plugin_instance = 0; + plugin_instance++; + } + char *type_instance = strchr(type, '-'); + if (type_instance != NULL) { + *type_instance = 0; + type_instance++; + } + + if (host != vl->host) { + sstrncpy(vl->host, host, sizeof(vl->host)); + } + sstrncpy(vl->plugin, plugin, sizeof(vl->plugin)); + if (plugin_instance != NULL) { + sstrncpy(vl->plugin_instance, plugin_instance, sizeof(vl->plugin_instance)); + } + sstrncpy(vl->type, type, sizeof(vl->type)); + if (type_instance != NULL) { + sstrncpy(vl->type_instance, type_instance, sizeof(vl->type_instance)); + } + + return 0; +} /* }}} int parse_identifier_vl */ + +metric_t *parse_legacy_identifier(char const *s) { + value_list_t vl = VALUE_LIST_INIT; + + char *data_source = NULL; + int status = parse_identifier_vl(s, &vl, &data_source); + if (status != 0) { + errno = status; + return NULL; + } + + data_set_t const *ds = plugin_get_ds(vl.type); + if (ds == NULL) { + errno = ENOENT; + return NULL; + } + + if ((ds->ds_num != 1) && (data_source == NULL)) { + DEBUG("parse_legacy_identifier: data set \"%s\" has multiple data sources, " + "but \"%s\" does not specify a data source", + ds->type, s); + errno = EINVAL; + return NULL; + } + + value_t values[ds->ds_num]; + memset(values, 0, sizeof(values)); + vl.values = values; + vl.values_len = ds->ds_num; + + size_t ds_index = 0; + if (data_source != NULL) { + bool found = 0; + for (size_t i = 0; i < ds->ds_num; i++) { + if (strcasecmp(data_source, ds->ds[i].name) == 0) { + ds_index = i; + found = true; + } + } + + if (!found) { + DEBUG("parse_legacy_identifier: data set \"%s\" does not have a \"%s\" " + "data source", + ds->type, data_source); + free(data_source); + errno = EINVAL; + return NULL; + } + } + free(data_source); + data_source = NULL; + + metric_family_t *fam = plugin_value_list_to_metric_family(&vl, ds, ds_index); + if (fam == NULL) { + return NULL; + } + + return fam->metric.ptr; +} + +EXPORT metric_family_t * +plugin_value_list_to_metric_family(value_list_t const *vl, data_set_t const *ds, + size_t index) { + if ((vl == NULL) || (ds == NULL)) { + errno = EINVAL; + return NULL; + } + + metric_family_t *fam = calloc(1, sizeof(*fam)); + if (fam == NULL) { + return NULL; + } + + data_source_t const *dsrc = ds->ds + index; + strbuf_t name = STRBUF_CREATE; + int status = metric_family_name(&name, vl, dsrc); + if (status != 0) { + STRBUF_DESTROY(name); + metric_family_free(fam); + errno = status; + return NULL; + } + fam->name = name.ptr; + name = (strbuf_t){0}; + + fam->type = + (dsrc->type == DS_TYPE_GAUGE) ? METRIC_TYPE_GAUGE : METRIC_TYPE_COUNTER; + + metric_t m = { + .family = fam, + .value = vl->values[index], + .time = vl->time, + .interval = vl->interval, + }; + + status = metric_label_set(&m, "instance", + (strlen(vl->host) != 0) ? vl->host : hostname_g); + if (strlen(vl->plugin_instance) != 0) { + status = status || metric_label_set(&m, vl->plugin, vl->plugin_instance); + } + if (strlen(vl->type_instance) != 0) { + char const *name = "type"; + if (strlen(vl->plugin_instance) == 0) { + name = vl->plugin; + } + status = status || metric_label_set(&m, name, vl->type_instance); + } + + status = status || metric_family_metric_append(fam, m); + if (status != 0) { + metric_reset(&m); + metric_family_free(fam); + errno = status; + return NULL; + } + + metric_reset(&m); + return fam; +} diff --git a/src/utils/value_list/value_list.h b/src/utils/value_list/value_list.h index e15a4fd39e..13d69dc773 100644 --- a/src/utils/value_list/value_list.h +++ b/src/utils/value_list/value_list.h @@ -29,6 +29,9 @@ #ifndef UTILS_VALUE_LIST_H #define UTILS_VALUE_LIST_H 1 +#include "daemon/data_set.h" +#include "daemon/plugin.h" + struct value_list_s { value_t *values; size_t values_len; @@ -97,4 +100,32 @@ __attribute__((sentinel)) int plugin_dispatch_multivalue(value_list_t const *vl, bool store_percentage, int store_type, ...); +int parse_identifier(char *str, char **ret_host, char **ret_plugin, + char **ret_type, char **ret_data_source, + char *default_host); + +/* parse_identifier_vl parses an identifier in the form + * "host/plugin[-inst]/type[-inst]/data_source" and stores the fields in a + * value_list_t. If vl->host is not empty, then it is used as the default value + * if a host name is omitted, i.e. the "plugin/type" format is accepted. If + * ret_data_source is not NULL, a four-part identifier is accepted and a + * pointer to the data source name is (optionally) stored and needs to be freed + * by the caller. If the provided format does not fit the provided arguments, + * e.g. a two-part format but no default host provided, or a four-part format + * but no ret_data_source pointer, then EINVAL is returned. + */ +int parse_identifier_vl(const char *str, value_list_t *vl, + char **ret_data_source); + +/* parse_legacy_identifier parses a legacy identifier in the form + * "host/plugin/type" and converts it to a metric_t. */ +metric_t *parse_legacy_identifier(char const *s); + +/* plugin_value_list_to_metric_family converts a value in a value_list_t to a + * metric_family_t. In case of error, errno is set and NULL is returned. The + * returned pointer must be freed using metric_family_free(). */ +metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl, + data_set_t const *ds, + size_t index); + #endif From 6817f227007e74b76ae0bd9153e21370079b9de9 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 09:38:08 +0100 Subject: [PATCH 4/8] value_list: Migrate `parse_values` out of `common`. --- Makefile.am | 27 ++++++--- src/daemon/plugin_mock.c | 2 - src/utils/common/common.c | 56 ----------------- src/utils/common/common.h | 1 - src/utils/common/common_test.c | 51 ---------------- src/utils/value_list/value_list.c | 56 +++++++++++++++++ src/utils/value_list/value_list.h | 2 + src/utils/value_list/value_list_test.c | 84 ++++++++++++++++++++++++++ 8 files changed, 161 insertions(+), 118 deletions(-) create mode 100644 src/utils/value_list/value_list_test.c diff --git a/Makefile.am b/Makefile.am index 2fe922908a..19ed9a253d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -384,7 +384,8 @@ test_utils_message_parser_SOURCES = \ src/utils/tail/tail.c src/utils/tail/tail.h \ src/utils/match/match.c src/utils/match/match.h \ src/utils/latency/latency.c src/utils/latency/latency.h \ - src/utils/latency/latency_config.c src/utils/latency/latency_config.h + src/utils/latency/latency_config.c src/utils/latency/latency_config.h \ + src/utils/value_list/value_list.c src/utils/value_list/value_list.h test_utils_message_parser_CPPFLAGS = $(AM_CPPFLAGS) test_utils_message_parser_LDADD = liboconfig.la libplugin_mock.la -lm @@ -497,7 +498,9 @@ test_format_json_LDADD = \ endif if BUILD_PLUGIN_CEPH -test_plugin_ceph_SOURCES = src/ceph_test.c +test_plugin_ceph_SOURCES = src/ceph_test.c \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h test_plugin_ceph_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) test_plugin_ceph_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) test_plugin_ceph_LDADD = libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS) @@ -544,6 +547,8 @@ libcmds_la_LIBADD = -lm test_utils_cmds_SOURCES = \ src/utils/cmds/cmds_test.c \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h \ src/testing.h test_utils_cmds_LDADD = \ libcmds.la \ @@ -937,16 +942,20 @@ pkglib_LTLIBRARIES += curl_json.la curl_json_la_SOURCES = \ src/curl_json.c \ src/utils/curl_stats/curl_stats.c \ - src/utils/curl_stats/curl_stats.h + src/utils/curl_stats/curl_stats.h \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h curl_json_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) curl_json_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) curl_json_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) test_plugin_curl_json_SOURCES = src/curl_json_test.c \ - src/utils/curl_stats/curl_stats.c \ src/daemon/configfile.c \ - src/daemon/types_list.c + src/daemon/types_list.c \ + src/utils/curl_stats/curl_stats.c \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h test_plugin_curl_json_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) test_plugin_curl_json_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) test_plugin_curl_json_LDADD = libavltree.la liboconfig.la libplugin_mock.la $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) @@ -1340,12 +1349,14 @@ logparser_la_CPPFLAGS = $(AM_CPPFLAGS) logparser_la_LDFLAGS = $(PLUGIN_LDFLAGS) -lm test_plugin_logparser_SOURCES = src/logparser_test.c \ + src/daemon/configfile.c \ + src/daemon/types_list.c \ + src/utils/match/match.c src/utils/match/match.h \ src/utils/message_parser/message_parser.c \ src/utils_tail_match.c src/utils_tail_match.h \ src/utils/tail/tail.c src/utils/tail/tail.h \ - src/utils/match/match.c src/utils/match/match.h \ - src/daemon/configfile.c \ - src/daemon/types_list.c + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h test_plugin_logparser_CPPFLAGS = $(AM_CPPFLAGS) test_plugin_logparser_LDFLAGS = $(PLUGIN_LDFLAGS) test_plugin_logparser_LDADD = liboconfig.la libplugin_mock.la liblatency.la diff --git a/src/daemon/plugin_mock.c b/src/daemon/plugin_mock.c index 180c919358..4fe205cc23 100644 --- a/src/daemon/plugin_mock.c +++ b/src/daemon/plugin_mock.c @@ -119,8 +119,6 @@ DECLARE_UNREGISTER(data_set) DECLARE_UNREGISTER(log) DECLARE_UNREGISTER(notification) -int plugin_dispatch_values(value_list_t const *vl) { return ENOTSUP; } - int plugin_dispatch_metric_family(metric_family_t const *fam) { return ENOTSUP; } diff --git a/src/utils/common/common.c b/src/utils/common/common.c index 46c4d1179f..34258f09ef 100644 --- a/src/utils/common/common.c +++ b/src/utils/common/common.c @@ -999,62 +999,6 @@ int parse_value(const char *value_orig, value_t *ret_value, int ds_type) { return 0; } /* int parse_value */ -int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds) { - size_t i; - char *dummy; - char *ptr; - char *saveptr; - - if ((buffer == NULL) || (vl == NULL) || (ds == NULL)) - return EINVAL; - - i = 0; - dummy = buffer; - saveptr = NULL; - vl->time = 0; - while ((ptr = strtok_r(dummy, ":", &saveptr)) != NULL) { - dummy = NULL; - - if (i >= vl->values_len) { - /* Make sure i is invalid. */ - i = 0; - break; - } - - if (vl->time == 0) { - if (strcmp("N", ptr) == 0) - vl->time = cdtime(); - else { - char *endptr = NULL; - double tmp; - - errno = 0; - tmp = strtod(ptr, &endptr); - if ((errno != 0) /* Overflow */ - || (endptr == ptr) /* Invalid string */ - || (endptr == NULL) /* This should not happen */ - || (*endptr != 0)) /* Trailing chars */ - return -1; - - vl->time = DOUBLE_TO_CDTIME_T(tmp); - } - - continue; - } - - if ((strcmp("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE)) - vl->values[i].gauge = NAN; - else if (0 != parse_value(ptr, &vl->values[i], ds->ds[i].type)) - return -1; - - i++; - } /* while (strtok_r) */ - - if ((ptr != NULL) || (i == 0)) - return -1; - return 0; -} /* int parse_values */ - int parse_value_file(char const *path, value_t *ret_value, int ds_type) { FILE *fh; char buffer[256]; diff --git a/src/utils/common/common.h b/src/utils/common/common.h index 6b9f8d79dd..51b4032c0e 100644 --- a/src/utils/common/common.h +++ b/src/utils/common/common.h @@ -331,7 +331,6 @@ int format_name(char *ret, int ret_len, const char *hostname, int format_values(strbuf_t *buf, metric_t const *m, bool store_rates); int parse_value(const char *value, value_t *ret_value, int ds_type); -int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds); /* parse_value_file reads "path" and parses its content as an integer or * floating point, depending on "ds_type". On success, the value is stored in diff --git a/src/utils/common/common_test.c b/src/utils/common/common_test.c index f2fd190e46..d4a667d4c1 100644 --- a/src/utils/common/common_test.c +++ b/src/utils/common/common_test.c @@ -272,56 +272,6 @@ DEF_TEST(strunescape) { return 0; } -DEF_TEST(parse_values) { - struct { - char buffer[64]; - int status; - gauge_t value; - } cases[] = { - {"1435044576:42", 0, 42.0}, {"1435044576:42:23", -1, NAN}, - {"1435044576:U", 0, NAN}, {"N:12.3", 0, 12.3}, - {"N:42.0:23", -1, NAN}, {"N:U", 0, NAN}, - {"T:42.0", -1, NAN}, - }; - - for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { - data_source_t dsrc = { - .name = "value", - .type = DS_TYPE_GAUGE, - .min = 0.0, - .max = NAN, - }; - data_set_t ds = { - .type = "example", - .ds_num = 1, - .ds = &dsrc, - }; - - value_t v = { - .gauge = NAN, - }; - value_list_t vl = { - .values = &v, - .values_len = 1, - .time = 0, - .interval = 0, - .host = "example.com", - .plugin = "common_test", - .type = "example", - .meta = NULL, - }; - - int status = parse_values(cases[i].buffer, &vl, &ds); - EXPECT_EQ_INT(cases[i].status, status); - if (status != 0) - continue; - - EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge); - } - - return 0; -} - DEF_TEST(value_to_rate) { struct { time_t t0; @@ -419,7 +369,6 @@ int main(void) { RUN_TEST(escape_slashes); RUN_TEST(escape_string); RUN_TEST(strunescape); - RUN_TEST(parse_values); RUN_TEST(value_to_rate); RUN_TEST(format_values); diff --git a/src/utils/value_list/value_list.c b/src/utils/value_list/value_list.c index ac49f81c7a..772328a436 100644 --- a/src/utils/value_list/value_list.c +++ b/src/utils/value_list/value_list.c @@ -428,3 +428,59 @@ plugin_value_list_to_metric_family(value_list_t const *vl, data_set_t const *ds, metric_reset(&m); return fam; } + +int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds) { + size_t i; + char *dummy; + char *ptr; + char *saveptr; + + if ((buffer == NULL) || (vl == NULL) || (ds == NULL)) + return EINVAL; + + i = 0; + dummy = buffer; + saveptr = NULL; + vl->time = 0; + while ((ptr = strtok_r(dummy, ":", &saveptr)) != NULL) { + dummy = NULL; + + if (i >= vl->values_len) { + /* Make sure i is invalid. */ + i = 0; + break; + } + + if (vl->time == 0) { + if (strcmp("N", ptr) == 0) + vl->time = cdtime(); + else { + char *endptr = NULL; + double tmp; + + errno = 0; + tmp = strtod(ptr, &endptr); + if ((errno != 0) /* Overflow */ + || (endptr == ptr) /* Invalid string */ + || (endptr == NULL) /* This should not happen */ + || (*endptr != 0)) /* Trailing chars */ + return -1; + + vl->time = DOUBLE_TO_CDTIME_T(tmp); + } + + continue; + } + + if ((strcmp("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE)) + vl->values[i].gauge = NAN; + else if (0 != parse_value(ptr, &vl->values[i], ds->ds[i].type)) + return -1; + + i++; + } /* while (strtok_r) */ + + if ((ptr != NULL) || (i == 0)) + return -1; + return 0; +} /* int parse_values */ diff --git a/src/utils/value_list/value_list.h b/src/utils/value_list/value_list.h index 13d69dc773..2b95fb8197 100644 --- a/src/utils/value_list/value_list.h +++ b/src/utils/value_list/value_list.h @@ -128,4 +128,6 @@ metric_family_t *plugin_value_list_to_metric_family(value_list_t const *vl, data_set_t const *ds, size_t index); +int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds); + #endif diff --git a/src/utils/value_list/value_list_test.c b/src/utils/value_list/value_list_test.c new file mode 100644 index 0000000000..016890551b --- /dev/null +++ b/src/utils/value_list/value_list_test.c @@ -0,0 +1,84 @@ +/** + * collectd - src/utils/value_list/value_list_test.c + * Copyright (C) 2013-2023 Florian octo Forster + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * Florian octo Forster + */ + +#include "utils/value_list/value_list.h" +#include "testing.h" + +DEF_TEST(parse_values) { + struct { + char buffer[64]; + int status; + gauge_t value; + } cases[] = { + {"1435044576:42", 0, 42.0}, {"1435044576:42:23", -1, NAN}, + {"1435044576:U", 0, NAN}, {"N:12.3", 0, 12.3}, + {"N:42.0:23", -1, NAN}, {"N:U", 0, NAN}, + {"T:42.0", -1, NAN}, + }; + + for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) { + data_source_t dsrc = { + .name = "value", + .type = DS_TYPE_GAUGE, + .min = 0.0, + .max = NAN, + }; + data_set_t ds = { + .type = "example", + .ds_num = 1, + .ds = &dsrc, + }; + + value_t v = { + .gauge = NAN, + }; + value_list_t vl = { + .values = &v, + .values_len = 1, + .time = 0, + .interval = 0, + .host = "example.com", + .plugin = "common_test", + .type = "example", + .meta = NULL, + }; + + int status = parse_values(cases[i].buffer, &vl, &ds); + EXPECT_EQ_INT(cases[i].status, status); + if (status != 0) + continue; + + EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge); + } + + return 0; +} + +int main(void) { + RUN_TEST(parse_values); + + END_TEST; +} From 9be4f1bc128bb05c075b3703ff2337ad23ba4252 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 15:20:50 +0100 Subject: [PATCH 5/8] intel_rdt plugin: Add the `value_list` utility to the unit test. --- Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 19ed9a253d..5b69283c90 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1224,10 +1224,12 @@ intel_rdt_la_LIBADD = $(BUILD_WITH_LIBPQOS_LIBS) test_plugin_intel_rdt_SOURCES = \ src/intel_rdt_test.c \ + src/daemon/configfile.c \ + src/daemon/types_list.c \ src/utils/config_cores/config_cores.c \ src/utils/proc_pids/proc_pids.c \ - src/daemon/configfile.c \ - src/daemon/types_list.c + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h test_plugin_intel_rdt_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQOS_CPPFLAGS) test_plugin_intel_rdt_LDFLAGS = $(AM_LDFLAGS) $(BUILD_WITH_LIBPQOS_LDFLAGS) test_plugin_intel_rdt_LDADD = liboconfig.la libplugin_mock.la $(BUILD_WITH_LIBPQOS_LIBS) From 9c0d50e78cffe7029079e25655cd2b14f3c01590 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 19:53:02 +0100 Subject: [PATCH 6/8] Link `value_list` into `libplugin_mock`. This is much simpler than adding the .c and .h files into all individual tests. --- Makefile.am | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5b69283c90..5d506584ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -384,8 +384,7 @@ test_utils_message_parser_SOURCES = \ src/utils/tail/tail.c src/utils/tail/tail.h \ src/utils/match/match.c src/utils/match/match.h \ src/utils/latency/latency.c src/utils/latency/latency.h \ - src/utils/latency/latency_config.c src/utils/latency/latency_config.h \ - src/utils/value_list/value_list.c src/utils/value_list/value_list.h + src/utils/latency/latency_config.c src/utils/latency/latency_config.h test_utils_message_parser_CPPFLAGS = $(AM_CPPFLAGS) test_utils_message_parser_LDADD = liboconfig.la libplugin_mock.la -lm @@ -448,7 +447,9 @@ libplugin_mock_la_SOURCES = \ src/daemon/utils_complain.c \ src/daemon/utils_complain.h \ src/daemon/utils_time.c \ - src/daemon/utils_time.h + src/daemon/utils_time.h \ + src/utils/value_list/value_list.c \ + src/utils/value_list/value_list.h libplugin_mock_la_CPPFLAGS = $(AM_CPPFLAGS) -DMOCK_TIME libplugin_mock_la_LIBADD = libcommon.la libignorelist.la libmetadata.la $(COMMON_LIBS) @@ -498,9 +499,7 @@ test_format_json_LDADD = \ endif if BUILD_PLUGIN_CEPH -test_plugin_ceph_SOURCES = src/ceph_test.c \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h +test_plugin_ceph_SOURCES = src/ceph_test.c test_plugin_ceph_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) test_plugin_ceph_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) test_plugin_ceph_LDADD = libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS) @@ -547,8 +546,6 @@ libcmds_la_LIBADD = -lm test_utils_cmds_SOURCES = \ src/utils/cmds/cmds_test.c \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h \ src/testing.h test_utils_cmds_LDADD = \ libcmds.la \ @@ -953,9 +950,7 @@ curl_json_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) test_plugin_curl_json_SOURCES = src/curl_json_test.c \ src/daemon/configfile.c \ src/daemon/types_list.c \ - src/utils/curl_stats/curl_stats.c \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h + src/utils/curl_stats/curl_stats.c test_plugin_curl_json_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) test_plugin_curl_json_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) test_plugin_curl_json_LDADD = libavltree.la liboconfig.la libplugin_mock.la $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS) @@ -1227,9 +1222,7 @@ test_plugin_intel_rdt_SOURCES = \ src/daemon/configfile.c \ src/daemon/types_list.c \ src/utils/config_cores/config_cores.c \ - src/utils/proc_pids/proc_pids.c \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h + src/utils/proc_pids/proc_pids.c test_plugin_intel_rdt_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQOS_CPPFLAGS) test_plugin_intel_rdt_LDFLAGS = $(AM_LDFLAGS) $(BUILD_WITH_LIBPQOS_LDFLAGS) test_plugin_intel_rdt_LDADD = liboconfig.la libplugin_mock.la $(BUILD_WITH_LIBPQOS_LIBS) @@ -1356,9 +1349,7 @@ test_plugin_logparser_SOURCES = src/logparser_test.c \ src/utils/match/match.c src/utils/match/match.h \ src/utils/message_parser/message_parser.c \ src/utils_tail_match.c src/utils_tail_match.h \ - src/utils/tail/tail.c src/utils/tail/tail.h \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h + src/utils/tail/tail.c src/utils/tail/tail.h test_plugin_logparser_CPPFLAGS = $(AM_CPPFLAGS) test_plugin_logparser_LDFLAGS = $(PLUGIN_LDFLAGS) test_plugin_logparser_LDADD = liboconfig.la libplugin_mock.la liblatency.la From cdcad26798a8933622b51e1b1de33af6d4478ea4 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 23:09:29 +0100 Subject: [PATCH 7/8] curl_json plugin: Remove `value_list` from build deps. --- Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5d506584ed..38b4a701f2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -939,9 +939,7 @@ pkglib_LTLIBRARIES += curl_json.la curl_json_la_SOURCES = \ src/curl_json.c \ src/utils/curl_stats/curl_stats.c \ - src/utils/curl_stats/curl_stats.h \ - src/utils/value_list/value_list.c \ - src/utils/value_list/value_list.h + src/utils/curl_stats/curl_stats.h curl_json_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS) curl_json_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS) curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS) From f8ab28ead87cc2b8d523df8b21890ce8cff594f5 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 18 Dec 2023 23:09:47 +0100 Subject: [PATCH 8/8] ./contrib/format.sh src/utils/value_list/value_list_test.c --- src/utils/value_list/value_list_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/value_list/value_list_test.c b/src/utils/value_list/value_list_test.c index 016890551b..07b8856832 100644 --- a/src/utils/value_list/value_list_test.c +++ b/src/utils/value_list/value_list_test.c @@ -24,8 +24,8 @@ * Florian octo Forster */ -#include "utils/value_list/value_list.h" #include "testing.h" +#include "utils/value_list/value_list.h" DEF_TEST(parse_values) { struct {