diff --git a/ldms/src/sampler/json/Plugin_json_stream_sampler.man b/ldms/src/sampler/json/Plugin_json_stream_sampler.man index 746f9f6e3..b89bed07c 100644 --- a/ldms/src/sampler/json/Plugin_json_stream_sampler.man +++ b/ldms/src/sampler/json/Plugin_json_stream_sampler.man @@ -71,6 +71,14 @@ The encoding of all JSON types except strings, dictionaries and lists is straightfoward. The coding of Strings, Lists and Dictionaries have additional limitations as described below. +.SS "Stream Meta-data" +.PP +Stream events include the user-id, and group-id of the application +publishing the stream data. This data is encoded in the metric set +with the special names \fBS_uid\fR, and \fBS_gid\fR respectively. The +intention is that this data can stored in rows as configured by the +user with a decomposition configuration. + .SS "Encoding Strings" Strings are encoded as LDMS_V_BYTE_ARRAY. By default, the length of the array is 255 unless an attribute with the name \fINAME\fR_max_len @@ -117,6 +125,8 @@ results in a metric set as follows: .nf $ ldms_ls -h localhost -p 10411 -a munge -E example -l ovs-5416_example: consistent, last update: Sat Aug 05 11:38:26 2023 -0500 [281178us] +D s32 S_uid 1002 +D s32 S_gid 1002 D s64 component_id 10001 D s64 job_id 2048 D list<> seq [1,2,3] @@ -145,6 +155,8 @@ results in the following LDMS metric set. .RS 4 .nf ovs-5416_dict: consistent, last update: Sat Aug 05 21:14:38 2023 -0500 [839029us] +D s32 S_uid 1002 +D s32 S_gid 1002 M record_type a_dict_record LDMS_V_RECORD_TYPE D record[] a_dict attr_2 attr_1 @@ -179,6 +191,8 @@ results in the following LDMS metric set. .RS 4 .nf ovs-5416_dict_list: consistent, last update: Sat Aug 05 21:23:11 2023 -0500 [52659us] +D s32 S_uid 1002 +D s32 S_gid 1002 M record_type a_dict_list_record LDMS_V_RECORD_TYPE D list<> a_dict_list attr_2 attr_1 @@ -187,6 +201,7 @@ D list<> a_dict_list D char[] schema "dict_list" .fi .RE +.PP .SH "CONFIG OPTIONS" .TP diff --git a/ldms/src/sampler/json/json_stream_sampler.c b/ldms/src/sampler/json/json_stream_sampler.c index 41d0acb38..bd5f91350 100644 --- a/ldms/src/sampler/json/json_stream_sampler.c +++ b/ldms/src/sampler/json/json_stream_sampler.c @@ -453,7 +453,7 @@ static json_setter_t setter_table[] = { static int get_schema_for_json(char *name, json_entity_t e, ldms_schema_t *sch) { - int rc = 0; + int i, rc = 0; ldms_schema_t schema; struct schema_entry *entry; struct rbn *rbn; @@ -492,6 +492,33 @@ static int get_schema_for_json(char *name, json_entity_t e, ldms_schema_t *sch) rbt_init(&entry->attr_tree, str_cmp); rbn_init(&entry->rbn, entry->name); + /* Add the special JSON stream attributes. These special + * attributes will have metric indices of 0 (uid) and + * 1 (gid) + */ + const char *stream_meta_attr[] = { "S_uid", "S_gid" }; + for (i = 0; i < sizeof(stream_meta_attr) / sizeof(stream_meta_attr[0]); i++) { + midx = ldms_schema_metric_add(schema, stream_meta_attr[i], LDMS_V_S32); + if (midx < 0) + goto err_3; + ae = calloc(1, sizeof(*ae)); + if (!ae) { + rc = errno; + goto err_3; + } + ae->name = strdup(stream_meta_attr[i]); + if (!ae->name) { + rc = ENOMEM; + free(ae); + goto err_3; + } + ae->type = JSON_INT_VALUE; + ae->ridx = -1; + ae->midx = midx; + rbn_init(&ae->rbn, ae->name); + rbt_ins(&entry->attr_tree, &ae->rbn); + } + for (json_attr = json_attr_first(e); json_attr; json_attr = json_attr_next(json_attr)) { @@ -552,6 +579,7 @@ static int get_schema_for_json(char *name, json_entity_t e, ldms_schema_t *sch) ae->name = strdup(json_attr_name(json_attr)->str); if (!ae->name) { rc = ENOMEM; + free(ae); goto err_3; } ae->type = type; @@ -774,7 +802,6 @@ static void update_set_data(struct json_cfg_inst *inst, entry = container_of(rbn, struct schema_entry, rbn); } - ldms_transaction_begin(set); for (json_attr = json_attr_first(entity); json_attr; json_attr = json_attr_next(json_attr)) { @@ -808,7 +835,6 @@ static void update_set_data(struct json_cfg_inst *inst, if (rc) LERROR("Error %d setting the metric value '%s'\n", rc, ae->name); } - ldms_transaction_end(set); } static int json_recv_cb(ldms_stream_event_t ev, void *arg) @@ -865,7 +891,14 @@ static int json_recv_cb(ldms_stream_event_t ev, void *arg) } } free(set_name); + + /* Update the stream meta-data in the set */ + ldms_transaction_begin(set); + ldms_metric_set_s32(set, 0, ev->recv.cred.uid); + ldms_metric_set_s32(set, 1, ev->recv.cred.gid); update_set_data(inst, set, entity); + ldms_transaction_end(set); + pthread_mutex_unlock(&inst->lock); return 0; err_1: