Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add uuid logic to health file generation
  • Loading branch information
bduranleau-nr committed Apr 8, 2025
commit fb05bb7f7c0209e6d1201457d21d531ff3fd9cb2
19 changes: 19 additions & 0 deletions axiom/util_health.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <time.h>

#include "util_health.h"
#include "nr_uuid.h"
#include "util_memory.h"
#include "util_strings.h"
#include "util_syscalls.h"
Expand Down Expand Up @@ -48,15 +49,33 @@ static nrhealth_t last_error_code = NRH_HEALTHY;
static char health_uuid[] = "bc21b5891f5e44fc9272caef924611a8";

nr_status_t nrh_set_uuid(char* uuid) {
char* rand_uuid = NULL;
if (NULL == uuid) {
// no uuid supplied, auto-generate instead
rand_uuid = nr_uuid_create(-1);
uuid = rand_uuid;
}

if (UUID_LEN != nr_strlen(uuid)) {
return NR_FAILURE;
}

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

nr_free(rand_uuid);
return NR_SUCCESS;
}

char* nrh_get_uuid(void) {
if (UUID_LEN != nr_strlen(health_uuid)) {
// handle edge case that uuid is not currently set
// or is set improperly
return NULL;
}

return nr_strdup(health_uuid);
}

char* nrh_strip_scheme_prefix(char* uri) {
char* filedir = NULL;
int prefix_len = nr_strlen("file://");
Expand Down
2 changes: 1 addition & 1 deletion axiom/util_health.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ typedef enum _nrhealth_t {
/* utility */
extern char* nrh_strip_scheme_prefix(char* uri);
extern nr_status_t nrh_write_health(char* uri);
extern char* nrh_generate_uuid(void);

/* getters */
extern char* nrh_get_health_location(char* uri);
Expand All @@ -41,6 +40,7 @@ extern char* nrh_get_health_filename(void);
extern long long nrh_get_start_time_ns(void);
extern long long nrh_get_current_time_ns(void);
extern nrhealth_t nrh_get_last_error(void);
extern char* nrh_get_uuid(void);

/* setters */
extern nr_status_t nrh_set_start_time(void);
Expand Down