Skip to content

Commit

Permalink
Merge pull request #8144 from avilevy18/avilevy-stackdriver-test-log-…
Browse files Browse the repository at this point in the history
…entry-format

out_stackdriver: test_log_entry_format will output log entries to stdout
  • Loading branch information
braydonk authored Nov 22, 2023
2 parents 2555bd4 + 5cf4486 commit 8733b25
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
41 changes: 28 additions & 13 deletions plugins/out_stackdriver/stackdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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}
};
Expand Down
1 change: 1 addition & 0 deletions plugins/out_stackdriver/stackdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 8733b25

Please sign in to comment.