Skip to content

Commit ff584f5

Browse files
imankurpatel000edsiper
authored andcommitted
in_http: use 'tag_key' option when json array is received
When a json array is received by http input, it doesn't use the 'tag_key' option and always sets the tag to 'http.N'. So this fixes the bug and also adds test cases to test for both json object and json array. Signed-off-by: Ankur Patel <[email protected]>
1 parent 1eb324a commit ff584f5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

plugins/in_http/http_prot.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,11 @@ static int process_pack_ng(struct flb_http *ctx, flb_sds_t tag, char *buf, size_
843843
{
844844
record = obj->via.array.ptr[i];
845845

846+
tag_from_record = NULL;
847+
if (ctx->tag_key) {
848+
tag_from_record = tag_key(ctx, &record);
849+
}
850+
846851
if (tag_from_record) {
847852
ret = process_pack_record(ctx, &tm, tag_from_record, &record);
848853
flb_sds_destroy(tag_from_record);

tests/runtime/in_http.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ void flb_test_http_failure_400_bad_disk_write()
588588
test_ctx_destroy(ctx);
589589
}
590590

591-
void flb_test_http_tag_key()
591+
void test_http_tag_key(char *input)
592592
{
593593
struct flb_lib_out_cb cb_data;
594594
struct test_ctx *ctx;
@@ -597,7 +597,7 @@ void flb_test_http_tag_key()
597597
int num;
598598
size_t b_sent;
599599

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

602602
clear_output_num();
603603

@@ -661,12 +661,23 @@ void flb_test_http_tag_key()
661661
test_ctx_destroy(ctx);
662662
}
663663

664+
void flb_test_http_tag_key_with_map_input()
665+
{
666+
test_http_tag_key("{\"tag\":\"new_tag\",\"test\":\"msg\"}");
667+
}
668+
669+
void flb_test_http_tag_key_with_array_input()
670+
{
671+
test_http_tag_key("[{\"tag\":\"new_tag\",\"test\":\"msg\"}]");
672+
}
673+
664674
TEST_LIST = {
665675
{"http", flb_test_http},
666676
{"successful_response_code_200", flb_test_http_successful_response_code_200},
667677
{"successful_response_code_204", flb_test_http_successful_response_code_204},
668678
{"failure_response_code_400_bad_json", flb_test_http_failure_400_bad_json},
669679
{"failure_response_code_400_bad_disk_write", flb_test_http_failure_400_bad_disk_write},
670-
{"tag_key", flb_test_http_tag_key},
680+
{"tag_key_with_map_input", flb_test_http_tag_key_with_map_input},
681+
{"tag_key_with_array_input", flb_test_http_tag_key_with_array_input},
671682
{NULL, NULL}
672683
};

0 commit comments

Comments
 (0)