Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_stackdriver: test_log_entry_format will output log entries to stdout #8144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
avilevy18 marked this conversation as resolved.
Show resolved Hide resolved
#endif
flb_upstream_conn_release(u_conn);
igorpeshansky marked this conversation as resolved.
Show resolved Hide resolved
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
Loading