diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 23d31ad4f0a..5c0a2cf8647 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -1226,6 +1226,10 @@ static int cb_stackdriver_init(struct flb_output_instance *ins, /* Set context */ flb_output_set_context(ins, ctx); + if (ctx->test_log_entry_format) { + return 0; + } + /* Network mode IPv6 */ if (ins->host.ipv6 == FLB_TRUE) { io_flags |= FLB_IO_IPV6; @@ -1789,7 +1793,7 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx, * "entries": [] */ msgpack_pack_map(&mp_pck, 3); - + /* Set partialSuccess to true */ msgpack_pack_str(&mp_pck, 14); msgpack_pack_str_body(&mp_pck, "partialSuccess", 14); @@ -2743,35 +2747,41 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, uint64_t ts = cfl_time_now(); #endif - /* Get upstream connection */ - u_conn = flb_upstream_conn_get(ctx->u); - if (!u_conn) { + /* Reformat msgpack to stackdriver JSON payload */ + payload_buf = stackdriver_format(ctx, + event_chunk->total_events, + event_chunk->tag, flb_sds_len(event_chunk->tag), + event_chunk->data, event_chunk->size); + if (!payload_buf) { #ifdef FLB_HAVE_METRICS cmt_counter_inc(ctx->cmt_failed_requests, ts, 1, (char *[]) {name}); /* OLD api */ flb_metrics_sum(FLB_STACKDRIVER_FAILED_REQUESTS, 1, ctx->ins->metrics); - - update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); #endif FLB_OUTPUT_RETURN(FLB_RETRY); } - /* Reformat msgpack to stackdriver JSON payload */ - payload_buf = stackdriver_format(ctx, - event_chunk->total_events, - event_chunk->tag, flb_sds_len(event_chunk->tag), - event_chunk->data, event_chunk->size); - if (!payload_buf) { + if (ctx->test_log_entry_format) { + printf("%s", payload_buf); + flb_sds_destroy(payload_buf); + FLB_OUTPUT_RETURN(FLB_OK); + } + + /* Get upstream connection */ + u_conn = flb_upstream_conn_get(ctx->u); + if (!u_conn) { #ifdef FLB_HAVE_METRICS cmt_counter_inc(ctx->cmt_failed_requests, ts, 1, (char *[]) {name}); /* OLD api */ flb_metrics_sum(FLB_STACKDRIVER_FAILED_REQUESTS, 1, ctx->ins->metrics); + + update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); #endif - flb_upstream_conn_release(u_conn); + flb_sds_destroy(payload_buf); FLB_OUTPUT_RETURN(FLB_RETRY); } @@ -3079,6 +3089,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_stackdriver, resource_labels), "Set the resource labels" }, + { + FLB_CONFIG_MAP_BOOL, "test_log_entry_format", "false", + 0, FLB_TRUE, offsetof(struct flb_stackdriver, test_log_entry_format), + "Test log entry format" + }, /* EOF */ {0} }; diff --git a/plugins/out_stackdriver/stackdriver.h b/plugins/out_stackdriver/stackdriver.h index 41ec385b507..4e2f33dfc82 100644 --- a/plugins/out_stackdriver/stackdriver.h +++ b/plugins/out_stackdriver/stackdriver.h @@ -179,6 +179,7 @@ struct flb_stackdriver { flb_sds_t http_request_key; int http_request_key_size; bool autoformat_stackdriver_trace; + bool test_log_entry_format; flb_sds_t stackdriver_agent;