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_kinesis_firehose: add support for log_key #2619

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions plugins/out_kinesis_firehose/firehose.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ static int cb_firehose_init(struct flb_output_instance *ins,
ctx->time_key_format = DEFAULT_TIME_KEY_FORMAT;
}

tmp = flb_output_get_property("log_key", ins);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assignment is not necessary if the offsetof() is used in the configmap

if (tmp) {
ctx->log_key = tmp;
}

if (ctx->log_key && ctx->time_key) {
flb_plg_error(ctx->ins, "'time_key' and 'log_key' can not be used together");
goto error;
}

tmp = flb_output_get_property("endpoint", ins);
if (tmp) {
ctx->custom_endpoint = FLB_TRUE;
Expand Down Expand Up @@ -413,6 +423,16 @@ static struct flb_config_map config_map[] = {
"Custom endpoint for the STS API."
},

{
FLB_CONFIG_MAP_STR, "log_key", NULL,
0, FLB_FALSE, 0,
"By default, the whole log record will be sent to Firehose. "
"If you specify a key name with this option, then only the value of "
"that key will be sent to Firehose. For example, if you are using "
"the Fluentd Docker log driver, you can specify `log_key log` and only "
"the log message will be sent to Firehose."
},

/* EOF */
{0}
};
Expand Down
11 changes: 11 additions & 0 deletions plugins/out_kinesis_firehose/firehose_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ static int process_event(struct flb_firehose *ctx, struct flush *buf,
return 2;
}

if (ctx->log_key) {
/*
* flb_msgpack_to_json will encase the value in quotes
* We don't want that for log_key, so we ignore the first
* and last character
*/
written -= 2;
tmp_buf_ptr++; /* pass over the opening quote */
buf->tmp_buf_offset++;
}

/* is (written + 1) because we still have to append newline */
if ((written + 1) >= MAX_EVENT_SIZE) {
flb_plg_warn(ctx->ins, "[size=%zu] Discarding record which is larger than "
Expand Down