@cryptotaxi247 / netdata-1 / commits / 8fe7485a6

Switching over to soft feature flag (#8545)

Preparing for the cloud release. This changes how we handle the feature flag so that it no longer requires installer switches and can be set from the config file. This still requires internal access to use and is not ready for public access yet.

Andrew Moss committed Mar 31, 2020 at 21:19 UTC 8fe7485a600f60be9ac20af923a61d516cb0335e
14 files changed +98 -45
Makefile.am
+11 -9
@@ -469,14 +469,18 @@ BACKENDS_PLUGIN_FILES = \
469 backends/prometheus/backend_prometheus.h \
470 $(NULL)
471
472 -CLAIM_PLUGIN_FILES = \
472 +CLAIM_FILES = \
473 claim/claim.c \
474 claim/claim.h \
475 $(NULL)
476
477 -ACLK_PLUGIN_FILES = \
477 +ACLK_FILES = \
478 aclk/aclk_common.c \
479 aclk/aclk_common.h \
480 + $(NULL)
481 +
482 +if ENABLE_ACLK
483 +ACLK_FILES += \
484 aclk/agent_cloud_link.c \
485 aclk/agent_cloud_link.h \
486 aclk/mqtt.c \
@@ -486,6 +490,9 @@ ACLK_PLUGIN_FILES = \
490 aclk/aclk_lws_https_client.c \
491 aclk/aclk_lws_https_client.h \
492 $(NULL)
493 +endif
494 +
495 +
496
497 EXPORTING_ENGINE_FILES = \
498 exporting/exporting_engine.c \
@@ -575,15 +582,10 @@ NETDATA_FILES = \
582 $(STREAMING_PLUGIN_FILES) \
583 $(STATSD_PLUGIN_FILES) \
584 $(WEB_PLUGIN_FILES) \
578 - $(CLAIM_PLUGIN_FILES) \
585 + $(CLAIM_FILES) \
586 + $(ACLK_FILES) \
587 $(NULL)
588
581 -if ENABLE_ACLK
582 - NETDATA_FILES += \
583 - $(ACLK_PLUGIN_FILES) \
584 - $(NULL)
585 -endif
586 -
589 if FREEBSD
590 NETDATA_FILES += \
591 $(FREEBSD_PLUGIN_FILES) \
aclk/agent_cloud_link.c
+7
@@ -1309,6 +1309,10 @@ void *aclk_main(void *ptr)
1309 struct netdata_static_thread *query_thread;
1310
1311 netdata_thread_cleanup_push(aclk_main_cleanup, ptr);
1312 + if (!netdata_cloud_setting) {
1313 + info("Killing ACLK thread -> cloud functionality has been disabled");
1314 + return NULL;
1315 + }
1316
1317 info("Waiting for netdata to be ready");
1318 while (!netdata_ready) {
@@ -1755,6 +1759,9 @@ int aclk_update_chart(RRDHOST *host, char *chart_name, ACLK_CMD aclk_cmd)
1759 UNUSED(chart_name);
1760 return 0;
1761 #else
1762 + if (!netdata_cloud_setting)
1763 + return 0;
1764 +
1765 if (host != localhost)
1766 return 0;
1767
claim/claim.c
+6 -4
@@ -41,11 +41,12 @@ extern struct registry registry;
41 /* rrd_init() must have been called before this function */
42 void claim_agent(char *claiming_arguments)
43 {
44 -#ifndef ENABLE_CLOUD
45 - info("The claiming feature has been disabled");
46 - return;
47 -#endif
44 + if (!netdata_cloud_setting) {
45 + error("Refusing to claim agent -> cloud functionality has been disabled");
46 + return;
47 + }
48
49 +#ifndef DISABLE_CLOUD
50 int exit_code;
51 pid_t command_pid;
52 char command_buffer[CLAIMING_COMMAND_LENGTH + 1];
@@ -106,6 +107,7 @@ void claim_agent(char *claiming_arguments)
107 }
108 error("Agent failed to be claimed with the following error message:");
109 error("\"%s\"", claiming_errors[exit_code]);
110 +#endif
111 }
112
113 void load_claiming_state(void)
configure.ac
+15 -9
@@ -169,19 +169,18 @@ AC_ARG_ENABLE(
169 [cloud],
170 [AS_HELP_STRING([--disable-cloud],
171 [Disables all cloud functionality])],
172 - [],
173 - [enable_cloud="no"]
172 + [ enable_cloud="$enableval" ],
173 + [ enable_cloud="yes" ]
174 )
175
176 AC_MSG_CHECKING([if cloud functionality should be enabled])
177 -if test "${enable_cloud}" != "no"; then
178 - AC_DEFINE([ENABLE_CLOUD], [1], [netdata cloud functionality])
179 - aclk_required="detect"
180 -else
177 +if test "${enable_cloud}" = "no"; then
178 + AC_DEFINE([DISABLE_CLOUD], [1], [disable netdata cloud functionality])
179 aclk_required="no"
180 +else
181 + aclk_required="detect"
182 fi
183 AC_MSG_RESULT([${enable_cloud}])
184 -AM_CONDITIONAL([ENABLE_CLOUD], [test "${enable_cloud}" = "yes"])
184
185 # -----------------------------------------------------------------------------
186 # netdata required checks
@@ -557,9 +556,16 @@ AM_CONDITIONAL([ENABLE_CAPABILITY], [test "${with_libcap}" = "yes"])
556 # ACLK
557
558 if test "$enable_cloud" = "yes"; then
560 - AC_MSG_CHECKING([if libmosquitto static lib is present])
559 + AC_MSG_CHECKING([if libmosquitto static lib is present (and builds)])
560 if test -f "externaldeps/mosquitto/libmosquitto.a"; then
562 - HAVE_libmosquitto_a="yes"
561 + LIBS_SAVES="$LIBS"
562 + LIBS="externaldeps/mosquitto/libmosquitto.a"
563 + AC_LINK_IFELSE([AC_LANG_SOURCE([[int main (int argc, char **argv)) {
564 + int m,mm,r;
565 + mosquitto_lib_version(&m, &mm, &r);
566 + }]]),
567 + [HAVE_libmosquitto_a="yes"],
568 + [HAVE_libmosquitto_a="no"]])
569 else
570 HAVE_libmosquitto_a="no"
571 AC_DEFINE([ACLK_NO_LIBMOSQ], [1], [Libmosquitto.a was not found during build.])
daemon/commands.c
+5 -1
@@ -186,7 +186,7 @@ static cmd_status_t cmd_reload_claiming_state_execute(char *args, char **message
186 (void)args;
187 (void)message;
188
189 -#ifndef ENABLE_CLOUD
189 +#ifdef DISABLE_CLOUD
190 info("The claiming feature has been disabled");
191 return CMD_STATUS_FAILURE;
192 #endif
@@ -194,6 +194,10 @@ static cmd_status_t cmd_reload_claiming_state_execute(char *args, char **message
194 info("Cloud functionality is not enabled because of missing dependencies at build-time.");
195 return CMD_STATUS_FAILURE;
196 #endif
197 + if (!netdata_cloud_setting) {
198 + error("Cannot reload claiming status -> cloud functionality has been disabled");
199 + return CMD_STATUS_FAILURE;
200 + }
201
202 error_log_limit_unlimited();
203 info("COMMAND: Reloading Agent Claiming configuration.");
daemon/common.c
+2
@@ -14,3 +14,5 @@ char *netdata_configured_home_dir = CACHE_DIR;
14 char *netdata_configured_host_prefix = NULL;
15 char *netdata_configured_timezone = NULL;
16 int netdata_ready;
17 +int netdata_cloud_setting;
18 +
daemon/common.h
+1
@@ -88,5 +88,6 @@ extern int netdata_zero_metrics_enabled;
88 extern int netdata_anonymous_statistics_enabled;
89
90 extern int netdata_ready;
91 +extern int netdata_cloud_setting;
92
93 #endif /* NETDATA_COMMON_H */
daemon/main.c
+15
@@ -575,6 +575,21 @@ static void get_netdata_configured_variables() {
575 get_system_HZ();
576 get_system_cpus();
577 get_system_pid_max();
578 +
579 + // --------------------------------------------------------------------
580 + // Check if the cloud is enabled
581 +#ifdef DISABLE_CLOUD
582 + netdata_cloud_setting = 0;
583 +#else
584 + char *cloud = config_get(CONFIG_SECTION_GLOBAL, "netdata cloud", "coming soon");
585 + if (!strcmp(cloud, "coming soon")) {
586 + netdata_cloud_setting = 0; // Note: this flips to 1 after the release
587 + } else if (!strcmp(cloud, "enable")) {
588 + netdata_cloud_setting = 1;
589 + } else if (!strcmp(cloud, "disable")) {
590 + netdata_cloud_setting = 0;
591 + }
592 +#endif
593 }
594
595 static void get_system_timezone(void) {
database/rrddim.c
+14 -7
@@ -184,7 +184,8 @@ void rrdcalc_link_to_rrddim(RRDDIM *rd, RRDSET *st, RRDHOST *host) {
184 }
185 }
186 #ifdef ENABLE_ACLK
187 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
187 + if (netdata_cloud_setting)
188 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
189 #endif
190 }
191
@@ -428,7 +429,8 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
429 }
430 rrdset_unlock(st);
431 #ifdef ENABLE_ACLK
431 - aclk_update_chart(host, st->id, ACLK_CMD_CHART);
432 + if (netdata_cloud_setting)
433 + aclk_update_chart(host, st->id, ACLK_CMD_CHART);
434 #endif
435 return(rd);
436 }
@@ -484,7 +486,8 @@ void rrddim_free(RRDSET *st, RRDDIM *rd)
486 break;
487 }
488 #ifdef ENABLE_ACLK
487 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
489 + if (netdata_cloud_setting)
490 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
491 #endif
492 }
493
@@ -505,7 +508,8 @@ int rrddim_hide(RRDSET *st, const char *id) {
508
509 rrddim_flag_set(rd, RRDDIM_FLAG_HIDDEN);
510 #ifdef ENABLE_ACLK
508 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
511 + if (netdata_cloud_setting)
512 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
513 #endif
514 return 0;
515 }
@@ -522,7 +526,8 @@ int rrddim_unhide(RRDSET *st, const char *id) {
526
527 rrddim_flag_clear(rd, RRDDIM_FLAG_HIDDEN);
528 #ifdef ENABLE_ACLK
525 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
529 + if (netdata_cloud_setting)
530 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
531 #endif
532 return 0;
533 }
@@ -533,7 +538,8 @@ inline void rrddim_is_obsolete(RRDSET *st, RRDDIM *rd) {
538 rrddim_flag_set(rd, RRDDIM_FLAG_OBSOLETE);
539 rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE_DIMENSIONS);
540 #ifdef ENABLE_ACLK
536 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
541 + if (netdata_cloud_setting)
542 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
543 #endif
544 }
545
@@ -542,7 +548,8 @@ inline void rrddim_isnot_obsolete(RRDSET *st __maybe_unused, RRDDIM *rd) {
548
549 rrddim_flag_clear(rd, RRDDIM_FLAG_OBSOLETE);
550 #ifdef ENABLE_ACLK
545 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
551 + if (netdata_cloud_setting)
552 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHART);
553 #endif
554 }
555
database/rrdset.c
+8 -4
@@ -425,8 +425,10 @@ void rrdset_delete(RRDSET *st) {
425
426 recursively_delete_dir(st->cache_dir, "left-over chart");
427 #ifdef ENABLE_ACLK
428 - aclk_del_collector(st->rrdhost->hostname, st->plugin_name, st->module_name);
429 - aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHARTDEL);
428 + if (netdata_cloud_setting) {
429 + aclk_del_collector(st->rrdhost->hostname, st->plugin_name, st->module_name);
430 + aclk_update_chart(st->rrdhost, st->id, ACLK_CMD_CHARTDEL);
431 + }
432 #endif
433 }
434
@@ -768,8 +770,10 @@ RRDSET *rrdset_create_custom(
770
771 rrdhost_unlock(host);
772 #ifdef ENABLE_ACLK
771 - aclk_add_collector(host->hostname, plugin, module);
772 - aclk_update_chart(host, st->id, ACLK_CMD_CHART);
773 + if (netdata_cloud_setting) {
774 + aclk_add_collector(host->hostname, plugin, module);
775 + aclk_update_chart(host, st->id, ACLK_CMD_CHART);
776 + }
777 #endif
778 return(st);
779 }
health/health.c
+6 -3
@@ -180,7 +180,8 @@ void health_reload_host(RRDHOST *host) {
180 */
181 void health_reload(void) {
182 #ifdef ENABLE_ACLK
183 - aclk_single_update_disable();
183 + if (netdata_cloud_setting)
184 + aclk_single_update_disable();
185 #endif
186 rrd_rdlock();
187
@@ -190,8 +191,10 @@ void health_reload(void) {
191
192 rrd_unlock();
193 #ifdef ENABLE_ACLK
193 - aclk_single_update_enable();
194 - aclk_alarm_reload();
194 + if (netdata_cloud_setting) {
195 + aclk_single_update_enable();
196 + aclk_alarm_reload();
197 + }
198 #endif
199 }
200
health/health_log.c
+2 -1
@@ -153,7 +153,8 @@ inline void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae) {
153 }
154 }
155 #ifdef ENABLE_ACLK
156 - aclk_update_alarm(host, ae);
156 + if (netdata_cloud_setting)
157 + aclk_update_alarm(host, ae);
158 #endif
159 }
160
netdata-installer.sh
-4
@@ -283,10 +283,6 @@ while [ -n "${1}" ]; do
283 NETDATA_DISABLE_CLOUD=1
284 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-cloud/} --disable-cloud"
285 ;;
286 - "--cloud-testing") # Temporary, until we flip the feature flag. Internal use only
287 - unset NETDATA_DISABLE_CLOUD
288 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-cloud/} --enable-cloud"
289 - ;;
286 "--install")
287 NETDATA_PREFIX="${2}/netdata"
288 shift 1
web/api/web_api_v1.c
+6 -3
@@ -862,10 +862,13 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
862 chartcollectors2json(host, wb);
863 buffer_strcat(wb, "\n\t],\n");
864
865 -#ifdef ENABLE_CLOUD
866 - buffer_strcat(wb, "\t\"cloud-enabled\": true,\n");
867 -#else
865 +#ifdef DISABLE_CLOUD
866 buffer_strcat(wb, "\t\"cloud-enabled\": false,\n");
867 +#else
868 + if (netdata_cloud_setting)
869 + buffer_strcat(wb, "\t\"cloud-enabled\": true,\n");
870 + else
871 + buffer_strcat(wb, "\t\"cloud-enabled\": false,\n");
872 #endif
873 #ifdef ENABLE_ACLK
874 buffer_strcat(wb, "\t\"cloud-available\": true,\n");