Skip to content

Commit

Permalink
out_cloudwatch_logs: Rename 'event' to 'cw_event'
Browse files Browse the repository at this point in the history
libevent exports a struct with the same name (`struct event` in
event2/event_struct.h). For this reason, this plugin fails to
compile if libevent backend is enabled.

Also unistd.h is not POSIX standard and not all platforms (in
particular Windows) do not provide it. Include flb_compat.h to
abstract away the header inclusion.

With this patch, I can confirm out_cloudwatch_logs can be compiled
and run on Windows.

Signed-off-by: Fujimoto Seiji <fujimoto@ceptord.net>
  • Loading branch information
fujimotos authored and edsiper committed Jul 2, 2020
1 parent 62816d7 commit 61ef808
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions cmake/windows-setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set(FLB_OUT_NULL Yes)
set(FLB_OUT_FLOWCOUNTER Yes)
set(FLB_OUT_KAFKA No)
set(FLB_OUT_KAFKA_REST No)
set(FLB_OUT_CLOUDWATCH_LOGS Yes)

# FILTER plugins
# ==============
Expand Down
24 changes: 12 additions & 12 deletions plugins/out_cloudwatch_logs/cloudwatch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the License.
*/

#include <fluent-bit/flb_compat.h>
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_utils.h>
Expand All @@ -39,7 +40,6 @@
#include <monkey/mk_core.h>
#include <msgpack.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include "cloudwatch_api.h"
Expand Down Expand Up @@ -152,8 +152,8 @@ struct flb_http_client *mock_http_call(char *error_env_var, char *api)

int compare_events(const void *a_arg, const void *b_arg)
{
struct event *r_a = (struct event *) a_arg;
struct event *r_b = (struct event *) b_arg;
struct cw_event *r_a = (struct cw_event *) a_arg;
struct cw_event *r_b = (struct cw_event *) b_arg;

if (r_a->timestamp < r_b->timestamp) {
return -1;
Expand Down Expand Up @@ -243,7 +243,7 @@ static int init_put_payload(struct flb_cloudwatch *ctx, struct cw_flush *buf,
* Writes a log event to the output buffer
*/
static int write_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
struct event *event, int *offset)
struct cw_event *event, int *offset)
{
char ts[50];

Expand Down Expand Up @@ -296,7 +296,7 @@ static int end_put_payload(struct flb_cloudwatch *ctx, struct cw_flush *buf,
}

static unsigned long long stream_time_span(struct log_stream *stream,
struct event *event)
struct cw_event *event)
{
if (stream->oldest_event == 0 || stream->newest_event == 0) {
return 0;
Expand All @@ -314,7 +314,7 @@ static unsigned long long stream_time_span(struct log_stream *stream,

/* returns FLB_TRUE if time span is less than 24 hours, FLB_FALSE if greater */
static int check_stream_time_span(struct log_stream *stream,
struct event *event)
struct cw_event *event)
{
unsigned long long span = stream_time_span(stream, event);

Expand All @@ -326,7 +326,7 @@ static int check_stream_time_span(struct log_stream *stream,
}

/* sets the oldest_event and newest_event fields */
static void set_stream_time_span(struct log_stream *stream, struct event *event)
static void set_stream_time_span(struct log_stream *stream, struct cw_event *event)
{
if (stream->oldest_event == 0 || stream->oldest_event > event->timestamp) {
stream->oldest_event = event->timestamp;
Expand All @@ -350,7 +350,7 @@ int process_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
size_t written;
size_t size;
int offset = 0;
struct event *event;
struct cw_event *event;
char *tmp_buf_ptr;

tmp_buf_ptr = buf->tmp_buf + buf->tmp_buf_offset;
Expand Down Expand Up @@ -453,14 +453,14 @@ int send_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
int ret;
int offset;
int i;
struct event *event;
struct cw_event *event;

if (buf->event_index == 0) {
return 0;
}

/* events must be sorted by timestamp in a put payload */
qsort(buf->events, buf->event_index, sizeof(struct event), compare_events);
qsort(buf->events, buf->event_index, sizeof(struct cw_event), compare_events);

retry:
stream->newest_event = 0;
Expand Down Expand Up @@ -517,7 +517,7 @@ int add_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
const msgpack_object *obj, struct flb_time *tms)
{
int ret;
struct event *event;
struct cw_event *event;
int new_len;
size_t size;
int retry_add = FLB_FALSE;
Expand All @@ -531,7 +531,7 @@ int add_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
/* re-alloc event buffer if needed */
if ((buf->event_index + 1) >= buf->events_capacity) {
new_len = MAX_EVENTS_PER_PUT;
size = sizeof(struct event) * new_len;
size = sizeof(struct cw_event) * new_len;
flb_plg_debug(ctx->ins, "Increasing event buffer to %d", new_len);
buf->events = flb_realloc(buf->events, size);
if (!buf->events) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/out_cloudwatch_logs/cloudwatch_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the License.
*/

#include <fluent-bit/flb_compat.h>
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_utils.h>
Expand All @@ -38,7 +39,6 @@
#include <monkey/mk_core.h>
#include <msgpack.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>

#include "cloudwatch_logs.h"
Expand Down Expand Up @@ -310,7 +310,7 @@ static int cb_cloudwatch_init(struct flb_output_instance *ins,
}
buf->tmp_buf_size = PUT_LOG_EVENTS_PAYLOAD_SIZE;

buf->events = flb_malloc(sizeof(struct event) * 1000);
buf->events = flb_malloc(sizeof(struct cw_event) * 1000);
if (!buf->events) {
flb_errno();
cw_flush_destroy(buf);
Expand Down
4 changes: 2 additions & 2 deletions plugins/out_cloudwatch_logs/cloudwatch_logs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct cw_flush {
size_t data_size;

/* log events- each of these has a pointer to their message in tmp_buf */
struct event *events;
struct cw_event *events;
int events_capacity;
/* current event */
int event_index;
Expand All @@ -54,7 +54,7 @@ struct cw_flush {
size_t event_buf_size;
};

struct event {
struct cw_event {
char *json;
size_t len;
// TODO: re-usable in kinesis streams plugin if we make it timespec instead
Expand Down

0 comments on commit 61ef808

Please sign in to comment.