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_pgsql: Add support for CockroachDB #2512

Merged
merged 1 commit into from
Sep 24, 2020
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
14 changes: 10 additions & 4 deletions plugins/out_pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ static int cb_pgsql_init(struct flb_output_instance *ins,
ctx->max_pool_size = 1;
}

/* CockroachDB Support */
tmp = flb_output_get_property("cockroachdb", ins);
if (tmp && flb_utils_bool(tmp)) {
ctx->cockroachdb = FLB_TRUE;
}
else {
ctx->cockroachdb = FLB_FALSE;
}

ret = pgsql_start_connections(ctx);
if (ret) {
return -1;
Expand Down Expand Up @@ -315,10 +324,7 @@ static void cb_pgsql_flush(const void *data, size_t bytes,


snprintf(query, str_len,
"INSERT INTO %s "
"SELECT %s, "
"to_timestamp(CAST(value->>'%s' as FLOAT)), * "
"FROM json_array_elements(%s);",
ctx->cockroachdb ? FLB_PGSQL_INSERT_COCKROACH : FLB_PGSQL_INSERT,
ctx->db_table, tag_escaped, ctx->timestamp_key, json);
flb_plg_trace(ctx->ins, "query: %s", query);

Expand Down
11 changes: 11 additions & 0 deletions plugins/out_pgsql/pgsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#define FLB_PGSQL_POOL_SIZE 4
#define FLB_PGSQL_MIN_POOL_SIZE 1
#define FLB_PGSQL_SYNC FLB_FALSE
#define FLB_PGSQL_COCKROACH FLB_FALSE

#define FLB_PGSQL_INSERT "INSERT INTO %s SELECT %s, " \
"to_timestamp(CAST(value->>'%s' as FLOAT))," \
" * FROM json_array_elements(%s);"
#define FLB_PGSQL_INSERT_COCKROACH "INSERT INTO %s SELECT %s," \
"CAST(value->>'%s' AS INTERVAL) + DATE'1970-01-01'," \
" * FROM json_array_elements(%s);"

struct flb_pgsql_conn {
struct mk_list _head;
Expand Down Expand Up @@ -70,6 +78,9 @@ struct flb_pgsql_config {

/* async mode or sync mode */
int async;

/* cockroachdb */
int cockroachdb;
};

void pgsql_conf_destroy(struct flb_pgsql_config *ctx);
Expand Down