Skip to content

Commit

Permalink
out_loki: extract function
Browse files Browse the repository at this point in the history
Signed-off-by: Kazuhiro Suzuki <[email protected]>
  • Loading branch information
ksauzz committed Sep 21, 2023
1 parent 50b3329 commit c887734
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions plugins/out_loki/loki.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,16 @@ static flb_sds_t loki_compose_payload(struct flb_loki *ctx,
return json;
}

static void payload_release(void *payload, int compressed)
{
if (compressed) {
flb_free(payload);
}
else {
flb_sds_destroy(payload);
}
}

static void cb_loki_flush(struct flb_event_chunk *event_chunk,
struct flb_output_flush *out_flush,
struct flb_input_instance *i_ins,
Expand Down Expand Up @@ -1562,12 +1572,7 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
if (!u_conn) {
flb_plg_error(ctx->ins, "no upstream connections available");

if (compressed) {
flb_free(out_buf);
}
else {
flb_sds_destroy(out_buf);
}
payload_release(out_buf, compressed);

FLB_OUTPUT_RETURN(FLB_RETRY);
}
Expand All @@ -1580,12 +1585,7 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
if (!c) {
flb_plg_error(ctx->ins, "cannot create HTTP client context");

if (compressed) {
flb_free(out_buf);
}
else {
flb_sds_destroy(out_buf);
}
payload_release(out_buf, compressed);
flb_upstream_conn_release(u_conn);

FLB_OUTPUT_RETURN(FLB_RETRY);
Expand Down Expand Up @@ -1628,12 +1628,7 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,

/* Send HTTP request */
ret = flb_http_do(c, &b_sent);
if (compressed) {
flb_free(out_buf);
}
else {
flb_sds_destroy(out_buf);
}
payload_release(out_buf, compressed);

/* Validate HTTP client return status */
if (ret == 0) {
Expand Down

0 comments on commit c887734

Please sign in to comment.