TSG-8057 Proxy新增公共日志字段common_device_tag

This commit is contained in:
fengweihao
2021-10-18 18:29:10 +08:00
parent ffd2ca6734
commit 665c47295a
5 changed files with 18 additions and 53 deletions

View File

@@ -18,7 +18,7 @@ struct maat_table_info
static Maat_feather_t static_maat = NULL;
static tfe_kafka_logger_t *kafka_logger = NULL;
static char *device_id = NULL;
static char *data_center=NULL;
static char *effective_device_tag=NULL;
static Maat_feather_t create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger)
{
@@ -243,11 +243,9 @@ finish:
return (char *)device_def_id;
}
static char* create_data_center(const char *profile, const char *section, void *logger)
static char* create_effective_device_tag(const char *profile, const char *section, void *logger)
{
int i =0;
char *data_cneter=NULL;
char accept_tag_key[TFE_PATH_MAX] = {0};
char *effective_device_tag=NULL;
char accept_path[TFE_PATH_MAX] = {0}, accept_tags[TFE_STRING_MAX] = {0};
MESA_load_profile_string_def(profile, section, "accept_path", accept_path, sizeof(accept_path), "");
@@ -259,43 +257,10 @@ static char* create_data_center(const char *profile, const char *section, void *
{
return NULL;
}
MESA_load_profile_string_def(profile, section, "accept_tag_key", accept_tag_key, sizeof(accept_tag_key), "data_center");
effective_device_tag = tfe_strdup(accept_tags);
TFE_LOG_INFO(logger, "tfe device tag : %s", effective_device_tag);
cJSON *object=cJSON_Parse(accept_tags);
if(object == NULL)
{
return NULL;
}
cJSON *array=cJSON_GetObjectItem(object, "tags");
if(array==NULL && array->type!=cJSON_Array)
{
TFE_LOG_ERROR(logger, "Invalid tags parameter: %s invalid json format", accept_tags);
goto finish;
}
for(i=0; i<cJSON_GetArraySize(array); i++)
{
cJSON *item=cJSON_GetArrayItem(array, i);
if(!item)
{
continue;
}
cJSON *tag_item=cJSON_GetObjectItem(item, "tag");
if(tag_item && tag_item->valuestring!=NULL &&
(memcmp(accept_tag_key, tag_item->valuestring, strlen(accept_tag_key)))==0)
{
cJSON *sub_item=cJSON_GetObjectItem(item, "value");
if(sub_item && sub_item->valuestring!=NULL)
{
data_cneter = tfe_strdup(sub_item->valuestring);
TFE_LOG_INFO(logger, "tfe data center : %s", data_cneter);
}
}
}
finish:
cJSON_Delete(object);
return data_cneter;
return effective_device_tag;
}
static struct maat_table_info maat_pub_tables[TABLE_TYPE_MAX] = {
@@ -338,7 +303,7 @@ int tfe_bussiness_resouce_init()
device_id = cerate_device_id(profile_path, "kafka", g_default_logger);
data_center = create_data_center(profile_path, "MAAT", g_default_logger);
effective_device_tag = create_effective_device_tag(profile_path, "MAAT", g_default_logger);
if (register_maat_table())
{
@@ -358,8 +323,8 @@ void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type)
return kafka_logger;
case DEVICE_ID:
return device_id;
case DATA_CENTER:
return data_center;
case EFFECTIVE_DEVICE_TAG:
return effective_device_tag;
default:
return NULL;
}