diff options
| author | 童宗振 <[email protected]> | 2024-05-17 11:30:53 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-05-17 11:30:53 +0000 |
| commit | 7796d0bb8b7d4ea204869e004f6a12c49d0f3d6d (patch) | |
| tree | 9f1eacfce3b1fa9c7af2ebb5f6661bf20f234bc8 | |
| parent | 2f6707f59cd7f1a22c1362307e1574b676b11ed8 (diff) | |
| parent | 919d42f20c3910e29335360c84368670594db4c4 (diff) | |
Merge branch 'apply_data_center' into 'master'
(TSG-21200)Apply data center
See merge request tsg/dp_telemetry_app!37
| -rw-r--r-- | etc/dp_telemetry_rules.json | 2 | ||||
| -rw-r--r-- | etc/dp_trace.conf | 1 | ||||
| -rw-r--r-- | include/config.h | 1 | ||||
| -rw-r--r-- | src/config.c | 2 | ||||
| -rw-r--r-- | src/job_ctx.c | 2 | ||||
| -rw-r--r-- | src/maat.c | 45 |
6 files changed, 38 insertions, 15 deletions
diff --git a/etc/dp_telemetry_rules.json b/etc/dp_telemetry_rules.json index 7a3b115..51d1aee 100644 --- a/etc/dp_telemetry_rules.json +++ b/etc/dp_telemetry_rules.json @@ -3,7 +3,7 @@ { "table_name": "DATAPATH_TELEMETRY_JOB", "table_content": [ - "72694b1c-6833-4c46-acde-52e2d6409314\t100000\thost\\b192.168.64.11\t60\t1\t200\t0\t{\"tag_sets\":[[{\"value\":[\"device-abc\",\"device-xxx\"],\"tag\":\"data_center\"}]]}\t[1000,10001]\t1" + "72694b1c-6833-4c46-acde-52e2d6409314\t100000\thost\\b192.168.64.11\t60\t1\t200\t0\t{\"tag_sets\":[[{\"value\":[\"group-xxg-tsgx-virtual1\",\"group-xxg-tsgx-virtual2\"],\"tag\":\"device_group\"}],[{\"value\":[\"center-nyj\",\"center-nyj-one\"],\"tag\":\"data_center\"}]]}\t[1000,10001]\t1" ] } ] diff --git a/etc/dp_trace.conf b/etc/dp_trace.conf index 6dfd0dc..21fbcce 100644 --- a/etc/dp_trace.conf +++ b/etc/dp_trace.conf @@ -3,6 +3,7 @@ iocore=4,5,6,7 zlog_config_path=../etc/dp_trace_zlog.conf dp_trace_dir=./ device_group="device-xxx" +data_center="center-nyj-one" monit_file_path=/var/run/mrzcpd/mrmonit.app.dp_trace_telemetry.saving send_ctrlbuf=0 diff --git a/include/config.h b/include/config.h index 9f58f75..c499a65 100644 --- a/include/config.h +++ b/include/config.h @@ -23,6 +23,7 @@ struct config // device Information char * sled_ip; char device_group[MR_SYMBOL_MAX]; + char data_center[MR_SYMBOL_MAX]; // server char str_listen_addr[INET6_ADDRSTRLEN]; diff --git a/src/config.c b/src/config.c index 0d7b01b..0bac464 100644 --- a/src/config.c +++ b/src/config.c @@ -80,6 +80,8 @@ void config_load() MESA_load_profile_string_def(config_path, "global", "device_group", g_conf->device_group, sizeof(g_conf->device_group), ""); + MESA_load_profile_string_def(config_path, "global", "data_center", g_conf->data_center, sizeof(g_conf->data_center), + ""); MESA_load_profile_string_def(config_path, "http_server", "listen_addr", g_conf->str_listen_addr, sizeof(g_conf->str_listen_addr), "127.0.0.1"); diff --git a/src/job_ctx.c b/src/job_ctx.c index 778dc29..352d63b 100644 --- a/src/job_ctx.c +++ b/src/job_ctx.c @@ -83,7 +83,7 @@ void telemetry_job_add_cb(const char * table_name, int table_id, const char * ke bool valid_rule = maat_rule_parse(table_line, &telemetry_desc); if (valid_rule == false) { - dzlog_warn("parse maat rule failed."); + dzlog_info("not a valid rule."); return; } @@ -121,26 +121,26 @@ bool maat_rule_parse(const char * table_line, struct dp_trace_telemetry_desc * t goto end; } - bool device_group_match = false; + bool device_group_or_date_center_match = false; if (strcasecmp(device_group, "{}") == 0) { dzlog_info("When device_group is empty, all devices are matched"); - device_group_match = true; - goto device_group_match_end; + device_group_or_date_center_match = true; + goto device_group_or_date_center_match_end; } device_group_json = cJSON_Parse(device_group); if (device_group_json == NULL) { dzlog_error("parse to json failed:%s", device_group); - goto device_group_match_end; + goto device_group_or_date_center_match_end; } cJSON * tag_sets_item = cJSON_GetObjectItem(device_group_json, "tag_sets"); if (!cJSON_IsArray(tag_sets_item)) { dzlog_warn("tag_sets value is not array"); - goto device_group_match_end; + goto device_group_or_date_center_match_end; } int tag_sets_array_size = cJSON_GetArraySize(tag_sets_item); @@ -150,18 +150,36 @@ bool maat_rule_parse(const char * table_line, struct dp_trace_telemetry_desc * t if (!cJSON_IsArray(tag_sets_item_i)) { dzlog_warn("tag_sets value %d is not array", i); - goto device_group_match_end; + goto device_group_or_date_center_match_end; } int tag_sets_item_i_array_size = cJSON_GetArraySize(tag_sets_item_i); for (int j = 0; j < tag_sets_item_i_array_size; j++) { cJSON * inner_item = cJSON_GetArrayItem(tag_sets_item_i, j); + + cJSON * tag_item = cJSON_GetObjectItem(inner_item, "tag"); + const char * tag_key_str = cJSON_GetStringValue(tag_item); + const char * tag_val_str = NULL; + if (tag_key_str == NULL) + { + dzlog_warn("tag_sets %d no 'tag'", i); + continue; + } + else if (strcasecmp(tag_key_str, "device_group") == 0) + { + tag_val_str = conf->device_group; + } + else if (strcasecmp(tag_key_str, "data_center") == 0) + { + tag_val_str = conf->data_center; + } + cJSON * inner_item_value = cJSON_GetObjectItem(inner_item, "value"); if (!cJSON_IsArray(inner_item_value)) { dzlog_warn("tag_sets %d-%d 'value' is not array", i, j); - goto device_group_match_end; + continue; } int value_array_size = cJSON_GetArraySize(inner_item_value); @@ -170,20 +188,21 @@ bool maat_rule_parse(const char * table_line, struct dp_trace_telemetry_desc * t cJSON * value_item_k = cJSON_GetArrayItem(inner_item_value, k); if (cJSON_IsString(value_item_k)) { - if (strcasecmp(conf->device_group, value_item_k->valuestring) == 0) + if (strcasecmp(tag_val_str, value_item_k->valuestring) == 0) { - device_group_match = true; - goto device_group_match_end; + device_group_or_date_center_match = true; + goto device_group_or_date_center_match_end; } } } } } -device_group_match_end: - if (device_group_match == false) +device_group_or_date_center_match_end: + if (device_group_or_date_center_match == false) { - dzlog_info("This rule does not apply to the current device(%s)", conf->device_group); + dzlog_info("This rule does not apply to the current center(%s) or device(%s)", conf->data_center, + conf->device_group); goto end; } |
