diff --git a/plugins/in_elasticsearch/in_elasticsearch.h b/plugins/in_elasticsearch/in_elasticsearch.h index 6af189559a5..10deb62aa4b 100644 --- a/plugins/in_elasticsearch/in_elasticsearch.h +++ b/plugins/in_elasticsearch/in_elasticsearch.h @@ -42,7 +42,7 @@ struct flb_in_elasticsearch { char cluster_name[16]; char node_name[12]; - struct flb_log_event_encoder log_encoder; + struct flb_log_event_encoder *log_encoder; struct flb_input_instance *ins; diff --git a/plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c b/plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c index ca9f7acfefc..0f452a26da8 100644 --- a/plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c +++ b/plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c @@ -418,9 +418,9 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char } if (error_op == FLB_FALSE) { - flb_log_event_encoder_reset(&ctx->log_encoder); + flb_log_event_encoder_reset(ctx->log_encoder); - ret = flb_log_event_encoder_begin_record(&ctx->log_encoder); + ret = flb_log_event_encoder_begin_record(ctx->log_encoder); if (ret != FLB_EVENT_ENCODER_SUCCESS) { flb_sds_destroy(write_op); @@ -431,7 +431,7 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char } ret = flb_log_event_encoder_set_timestamp( - &ctx->log_encoder, + ctx->log_encoder, &tm); if (ret != FLB_EVENT_ENCODER_SUCCESS) { @@ -444,7 +444,7 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char if (ret == FLB_EVENT_ENCODER_SUCCESS) { ret = flb_log_event_encoder_append_body_values( - &ctx->log_encoder, + ctx->log_encoder, FLB_LOG_EVENT_CSTRING_VALUE((char *) ctx->meta_key), FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(&result.data)); } @@ -469,7 +469,7 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char map_copy_entry = &result.data.via.map.ptr[map_copy_index]; ret = flb_log_event_encoder_append_body_values( - &ctx->log_encoder, + ctx->log_encoder, FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(&map_copy_entry->key), FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(&map_copy_entry->val)); } @@ -481,7 +481,7 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char break; } - ret = flb_log_event_encoder_commit_record(&ctx->log_encoder); + ret = flb_log_event_encoder_commit_record(ctx->log_encoder); if (ret != FLB_EVENT_ENCODER_SUCCESS) { flb_plg_error(ctx->ins, "event encoder error : %d", ret); @@ -501,8 +501,8 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char flb_input_log_append(ctx->ins, tag_from_record, flb_sds_len(tag_from_record), - ctx->log_encoder.output_buffer, - ctx->log_encoder.output_length); + ctx->log_encoder->output_buffer, + ctx->log_encoder->output_length); flb_sds_destroy(tag_from_record); } @@ -510,17 +510,17 @@ static int process_ndpack(struct flb_in_elasticsearch *ctx, flb_sds_t tag, char flb_input_log_append(ctx->ins, tag, flb_sds_len(tag), - ctx->log_encoder.output_buffer, - ctx->log_encoder.output_length); + ctx->log_encoder->output_buffer, + ctx->log_encoder->output_length); } else { /* use default plugin Tag (it internal name, e.g: http.0 */ flb_input_log_append(ctx->ins, NULL, 0, - ctx->log_encoder.output_buffer, - ctx->log_encoder.output_length); + ctx->log_encoder->output_buffer, + ctx->log_encoder->output_length); } - flb_log_event_encoder_reset(&ctx->log_encoder); + flb_log_event_encoder_reset(ctx->log_encoder); } if (op_ret) { if (flb_sds_cmp(write_op, "index", op_str_size) == 0) { diff --git a/plugins/in_elasticsearch/in_elasticsearch_config.c b/plugins/in_elasticsearch/in_elasticsearch_config.c index e8c53f12bc7..56b5a4e099f 100644 --- a/plugins/in_elasticsearch/in_elasticsearch_config.c +++ b/plugins/in_elasticsearch/in_elasticsearch_config.c @@ -59,15 +59,12 @@ struct flb_in_elasticsearch *in_elasticsearch_config_create(struct flb_input_ins * moment so we want to make sure that it stays that way! */ - ret = flb_log_event_encoder_init(&ctx->log_encoder, - FLB_LOG_EVENT_FORMAT_DEFAULT); - - if (ret != FLB_EVENT_ENCODER_SUCCESS) { - flb_plg_error(ctx->ins, "error initializing event encoder : %d", ret); - + ctx->log_encoder = flb_log_event_encoder_create(FLB_LOG_EVENT_FORMAT_DEFAULT); + if (ctx->log_encoder == NULL) { + flb_plg_error(ctx->ins, "event encoder initialization error"); in_elasticsearch_config_destroy(ctx); - return ctx = NULL; + return NULL; } @@ -76,7 +73,7 @@ struct flb_in_elasticsearch *in_elasticsearch_config_create(struct flb_input_ins int in_elasticsearch_config_destroy(struct flb_in_elasticsearch *ctx) { - flb_log_event_encoder_destroy(&ctx->log_encoder); + flb_log_event_encoder_destroy(ctx->log_encoder); /* release all connections */ in_elasticsearch_bulk_conn_release_all(ctx);