Skip to content

Commit fb05bb7

Browse files
committed
feat: add uuid logic to health file generation
1 parent cbbc448 commit fb05bb7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

axiom/util_health.c

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <time.h>
1414

1515
#include "util_health.h"
16+
#include "nr_uuid.h"
1617
#include "util_memory.h"
1718
#include "util_strings.h"
1819
#include "util_syscalls.h"
@@ -48,15 +49,33 @@ static nrhealth_t last_error_code = NRH_HEALTHY;
4849
static char health_uuid[] = "bc21b5891f5e44fc9272caef924611a8";
4950

5051
nr_status_t nrh_set_uuid(char* uuid) {
52+
char* rand_uuid = NULL;
53+
if (NULL == uuid) {
54+
// no uuid supplied, auto-generate instead
55+
rand_uuid = nr_uuid_create(-1);
56+
uuid = rand_uuid;
57+
}
58+
5159
if (UUID_LEN != nr_strlen(uuid)) {
5260
return NR_FAILURE;
5361
}
5462

5563
nr_strlcpy(&health_uuid[0], uuid, UUID_LEN + 1);
5664

65+
nr_free(rand_uuid);
5766
return NR_SUCCESS;
5867
}
5968

69+
char* nrh_get_uuid(void) {
70+
if (UUID_LEN != nr_strlen(health_uuid)) {
71+
// handle edge case that uuid is not currently set
72+
// or is set improperly
73+
return NULL;
74+
}
75+
76+
return nr_strdup(health_uuid);
77+
}
78+
6079
char* nrh_strip_scheme_prefix(char* uri) {
6180
char* filedir = NULL;
6281
int prefix_len = nr_strlen("file://");

axiom/util_health.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ typedef enum _nrhealth_t {
3232
/* utility */
3333
extern char* nrh_strip_scheme_prefix(char* uri);
3434
extern nr_status_t nrh_write_health(char* uri);
35-
extern char* nrh_generate_uuid(void);
3635

3736
/* getters */
3837
extern char* nrh_get_health_location(char* uri);
@@ -41,6 +40,7 @@ extern char* nrh_get_health_filename(void);
4140
extern long long nrh_get_start_time_ns(void);
4241
extern long long nrh_get_current_time_ns(void);
4342
extern nrhealth_t nrh_get_last_error(void);
43+
extern char* nrh_get_uuid(void);
4444

4545
/* setters */
4646
extern nr_status_t nrh_set_start_time(void);

0 commit comments

Comments
 (0)