Skip to content

Commit ec59b32

Browse files
committed
pipeline: outputs: es: fixed tests after modification of formatter callback contract
Signed-off-by: Marat Abrarov <[email protected]>
1 parent e2fecd3 commit ec59b32

File tree

4 files changed

+93
-42
lines changed

4 files changed

+93
-42
lines changed

plugins/out_es/es.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <fluent-bit/flb_record_accessor.h>
3232
#include <fluent-bit/flb_ra_key.h>
3333
#include <fluent-bit/flb_log_event_decoder.h>
34+
#include <fluent-bit/flb_upstream_node.h>
3435

3536
#include "es.h"
3637
#include "es_conf.h"
@@ -647,7 +648,7 @@ static struct flb_elasticsearch_config *flb_elasticsearch_target(
647648
struct flb_upstream_node *target_node;
648649

649650
if (ctx->ha_mode == FLB_FALSE) {
650-
ec = mk_list_entry_first(&ctx->configs, struct flb_elasticsearch_config, _head);
651+
ec = flb_es_upstream_conf(ctx, NULL);
651652
*node = NULL;
652653
return ec;
653654
}
@@ -658,8 +659,7 @@ static struct flb_elasticsearch_config *flb_elasticsearch_target(
658659
return NULL;
659660
}
660661

661-
/* Get elasticsearch_config stored in node opaque data */
662-
ec = flb_upstream_node_get_data(target_node);
662+
ec = flb_es_upstream_conf(ctx, target_node);
663663
*node = target_node;
664664

665665
return ec;

plugins/out_es/es_conf.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,19 @@ void flb_es_conf_destroy(struct flb_elasticsearch *ctx)
428428

429429
flb_free(ctx);
430430
}
431+
432+
struct flb_elasticsearch_config *flb_es_upstream_conf(struct flb_elasticsearch *ctx,
433+
struct flb_upstream_node *node)
434+
{
435+
if (!ctx) {
436+
return NULL;
437+
}
438+
if (node) {
439+
/* Get elasticsearch_config stored in node opaque data */
440+
return flb_upstream_node_get_data(node);
441+
}
442+
if (mk_list_is_empty(&ctx->configs) == 0) {
443+
return NULL;
444+
}
445+
return mk_list_entry_last(&ctx->configs, struct flb_elasticsearch_config, _head);
446+
}

plugins/out_es/es_conf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
#ifndef FLB_OUT_ES_CONF_H
2121
#define FLB_OUT_ES_CONF_H
2222

23+
#include <fluent-bit/flb_upstream_node.h>
24+
2325
#include "es.h"
2426

2527
struct flb_elasticsearch *flb_es_conf_create(struct flb_output_instance *ins,
2628
struct flb_config *config);
2729

2830
void flb_es_conf_destroy(struct flb_elasticsearch *ctx);
2931

32+
struct flb_elasticsearch_config *flb_es_upstream_conf(struct flb_elasticsearch *ctx,
33+
struct flb_upstream_node *node);
34+
3035
#endif

tests/runtime/out_elasticsearch.c

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
22

3+
#include <monkey/mk_core/mk_list.h>
34
#include <fluent-bit.h>
45
#include "flb_tests_runtime.h"
56

67
/* Test data */
78
#include "data/es/json_es.h" /* JSON_ES */
89

10+
/*
11+
* Include plugin headers to get the definition of structure used as flush context
12+
* and to know how to extract that structure from plugin context.
13+
*/
14+
#include "../../plugins/out_es/es.h"
15+
#include "../../plugins/out_es/es_conf.h"
16+
17+
static void *cb_flush_context(struct flb_config *config, struct flb_input_instance *ins,
18+
void *plugin_context, void *flush_ctx)
19+
{
20+
struct flb_elasticsearch *ctx = plugin_context;
21+
(void) config;
22+
(void) ins;
23+
(void) flush_ctx;
24+
return flb_es_upstream_conf(ctx, NULL);
25+
}
926

1027
static void cb_check_write_op_index(void *ctx, int ffd,
1128
int res_ret, void *res_data,
@@ -195,9 +212,10 @@ void flb_test_write_operation_index()
195212
NULL);
196213

197214
/* Enable test mode */
198-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
199-
cb_check_write_op_index,
200-
NULL, NULL);
215+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
216+
cb_check_write_op_index,
217+
NULL, NULL, cb_flush_context);
218+
TEST_CHECK(ret == 0);
201219

202220
/* Start */
203221
ret = flb_start(ctx);
@@ -239,9 +257,10 @@ void flb_test_write_operation_create()
239257
NULL);
240258

241259
/* Enable test mode */
242-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
243-
cb_check_write_op_create,
244-
NULL, NULL);
260+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
261+
cb_check_write_op_create,
262+
NULL, NULL, cb_flush_context);
263+
TEST_CHECK(ret == 0);
245264

