-
Notifications
You must be signed in to change notification settings - Fork 1.8k
in_udp: Add capability to insert source IP when format none is set #11160
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
base: master
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 |
|---|---|---|
|
|
@@ -431,10 +431,77 @@ void flb_test_format_none_separator() | |
| test_ctx_destroy(ctx); | ||
| } | ||
|
|
||
| void flb_test_format_none_with_source_address() | ||
| { | ||
| struct flb_lib_out_cb cb_data; | ||
| struct test_ctx *ctx; | ||
| struct sockaddr_in addr; | ||
| flb_sockfd_t fd; | ||
| int ret; | ||
| int num; | ||
| ssize_t w_size; | ||
|
|
||
| char *buf = "message\n"; | ||
|
Contributor
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. Please declare this variable as a |
||
| size_t size = strlen(buf); | ||
|
Contributor
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. Please separate the definition of this variable from the assignment of it. |
||
|
|
||
| clear_output_num(); | ||
|
|
||
| cb_data.cb = cb_check_result_json; | ||
| cb_data.data = "\"log\":\"message\",\"source_host\":\"udp://"; | ||
|
|
||
| ctx = test_ctx_create(&cb_data); | ||
| if (!TEST_CHECK(ctx != NULL)) { | ||
| TEST_MSG("test_ctx_create failed"); | ||
| exit(EXIT_FAILURE); | ||
|
Contributor
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 could be wrong but I think failed test cases shouldn't |
||
| } | ||
|
|
||
| ret = flb_output_set(ctx->flb, ctx->o_ffd, | ||
| "match", "*", | ||
| "format", "json", | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| ret = flb_input_set(ctx->flb, ctx->i_ffd, | ||
| "format", "none", | ||
| "source_address_key", "source_host", | ||
| NULL); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| /* Start the engine */ | ||
| ret = flb_start(ctx->flb); | ||
| TEST_CHECK(ret == 0); | ||
|
|
||
| /* use default host/port */ | ||
| fd = init_udp(NULL, -1, &addr); | ||
| if (!TEST_CHECK(fd >= 0)) { | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| w_size = sendto(fd, buf, size, 0, (const struct sockaddr *)&addr, sizeof(addr)); | ||
| if (!TEST_CHECK(w_size == size)) { | ||
| TEST_MSG("failed to send, errno=%d", errno); | ||
| flb_socket_close(fd); | ||
| test_ctx_destroy(ctx); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| /* waiting to flush */ | ||
| flb_time_msleep(1500); | ||
|
Contributor
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. As a general rule, basing non timing related tests on timing is problematic, particularly when CI runs on nodes that are somewhat loaded as it tends to create false positives. |
||
|
|
||
| num = get_output_num(); | ||
| if (!TEST_CHECK(num > 0)) { | ||
| TEST_MSG("no outputs"); | ||
| } | ||
|
|
||
| flb_socket_close(fd); | ||
| test_ctx_destroy(ctx); | ||
| } | ||
|
|
||
| TEST_LIST = { | ||
| {"udp", flb_test_udp}, | ||
| {"udp_with_source_address", flb_test_udp_with_source_address}, | ||
| {"format_none", flb_test_format_none}, | ||
| {"format_none_separator", flb_test_format_none_separator}, | ||
| {"format_none_with_source_address", flb_test_format_none_with_source_address}, | ||
| {NULL, NULL} | ||
| }; | ||
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.
Using meaningful variable names is preferred to these generic names because even though this is a simple test case neglecting to do so leads to using these types of names in more complex (and meaningful) pieces of code which means someone who reads the code later on might have a harder time understanding it or even miss the point and end up introducing a bug.