From ae5f5eb20d4b7f7aa2add50f320cef2eb63a3067 Mon Sep 17 00:00:00 2001 From: avilevy Date: Tue, 7 Nov 2023 16:50:02 +0000 Subject: [PATCH 1/6] out_stackdriver: test_log_entry_format will output log entries to stdout Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 42 ++++++++++++++++++--------- plugins/out_stackdriver/stackdriver.h | 1 + 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 5c48a338b81..07197ff3b1b 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -1207,6 +1207,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; @@ -2534,36 +2538,43 @@ 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_http_metrics(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); - update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR, FLB_RETRY); #endif + flb_upstream_conn_release(u_conn); 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); + return; + } + + /* 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_http_metrics(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); + update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR, FLB_RETRY); #endif - flb_upstream_conn_release(u_conn); FLB_OUTPUT_RETURN(FLB_RETRY); } @@ -2846,6 +2857,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 239a3ee318a..014daaff6d9 100644 --- a/plugins/out_stackdriver/stackdriver.h +++ b/plugins/out_stackdriver/stackdriver.h @@ -174,6 +174,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; From 1dc14abd48edc94ba1a8c437f4501c51924247c3 Mon Sep 17 00:00:00 2001 From: avilevy Date: Fri, 10 Nov 2023 16:51:31 +0000 Subject: [PATCH 2/6] Addressed comments Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 07197ff3b1b..90f062fc28c 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -2538,7 +2538,7 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, uint64_t ts = cfl_time_now(); #endif - /* Reformat msgpack to stackdriver JSON payload */ + /* Reformat msgpack to stackdriver JSON payload */ payload_buf = stackdriver_format(ctx, event_chunk->total_events, event_chunk->tag, flb_sds_len(event_chunk->tag), @@ -2551,7 +2551,6 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, /* OLD api */ flb_metrics_sum(FLB_STACKDRIVER_FAILED_REQUESTS, 1, ctx->ins->metrics); #endif - flb_upstream_conn_release(u_conn); FLB_OUTPUT_RETURN(FLB_RETRY); } @@ -2566,6 +2565,7 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, u_conn = flb_upstream_conn_get(ctx->u); if (!u_conn) { #ifdef FLB_HAVE_METRICS + flb_upstream_conn_release(u_conn); cmt_counter_inc(ctx->cmt_failed_requests, ts, 1, (char *[]) {name}); From 71912c6df099b2154ab1df84058d30422b1523d0 Mon Sep 17 00:00:00 2001 From: avilevy Date: Tue, 21 Nov 2023 20:07:17 +0000 Subject: [PATCH 3/6] Bug fix Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index ad7cd190921..b271ce965d6 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -2776,7 +2776,6 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, u_conn = flb_upstream_conn_get(ctx->u); if (!u_conn) { #ifdef FLB_HAVE_METRICS - flb_upstream_conn_release(u_conn); cmt_counter_inc(ctx->cmt_failed_requests, ts, 1, (char *[]) {name}); @@ -2784,8 +2783,8 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, flb_metrics_sum(FLB_STACKDRIVER_FAILED_REQUESTS, 1, ctx->ins->metrics); update_http_metrics(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); - update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR, FLB_RETRY); #endif + flb_upstream_conn_release(u_conn); FLB_OUTPUT_RETURN(FLB_RETRY); } From c1dcc7e329da8f75a2d145652fc8ae4cd0557f1f Mon Sep 17 00:00:00 2001 From: avilevy Date: Tue, 21 Nov 2023 20:17:26 +0000 Subject: [PATCH 4/6] Bug fix Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index b271ce965d6..188dcf8d49c 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -2782,7 +2782,7 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, /* OLD api */ flb_metrics_sum(FLB_STACKDRIVER_FAILED_REQUESTS, 1, ctx->ins->metrics); - update_http_metrics(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); + update_retry_metric(ctx, event_chunk, ts, STACKDRIVER_NET_ERROR); #endif flb_upstream_conn_release(u_conn); FLB_OUTPUT_RETURN(FLB_RETRY); From deb51c8605d7ceb59183532f7604aacbfbfa5779 Mon Sep 17 00:00:00 2001 From: avilevy Date: Tue, 21 Nov 2023 23:48:12 +0000 Subject: [PATCH 5/6] Addressed comments Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 188dcf8d49c..d8af6e721c1 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -2769,7 +2769,6 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, printf("%s", payload_buf); flb_sds_destroy(payload_buf); FLB_OUTPUT_RETURN(FLB_OK); - return; } /* Get upstream connection */ @@ -2784,7 +2783,7 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, 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); } From 5cf44867803082d49a5bb19286ed93018222e4d7 Mon Sep 17 00:00:00 2001 From: avilevy Date: Tue, 21 Nov 2023 23:56:10 +0000 Subject: [PATCH 6/6] Addressed comments Signed-off-by: avilevy --- plugins/out_stackdriver/stackdriver.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index d8af6e721c1..5c0a2cf8647 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -2759,8 +2759,6 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk, /* 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); }