Skip to content

Commit dc025f8

Browse files
authored
Remove entity related log messages and rename entity fields (fluent#22)
1 parent ca0749b commit dc025f8

17 files changed

+186
-94
lines changed

plugins/filter_aws/aws.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,22 @@ static int cb_aws_filter(const void *data, size_t bytes,
558558
ctx->availability_zone_len);
559559
}
560560

561-
if (ctx->instance_id_include) {
561+
if (ctx->instance_id_include && !ctx->enable_entity) {
562562
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_INSTANCE_ID_KEY_LEN);
563563
msgpack_pack_str_body(&tmp_pck,
564564
FLB_FILTER_AWS_INSTANCE_ID_KEY,
565565
FLB_FILTER_AWS_INSTANCE_ID_KEY_LEN);
566566
msgpack_pack_str(&tmp_pck, ctx->instance_id_len);
567567
msgpack_pack_str_body(&tmp_pck,
568568
ctx->instance_id, ctx->instance_id_len);
569+
} else if (ctx->instance_id_include && ctx->enable_entity) {
570+
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
571+
msgpack_pack_str_body(&tmp_pck,
572+
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY,
573+
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
574+
msgpack_pack_str(&tmp_pck, ctx->instance_id_len);
575+
msgpack_pack_str_body(&tmp_pck,
576+
ctx->instance_id, ctx->instance_id_len);
569577
}
570578

571579
if (ctx->instance_type_include) {
@@ -740,6 +748,11 @@ static struct flb_config_map config_map[] = {
740748
0, FLB_TRUE, offsetof(struct flb_filter_aws, hostname_include),
741749
"Enable EC2 instance hostname"
742750
},
751+
{
752+
FLB_CONFIG_MAP_BOOL, "enable_entity", "false",
753+
0, FLB_TRUE, offsetof(struct flb_filter_aws, enable_entity),
754+
"Enable entity prefix for necessary fields"
755+
},
743756
{0}
744757
};
745758

plugins/filter_aws/aws.h

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#define FLB_FILTER_AWS_AVAILABILITY_ZONE_KEY_LEN 2
5252
#define FLB_FILTER_AWS_INSTANCE_ID_KEY "ec2_instance_id"
5353
#define FLB_FILTER_AWS_INSTANCE_ID_KEY_LEN 15
54+
#define FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY "aws_entity_ec2_instance_id"
55+
#define FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN 26
5456
#define FLB_FILTER_AWS_INSTANCE_TYPE_KEY "ec2_instance_type"
5557
#define FLB_FILTER_AWS_INSTANCE_TYPE_KEY_LEN 17
5658
#define FLB_FILTER_AWS_PRIVATE_IP_KEY "private_ip"
@@ -111,6 +113,12 @@ struct flb_filter_aws {
111113
size_t hostname_len;
112114
int hostname_include;
113115

116+
/*
117+
* Enable entity prefix appending. This appends
118+
* 'aws_entity' to relevant keys
119+
*/
120+
int enable_entity;
121+
114122
/* number of new keys added by this plugin */
115123
int new_keys;
116124

plugins/filter_kubernetes/kube_meta.c

+12-59
Original file line numberDiff line numberDiff line change
@@ -1028,27 +1028,6 @@ static int search_item_in_items(struct flb_kube_meta *meta,
10281028
return ret;
10291029
}
10301030

1031-
static char* find_fallback_environment(struct flb_kube *ctx, struct flb_kube_meta *meta) {
1032-
char *fallback_env = NULL;
1033-
1034-
/*
1035-
* Possible fallback environments:
1036-
* 1. eks:cluster-name/namespace
1037-
* 2. k8s:cluster-name/namespace
1038-
*/
1039-
if(ctx->platform == NULL && ctx->set_platform != NULL) {
1040-
ctx->platform = flb_strdup(ctx->set_platform);
1041-
}
1042-
if (ctx->platform != NULL && meta->cluster != NULL && meta->namespace != NULL) {
1043-
int ret = asprintf(&fallback_env, "%s:%s/%s", ctx->platform, meta->cluster, meta->namespace);
1044-
if (ret == -1) {
1045-
return NULL;
1046-
}
1047-
return fallback_env;
1048-
}
1049-
return NULL;
1050-
}
1051-
10521031
static int merge_meta_from_tag(struct flb_kube *ctx, struct flb_kube_meta *meta,
10531032
char **out_buf, size_t *out_size)
10541033
{
@@ -1260,25 +1239,13 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
12601239
}
12611240
}
12621241
}
1263-
int fallback_environment_len = 0;
1264-
char *fallback_environment = NULL;
12651242
if(ctx->use_pod_association) {
1266-
fallback_environment = find_fallback_environment(ctx,meta);
1267-
if(fallback_environment) {
1268-
fallback_environment_len = strlen(fallback_environment);
1269-
}
12701243
pod_service_found = flb_hash_get(ctx->pod_hash_table,
12711244
meta->podname, meta->podname_len,
12721245
&tmp_service_attributes, &tmp_service_attr_size);
12731246
if (pod_service_found != -1 && tmp_service_attributes != NULL) {
12741247
map_size += tmp_service_attributes->fields;
12751248
}
1276-
if(pod_service_found != -1 && tmp_service_attributes != NULL && tmp_service_attributes->environment[0] == '\0' && fallback_environment) {
1277-
map_size++;
1278-
}
1279-
if(pod_service_found == -1 && meta->workload != NULL && fallback_environment) {
1280-
map_size++;
1281-
}
12821249
if(ctx->platform) {
12831250
map_size++;
12841251
}
@@ -1304,51 +1271,41 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
13041271
if(ctx->use_pod_association) {
13051272
if (pod_service_found != -1 && tmp_service_attributes != NULL) {
13061273
if (tmp_service_attributes->name[0] != '\0') {
1307-
msgpack_pack_str(&mp_pck, 12);
1308-
msgpack_pack_str_body(&mp_pck, "service_name", 12);
1274+
msgpack_pack_str(&mp_pck, 23);
1275+
msgpack_pack_str_body(&mp_pck, "aws_entity_service_name", 23);
13091276
msgpack_pack_str(&mp_pck, tmp_service_attributes->name_len);
13101277
msgpack_pack_str_body(&mp_pck, tmp_service_attributes->name, tmp_service_attributes->name_len);
13111278
}
13121279
if (tmp_service_attributes->environment[0] != '\0') {
1313-
msgpack_pack_str(&mp_pck, 11);
1314-
msgpack_pack_str_body(&mp_pck, "environment", 11);
1280+
msgpack_pack_str(&mp_pck, 22);
1281+
msgpack_pack_str_body(&mp_pck, "aws_entity_environment", 22);
13151282
msgpack_pack_str(&mp_pck, tmp_service_attributes->environment_len);
13161283
msgpack_pack_str_body(&mp_pck, tmp_service_attributes->environment, tmp_service_attributes->environment_len);
1317-
} else if(tmp_service_attributes->environment[0] == '\0' && fallback_environment) {
1318-
msgpack_pack_str(&mp_pck, 11);
1319-
msgpack_pack_str_body(&mp_pck, "environment", 11);
1320-
msgpack_pack_str(&mp_pck, fallback_environment_len);
1321-
msgpack_pack_str_body(&mp_pck, fallback_environment, fallback_environment_len);
13221284
}
13231285
if (tmp_service_attributes->name_source[0] != '\0') {
1324-
msgpack_pack_str(&mp_pck, 11);
1325-
msgpack_pack_str_body(&mp_pck, "name_source", 11);
1286+
msgpack_pack_str(&mp_pck, 22);
1287+
msgpack_pack_str_body(&mp_pck, "aws_entity_name_source", 22);
13261288
msgpack_pack_str(&mp_pck, tmp_service_attributes->name_source_len);
13271289
msgpack_pack_str_body(&mp_pck, tmp_service_attributes->name_source, tmp_service_attributes->name_source_len);
13281290
}
1329-
} else if ( pod_service_found == -1 && meta->workload != NULL && fallback_environment) {
1330-
msgpack_pack_str(&mp_pck, 11);
1331-
msgpack_pack_str_body(&mp_pck, "environment", 11);
1332-
msgpack_pack_str(&mp_pck, fallback_environment_len);
1333-
msgpack_pack_str_body(&mp_pck, fallback_environment, fallback_environment_len);
13341291
}
13351292

13361293
if(ctx->platform != NULL) {
13371294
int platform_len = strlen(ctx->platform);
1338-
msgpack_pack_str(&mp_pck, 8);
1339-
msgpack_pack_str_body(&mp_pck, "platform", 8);
1295+
msgpack_pack_str(&mp_pck, 19);
1296+
msgpack_pack_str_body(&mp_pck, "aws_entity_platform", 19);
13401297
msgpack_pack_str(&mp_pck, platform_len);
13411298
msgpack_pack_str_body(&mp_pck, ctx->platform, platform_len);
13421299
}
13431300
if (meta->cluster != NULL) {
1344-
msgpack_pack_str(&mp_pck, 7);
1345-
msgpack_pack_str_body(&mp_pck, "cluster", 7);
1301+
msgpack_pack_str(&mp_pck, 18);
1302+
msgpack_pack_str_body(&mp_pck, "aws_entity_cluster", 18);
13461303
msgpack_pack_str(&mp_pck, meta->cluster_len);
13471304
msgpack_pack_str_body(&mp_pck, meta->cluster, meta->cluster_len);
13481305
}
13491306
if (meta->workload != NULL) {
1350-
msgpack_pack_str(&mp_pck, 8);
1351-
msgpack_pack_str_body(&mp_pck, "workload", 8);
1307+
msgpack_pack_str(&mp_pck, 19);
1308+
msgpack_pack_str_body(&mp_pck, "aws_entity_workload", 19);
13521309
msgpack_pack_str(&mp_pck, meta->workload_len);
13531310
msgpack_pack_str_body(&mp_pck, meta->workload, meta->workload_len);
13541311
}
@@ -1460,10 +1417,6 @@ static int merge_meta(struct flb_kube_meta *meta, struct flb_kube *ctx,
14601417
*out_buf = mp_sbuf.data;
14611418
*out_size = mp_sbuf.size;
14621419

1463-
if(fallback_environment) {
1464-
flb_free(fallback_environment);
1465-
}
1466-
14671420
return 0;
14681421
}
14691422

0 commit comments

Comments
 (0)