246265
/* Start */
247266
ret = flb_start(ctx);
@@ -285,9 +304,10 @@ void flb_test_write_operation_update()
285304
NULL);
286305

287306
/* Enable test mode */
288-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
289-
cb_check_write_op_update,
290-
NULL, NULL);
307+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
308+
cb_check_write_op_update,
309+
NULL, NULL, cb_flush_context);
310+
TEST_CHECK(ret == 0);
291311

292312
/* Start */
293313
ret = flb_start(ctx);
@@ -331,9 +351,10 @@ void flb_test_write_operation_upsert()
331351
NULL);
332352

333353
/* Enable test mode */
334-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
335-
cb_check_write_op_upsert,
336-
NULL, NULL);
354+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
355+
cb_check_write_op_upsert,
356+
NULL, NULL, cb_flush_context);
357+
TEST_CHECK(ret == 0);
337358

338359
/* Start */
339360
ret = flb_start(ctx);
@@ -376,9 +397,10 @@ void flb_test_index_type()
376397
NULL);
377398

378399
/* Enable test mode */
379-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
380-
cb_check_index_type,
381-
NULL, NULL);
400+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
401+
cb_check_index_type,
402+
NULL, NULL, cb_flush_context);
403+
TEST_CHECK(ret == 0);
382404

383405
/* Start */
384406
ret = flb_start(ctx);
@@ -422,9 +444,10 @@ void flb_test_logstash_format()
422444
NULL);
423445

424446
/* Enable test mode */
425-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
426-
cb_check_logstash_format,
427-
NULL, NULL);
447+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
448+
cb_check_logstash_format,
449+
NULL, NULL, cb_flush_context);
450+
TEST_CHECK(ret == 0);
428451

429452
/* Start */
430453
ret = flb_start(ctx);
@@ -469,9 +492,10 @@ void flb_test_logstash_format_nanos()
469492
NULL);
470493

471494
/* Enable test mode */
472-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
473-
cb_check_logstash_format_nanos,
474-
NULL, NULL);
495+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
496+
cb_check_logstash_format_nanos,
497+
NULL, NULL, cb_flush_context);
498+
TEST_CHECK(ret == 0);
475499

476500
/* Start */
477501
ret = flb_start(ctx);
@@ -514,9 +538,10 @@ void flb_test_tag_key()
514538
NULL);
515539

516540
/* Enable test mode */
517-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
518-
cb_check_tag_key,
519-
NULL, NULL);
541+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
542+
cb_check_tag_key,
543+
NULL, NULL, cb_flush_context);
544+
TEST_CHECK(ret == 0);
520545

521546
/* Start */
522547
ret = flb_start(ctx);
@@ -558,9 +583,10 @@ void flb_test_replace_dots()
558583
NULL);
559584

560585
/* Enable test mode */
561-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
562-
cb_check_replace_dots,
563-
NULL, NULL);
586+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
587+
cb_check_replace_dots,
588+
NULL, NULL, cb_flush_context);
589+
TEST_CHECK(ret == 0);
564590

565591
/* Start */
566592
ret = flb_start(ctx);
@@ -602,9 +628,10 @@ void flb_test_id_key()
602628
NULL);
603629

604630
/* Enable test mode */
605-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
606-
cb_check_id_key,
607-
NULL, NULL);
631+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
632+
cb_check_id_key,
633+
NULL, NULL, cb_flush_context);
634+
TEST_CHECK(ret == 0);
608635

609636
/* Start */
610637
ret = flb_start(ctx);
@@ -656,9 +683,10 @@ void flb_test_div0()
656683
NULL);
657684

658685
/* Enable test mode */
659-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
660-
cb_check_nothing,
661-
NULL, NULL);
686+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
687+
cb_check_nothing,
688+
NULL, NULL, cb_flush_context);
689+
TEST_CHECK(ret == 0);
662690

663691
/* Start */
664692
ret = flb_start(ctx);
@@ -736,9 +764,10 @@ void flb_test_long_index()
736764
NULL);
737765

738766
/* Enable test mode */
739-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
740-
cb_check_long_index,
741-
NULL, NULL);
767+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
768+
cb_check_long_index,
769+
NULL, NULL, cb_flush_context);
770+
TEST_CHECK(ret == 0);
742771

743772
/* Start */
744773
ret = flb_start(ctx);
@@ -783,9 +812,10 @@ void flb_test_logstash_prefix_separator()
783812
NULL);
784813

785814
/* Enable test mode */
786-
ret = flb_output_set_test(ctx, out_ffd, "formatter",
787-
cb_check_logstash_prefix_separator,
788-
NULL, NULL);
815+
ret = flb_output_set_test_with_ctx_callback(ctx, out_ffd, "formatter",
816+
cb_check_logstash_prefix_separator,
817+
NULL, NULL, cb_flush_context);
818+
TEST_CHECK(ret == 0);
789819

790820
/* Start */
791821
ret = flb_start(ctx);

0 commit comments

Comments
 (0)