Skip to content

Commit

Permalink
out_loki: fix per review
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 cf81573 commit 50b3329
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 11 additions & 9 deletions plugins/out_loki/loki.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,6 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
event_chunk->data, event_chunk->size,
&dynamic_tenant_id->value);


if (!payload) {
flb_plg_error(ctx->ins, "cannot compose request payload");

Expand Down Expand Up @@ -1564,10 +1563,10 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
flb_plg_error(ctx->ins, "no upstream connections available");

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

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

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

FLB_OUTPUT_RETURN(FLB_RETRY);
Expand All @@ -1606,9 +1610,7 @@ static void cb_loki_flush(struct flb_event_chunk *event_chunk,
FLB_LOKI_CT_JSON, sizeof(FLB_LOKI_CT_JSON) - 1);

if (compressed == FLB_TRUE) {
flb_http_add_header(c,
FLB_LOKI_HEADER_CE, sizeof(FLB_LOKI_HEADER_CE) - 1,
FLB_LOKI_CE_GZIP, sizeof(FLB_LOKI_CE_GZIP) - 1);
flb_http_set_content_encoding_gzip(c);
}

/* Add X-Scope-OrgID header */
Expand All @@ -1627,10 +1629,10 @@ 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);
flb_free(out_buf);
}
else {
flb_sds_destroy(out_buf);
flb_sds_destroy(out_buf);
}

/* Validate HTTP client return status */
Expand Down
2 changes: 0 additions & 2 deletions plugins/out_loki/loki.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#define FLB_LOKI_HOST "127.0.0.1"
#define FLB_LOKI_PORT 3100
#define FLB_LOKI_HEADER_SCOPE "X-Scope-OrgID"
#define FLB_LOKI_HEADER_CE "Content-Encoding"
#define FLB_LOKI_CE_GZIP "gzip"

#define FLB_LOKI_KV_STR 0 /* sds string */
#define FLB_LOKI_KV_RA 1 /* record accessor */
Expand Down

0 comments on commit 50b3329

Please sign in to comment.