diff options
| author | 童宗振 <[email protected]> | 2024-04-19 03:30:51 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-04-19 03:30:51 +0000 |
| commit | f23ca6048de819961182e15ce8e0fd8de0b9cfe3 (patch) | |
| tree | 1f4ec5d8fbab47a339b54771f39ce887cf6b01e8 | |
| parent | 02248a63b89645d2a355943761b4835a2636d938 (diff) | |
| parent | 8e6c29c2c054bc25ebceff5fadb8a64bf941d66f (diff) | |
Merge branch 'mod_maat_table_info' into 'master'
Mod maat table info
See merge request tsg/dp_telemetry_app!16
| -rw-r--r-- | etc/dp_telemetry_rules.json | 3 | ||||
| -rw-r--r-- | etc/table_schema.json | 5 | ||||
| -rw-r--r-- | include/job_ctx.h | 1 | ||||
| -rw-r--r-- | src/job_ctx.c | 80 | ||||
| -rw-r--r-- | src/trace_output.c | 4 |
5 files changed, 33 insertions, 60 deletions
diff --git a/etc/dp_telemetry_rules.json b/etc/dp_telemetry_rules.json index 6623063..b7e6bd0 100644 --- a/etc/dp_telemetry_rules.json +++ b/etc/dp_telemetry_rules.json @@ -3,8 +3,7 @@ { "table_name": "DP_TRACE_TELEMETRY_TABLE", "table_content": [ - "0\t{\"job_id\":\"72694b1c-6833-4c46-acde-52e2d6409314\",\"job_name\":\"test_xx\",\"bpf_expr\":\"ip host 172.19.199.171\",\"pkt_cnt_max\":100,\"timeout\":60,\"sampling\":2,\"snaplen\":100}\t1", - "1\t{\"job_id\":\"499a49aa-b4b9-4e8e-a66c-80d4cd40257b\",\"job_name\":\"test_2\",\"bpf_expr\":\"ether host 00:15:5d:b8:10:a6\",\"pkt_cnt_max\":100,\"timeout\":120,\"sampling\":2,\"snaplen\":100}\t1" + "72694b1c-6833-4c46-acde-52e2d6409314\t100\tether host 00:15:5d:b8:10:a6\t60\t2\t200\t0\t{}\t1" ] } ] diff --git a/etc/table_schema.json b/etc/table_schema.json index 31067a6..422dabd 100644 --- a/etc/table_schema.json +++ b/etc/table_schema.json @@ -3,11 +3,10 @@ "table_id": 1, "table_name": "DP_TRACE_TELEMETRY_TABLE", "table_type": "plugin", - "valid_column": 3, + "valid_column": 9, "custom": { "key": 1, - "key_type": "integer", - "key_len": 8 + "key_type": "pointer" } } ]
\ No newline at end of file diff --git a/include/job_ctx.h b/include/job_ctx.h index 6ce69f4..aed399c 100644 --- a/include/job_ctx.h +++ b/include/job_ctx.h @@ -5,7 +5,6 @@ struct dp_trace_telemetry_desc { uuid_t uuid; - char job_name[128]; struct dp_trace_job_desc job_desc; }; diff --git a/src/job_ctx.c b/src/job_ctx.c index 8c5b0be..79d6f1d 100644 --- a/src/job_ctx.c +++ b/src/job_ctx.c @@ -73,67 +73,50 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke long argl, void * argp) { int ret = 0; - size_t offset = 0; - size_t len = 0; - char * json_str = NULL; - cJSON * json = NULL; + struct dp_trace_telemetry_desc telemetry_desc = {}; + struct dp_trace_job_desc * job_desc = &telemetry_desc.job_desc; - ret = maat_helper_read_column(table_line, 2, &offset, &len); - if (ret < 0) + char uuid[40] = {}; + unsigned int pkt_cnt_max = 0; + char bpf_expr[MR_BPF_EXPRESSION_MAX]; + unsigned int timeout = 0; + unsigned int sampling = 0; + unsigned int snaplen = 0; + unsigned int with_packet_capture = 0; + char device_group[512]; + unsigned int is_valid = 0; + + ret = sscanf(table_line, "%s\t%u\t%128[^\t]\t%u\t%u\t%u\t%u\t%s\t%u", uuid, &pkt_cnt_max, bpf_expr, &timeout, + &sampling, &snaplen, &with_packet_capture, device_group, &is_valid); + if (ret != 9) { - dzlog_error("fail to get data path rule in maat."); - goto out; + dzlog_warn("maat parse config failed:%s", table_line); + return; } - json_str = calloc(sizeof(char), len + 1); - memcpy(json_str, table_line + offset, len); - json = cJSON_Parse(json_str); - if (json == NULL) + if (is_valid == 0) { - dzlog_error("Invalid decryption parameter: %s", table_line); - goto out; + dzlog_warn("rule is not valid:%s", table_line); + return; } - struct dp_trace_telemetry_desc telemetry_desc = {}; - struct dp_trace_job_desc * job_desc = &telemetry_desc.job_desc; - - cJSON * uuid_obj = cJSON_GetObjectItem(json, "job_id"); - DP_TRACE_VERIFY(cJSON_IsString(uuid_obj), "uuid is not string"); - ret = uuid_parse(uuid_obj->valuestring, telemetry_desc.uuid); + ret = uuid_parse(uuid, telemetry_desc.uuid); if (ret != 0) { - dzlog_error("uuid parsing failed: %s", uuid_obj->valuestring); - goto out; + dzlog_error("uuid parsing failed: %s", uuid); + return; } - cJSON * job_name_obj = cJSON_GetObjectItem(json, "job_name"); - DP_TRACE_VERIFY(cJSON_IsString(job_name_obj), "job_name is not string"); - snprintf(telemetry_desc.job_name, sizeof(telemetry_desc.job_name), "%s", job_name_obj->valuestring); - - cJSON * bpf_expr_obj = cJSON_GetObjectItem(json, "bpf_expr"); - DP_TRACE_VERIFY(cJSON_IsString(bpf_expr_obj), "bpf expr is not string"); - snprintf(job_desc->bpf_expr, sizeof(job_desc->bpf_expr), "%s", bpf_expr_obj->valuestring); - -#if 0 - cJSON * pkt_cnt_max_obj = cJSON_GetObjectItem(json, "pkt_cnt_max"); - DP_TRACE_VERIFY(cJSON_IsNumber(pkt_cnt_max_obj), "pkt_cnt_max is not number"); - job_desc->pkt_cnt_max = pkt_cnt_max_obj->valueint; -#endif - job_desc->pkt_cnt_max = 0; - - cJSON * sampling_obj = cJSON_GetObjectItem(json, "sampling"); - DP_TRACE_VERIFY(cJSON_IsNumber(sampling_obj), "sampling is not number"); - job_desc->sampling = sampling_obj->valueint; - - cJSON * snaplen_obj = cJSON_GetObjectItem(json, "snaplen"); - DP_TRACE_VERIFY(cJSON_IsNumber(snaplen_obj), "snaplen is not number"); - job_desc->snaplen = snaplen_obj->valueint; + snprintf(job_desc->bpf_expr, sizeof(job_desc->bpf_expr), "%s", bpf_expr); + job_desc->pkt_cnt_max = pkt_cnt_max; + job_desc->sampling = sampling; + job_desc->snaplen = snaplen; int index = telemetry_unused_job_index_get(); if (index < 0) { dzlog_warn("no enough job for bpf_expr:", job_desc->bpf_expr); - goto out; + return; } job_desc->rule_index = index; @@ -144,13 +127,6 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke job_rule_apply(&telemetry_descs[index].job_desc, 1, DP_TELEMETRY_ROLE); *ad = &telemetry_descs[index]; - -out: - if (json) - cJSON_Delete(json); - if (json_str) - free(json_str); - return; } void telemetry_job_del_cb(int table_id, void ** ad, long argl, void * argp) diff --git a/src/trace_output.c b/src/trace_output.c index 54631b8..1a2c7d5 100644 --- a/src/trace_output.c +++ b/src/trace_output.c @@ -493,7 +493,7 @@ static void dp_trace_decode_to_message_pack(marsio_buff_t * mr_mbuf, char ** dat const char * comment = cur + sizeof(struct dp_trace_record_header); const unsigned int comment_len = record_header->recode_len; - if ((record_header->tag == DP_TRACE_RECORD_TYPE_TELEMETRY) != 0) + if ((record_header->type == DP_TRACE_RECORD_TYPE_TELEMETRY) != 0) { mpack_start_map(&writer, 4); @@ -544,7 +544,7 @@ static int dp_trace_record_decode_to_str(marsio_buff_t * mr_mbuf, char * data, u const char * str = cur + sizeof(struct dp_trace_record_header); const unsigned int str_len = record_header->recode_len; - if (record_header->tag == DP_TRACE_RECORD_TYPE_TRACE) + if (record_header->type == DP_TRACE_RECORD_TYPE_TRACE) { int n = snprintf(data, size, "[%s:%s:] %ld.%ld ", record_header->appsym, record_header->module, record_header->ts.tv_sec, record_header->ts.tv_nsec); |
