Skip to content

Commit fb3d7ed

Browse files
committed
job-list: initialize queue stats
Problem: Job queue stats are generated in job-list when a job is submitted into it. If a job queue never has a job submitted to it, no job stats exist for the queue. This isn't what users would expect, they should expect queue stats to be 0 for the queue. Solution: Read the flux config and initialize queue stats to 0 for any queues that have been configured. Fixes #5688
1 parent c5e658e commit fb3d7ed

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

src/modules/job-list/job-list.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@ static void disconnect_cb (flux_t *h,
107107
job_stats_disconnect (ctx->jsctx->statsctx, msg);
108108
}
109109

110+
static void config_reload_cb (flux_t *h,
111+
flux_msg_handler_t *mh,
112+
const flux_msg_t *msg,
113+
void *arg)
114+
{
115+
struct list_ctx *ctx = arg;
116+
const flux_conf_t *conf;
117+
flux_error_t error;
118+
const char *errstr = NULL;
119+
120+
if (flux_conf_reload_decode (msg, &conf) < 0)
121+
goto error;
122+
if (job_state_config_reload (ctx->jsctx, conf, &error) < 0) {
123+
errstr = error.text;
124+
goto error;
125+
}
126+
if (flux_respond (h, msg, NULL) < 0)
127+
flux_log_error (h, "error responding to config-reload request");
128+
return;
129+
error:
130+
if (flux_respond_error (h, msg, errno, errstr) < 0)
131+
flux_log_error (h, "error responding to config-reload request");
132+
}
133+
110134
static const struct flux_msg_handler_spec htab[] = {
111135
{ .typemask = FLUX_MSGTYPE_REQUEST,
112136
.topic_glob = "job-list.list",
@@ -148,6 +172,12 @@ static const struct flux_msg_handler_spec htab[] = {
148172
.cb = disconnect_cb,
149173
.rolemask = FLUX_ROLE_USER,
150174
},
175+
{
176+
.typemask = FLUX_MSGTYPE_REQUEST,
177+
.topic_glob = "job-list.config-reload",
178+
.cb = config_reload_cb,
179+
.rolemask = 0
180+
},
151181
FLUX_MSGHANDLER_TABLE_END,
152182
};
153183

src/modules/job-list/job_state.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,13 @@ void job_state_destroy (void *data)
17981798
}
17991799
}
18001800

1801+
int job_state_config_reload (struct job_state_ctx *jsctx,
1802+
const flux_conf_t *conf,
1803+
flux_error_t *errp)
1804+
{
1805+
return job_stats_config_reload (jsctx->statsctx, conf, errp);
1806+
}
1807+
18011808
/*
18021809
* vi:tabstop=4 shiftwidth=4 expandtab
18031810
*/

src/modules/job-list/job_state.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ void job_state_unpause_cb (flux_t *h, flux_msg_handler_t *mh,
7272

7373
int job_state_init_from_kvs (struct job_state_ctx *jsctx);
7474

75+
int job_state_config_reload (struct job_state_ctx *jsctx,
76+
const flux_conf_t *conf,
77+
flux_error_t *errp);
78+
7579
#endif /* ! _FLUX_JOB_LIST_JOB_STATE_H */
7680

7781
/*

src/modules/job-list/stats.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,36 @@ static void job_stats_cb (flux_t *h,
423423
flux_log_error (h, "error responding to job-stats request");
424424
}
425425

426+
static int config_parse_queues (struct job_stats_ctx *statsctx,
427+
const flux_conf_t *conf,
428+
flux_error_t *errp)
429+
{
430+
json_t *queues;
431+
432+
if (flux_conf_unpack (conf, NULL, "{s:o}", "queues", &queues) == 0
433+
&& json_object_size (queues) > 0) {
434+
const char *name;
435+
json_t *value;
436+
json_object_foreach (queues, name, value) {
437+
/* setup initial queue stats, so that user gets initial
438+
* stats before first job is submitted to the queue */
439+
if (!queue_stats_lookup (statsctx, name, true)) {
440+
flux_log_error (statsctx->h, "queue_stats_lookup");
441+
return -1;
442+
}
443+
}
444+
}
445+
446+
return 0;
447+
}
448+
449+
int job_stats_config_reload (struct job_stats_ctx *statsctx,
450+
const flux_conf_t *conf,
451+
flux_error_t *errp)
452+
{
453+
return config_parse_queues (statsctx, conf, errp);
454+
}
455+
426456
static const struct flux_msg_handler_spec htab[] = {
427457
{ .typemask = FLUX_MSGTYPE_REQUEST,
428458
.topic_glob = "job-list.job-stats",
@@ -435,6 +465,7 @@ static const struct flux_msg_handler_spec htab[] = {
435465
struct job_stats_ctx *job_stats_ctx_create (flux_t *h)
436466
{
437467
struct job_stats_ctx *statsctx = NULL;
468+
flux_error_t error;
438469

439470
if (!(statsctx = calloc (1, sizeof (*statsctx))))
440471
return NULL;
@@ -456,6 +487,13 @@ struct job_stats_ctx *job_stats_ctx_create (flux_t *h)
456487
statsctx)))
457488
goto error;
458489

490+
if (config_parse_queues (statsctx,
491+
flux_get_conf (statsctx->h),
492+
&error) < 0) {
493+
flux_log (statsctx->h, LOG_ERR, "%s", error.text);
494+
goto error;
495+
}
496+
459497
return statsctx;
460498

461499
error:

src/modules/job-list/stats.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ void job_stats_disconnect (struct job_stats_ctx *statsctx,
5151
*/
5252
int job_stats_watchers (struct job_stats_ctx *statsctx);
5353

54+
int job_stats_config_reload (struct job_stats_ctx *statsctx,
55+
const flux_conf_t *conf,
56+
flux_error_t *errp);
57+
5458
#endif /* ! _FLUX_JOB_LIST_JOB_STATS_H */
5559

5660
// vi: ts=4 sw=4 expandtab

0 commit comments

Comments
 (0)