summaryrefslogtreecommitdiffstats
path: root/libnetdata/config
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:47 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-06-09 04:52:57 +0000
commit00151562145df50cc65e9902d52d5fa77f89fe50 (patch)
tree2737716802f6725a5074d606ec8fe5422c58a83c /libnetdata/config
parentReleasing debian version 1.34.1-1. (diff)
downloadnetdata-00151562145df50cc65e9902d52d5fa77f89fe50.tar.xz
netdata-00151562145df50cc65e9902d52d5fa77f89fe50.zip
Merging upstream version 1.35.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libnetdata/config')
-rw-r--r--libnetdata/config/appconfig.c121
-rw-r--r--libnetdata/config/appconfig.h32
2 files changed, 99 insertions, 54 deletions
diff --git a/libnetdata/config/appconfig.c b/libnetdata/config/appconfig.c
index 0daa6e5e4..0272877bf 100644
--- a/libnetdata/config/appconfig.c
+++ b/libnetdata/config/appconfig.c
@@ -257,6 +257,54 @@ void appconfig_section_destroy_non_loaded(struct config *root, const char *secti
freez(co);
}
+void appconfig_section_option_destroy_non_loaded(struct config *root, const char *section, const char *name)
+{
+ debug(D_CONFIG, "Destroying section option '%s -> %s'.", section, name);
+
+ struct section *co;
+ co = appconfig_section_find(root, section);
+ if (!co) {
+ error("Could not destroy section option '%s -> %s'. The section not found.", section, name);
+ return;
+ }
+
+ config_section_wrlock(co);
+
+ struct config_option *cv;
+
+ cv = appconfig_option_index_find(co, name, simple_hash(name));
+
+ if (cv && cv->flags & CONFIG_VALUE_LOADED) {
+ config_section_unlock(co);
+ return;
+ }
+
+ if (unlikely(!(cv && appconfig_option_index_del(co, cv)))) {
+ config_section_unlock(co);
+ error("Could not destroy section option '%s -> %s'. The option not found.", section, name);
+ return;
+ }
+
+ if (co->values == cv) {
+ co->values = co->values->next;
+ } else {
+ struct config_option *cv_cur = co->values, *cv_prev = NULL;
+ while (cv_cur && cv_cur != cv) {
+ cv_prev = cv_cur;
+ cv_cur = cv_cur->next;
+ }
+ if (cv_cur) {
+ cv_prev->next = cv_cur->next;
+ }
+ }
+
+ freez(cv->value);
+ freez(cv->name);
+ freez(cv);
+
+ config_section_unlock(co);
+ return;
+}
// ----------------------------------------------------------------------------
// config name-value methods
@@ -757,49 +805,40 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
struct section *co;
struct config_option *cv;
- for(i = 0; i < 3 ;i++) {
- switch(i) {
- case 0:
- buffer_strcat(wb,
- "# netdata configuration\n"
- "#\n"
- "# You can download the latest version of this file, using:\n"
- "#\n"
- "# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
- "# or\n"
- "# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
- "#\n"
- "# You can uncomment and change any of the options below.\n"
- "# The value shown in the commented settings, is the default value.\n"
- "#\n"
- "\n# global netdata configuration\n");
- break;
-
- case 1:
- buffer_strcat(wb, "\n\n# per plugin configuration\n");
- break;
-
- case 2:
- buffer_strcat(wb, "\n\n# per chart configuration\n");
- break;
- }
-
+ buffer_strcat(wb,
+ "# netdata configuration\n"
+ "#\n"
+ "# You can download the latest version of this file, using:\n"
+ "#\n"
+ "# wget -O /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
+ "# or\n"
+ "# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf\n"
+ "#\n"
+ "# You can uncomment and change any of the options below.\n"
+ "# The value shown in the commented settings, is the default value.\n"
+ "#\n"
+ "\n# global netdata configuration\n");
+
+ for(i = 0; i <= 15 ;i++) {
appconfig_wrlock(root);
for(co = root->first_section; co ; co = co->next) {
- if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)
- || !strcmp(co->name, CONFIG_SECTION_WEB)
- || !strcmp(co->name, CONFIG_SECTION_STATSD)
- || !strcmp(co->name, CONFIG_SECTION_PLUGINS)
- || !strcmp(co->name, CONFIG_SECTION_CLOUD)
- || !strcmp(co->name, CONFIG_SECTION_REGISTRY)
- || !strcmp(co->name, CONFIG_SECTION_HEALTH)
- || !strcmp(co->name, CONFIG_SECTION_STREAM)
- || !strcmp(co->name, CONFIG_SECTION_HOST_LABEL)
- || !strcmp(co->name, CONFIG_SECTION_ML)
- )
- pri = 0;
- else if(!strncmp(co->name, "plugin:", 7)) pri = 1;
- else pri = 2;
+ if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)) pri = 0;
+ else if(!strcmp(co->name, CONFIG_SECTION_DIRECTORIES)) pri = 1;
+ else if(!strcmp(co->name, CONFIG_SECTION_LOGS)) pri = 2;
+ else if(!strcmp(co->name, CONFIG_SECTION_ENV_VARS)) pri = 3;
+ else if(!strcmp(co->name, CONFIG_SECTION_HOST_LABEL)) pri = 4;
+ else if(!strcmp(co->name, CONFIG_SECTION_SQLITE)) pri = 5;
+ else if(!strcmp(co->name, CONFIG_SECTION_CLOUD)) pri = 6;
+ else if(!strcmp(co->name, CONFIG_SECTION_ML)) pri = 7;
+ else if(!strcmp(co->name, CONFIG_SECTION_HEALTH)) pri = 8;
+ else if(!strcmp(co->name, CONFIG_SECTION_WEB)) pri = 9;
+ // by default, new sections will get pri = 10 (set at the end, below)
+ else if(!strcmp(co->name, CONFIG_SECTION_REGISTRY)) pri = 11;
+ else if(!strcmp(co->name, CONFIG_SECTION_GLOBAL_STATISTICS)) pri = 12;
+ else if(!strcmp(co->name, CONFIG_SECTION_PLUGINS)) pri = 13;
+ else if(!strcmp(co->name, CONFIG_SECTION_STATSD)) pri = 14;
+ else if(!strncmp(co->name, "plugin:", 7)) pri = 15; // << change the loop too if you change this
+ else pri = 10; // this is used for any new (currently unknown) sections
if(i == pri) {
int loaded = 0;
diff --git a/libnetdata/config/appconfig.h b/libnetdata/config/appconfig.h
index b5cf77419..f1f61e31d 100644
--- a/libnetdata/config/appconfig.h
+++ b/libnetdata/config/appconfig.h
@@ -82,19 +82,24 @@
#define CONFIG_FILENAME "netdata.conf"
-#define CONFIG_SECTION_GLOBAL "global"
-#define CONFIG_SECTION_WEB "web"
-#define CONFIG_SECTION_STATSD "statsd"
-#define CONFIG_SECTION_PLUGINS "plugins"
-#define CONFIG_SECTION_CLOUD "cloud"
-#define CONFIG_SECTION_REGISTRY "registry"
-#define CONFIG_SECTION_HEALTH "health"
-#define CONFIG_SECTION_STREAM "stream"
-#define CONFIG_SECTION_ML "ml"
-#define CONFIG_SECTION_EXPORTING "exporting:global"
-#define CONFIG_SECTION_PROMETHEUS "prometheus:exporter"
-#define CONFIG_SECTION_HOST_LABEL "host labels"
-#define EXPORTING_CONF "exporting.conf"
+#define CONFIG_SECTION_GLOBAL "global"
+#define CONFIG_SECTION_DIRECTORIES "directories"
+#define CONFIG_SECTION_LOGS "logs"
+#define CONFIG_SECTION_ENV_VARS "environment variables"
+#define CONFIG_SECTION_SQLITE "sqlite"
+#define CONFIG_SECTION_WEB "web"
+#define CONFIG_SECTION_STATSD "statsd"
+#define CONFIG_SECTION_PLUGINS "plugins"
+#define CONFIG_SECTION_CLOUD "cloud"
+#define CONFIG_SECTION_REGISTRY "registry"
+#define CONFIG_SECTION_HEALTH "health"
+#define CONFIG_SECTION_STREAM "stream"
+#define CONFIG_SECTION_ML "ml"
+#define CONFIG_SECTION_EXPORTING "exporting:global"
+#define CONFIG_SECTION_PROMETHEUS "prometheus:exporter"
+#define CONFIG_SECTION_HOST_LABEL "host labels"
+#define EXPORTING_CONF "exporting.conf"
+#define CONFIG_SECTION_GLOBAL_STATISTICS "global statistics"
// these are used to limit the configuration names and values lengths
// they are not enforced by config.c functions (they will strdup() all strings, no matter of their length)
@@ -183,6 +188,7 @@ extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed
extern int appconfig_section_compare(void *a, void *b);
extern void appconfig_section_destroy_non_loaded(struct config *root, const char *section);
+extern void appconfig_section_option_destroy_non_loaded(struct config *root, const char *section, const char *name);
extern int config_parse_duration(const char* string, int* result);