Skip to content

Commit

Permalink
out_opentelemetry: add support for zstd compression
Browse files Browse the repository at this point in the history
This patch adds a new compression mechanism called 'zstd', this is
available through the 'compress' configuration property, in the configuration file
it can be enabled with:

  pipeline:
     outputs:
      - name: opentelemetry
        match: '*'
        compress: zstd

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jan 14, 2025
1 parent fab6bdc commit d5dca8f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions plugins/out_opentelemetry/opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
if (ctx->compress_gzip == FLB_TRUE) {
compression_algorithm = "gzip";
}
else if (ctx->compress_zstd == FLB_TRUE) {
compression_algorithm = "zstd";
}

result = flb_http_request_set_parameters(request,
FLB_HTTP_CLIENT_ARGUMENT_URI(http_uri),
Expand Down Expand Up @@ -407,7 +410,7 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
if (ctx->log_response_payload &&
response->body != NULL &&
cfl_sds_len(response->body) > 0) {
flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i\n%s",
flb_plg_info(ctx->ins, "%s:%i, HTTP status=%i%s",
ctx->host, ctx->port,
response->status, response->body);
}
Expand Down Expand Up @@ -840,7 +843,7 @@ static struct flb_config_map config_map[] = {
{
FLB_CONFIG_MAP_STR, "compress", NULL,
0, FLB_FALSE, 0,
"Set payload compression mechanism. Option available is 'gzip'"
"Set payload compression mechanism. Options available are 'gzip' and 'zstd'."
},
/*
* Logs Properties
Expand Down
5 changes: 4 additions & 1 deletion plugins/out_opentelemetry/opentelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ struct opentelemetry_context {
/* instance context */
struct flb_output_instance *ins;

/* Compression mode (gzip) */
/* compression: gzip */
int compress_gzip;

/* compression: zstd */
int compress_zstd;

/* FLB/OTLP Record accessor patterns */
struct flb_record_accessor *ra_meta_schema;
struct flb_record_accessor *ra_meta_resource_id;
Expand Down
7 changes: 7 additions & 0 deletions plugins/out_opentelemetry/opentelemetry_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ struct opentelemetry_context *flb_opentelemetry_context_create(struct flb_output
if (strcasecmp(tmp, "gzip") == 0) {
ctx->compress_gzip = FLB_TRUE;
}
else if (strcasecmp(tmp, "zstd") == 0) {
ctx->compress_zstd = FLB_TRUE;
}
else {
flb_plg_error(ctx->ins, "Unknown compression method %s", tmp);
return NULL;
}
}

ctx->ra_observed_timestamp_metadata = flb_ra_create((char*)ctx->logs_observed_timestamp_metadata_key,
Expand Down

0 comments on commit d5dca8f

Please sign in to comment.