-
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
out_es: out_es: use snprintf wrapper function for bulk header(#4311) #4361
out_es: out_es: use snprintf wrapper function for bulk header(#4311) #4361
Conversation
Signed-off-by: Takahiro Yamashita <[email protected]>
The function is a wrapper of snprintf. It can increase sds if sds doesn't have enough buffer. Signed-off-by: Takahiro Yamashita <[email protected]>
We used fixed char array to construct bulk header. If long index comes, it needs larger buffer. out_es uses snprintf wrapper function. If the buffer is small, the api increases the buffer. Signed-off-by: Takahiro Yamashita <[email protected]>
@@ -407,3 +407,31 @@ void flb_sds_destroy(flb_sds_t s) | |||
head = FLB_SDS_HEADER(s); | |||
flb_free(head); | |||
} | |||
|
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.
I think this function is not necessary and we can simply rely on flb_sds_printf() functionality.
flb_sds_t by default always reallocate if necessary, and calculating the final length can be done with flb_sds_len()
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.
Functionality is a little different.
flb_sds_printf
appends offset flb_sds_len(s)
and it means appends string.
https://github.com/fluent/fluent-bit/blob/v1.8.10/src/flb_sds.c#L367
I want to overwrite flb_sds_t.
So if we use the API to overwrite, we need to call flb_sds_len_set(sds, 0)
before the API.
flb_sds_len_set(j_index, 0);
out_buf = flb_sds_printf(&j_index,
ES_BULK_INDEX_FMT_ID_WITHOUT_TYPE,
es_index, id_key_str);
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.
ah I understand. thanks for the clarification.
On that case so I would suggest renaming the new function from:
- flb_sds_snprintf_realloc
to
- flb_sds_snprintf
basically the "realloc" context is something that works behind the scenes, where the user don't need to be aware of it (similar to other sds...)
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.
Thank you for comment.
I renamed.
Signed-off-by: Takahiro Yamashita <[email protected]>
Signed-off-by: Takahiro Yamashita <[email protected]>
Note: I sent a PR #4480 to fix test cases. |
Fixes #4311.
We used fixed char array to construct bulk header.
If long index( the length is greater than 80) , out_es creates broken json since the buffer is small and fixed.
We can reproduce the issue using below command.
This PR is to
flb_sds_snprintf_realloc
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
Documentation
Example Configuration
nc -l 9200
Debug output
Valgrind output
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.