-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data_dog: partially revert recent datadog PR to avoid provider ecs segfault #6785
base: 1.9
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,7 +179,7 @@ static int datadog_format(struct flb_config *config, | |
return -1; | ||
} | ||
} else if (flb_sds_len(remapped_tags) < byte_cnt) { | ||
tmp = flb_sds_increase(remapped_tags, flb_sds_len(remapped_tags) - byte_cnt); | ||
tmp = flb_sds_increase(remapped_tags, byte_cnt - flb_sds_len(remapped_tags)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, the 2nd arg to flb_sds_increase is the new size, so shouldn't that be byte_cnt? And we shouldn't subtract anything from it? |
||
if (!tmp) { | ||
flb_errno(); | ||
flb_sds_destroy(remapped_tags); | ||
|
@@ -254,11 +254,8 @@ static int datadog_format(struct flb_config *config, | |
* (so they won't be packed as attr) | ||
*/ | ||
if (ctx->remap && (ind = dd_attr_need_remapping(k, v)) >=0 ) { | ||
ret = remapping[ind].remap_to_tag(remapping[ind].remap_tag_name, v, | ||
&remapped_tags); | ||
if (ret < 0) { | ||
flb_plg_error(ctx->ins, "Failed to remap tag: %s, skipping", remapping[ind].remap_tag_name); | ||
} | ||
remapping[ind].remap_to_tag(remapping[ind].remap_tag_name, v, | ||
remapped_tags); | ||
continue; | ||
} | ||
|
||
|
@@ -280,25 +277,9 @@ static int datadog_format(struct flb_config *config, | |
/* here we concatenate ctx->dd_tags and remapped_tags, depending on their presence */ | ||
if (remap_cnt) { | ||
if (ctx->dd_tags != NULL) { | ||
tmp = flb_sds_cat(remapped_tags, FLB_DATADOG_TAG_SEPERATOR, | ||
strlen(FLB_DATADOG_TAG_SEPERATOR)); | ||
if (!tmp) { | ||
flb_errno(); | ||
flb_sds_destroy(remapped_tags); | ||
msgpack_sbuffer_destroy(&mp_sbuf); | ||
msgpack_unpacked_destroy(&result); | ||
return -1; | ||
} | ||
remapped_tags = tmp; | ||
flb_sds_cat(remapped_tags, FLB_DATADOG_TAG_SEPERATOR, | ||
strlen(FLB_DATADOG_TAG_SEPERATOR)); | ||
flb_sds_cat(remapped_tags, ctx->dd_tags, strlen(ctx->dd_tags)); | ||
if (!tmp) { | ||
flb_errno(); | ||
flb_sds_destroy(remapped_tags); | ||
msgpack_sbuffer_destroy(&mp_sbuf); | ||
msgpack_unpacked_destroy(&result); | ||
return -1; | ||
} | ||
remapped_tags = tmp; | ||
} | ||
dd_msgpack_pack_key_value_str(&mp_pck, | ||
FLB_DATADOG_DD_TAGS_KEY, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,172 +28,98 @@ const char *ECS_ARN_PREFIX = "arn:aws:ecs:"; | |
const char *ECS_CLUSTER_PREFIX = "cluster/"; | ||
const char *ECS_TASK_PREFIX = "task/"; | ||
|
||
static int dd_remap_append_kv_to_ddtags(const char *key, | ||
const char *val, size_t val_len, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_append_kv_to_ddtags(const char *key, | ||
const char *val, size_t val_len, flb_sds_t dd_tags) | ||
{ | ||
flb_sds_t tmp; | ||
|
||
if (flb_sds_len(*dd_tags_buf) != 0) { | ||
tmp = flb_sds_cat(*dd_tags_buf, FLB_DATADOG_TAG_SEPERATOR, strlen(FLB_DATADOG_TAG_SEPERATOR)); | ||
if (!tmp) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
*dd_tags_buf = tmp; | ||
if (flb_sds_len(dd_tags) != 0) { | ||
flb_sds_cat(dd_tags, FLB_DATADOG_TAG_SEPERATOR, strlen(FLB_DATADOG_TAG_SEPERATOR)); | ||
} | ||
|
||
tmp = flb_sds_cat(*dd_tags_buf, key, strlen(key)); | ||
if (!tmp) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
*dd_tags_buf = tmp; | ||
|
||
tmp = flb_sds_cat(*dd_tags_buf, ":", 1); | ||
if (!tmp) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
*dd_tags_buf = tmp; | ||
|
||
tmp = flb_sds_cat(*dd_tags_buf, val, val_len); | ||
if (!tmp) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
*dd_tags_buf = tmp; | ||
|
||
return 0; | ||
flb_sds_cat(dd_tags, key, strlen(key)); | ||
flb_sds_cat(dd_tags, ":", 1); | ||
flb_sds_cat(dd_tags, val, val_len); | ||
} | ||
|
||
/* default remapping: just move the key/val pair under dd_tags */ | ||
static int dd_remap_move_to_tags(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_move_to_tags(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t dd_tags) | ||
{ | ||
return dd_remap_append_kv_to_ddtags(tag_name, attr_value.via.str.ptr, | ||
attr_value.via.str.size, dd_tags_buf); | ||
dd_remap_append_kv_to_ddtags(tag_name, attr_value.via.str.ptr, | ||
attr_value.via.str.size, dd_tags); | ||
} | ||
|
||
/* remapping function for container_name */ | ||
static int dd_remap_container_name(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_container_name(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t dd_tags) | ||
Comment on lines
-78
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. help me understand again, why are we reverting these changes which probably still are a real fix? Also if we are going to revert them, why not put it in a revert commit? Why same commit as this new fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested the individual parts of the datadog pr and it turns out that completely unrelated error handling code was triggering a segfault somewhere random in the code (like on a network call). We decided that this PR would keep only the essential portions of the recent PR and ditch the lower priority ones to avoid adding the segfault |
||
{ | ||
/* remove the first / if present */ | ||
unsigned int adjust; | ||
flb_sds_t buf = NULL; | ||
int ret; | ||
flb_sds_t buf; | ||
|
||
adjust = attr_value.via.str.ptr[0] == '/' ? 1 : 0; | ||
buf = flb_sds_create_len(attr_value.via.str.ptr + adjust, | ||
attr_value.via.str.size - adjust); | ||
if (!buf) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags_buf); | ||
dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags); | ||
flb_sds_destroy(buf); | ||
if (ret < 0) { | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* remapping function for ecs_cluster */ | ||
static int dd_remap_ecs_cluster(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_ecs_cluster(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t dd_tags) | ||
{ | ||
flb_sds_t buf = NULL; | ||
flb_sds_t buf; | ||
char *cluster_name; | ||
int ret; | ||
|
||
buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size); | ||
if (!buf) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
cluster_name = strstr(buf, ECS_CLUSTER_PREFIX); | ||
|
||
if (cluster_name != NULL) { | ||
cluster_name += strlen(ECS_CLUSTER_PREFIX); | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, cluster_name, strlen(cluster_name), dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
dd_remap_append_kv_to_ddtags(tag_name, cluster_name, strlen(cluster_name), dd_tags); | ||
} | ||
else { | ||
/* | ||
* here the input is invalid: not in form of "XXXXXXcluster/"cluster-name | ||
* we preverse the original value under tag "cluster_name". | ||
*/ | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags); | ||
} | ||
flb_sds_destroy(buf); | ||
return 0; | ||
} | ||
|
||
/* remapping function for ecs_task_definition */ | ||
static int dd_remap_ecs_task_definition(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_ecs_task_definition(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t dd_tags) | ||
{ | ||
flb_sds_t buf = NULL; | ||
flb_sds_t buf; | ||
char *split; | ||
int ret; | ||
|
||
buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size); | ||
if (!buf) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
split = strchr(buf, ':'); | ||
|
||
if (split != NULL) { | ||
ret = dd_remap_append_kv_to_ddtags("task_family", buf, split-buf, dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
ret = dd_remap_append_kv_to_ddtags("task_version", split+1, strlen(split+1), dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
dd_remap_append_kv_to_ddtags("task_family", buf, split-buf, dd_tags); | ||
dd_remap_append_kv_to_ddtags("task_version", split+1, strlen(split+1), dd_tags); | ||
} | ||
else { | ||
/* | ||
* here the input is invalid: not in form of task_name:task_version | ||
* we preverse the original value under tag "ecs_task_definition". | ||
*/ | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags); | ||
} | ||
flb_sds_destroy(buf); | ||
return 0; | ||
} | ||
|
||
/* remapping function for ecs_task_arn */ | ||
static int dd_remap_ecs_task_arn(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t *dd_tags_buf) | ||
static void dd_remap_ecs_task_arn(const char *tag_name, | ||
msgpack_object attr_value, flb_sds_t dd_tags) | ||
{ | ||
flb_sds_t buf; | ||
char *remain; | ||
char *split; | ||
char *task_arn; | ||
int ret; | ||
|
||
buf = flb_sds_create_len(attr_value.via.str.ptr, attr_value.via.str.size); | ||
if (!buf) { | ||
flb_errno(); | ||
return -1; | ||
} | ||
|
||
/* | ||
* if the input is invalid, not in the form of "arn:aws:ecs:region:XXXX" | ||
|
@@ -206,33 +132,24 @@ static int dd_remap_ecs_task_arn(const char *tag_name, | |
split = strchr(remain, ':'); | ||
|
||
if (split != NULL) { | ||
ret = dd_remap_append_kv_to_ddtags("region", remain, split-remain, dd_tags_buf); | ||
if (ret < 0) { | ||
flb_sds_destroy(buf); | ||
return -1; | ||
} | ||
dd_remap_append_kv_to_ddtags("region", remain, split-remain, dd_tags); | ||
} | ||
} | ||
|
||
task_arn = strstr(buf, ECS_TASK_PREFIX); | ||
if (task_arn != NULL) { | ||
/* parse out the task_arn */ | ||
task_arn += strlen(ECS_TASK_PREFIX); | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, task_arn, strlen(task_arn), dd_tags_buf); | ||
dd_remap_append_kv_to_ddtags(tag_name, task_arn, strlen(task_arn), dd_tags); | ||
} | ||
else { | ||
/* | ||
* if the input is invalid, not in the form of "XXXXXXXXtask/"task-arn | ||
* then we preverse the original value under tag "task_arn". | ||
*/ | ||
ret = dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags_buf); | ||
dd_remap_append_kv_to_ddtags(tag_name, buf, strlen(buf), dd_tags); | ||
} | ||
flb_sds_destroy(buf); | ||
if (ret < 0) { | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the data buffer resize fix from here: #6570