@cryptotaxi247 / netdata-1 / commits / 1d23e1471

Initialize machine GUID earlier in the agent startup sequence (#14922)

* Read (cache) machine guid earlier, so that a fatal event during init will have the correct machine guid * Setup analytics global environment explicitly if we fail to initialize before localhost is created

Stelios Fragkakis committed Apr 20, 2023 at 14:15 UTC 1d23e1471cff9e0f10de8540e0f60f6d076cb18b
4 files changed +16 -12
daemon/analytics.c
+7 -7
@@ -354,16 +354,16 @@ void analytics_alarms_notifications(void)
354 buffer_free(b);
355 }
356
357 -void analytics_get_install_type(void)
357 +static void analytics_get_install_type(struct rrdhost_system_info *system_info)
358 {
359 - if (localhost->system_info->install_type == NULL) {
359 + if (system_info->install_type == NULL) {
360 analytics_set_data_str(&analytics_data.netdata_install_type, "unknown");
361 } else {
362 - analytics_set_data_str(&analytics_data.netdata_install_type, localhost->system_info->install_type);
362 + analytics_set_data_str(&analytics_data.netdata_install_type, system_info->install_type);
363 }
364
365 - if (localhost->system_info->prebuilt_dist != NULL) {
366 - analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, localhost->system_info->prebuilt_dist);
365 + if (system_info->prebuilt_dist != NULL) {
366 + analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, system_info->prebuilt_dist);
367 }
368 }
369
@@ -632,7 +632,7 @@ static const char *verify_required_directory(const char *dir)
632 * This is called after the rrdinit
633 * These values will be sent on the START event
634 */
635 -void set_late_global_environment()
635 +void set_late_global_environment(struct rrdhost_system_info *system_info)
636 {
637 analytics_set_data(&analytics_data.netdata_config_stream_enabled, default_rrdpush_enabled ? "true" : "false");
638 analytics_set_data_str(&analytics_data.netdata_config_memory_mode, (char *)rrd_memory_mode_name(default_rrd_memory_mode));
@@ -676,7 +676,7 @@ void set_late_global_environment()
676 buffer_free(bi);
677 }
678
679 - analytics_get_install_type();
679 + analytics_get_install_type(system_info);
680 }
681
682 void get_system_timezone(void)
daemon/analytics.h
+1 -1
@@ -74,7 +74,7 @@ struct analytics_data {
74 bool exporting_enabled;
75 };
76
77 -void set_late_global_environment(void);
77 +void set_late_global_environment(struct rrdhost_system_info *system_info);
78 void analytics_free_data(void);
79 void set_global_environment(void);
80 void send_statistics(const char *action, const char *action_result, const char *action_data);
daemon/main.c
+5 -3
@@ -2024,13 +2024,16 @@ int main(int argc, char **argv) {
2024 struct rrdhost_system_info *system_info = callocz(1, sizeof(struct rrdhost_system_info));
2025 __atomic_sub_fetch(&netdata_buffers_statistics.rrdhost_allocations_size, sizeof(struct rrdhost_system_info), __ATOMIC_RELAXED);
2026 get_system_info(system_info);
2027 + (void) registry_get_this_machine_guid();
2028 system_info->hops = 0;
2029 get_install_type(&system_info->install_type, &system_info->prebuilt_arch, &system_info->prebuilt_dist);
2030
2031 delta_startup_time("initialize RRD structures");
2032
2032 - if(rrd_init(netdata_configured_hostname, system_info, false))
2033 + if(rrd_init(netdata_configured_hostname, system_info, false)) {
2034 + set_late_global_environment(system_info);
2035 fatal("Cannot initialize localhost instance with name '%s'.", netdata_configured_hostname);
2036 + }
2037
2038 delta_startup_time("check for incomplete shutdown");
2039
@@ -2072,8 +2075,7 @@ int main(int argc, char **argv) {
2075
2076 netdata_zero_metrics_enabled = config_get_boolean_ondemand(CONFIG_SECTION_DB, "enable zero metrics", CONFIG_BOOLEAN_NO);
2077
2075 - set_late_global_environment();
2076 -
2078 + set_late_global_environment(system_info);
2079 for (i = 0; static_threads[i].name != NULL ; i++) {
2080 struct netdata_static_thread *st = &static_threads[i];
2081
database/rrdhost.c
+3 -1
@@ -919,8 +919,10 @@ int rrd_init(char *hostname, struct rrdhost_system_info *system_info, bool unitt
919 rrdhost_init();
920
921 if (unlikely(sql_init_database(DB_CHECK_NONE, system_info ? 0 : 1))) {
922 - if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE)
922 + if (default_rrd_memory_mode == RRD_MEMORY_MODE_DBENGINE) {
923 + set_late_global_environment(system_info);
924 fatal("Failed to initialize SQLite");
925 + }
926 info("Skipping SQLITE metadata initialization since memory mode is not dbengine");
927 }
928