TSG-8057 Proxy新增公共日志字段common_device_tag
This commit is contained in:
@@ -5,7 +5,7 @@ enum RESOURCE_TYPE
|
||||
STATIC_MAAT,
|
||||
KAFKA_LOGGER,
|
||||
DEVICE_ID,
|
||||
DATA_CENTER,
|
||||
EFFECTIVE_DEVICE_TAG,
|
||||
};
|
||||
|
||||
enum TABLE_TYPE
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ int doh_kafka_init(const char *profile, struct doh_conf *conf)
|
||||
return 0;
|
||||
}
|
||||
conf->device_id = (const char *)tfe_bussiness_resouce_get(DEVICE_ID);
|
||||
conf->data_center = (const char *)tfe_bussiness_resouce_get(DATA_CENTER);
|
||||
conf->effective_device_tag = (const char *)tfe_bussiness_resouce_get(EFFECTIVE_DEVICE_TAG);
|
||||
conf->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
|
||||
if (conf->kafka_logger && !conf->kafka_logger->enable)
|
||||
{
|
||||
@@ -406,9 +406,9 @@ int doh_send_log(struct doh_conf *handle, const struct tfe_http_session *http, c
|
||||
cJSON_AddNumberToObject(common_obj, "common_s2c_byte_num", s2c_byte_num);
|
||||
cJSON_AddStringToObject(common_obj, "doh_url", http->req->req_spec.url);
|
||||
cJSON_AddStringToObject(common_obj, "doh_host", http->req->req_spec.host);
|
||||
if(handle->data_center)
|
||||
if(handle->effective_device_tag)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "common_data_center", handle->data_center);
|
||||
cJSON_AddStringToObject(common_obj, "common_device_tag", handle->effective_device_tag);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < sizeof(req_fields) / sizeof(struct json_spec); i++)
|
||||
|
||||
@@ -59,7 +59,7 @@ struct doh_conf
|
||||
int entry_id;
|
||||
int en_sendlog;
|
||||
const char *device_id;
|
||||
const char *data_center;
|
||||
const char *effective_device_tag;
|
||||
tfe_kafka_logger_t *kafka_logger;
|
||||
|
||||
int fs_id[DOH_STAT_MAX];
|
||||
|
||||
@@ -17,7 +17,7 @@ struct pangu_logger
|
||||
int entry_id;
|
||||
unsigned int en_sendlog;
|
||||
const char *device_id;
|
||||
const char *data_center;
|
||||
const char *effective_device_tag;
|
||||
void* local_logger;
|
||||
|
||||
unsigned long long send_cnt;
|
||||
@@ -59,7 +59,7 @@ struct pangu_logger* pangu_log_handle_create(const char* profile, const char* s
|
||||
}
|
||||
|
||||
instance->device_id = (const char *)tfe_bussiness_resouce_get(DEVICE_ID);
|
||||
instance->data_center = (const char *)tfe_bussiness_resouce_get(DATA_CENTER);
|
||||
instance->effective_device_tag = (const char *)tfe_bussiness_resouce_get(EFFECTIVE_DEVICE_TAG);
|
||||
instance->kafka_logger = (tfe_kafka_logger_t *)tfe_bussiness_resouce_get(KAFKA_LOGGER);
|
||||
if (instance->kafka_logger && !instance->kafka_logger->enable)
|
||||
{
|
||||
@@ -225,9 +225,9 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
|
||||
cJSON_AddNumberToObject(common_obj, "common_s2c_byte_num", s2c_byte_num);
|
||||
cJSON_AddStringToObject(common_obj, "http_url", http->req->req_spec.url);
|
||||
cJSON_AddStringToObject(common_obj, "http_host", http->req->req_spec.host);
|
||||
if(handle->data_center)
|
||||
if(handle->effective_device_tag)
|
||||
{
|
||||
cJSON_AddStringToObject(common_obj, "common_data_center", handle->data_center);
|
||||
cJSON_AddStringToObject(common_obj, "common_device_tag", handle->effective_device_tag);
|
||||
}
|
||||
|
||||
for(size_t i=0;i<sizeof(req_fields)/sizeof(struct json_spec);i++)
|
||||
|
||||
Reference in New Issue
Block a user