Skip to content

Commit c2b3d47

Browse files
committed
out_opentelemetry: auto configure HTTP/2 protocol when gRPC is enabled.
Previously, enabling gRPC required setting both `grpc: on` and `http2: on`. For plaintext communication, users had to set `http2: force`, which was confusing. This change simplifies the config: - `grpc: on` now automatically enables HTTP/2. - Plaintext gRPC works without needing `http2: force`. This PR improves usability by reducing unnecessary config steps. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 8808a93 commit c2b3d47

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

plugins/out_opentelemetry/opentelemetry.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,9 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
384384
}
385385

386386
response = flb_http_client_request_execute(request);
387-
388387
if (response == NULL) {
389-
flb_debug("http request execution error");
390-
388+
flb_plg_warn(ctx->ins, "error performing HTTP request, remote host=%s:%i connection error",
389+
ctx->host, ctx->port);
391390
flb_http_client_request_destroy(request, FLB_TRUE);
392391

393392
return FLB_RETRY;
@@ -404,7 +403,6 @@ int opentelemetry_post(struct opentelemetry_context *ctx,
404403
* - 205: Reset content
405404
*
406405
*/
407-
408406
if (response->status < 200 || response->status > 205) {
409407
if (ctx->log_response_payload &&
410408
response->body != NULL &&

plugins/out_opentelemetry/opentelemetry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct opentelemetry_body_key {
4545
/* Plugin context */
4646
struct opentelemetry_context {
4747
int enable_http2_flag;
48-
char *enable_http2;
48+
flb_sds_t enable_http2;
4949
int enable_grpc_flag;
5050

5151
/* HTTP Auth */

plugins/out_opentelemetry/opentelemetry_conf.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,36 @@ struct opentelemetry_context *flb_opentelemetry_context_create(struct flb_output
567567

568568
ctx->enable_http2_flag = FLB_TRUE;
569569

570+
/* if gRPC has been enabled, auto-enable HTTP/2 to make end-user life easier */
571+
if (ctx->enable_grpc_flag && !flb_utils_bool(ctx->enable_http2)) {
572+
flb_plg_info(ctx->ins, "gRPC enabled, HTTP/2 has been auto-enabled");
573+
flb_sds_destroy(ctx->enable_http2);
574+
ctx->enable_http2 = flb_sds_create("on");
575+
}
576+
577+
/*
578+
* 'force' aims to be used for plaintext communication when HTTP/2 is set. Note that
579+
* moving forward it wont be necessary since we are now setting some special defaults
580+
* in case of gRPC is enabled (which is the only case where HTTP/2 is mandatory).
581+
*/
570582
if (strcasecmp(ctx->enable_http2, "force") == 0) {
571583
http_protocol_version = HTTP_PROTOCOL_VERSION_20;
572584
}
573585
else if (flb_utils_bool(ctx->enable_http2)) {
574-
http_protocol_version = HTTP_PROTOCOL_VERSION_AUTODETECT;
586+
if (!ins->use_tls) {
587+
http_protocol_version = HTTP_PROTOCOL_VERSION_20;
588+
}
589+
else {
590+
http_protocol_version = HTTP_PROTOCOL_VERSION_AUTODETECT;
591+
}
575592
}
576593
else {
577594
http_protocol_version = HTTP_PROTOCOL_VERSION_11;
578595

579596
ctx->enable_http2_flag = FLB_FALSE;
580597
}
581598

599+
582600
ret = flb_http_client_ng_init(&ctx->http_client,
583601
NULL,
584602
ctx->u,

0 commit comments

Comments
 (0)