@@ -926,6 +926,30 @@ static int get_ec2_metadata(struct flb_filter_aws *ctx)
926926 ctx -> metadata_retrieved = FLB_TRUE ;
927927 }
928928
929+ if (ctx -> enable_entity ) {
930+ if (!ctx -> account_id ) {
931+ ret = flb_aws_imds_request_by_key (ctx -> client_imds , FLB_AWS_IMDS_ACCOUNT_ID_PATH ,
932+ & ctx -> account_id , & ctx -> account_id_len ,
933+ "accountId" );
934+
935+ if (ret < 0 ) {
936+ flb_plg_error (ctx -> ins , "Failed to get Account ID" );
937+ return -1 ;
938+ }
939+ }
940+
941+ if (!ctx -> instance_id ) {
942+ ret = flb_aws_imds_request (ctx -> client_imds , FLB_AWS_IMDS_INSTANCE_ID_PATH ,
943+ & ctx -> instance_id ,
944+ & ctx -> instance_id_len );
945+ if (ret < 0 ) {
946+ flb_plg_error (ctx -> ins , "Failed to get instance ID" );
947+ return -1 ;
948+ }
949+ }
950+ }
951+
952+ ctx -> metadata_retrieved = FLB_TRUE ;
929953 return 0 ;
930954}
931955
@@ -1104,6 +1128,23 @@ static int cb_aws_filter(const void *data, size_t bytes,
11041128 }
11051129 }
11061130
1131+ if (ctx -> enable_entity &&
1132+ ctx -> instance_id &&
1133+ ctx -> account_id &&
1134+ ret == FLB_EVENT_ENCODER_SUCCESS ) {
1135+ ret = flb_log_event_encoder_append_body_values (
1136+ & log_encoder ,
1137+ FLB_LOG_EVENT_CSTRING_VALUE (FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY ),
1138+ FLB_LOG_EVENT_STRING_VALUE (ctx -> instance_id ,
1139+ ctx -> instance_id_len ));
1140+ ret = flb_log_event_encoder_append_body_values (
1141+ & log_encoder ,
1142+ FLB_LOG_EVENT_CSTRING_VALUE (FLB_FILTER_AWS_ENTITY_ACCOUNT_ID_KEY ),
1143+ FLB_LOG_EVENT_STRING_VALUE (ctx -> account_id ,
1144+ ctx -> account_id_len ));
1145+ }
1146+
1147+
11071148 if (ret == FLB_EVENT_ENCODER_SUCCESS ) {
11081149 ret = flb_log_event_encoder_commit_record (& log_encoder );
11091150 }
@@ -1273,6 +1314,12 @@ static struct flb_config_map config_map[] = {
12731314 0 , FLB_TRUE , offsetof(struct flb_filter_aws , retry_required_interval ),
12741315 "Defines minimum duration between retries for fetching metadata groups"
12751316 },
1317+ {
1318+ FLB_CONFIG_MAP_BOOL , "enable_entity" , "false" ,
1319+ 0 , FLB_TRUE , offsetof(struct flb_filter_aws , enable_entity ),
1320+ "Enable entity prefix for fields used for constructing entity."
1321+ "This currently only affects instance ID"
1322+ },
12761323 {0 }
12771324};
12781325
0 commit comments