Skip to content

Commit

Permalink
Merge pull request collectd#4195 from octo/6/value_list
Browse files Browse the repository at this point in the history
[collectd 6] Move legacy code into its own package.
  • Loading branch information
octo authored Dec 18, 2023
2 parents 0693ea8 + f8ab28e commit 5e639b8
Show file tree
Hide file tree
Showing 12 changed files with 902 additions and 711 deletions.
28 changes: 17 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -259,7 +261,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)
Expand Down Expand Up @@ -443,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)
Expand Down Expand Up @@ -940,9 +946,9 @@ 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
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)
Expand Down Expand Up @@ -1211,10 +1217,10 @@ intel_rdt_la_LIBADD = $(BUILD_WITH_LIBPQOS_LIBS)

test_plugin_intel_rdt_SOURCES = \
src/intel_rdt_test.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/daemon/types_list.c \
src/utils/config_cores/config_cores.c \
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)
Expand Down Expand Up @@ -1336,12 +1342,12 @@ 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/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
Expand Down
121 changes: 121 additions & 0 deletions src/daemon/data_set.c
Original file line number Diff line number Diff line change
@@ -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 <octo at collectd.org>
* Sebastian Harl <sh at tokkee.org>
* Manoj Srivastava <srivasta at google.com>
**/

#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 <sys/stat.h>
#include <unistd.h>
#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 */
54 changes: 54 additions & 0 deletions src/daemon/data_set.h
Original file line number Diff line number Diff line change
@@ -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 <octo at collectd.org>
* Sebastian Harl <sh at tokkee.org>
* Manoj Srivastava <srivasta at google.com>
**/

#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 */
Loading

0 comments on commit 5e639b8

Please sign in to comment.