Skip to content
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

in_http: use 'tag_key' option when json array is received #9590

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/in_http/http_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,11 @@ static int process_pack_ng(struct flb_http *ctx, flb_sds_t tag, char *buf, size_
{
record = obj->via.array.ptr[i];

tag_from_record = NULL;
if (ctx->tag_key) {
tag_from_record = tag_key(ctx, &record);
}

if (tag_from_record) {
ret = process_pack_record(ctx, &tm, tag_from_record, &record);
flb_sds_destroy(tag_from_record);
Expand Down
17 changes: 14 additions & 3 deletions tests/runtime/in_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void flb_test_http_failure_400_bad_disk_write()
test_ctx_destroy(ctx);
}

void flb_test_http_tag_key()
void test_http_tag_key(char *input)
{
struct flb_lib_out_cb cb_data;
struct test_ctx *ctx;
Expand All @@ -597,7 +597,7 @@ void flb_test_http_tag_key()
int num;
size_t b_sent;

char *buf = "{\"test\":\"msg\", \"tag\":\"new_tag\"}";
char *buf = input;

clear_output_num();

Expand Down Expand Up @@ -661,12 +661,23 @@ void flb_test_http_tag_key()
test_ctx_destroy(ctx);
}

void flb_test_http_tag_key_with_map_input()
{
test_http_tag_key("{\"tag\":\"new_tag\",\"test\":\"msg\"}");
}

void flb_test_http_tag_key_with_array_input()
{
test_http_tag_key("[{\"tag\":\"new_tag\",\"test\":\"msg\"}]");
}

TEST_LIST = {
{"http", flb_test_http},
{"successful_response_code_200", flb_test_http_successful_response_code_200},
{"successful_response_code_204", flb_test_http_successful_response_code_204},
{"failure_response_code_400_bad_json", flb_test_http_failure_400_bad_json},
{"failure_response_code_400_bad_disk_write", flb_test_http_failure_400_bad_disk_write},
{"tag_key", flb_test_http_tag_key},
{"tag_key_with_map_input", flb_test_http_tag_key_with_map_input},
{"tag_key_with_array_input", flb_test_http_tag_key_with_array_input},
{NULL, NULL}
};
Loading