status file v21 (#19928)
* do not report CI jobs * make version 21 * make sure the machine guid filename is available on start * fix crash * remove machine guid maintenance from registry and make sure it never fails * cleanup * polishing and cleanup * fix portability of struct stat timestamps * increase stack traces provider buffer
Costa Tsaousis committed
Mar 21, 2025 at 22:42 UTC
7439280f57ebee3d1a01dcbafe438c4661123a6e
17 files changed
+325
-105
CMakeLists.txt
+2
@@ -1276,6 +1276,8 @@ set(DAEMON_FILES
1276
src/daemon/config/netdata-conf-ssl.h
1277
src/daemon/daemon-systemd-watcher.c
1278
src/daemon/daemon-systemd-watcher.h
1279
+ src/daemon/machine-guid.c
1280
+ src/daemon/machine-guid.h
1281
)
1282
1283
set(H2O_FILES
src/claim/claim-with-api.c
+1
-1
@@ -380,7 +380,7 @@ bool claim_agent(const char *url, const char *token, const char *rooms, const ch
380
bool done = false, can_retry = true;
381
size_t retries = 0;
382
do {
383
- done = send_curl_request(registry_get_this_machine_guid(true), registry_get_this_machine_hostname(), token, rooms, url, proxy, insecure, &can_retry);
383
+ done = send_curl_request(machine_guid_get_txt(), registry_get_this_machine_hostname(), token, rooms, url, proxy, insecure, &can_retry);
384
if (done) break;
385
sleep_usec(300 * USEC_PER_MS + 100 * retries * USEC_PER_MS);
386
retries++;
src/claim/cloud-conf.c
+1
-1
@@ -79,7 +79,7 @@ void cloud_conf_init_after_registry(void) {
79
80
// for machine guid and hostname we have to use inicfg_set() for that they will be saved uncommented
81
if(!machine_guid || !*machine_guid)
82
- inicfg_set(&cloud_config, CONFIG_SECTION_GLOBAL, "machine_guid", registry_get_this_machine_guid(true));
82
+ inicfg_set(&cloud_config, CONFIG_SECTION_GLOBAL, "machine_guid", machine_guid_get_txt());
83
84
if(!hostname || !*hostname)
85
inicfg_set(&cloud_config, CONFIG_SECTION_GLOBAL, "hostname", registry_get_this_machine_hostname());
src/daemon/config/netdata-conf-global.c
+8
-6
@@ -88,14 +88,9 @@ void libuv_initialize(void) {
88
setenv("UV_THREADPOOL_SIZE", buf, 1);
89
}
90
91
-void netdata_conf_section_global(void) {
91
+void netdata_conf_section_global_hostname(void) {
92
FUNCTION_RUN_ONCE();
93
94
- netdata_conf_section_directories();
95
-
96
- // ------------------------------------------------------------------------
97
- // get the hostname
98
-
94
netdata_configured_host_prefix = inicfg_get(&netdata_config, CONFIG_SECTION_GLOBAL, "host access prefix", "");
95
(void) verify_netdata_host_prefix(true);
96
@@ -105,6 +100,13 @@ void netdata_conf_section_global(void) {
100
101
netdata_configured_hostname = inicfg_get(&netdata_config, CONFIG_SECTION_GLOBAL, "hostname", buf);
102
netdata_log_debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
103
+}
104
+
105
+void netdata_conf_section_global(void) {
106
+ FUNCTION_RUN_ONCE();
107
+
108
+ netdata_conf_section_directories();
109
+ netdata_conf_section_global_hostname();
110
111
nd_profile_setup(); // required for configuring the database
112
netdata_conf_section_db();
src/daemon/config/netdata-conf-global.h
+1
@@ -7,6 +7,7 @@
7
8
void netdata_conf_section_global(void);
9
void netdata_conf_section_global_run_as_user(const char **user);
10
+void netdata_conf_section_global_hostname(void);
11
12
size_t netdata_conf_cpus(void);
13
void libuv_initialize(void);
src/daemon/daemon-status-file.c
+40
-13
@@ -539,11 +539,10 @@ static void daemon_status_file_migrate_once(void) {
539
session_status.node_id = last_session_status.node_id;
540
session_status.host_id = last_session_status.host_id;
541
if(UUIDiszero(session_status.host_id)) {
542
- const char *machine_guid = registry_get_this_machine_guid(false);
543
- if(machine_guid && *machine_guid) {
544
- if (uuid_parse_flexi(machine_guid, session_status.host_id.uuid) != 0)
545
- session_status.host_id = UUID_ZERO;
546
- }
542
+ if(!UUIDiszero(last_session_status.host_id))
543
+ session_status.host_id = last_session_status.host_id;
544
+ else
545
+ session_status.host_id = machine_guid_get()->uuid;
546
}
547
548
strncpyz(session_status.architecture, last_session_status.architecture, sizeof(session_status.architecture) - 1);
@@ -610,6 +609,7 @@ static void daemon_status_file_refresh(DAEMON_STATUS status) {
609
if(session_status.status == DAEMON_STATUS_EXITING)
610
session_status.timings.exit = (time_t)((now_ut - session_status.timings.exit_started_ut + USEC_PER_SEC/2) / USEC_PER_SEC);
611
612
+ session_status.host_id = machine_guid_get()->uuid;
613
session_status.boottime = now_boottime_sec();
614
session_status.uptime = now_realtime_sec() - netdata_start_time;
615
session_status.timestamp_ut = now_ut;
@@ -1027,8 +1027,30 @@ struct log_priority PRI_DEADLY_SIGNAL = { NDLP_CRIT, NDLP_CRIT };
1027
struct log_priority PRI_KILLED_HARD = { NDLP_ERR, NDLP_WARNING };
1028
1029
static bool is_ci(void) {
1030
- const char *ci = getenv("CI");
1031
- return ci && *ci && strcasecmp(ci, "true") == 0;
1030
+ // List of known CI environment variables.
1031
+ const char *ci_vars[] = {
1032
+ "CI", // Generic CI flag
1033
+ "TRAVIS", // Travis CI
1034
+ "GITHUB_ACTIONS", // GitHub Actions
1035
+ "GITLAB_CI", // GitLab CI
1036
+ "CIRCLECI", // CircleCI
1037
+ "APPVEYOR", // AppVeyor
1038
+ NULL
1039
+ };
1040
+
1041
+ // Iterate over the CI environment variable names.
1042
+ for (const char **env = ci_vars; *env; env++) {
1043
+ const char *val = getenv(*env);
1044
+ if (val && *val &&
1045
+ (strcasecmp(val, "true") == 0 ||
1046
+ strcasecmp(val, "yes") == 0 ||
1047
+ strcasecmp(val, "on") == 0 ||
1048
+ strcasecmp(val, "1") == 0)) {
1049
+ return true;
1050
+ }
1051
+ }
1052
+
1053
+ return false;
1054
}
1055
1056
enum crash_report_t {
@@ -1269,13 +1291,11 @@ void daemon_status_file_check_crash(void) {
1291
if( // must be first for netdata.conf option to be used
1292
(r == DSF_REPORT_ALL || (this_is_a_crash && r == DSF_REPORT_CRASHES)) &&
1293
1272
- // we have a previous status, or we managed to save the current one
1273
- (!no_previous_status || daemon_status_file_saved) &&
1274
-
1275
- // we are not running in CI
1276
- (last_session_status.restarts >= 10 || !is_ci()) &&
1294
+ // we have a previous status, or
1295
+ // (we managed to save the current one, and (we have more than 2 restarts, or this is not a CI run))
1296
+ (!no_previous_status || (daemon_status_file_saved && (last_session_status.restarts > 2 || !is_ci()))) &&
1297
1278
- // we have not already reported this
1298
+ // we have not reported this
1299
!dedup_already_posted(&session_status, daemon_status_file_hash(&last_session_status, msg, cause), false)
1300
1301
) {
@@ -1624,3 +1644,10 @@ size_t daemon_status_file_get_restarts(void) {
1644
ssize_t daemon_status_file_get_reliability(void) {
1645
return session_status.reliability;
1646
}
1647
+
1648
+ND_UUID daemon_status_file_get_host_id(void) {
1649
+ if(!UUIDiszero(session_status.host_id))
1650
+ return session_status.host_id;
1651
+ else
1652
+ return last_session_status.host_id;
1653
+}
src/daemon/daemon-status-file.h
+3
-2
@@ -7,7 +7,7 @@
7
#include "daemon/config/netdata-conf-profile.h"
8
#include "database/rrd-database-mode.h"
9
10
-#define STATUS_FILE_VERSION 20
10
+#define STATUS_FILE_VERSION 21
11
12
typedef enum {
13
DAEMON_STATUS_NONE,
@@ -79,7 +79,7 @@ typedef struct daemon_status_file {
79
char cloud_instance_region[32];
80
bool read_system_info;
81
82
- char stack_traces[15]; // the backend for capturing stack traces
82
+ char stack_traces[63]; // the backend for capturing stack traces
83
84
struct {
85
SPINLOCK spinlock;
@@ -149,5 +149,6 @@ long daemon_status_file_get_fatal_line(void);
149
DAEMON_STATUS daemon_status_file_get_status(void);
150
size_t daemon_status_file_get_restarts(void);
151
ssize_t daemon_status_file_get_reliability(void);
152
+ND_UUID daemon_status_file_get_host_id(void);
153
154
#endif //NETDATA_DAEMON_STATUS_FILE_H
src/daemon/daemon.h
+2
@@ -3,6 +3,8 @@
3
#ifndef NETDATA_DAEMON_H
4
#define NETDATA_DAEMON_H 1
5
6
+#include "machine-guid.h"
7
+
8
int become_daemon(int dont_fork, const char *user);
9
10
void get_netdata_execution_path(void);
src/daemon/machine-guid.c
new
+212
@@ -0,0 +1,212 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#include "common.h"
4
+#include "machine-guid.h"
5
+
6
+static bool machine_guid_check_blacklisted(const char *guid) {
7
+ // these are machine GUIDs that have been included in distribution packages.
8
+ // we blacklist them here, so that the next version of netdata will generate
9
+ // new ones.
10
+
11
+ static char *blacklisted[] = {
12
+ "8a795b0c-2311-11e6-8563-000c295076a6",
13
+ "4aed1458-1c3e-11e6-a53f-000c290fc8f5",
14
+ };
15
+
16
+ for(size_t i = 0; i < _countof(blacklisted); i++) {
17
+ if (!strcmp(guid, blacklisted[i])) {
18
+ nd_log(NDLS_DAEMON, NDLP_INFO, "MACHINE_GUID: blacklisted machine GUID '%s' found, generating new one.", guid);
19
+ return true;
20
+ }
21
+ }
22
+
23
+ return false;
24
+}
25
+
26
+static bool machine_guid_read_from_file(const char *filename, ND_MACHINE_GUID *host_id) {
27
+ if (!filename || !*filename)
28
+ return false;
29
+
30
+ ND_MACHINE_GUID h;
31
+ memset(&h, 0, sizeof(h));
32
+
33
+ int fd = open(filename, O_RDONLY | O_CLOEXEC);
34
+ if (fd == -1) {
35
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot open GUID file '%s' for reading", filename);
36
+ return false;
37
+ }
38
+
39
+ if (read(fd, h.txt, sizeof(h.txt) - 1) != sizeof(h.txt) - 1) {
40
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot read GUID file '%s'", filename);
41
+ close(fd);
42
+ return false;
43
+ }
44
+ h.txt[sizeof(h.txt) - 1] = '\0';
45
+
46
+ if (uuid_parse(h.txt, h.uuid.uuid) != 0) {
47
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot parse GUID from file '%s'", filename);
48
+ close(fd);
49
+ return false;
50
+ }
51
+
52
+ if (UUIDiszero(h.uuid)) {
53
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: GUID read from file '%s' is zero", filename);
54
+ close(fd);
55
+ return false;
56
+ }
57
+
58
+ struct stat st;
59
+ if (fstat(fd, &st) != 0) {
60
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot stat the GUID file '%s'", filename);
61
+ close(fd);
62
+ return false;
63
+ }
64
+ close(fd);
65
+
66
+ // Recreate the text version of it, ensuring lowercase format.
67
+ uuid_unparse_lower(h.uuid.uuid, h.txt);
68
+
69
+ if (machine_guid_check_blacklisted(h.txt))
70
+ return false;
71
+
72
+ // Update last modified timestamp.
73
+ h.last_modified_ut = STAT_GET_MTIME_SEC(st) * USEC_PER_SEC + STAT_GET_MTIME_NSEC(st) / 1000;
74
+ *host_id = h;
75
+
76
+ nd_log(NDLS_DAEMON, NDLP_INFO, "MACHINE_GUID: GUID read from file '%s'", filename);
77
+
78
+ return true;
79
+}
80
+
81
+static struct timespec usec_to_timespec(usec_t usec) {
82
+ struct timespec ts;
83
+ ts.tv_sec = usec / USEC_PER_SEC;
84
+ ts.tv_nsec = (usec % USEC_PER_SEC) * 1000;
85
+ return ts;
86
+}
87
+
88
+static bool machine_guid_write_to_file(const char *filename, ND_MACHINE_GUID *host_id) {
89
+ static size_t save_id = 0;
90
+
91
+ if (!filename || !*filename)
92
+ return false;
93
+
94
+ ND_MACHINE_GUID h;
95
+ memset(&h, 0, sizeof(h));
96
+
97
+ if (host_id) {
98
+ h.uuid = host_id->uuid;
99
+ h.last_modified_ut = host_id->last_modified_ut;
100
+ }
101
+
102
+ // Create the text representation before writing.
103
+ uuid_unparse_lower(h.uuid.uuid, h.txt);
104
+
105
+ // Use a temporary filename for atomic writes.
106
+ char tmp_filename[FILENAME_MAX];
107
+ snprintf(tmp_filename, sizeof(tmp_filename), "%s.%zu", filename, __atomic_add_fetch(&save_id, 1, __ATOMIC_RELAXED));
108
+
109
+ int fd = open(tmp_filename, O_WRONLY | O_CREAT | O_TRUNC, 0444);
110
+ if (fd == -1) {
111
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot create the temporary GUID file '%s'", tmp_filename);
112
+ return false;
113
+ }
114
+
115
+ if (write(fd, h.txt, sizeof(h.txt) - 1) != sizeof(h.txt) - 1) {
116
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot write GUID to the temporary GUID file '%s'", tmp_filename);
117
+ close(fd);
118
+ return false;
119
+ }
120
+
121
+ close(fd);
122
+
123
+ struct timespec times[2] = {
124
+ usec_to_timespec(h.last_modified_ut), // access time
125
+ usec_to_timespec(h.last_modified_ut), // modification time
126
+ };
127
+
128
+ // Update file timestamps.
129
+ if (utimensat(AT_FDCWD, tmp_filename, times, 0) < 0)
130
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot update the timestamps of the temporary GUID file '%s'", tmp_filename);
131
+
132
+ // Rename the temporary file to the target filename atomically.
133
+ if (rename(tmp_filename, filename) != 0) {
134
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot rename temporary GUID file '%s' to '%s'", tmp_filename, filename);
135
+ unlink(tmp_filename);
136
+ return false;
137
+ }
138
+
139
+ nd_log(NDLS_DAEMON, NDLP_INFO, "MACHINE_GUID: GUID saved to file '%s'", filename);
140
+
141
+ return true;
142
+}
143
+
144
+static ND_MACHINE_GUID nd_machine_guid = { 0 };
145
+
146
+static ND_MACHINE_GUID machine_guid_get_or_create(void) {
147
+ char pathname[FILENAME_MAX];
148
+ char filename[FILENAME_MAX];
149
+
150
+ netdata_conf_section_directories();
151
+
152
+ ND_MACHINE_GUID h;
153
+ memset(&h, 0, sizeof(h));
154
+
155
+ // Build the file path.
156
+ snprintfz(pathname, sizeof(pathname), "%s/registry", netdata_configured_varlib_dir);
157
+ snprintfz(filename, sizeof(filename), "%s/%s", pathname, "netdata.public.unique.id");
158
+
159
+ // Attempt to read the GUID from the file.
160
+ if (machine_guid_read_from_file(filename, &h))
161
+ return h;
162
+
163
+ // Log failure to read the file.
164
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: failed to read GUID from file '%s'", filename);
165
+
166
+ // Attempt to retrieve GUID from daemon status file.
167
+ h.uuid = daemon_status_file_get_host_id();
168
+ if (UUIDiszero(h.uuid)) {
169
+ // If the status file does not contain a GUID, generate a new one.
170
+ nd_log(NDLS_DAEMON, NDLP_INFO, "MACHINE_GUID: generating a new GUID");
171
+ uuid_generate_time(h.uuid.uuid);
172
+ }
173
+ else
174
+ nd_log(NDLS_DAEMON, NDLP_INFO, "MACHINE_GUID: got previous GUID from daemon status file");
175
+
176
+ // Ensure the text representation is updated.
177
+ uuid_unparse_lower(h.uuid.uuid, h.txt);
178
+ h.last_modified_ut = now_realtime_usec();
179
+ nd_machine_guid = h;
180
+
181
+ // Ensure the registry directory exists.
182
+ if (access(pathname, W_OK) != 0) {
183
+ nd_log(NDLS_DAEMON, NDLP_DEBUG, "MACHINE_GUID: cannot access directory '%s'. Attempting to create it.", pathname);
184
+
185
+ errno_clear();
186
+ if (mkdir(pathname, 0775) != 0 && errno != EEXIST) {
187
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot create directory '%s'", pathname);
188
+ // Even if directory creation fails, continue with in-memory GUID.
189
+ return h;
190
+ }
191
+ }
192
+
193
+ errno_clear();
194
+ if (!machine_guid_write_to_file(filename, &h))
195
+ nd_log(NDLS_DAEMON, NDLP_ERR, "MACHINE_GUID: cannot save GUID to file '%s'", filename);
196
+
197
+ return h;
198
+}
199
+
200
+ND_MACHINE_GUID *machine_guid_get(void) {
201
+ if(UUIDiszero(nd_machine_guid.uuid)) {
202
+ nd_machine_guid = machine_guid_get_or_create();
203
+ nd_setenv("NETDATA_REGISTRY_UNIQUE_ID", nd_machine_guid.txt, 1);
204
+ }
205
+
206
+ return &nd_machine_guid;
207
+}
208
+
209
+const char *machine_guid_get_txt(void) {
210
+ ND_MACHINE_GUID *h = machine_guid_get();
211
+ return h->txt;
212
+}
src/daemon/machine-guid.h
new
+17
@@ -0,0 +1,17 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef NETDATA_MACHINE_GUID_H
4
+#define NETDATA_MACHINE_GUID_H
5
+
6
+#include "libnetdata/libnetdata.h"
7
+
8
+typedef struct nd_machine_guid {
9
+ char txt[UUID_STR_LEN];
10
+ ND_UUID uuid;
11
+ usec_t last_modified_ut;
12
+} ND_MACHINE_GUID;
13
+
14
+ND_MACHINE_GUID *machine_guid_get(void);
15
+const char *machine_guid_get_txt(void);
16
+
17
+#endif //NETDATA_MACHINE_GUID_H
src/daemon/main.c
+3
-4
@@ -767,6 +767,7 @@ int netdata_main(int argc, char **argv) {
767
// initialize the logging system
768
// IMPORTANT: KEEP THIS FIRST SO THAT THE REST OF NETDATA WILL LOG PROPERLY
769
770
+ netdata_conf_section_directories();
771
netdata_conf_section_logs();
772
nd_log_limits_unlimited();
773
nd_log_initialize();
@@ -775,6 +776,7 @@ int netdata_main(int argc, char **argv) {
776
// this MUST be before anything else - to load the old status file before saving a new one
777
778
daemon_status_file_init(); // this loads the old file
779
+ machine_guid_get(); // after loading the old daemon status file - we may need the machine guid from it
780
nd_log_register_fatal_hook_cb(daemon_status_file_register_fatal);
781
nd_log_register_fatal_final_cb(fatal_status_file_save);
782
exit_initiated_init();
@@ -1018,11 +1020,8 @@ int netdata_main(int argc, char **argv) {
1020
cloud_conf_init_after_registry();
1021
netdata_random_session_id_generate();
1022
1021
- const char *guid = registry_get_this_machine_guid(true);
1023
#ifdef ENABLE_SENTRY
1023
- nd_sentry_set_user(guid);
1024
-#else
1025
- UNUSED(guid);
1024
+ nd_sentry_set_user(machine_guid_get_txt());
1025
#endif
1026
1027
// ----------------------------------------------------------------------------------------------------------------
src/database/rrd.c
+1
-1
@@ -121,7 +121,7 @@ int rrd_init(const char *hostname, struct rrdhost_system_info *system_info, bool
121
localhost = rrdhost_create(
122
hostname
123
, registry_get_this_machine_hostname()
124
- , registry_get_this_machine_guid(true)
124
+ , machine_guid_get_txt()
125
, os_type
126
, netdata_configured_timezone
127
, netdata_configured_abbrev_timezone
src/libnetdata/common.h
+21
@@ -468,6 +468,27 @@ typedef uint32_t uid_t;
468
// #include <winternl.h> // conflicts on STRING,
469
#endif
470
471
+// --------------------------------------------------------------------------------------------------------------------
472
+
473
+/* Define a portable way to access st_mtim across Unix variants */
474
+#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L
475
+/* POSIX.1-2008 compliant systems have st_mtim */
476
+#define STAT_GET_MTIME_SEC(st) ((st).st_mtim.tv_sec)
477
+#define STAT_GET_MTIME_NSEC(st) ((st).st_mtim.tv_nsec)
478
+#elif defined(__APPLE__) || defined(__darwin__) || defined(__MACH__)
479
+/* macOS has st_mtimespec */
480
+#define STAT_GET_MTIME_SEC(st) ((st).st_mtimespec.tv_sec)
481
+#define STAT_GET_MTIME_NSEC(st) ((st).st_mtimespec.tv_nsec)
482
+#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__)
483
+/* BSD systems typically have st_mtim or provide a compatibility layer */
484
+#define STAT_GET_MTIME_SEC(st) ((st).st_mtim.tv_sec)
485
+#define STAT_GET_MTIME_NSEC(st) ((st).st_mtim.tv_nsec)
486
+#else
487
+/* Fallback for systems with only second precision */
488
+#define STAT_GET_MTIME_SEC(st) ((st).st_mtime)
489
+#define STAT_GET_MTIME_NSEC(st) (0)
490
+#endif
491
+
492
# ifdef __cplusplus
493
}
494
# endif
src/registry/registry.h
+1
-1
@@ -55,6 +55,7 @@
55
56
// initialize the registry
57
// should only happen when netdata starts
58
+void netdata_conf_section_registry(void);
59
void registry_init(void);
60
bool registry_load(void);
61
@@ -75,7 +76,6 @@ void registry_update_cloud_base_url();
76
// update the registry monitoring charts
77
void registry_statistics(void);
78
78
-const char *registry_get_this_machine_guid(bool create_it);
79
char *registry_get_mgmt_api_key(void);
80
const char *registry_get_this_machine_hostname(void);
81
src/registry/registry_init.c
+12
-8
@@ -62,10 +62,11 @@ void registry_generate_curl_urls(void) {
62
fclose(fp);
63
}
64
65
-void registry_init(void) {
65
+void netdata_conf_section_registry(void) {
66
FUNCTION_RUN_ONCE();
67
68
- netdata_conf_section_global();
68
+ netdata_conf_section_directories();
69
+ netdata_conf_section_global_hostname();
70
71
char filename[FILENAME_MAX + 1];
72
@@ -82,12 +83,8 @@ void registry_init(void) {
83
// path names
84
snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir);
85
registry.pathname = inicfg_get(&netdata_config, CONFIG_SECTION_DIRECTORIES, "registry", filename);
85
- verify_required_directory(NULL, registry.pathname, true, 0770);
86
87
// filenames
88
- snprintfz(filename, FILENAME_MAX, "%s/netdata.public.unique.id", registry.pathname);
89
- registry.machine_guid_filename = inicfg_get(&netdata_config, CONFIG_SECTION_REGISTRY, "netdata unique id file", filename);
90
-
88
snprintfz(filename, FILENAME_MAX, "%s/registry.db", registry.pathname);
89
registry.db_filename = inicfg_get(&netdata_config, CONFIG_SECTION_REGISTRY, "registry db file", filename);
90
@@ -96,8 +93,7 @@ void registry_init(void) {
93
94
// configuration options
95
registry.save_registry_every_entries = (unsigned long long)inicfg_get_number(&netdata_config, CONFIG_SECTION_REGISTRY, "registry save db every new entries", 1000000);
99
- registry.persons_expiration = inicfg_get_duration_days_to_seconds(
100
- &netdata_config, CONFIG_SECTION_REGISTRY, "registry expire idle persons", 365 * 86400);
96
+ registry.persons_expiration = inicfg_get_duration_days_to_seconds(&netdata_config, CONFIG_SECTION_REGISTRY, "registry expire idle persons", 365 * 86400);
97
registry.registry_domain = inicfg_get(&netdata_config, CONFIG_SECTION_REGISTRY, "registry domain", "");
98
registry.registry_to_announce = inicfg_get(&netdata_config, CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io");
99
registry.hostname = inicfg_get(&netdata_config, CONFIG_SECTION_REGISTRY, "registry hostname", netdata_configured_hostname);
@@ -119,6 +115,14 @@ void registry_init(void) {
115
registry.max_name_length = 10;
116
inicfg_set_number(&netdata_config, CONFIG_SECTION_REGISTRY, "max URL name length", (long long)registry.max_name_length);
117
}
118
+}
119
+
120
+void registry_init(void) {
121
+ FUNCTION_RUN_ONCE();
122
+
123
+ netdata_conf_section_registry();
124
+
125
+ verify_required_directory(NULL, registry.pathname, true, 0770);
126
127
// initialize entries counters
128
registry.persons_count = 0;
src/registry/registry_internals.c
-67
@@ -249,74 +249,7 @@ REGISTRY_MACHINE *registry_request_machine(const char *person_guid, char *reques
249
250
251
// ----------------------------------------------------------------------------
252
-// REGISTRY THIS MACHINE UNIQUE ID
253
-
254
-static inline int is_machine_guid_blacklisted(const char *guid) {
255
- // these are machine GUIDs that have been included in distribution packages.
256
- // we blacklist them here, so that the next version of netdata will generate
257
- // new ones.
258
-
259
- if(!strcmp(guid, "8a795b0c-2311-11e6-8563-000c295076a6")
260
- || !strcmp(guid, "4aed1458-1c3e-11e6-a53f-000c290fc8f5")
261
- ) {
262
- netdata_log_error("Blacklisted machine GUID '%s' found.", guid);
263
- return 1;
264
- }
265
-
266
- return 0;
267
-}
252
253
const char *registry_get_this_machine_hostname(void) {
254
return registry.hostname;
255
}
272
-
273
-const char *registry_get_this_machine_guid(bool create_it) {
274
- static char guid[GUID_LEN + 1] = "";
275
-
276
- if(likely(guid[0]))
277
- return guid;
278
-
279
- // read it from disk
280
- int fd = open(registry.machine_guid_filename, O_RDONLY | O_CLOEXEC);
281
- if(fd != -1) {
282
- char buf[GUID_LEN + 1];
283
- if(read(fd, buf, GUID_LEN) != GUID_LEN)
284
- netdata_log_error("Failed to read machine GUID from '%s'", registry.machine_guid_filename);
285
- else {
286
- buf[GUID_LEN] = '\0';
287
- if(regenerate_guid(buf, guid) == -1) {
288
- netdata_log_error("Failed to validate machine GUID '%s' from '%s'. Ignoring it - this might mean this netdata will appear as duplicate in the registry.",
289
- buf, registry.machine_guid_filename);
290
-
291
- guid[0] = '\0';
292
- }
293
- else if(is_machine_guid_blacklisted(guid))
294
- guid[0] = '\0';
295
- }
296
- close(fd);
297
- }
298
-
299
- // generate a new one?
300
- if(!guid[0] && create_it) {
301
- nd_uuid_t uuid;
302
-
303
- uuid_generate_time(uuid);
304
- uuid_unparse_lower(uuid, guid);
305
- guid[GUID_LEN] = '\0';
306
-
307
- // save it
308
- fd = open(registry.machine_guid_filename, O_WRONLY|O_CREAT|O_TRUNC | O_CLOEXEC, 444);
309
- if(fd == -1)
310
- fatal("Cannot create unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
311
-
312
- if(write(fd, guid, GUID_LEN) != GUID_LEN)
313
- fatal("Cannot write the unique machine id file '%s'. Please fix this.", registry.machine_guid_filename);
314
-
315
- close(fd);
316
- }
317
-
318
- if(guid[0])
319
- nd_setenv("NETDATA_REGISTRY_UNIQUE_ID", guid, 1);
320
-
321
- return guid;
322
-}
src/registry/registry_internals.h
-1
@@ -45,7 +45,6 @@ struct registry {
45
const char *pathname;
46
const char *db_filename;
47
const char *log_filename;
48
- const char *machine_guid_filename;
48
49
// open files
50
FILE *log_fp;