Skip to content

Commit

Permalink
in_elasticsearch: Store log_encoder pointer (CID 508245)
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Aug 15, 2024
1 parent 26873b2 commit a827c93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion plugins/in_elasticsearch/in_elasticsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 13 additions & 13 deletions plugins/in_elasticsearch/in_elasticsearch_bulk_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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);
Expand All @@ -501,26 +501,26 @@ 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);
}
else if (tag) {
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) {
Expand Down
13 changes: 5 additions & 8 deletions plugins/in_elasticsearch/in_elasticsearch_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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);
Expand Down

0 comments on commit a827c93

Please sign in to comment.