Skip to content

Commit

Permalink
DAOS-16781 client: Allow daos_metrics read via pid (#15448)
Browse files Browse the repository at this point in the history
In cases where the client telemetry has been manually
enabled, daos_metrics should be able to read it as
long as the client's PID is known and the user has
read access to the shared memory segment.

Moves the daos_metrics utility into the common daos
package for use from both server and client sides.

Required-githooks: true

Change-Id: Ibdcbb88de450b02bf31513ca7fadf9d73f16bd97
Signed-off-by: Michael MacDonald <[email protected]>
  • Loading branch information
mjmac committed Nov 7, 2024
1 parent 46b5d32 commit 1992c4f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
1 change: 0 additions & 1 deletion debian/daos-server.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ usr/bin/daos_server_helper
# set daos_server to be setgid daos_server in order to invoke daos_server_helper
usr/bin/daos_server
usr/bin/daos_engine
usr/bin/daos_metrics
usr/bin/ddb
usr/lib64/daos_srv/libchk.so
usr/lib64/daos_srv/libcont.so
Expand Down
1 change: 1 addition & 0 deletions debian/daos.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/bin/daos_metrics
etc/daos/memcheck-cart.supp
# Certificate generation files
usr/lib64/daos/certgen/*
Expand Down
11 changes: 2 additions & 9 deletions src/client/api/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ bool daos_client_metric_retain;
* root/job_id/pid/....
*/

static int
shm_key(pid_t pid)
{
/* Set the key based on our pid so that it can be easily found. */
return pid - D_TM_SHARED_MEMORY_KEY;
}

static int
shm_chown(key_t key, uid_t new_owner)
{
Expand Down Expand Up @@ -73,7 +66,7 @@ init_root(const char *name, pid_t pid, int flags)
key_t key;
int rc;

key = shm_key(pid);
key = d_tm_cli_pid_key(pid);
rc = d_tm_init_with_name(key, MAX_IDS_SIZE(INIT_JOB_NUM), flags, name);
if (rc != 0) {
DL_ERROR(rc, "failed to initialize root for %s.", name);
Expand Down Expand Up @@ -214,7 +207,7 @@ dump_tm_file(const char *dump_dir)
filter = D_TM_COUNTER | D_TM_DURATION | D_TM_TIMESTAMP | D_TM_MEMINFO |
D_TM_TIMER_SNAPSHOT | D_TM_GAUGE | D_TM_STATS_GAUGE;

ctx = d_tm_open(shm_key(pid));
ctx = d_tm_open(d_tm_cli_pid_key(pid));
if (ctx == NULL)
D_GOTO(close, rc = -DER_NOMEM);

Expand Down
12 changes: 12 additions & 0 deletions src/gurt/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -3929,6 +3929,18 @@ d_tm_get_srv_key(int srv_idx)
return D_TM_SHARED_MEMORY_KEY + srv_idx;
}

key_t
d_tm_cli_pid_key(pid_t pid)
{
/*
* Set the key based the pid so that it can be easily found.
* NB: This is the inverse of d_tm_get_srv_key() above; we
* do it this way to hide the implementation details and avoid
* unnecessary code changes.
*/
return pid - D_TM_SHARED_MEMORY_KEY;
}

/**
* Allocates a shared memory segment for a given key.
*
Expand Down
4 changes: 4 additions & 0 deletions src/include/gurt/telemetry_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ struct d_tm_nodeList_t {
struct d_tm_context;

key_t d_tm_get_srv_key(int srv_idx);
key_t
d_tm_cli_pid_key(int pid);

struct d_tm_node_t *d_tm_follow_link(struct d_tm_context *ctx,
struct d_tm_node_t *link);
int d_tm_list_add_node(struct d_tm_node_t *src,
Expand All @@ -266,4 +269,5 @@ double d_tm_compute_standard_dev(double sum_of_squares, uint64_t sample_size,
double mean);
void d_tm_compute_histogram(struct d_tm_node_t *node, uint64_t value);
void d_tm_print_stats(FILE *stream, struct d_tm_stats_t *stats, int format);

#endif /* __TELEMETRY_COMMON_H__ */
13 changes: 11 additions & 2 deletions src/utils/daos_metrics/daos_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ print_usage(const char *prog_name)
"--reset, -e\n"
"\tReset all metrics to zero\n"
"--jobid, -j\n"
"\tDisplay metrics of the specified job\n",
"\tDisplay metrics of the specified job (if agent-managed)\n"
"--cli_pid, -P\n"
"\tDisplay metrics of the specified client process\n",
prog_name);
}

Expand Down Expand Up @@ -125,6 +127,7 @@ main(int argc, char **argv)
{
char dirname[D_TM_MAX_NAME_LEN] = {0};
char jobid[D_TM_MAX_NAME_LEN] = {0};
int cli_pid = 0;
bool show_meta = false;
bool show_when_read = false;
bool show_type = false;
Expand Down Expand Up @@ -158,10 +161,11 @@ main(int argc, char **argv)
{"read", no_argument, NULL, 'r'},
{"reset", no_argument, NULL, 'e'},
{"jobid", required_argument, NULL, 'j'},
{"cli_pid", required_argument, NULL, 'P'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}};

opt = getopt_long_only(argc, argv, "S:cCdtsgi:p:D:MmTrj:he", long_options, NULL);
opt = getopt_long_only(argc, argv, "S:cCdtsgi:p:D:MmTrj:P:he", long_options, NULL);
if (opt == -1)
break;

Expand Down Expand Up @@ -214,6 +218,9 @@ main(int argc, char **argv)
case 'j':
snprintf(jobid, sizeof(jobid), "%s", optarg);
break;
case 'P':
cli_pid = atoi(optarg);
break;
case 'h':
case '?':
default:
Expand Down Expand Up @@ -244,6 +251,8 @@ main(int argc, char **argv)
if (strlen(jobid) > 0) {
srv_idx = DC_TM_JOB_ROOT_ID;
snprintf(dirname, sizeof(dirname), "%s", jobid);
} else if (cli_pid > 0) {
srv_idx = d_tm_cli_pid_key(cli_pid);
}

/* fetch metrics from server side */
Expand Down
2 changes: 1 addition & 1 deletion utils/rpms/daos.spec
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ getent passwd daos_agent >/dev/null || useradd -s /sbin/nologin -r -g daos_agent
%{_sysconfdir}/bash_completion.d/daos.bash
# Certificate generation files
%dir %{_libdir}/%{name}
%{_bindir}/daos_metrics
%{_libdir}/%{name}/certgen/
%{_libdir}/%{name}/VERSION
%{_libdir}/libcart.so.*
Expand All @@ -443,7 +444,6 @@ getent passwd daos_agent >/dev/null || useradd -s /sbin/nologin -r -g daos_agent
# and/or daos_firmware_helper
%attr(2755,root,daos_server) %{_bindir}/daos_server
%{_bindir}/daos_engine
%{_bindir}/daos_metrics
%{_bindir}/ddb
%{_sysconfdir}/ld.so.conf.d/daos.conf
%dir %{_libdir}/daos_srv
Expand Down

0 comments on commit 1992c4f

Please sign in to comment.