Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nathalapooja committed Jan 13, 2025
1 parent efa1569 commit c188ff9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 52 deletions.
58 changes: 30 additions & 28 deletions plugins/filter_aws/aws.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,16 +953,7 @@ static int cb_aws_filter(const void *data, size_t bytes,
ctx->hostname, ctx->hostname_len);
}

if (ctx->enable_entity && ctx->instance_id != NULL && ctx->account_id != NULL && strncmp(ctx->entity_type , FLB_FILTER_ENTITY_TYPE_SERVICE, FLB_FILTER_ENTITY_TYPE_SERVICE_LEN) == 0) {
// Pack instance ID with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY,
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->instance_id_len);
msgpack_pack_str_body(&tmp_pck,
ctx->instance_id, ctx->instance_id_len);

if (ctx->enable_entity && ctx->account_id != NULL ) {
// Pack account ID with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_ACCOUNT_ID_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
Expand All @@ -971,25 +962,36 @@ static int cb_aws_filter(const void *data, size_t bytes,
msgpack_pack_str(&tmp_pck, ctx->account_id_len);
msgpack_pack_str_body(&tmp_pck,
ctx->account_id, ctx->account_id_len);
}

if (ctx->instance_id != NULL && strncmp(ctx->entity_type , FLB_FILTER_ENTITY_TYPE_SERVICE, FLB_FILTER_ENTITY_TYPE_SERVICE_LEN) == 0) {
// Pack instance ID with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY,
FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->instance_id_len);
msgpack_pack_str_body(&tmp_pck,
ctx->instance_id, ctx->instance_id_len);
}

if (ctx->enable_entity && ctx->cluster != NULL && ctx->platform != NULL && strncmp(ctx->entity_type , FLB_FILTER_ENTITY_TYPE_RESOURCE, FLB_FILTER_ENTITY_TYPE_RESOURCE_LEN) == 0 ) {
// Pack cluster name with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_CLUSTER_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_CLUSTER_KEY,
FLB_FILTER_AWS_ENTITY_CLUSTER_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->cluster_len);
msgpack_pack_str_body(&tmp_pck,
ctx->cluster, ctx->cluster_len);
// Pack platform with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_PLATFORM_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_PLATFORM_KEY,
FLB_FILTER_AWS_ENTITY_PLATFORM_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->platform_len);
msgpack_pack_str_body(&tmp_pck,
ctx->platform, ctx->platform_len);
if (ctx->cluster != NULL && ctx->platform != NULL && strncmp(ctx->entity_type , FLB_FILTER_ENTITY_TYPE_RESOURCE, FLB_FILTER_ENTITY_TYPE_RESOURCE_LEN) == 0 ) {
// Pack cluster name with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_CLUSTER_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_CLUSTER_KEY,
FLB_FILTER_AWS_ENTITY_CLUSTER_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->cluster_len);
msgpack_pack_str_body(&tmp_pck,
ctx->cluster, ctx->cluster_len);
// Pack platform with entity prefix for further processing
msgpack_pack_str(&tmp_pck, FLB_FILTER_AWS_ENTITY_PLATFORM_KEY_LEN);
msgpack_pack_str_body(&tmp_pck,
FLB_FILTER_AWS_ENTITY_PLATFORM_KEY,
FLB_FILTER_AWS_ENTITY_PLATFORM_KEY_LEN);
msgpack_pack_str(&tmp_pck, ctx->platform_len);
msgpack_pack_str_body(&tmp_pck,
ctx->platform, ctx->platform_len);
}
}

}
Expand Down
58 changes: 34 additions & 24 deletions plugins/out_cloudwatch_logs/cloudwatch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ static int entity_add_resource_key_attributes(struct flb_cloudwatch *ctx, struct
goto error;
}
}
if(stream->entity->key_attributes->account_id != NULL && strlen(stream->entity->key_attributes->account_id) != 0) {
if (!snprintf(ts,KEY_ATTRIBUTES_MAX_LEN, ",%s%s%s","\"AwsAccountId\":\"",stream->entity->key_attributes->account_id,"\"")) {
goto error;
}
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,ts,0)) {
goto error;
}
}
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,
"}", 1)) {
goto error;
Expand Down Expand Up @@ -417,39 +425,41 @@ static int init_put_payload(struct flb_cloudwatch *ctx, struct cw_flush *buf,
// If we are missing the service name, the entity will get rejected by the frontend anyway
// so do not emit entity unless service name is filled. If we are missing account ID
// it is considered not having sufficient information for entity therefore we should drop the entity.
if(ctx->add_entity && stream->entity != NULL && stream->entity->key_attributes != NULL ) {
if(ctx->add_entity && stream->entity != NULL && stream->entity->key_attributes != NULL && strncmp(ctx->entity_type, FLB_FILTER_ENTITY_TYPE_RESOURCE, FLB_FILTER_ENTITY_TYPE_RESOURCE_LEN) == 0 && stream->entity->key_attributes->platform != NULL && stream->entity->key_attributes->cluster_name != NULL && stream->entity->key_attributes->account_id != NULL) {
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,
"\"entity\":{", 10)) {
goto error;
}
if (strncmp(ctx->entity_type, FLB_FILTER_ENTITY_TYPE_RESOURCE, FLB_FILTER_ENTITY_TYPE_RESOURCE_LEN) == 0 && stream->entity->key_attributes->platform != NULL && stream->entity->key_attributes->cluster_name != NULL) {
if(stream->entity->key_attributes != NULL) {
ret = entity_add_resource_key_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Resource Entity KeyAttributes");
goto error;
}
}
ret = entity_add_resource_key_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Resource Entity KeyAttributes");
goto error;
}
else if (stream->entity->key_attributes->name != NULL && stream->entity->key_attributes->account_id != NULL) {
if(stream->entity->key_attributes != NULL) {
ret = entity_add_key_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Entity KeyAttributes");
goto error;
}
}
if(stream->entity->attributes != NULL) {
ret = entity_add_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Entity Attributes");
goto error;
}
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,
"},", 2)) {
goto error;
}
}
else if (ctx->add_entity && stream->entity != NULL && stream->entity->key_attributes != NULL && stream->entity->key_attributes->name != NULL && stream->entity->key_attributes->account_id != NULL) {
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,
"\"entity\":{", 10)) {
goto error;
}
ret = entity_add_key_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Entity KeyAttributes");
goto error;
}
if(stream->entity->attributes != NULL) {
ret = entity_add_attributes(ctx,buf,stream,offset);
if (ret < 0) {
flb_plg_error(ctx->ins, "Failed to initialize Entity Attributes");
goto error;
}
}
if (!try_to_write(buf->out_buf, offset, buf->out_buf_size,
"},", 2)) {
goto error;
goto error;
}
}

Expand Down

0 comments on commit c188ff9

Please sign in to comment.