From 39156e3b855cef217e248138d0f12ce7647be6da Mon Sep 17 00:00:00 2001 From: Nicolas Duvivier Date: Wed, 18 Sep 2024 11:14:24 +0200 Subject: [PATCH] feat(TimeOut): Enable the TimeOut Settings from HttpEventCollectorSender #284 --- .../includes/quarkus-log-handler-splunk.adoc | 92 ++++++++++++++++++- .../logging/splunk/SplunkHandlerConfig.java | 31 +++++++ .../splunk/SplunkLogHandlerRecorder.java | 12 ++- 3 files changed, 132 insertions(+), 3 deletions(-) diff --git a/docs/modules/ROOT/pages/includes/quarkus-log-handler-splunk.adoc b/docs/modules/ROOT/pages/includes/quarkus-log-handler-splunk.adoc index 6b0ddfc..ae08dac 100644 --- a/docs/modules/ROOT/pages/includes/quarkus-log-handler-splunk.adoc +++ b/docs/modules/ROOT/pages/includes/quarkus-log-handler-splunk.adoc @@ -1065,6 +1065,95 @@ endif::add-copy-button-to-env-var[] `block`, `discard` |`block` + +a| [[quarkus-log-handler-splunk_quarkus-log-handler-splunk-connectTimeout]]`link:#quarkus-log-handler-splunk_quarkus-log-handler-splunk-connectTimeout[quarkus.log.handler.splunk.connectTimeout]` + + +[.description] +-- +Sets the default connect timeout for new connections in milliseconds. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_HANDLER_SPLUNK_CONNECTTIMEOUT+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_CONNECTTIMEOUT+++` +endif::add-copy-button-to-env-var[] +-- a| +long +|`3000` + + +a| [[quarkus-log-handler-splunk_quarkus-log-handler-splunk-callTimeout]]`link:#quarkus-log-handler-splunk_quarkus-log-handler-splunk-callTimeout[quarkus.log.handler.splunk.callTimeout]` + + +[.description] +-- +Sets the default timeout for complete calls in milliseconds. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_HANDLER_SPLUNK_CALLTIMEOUT+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_CALLTIMEOUT+++` +endif::add-copy-button-to-env-var[] +-- a| +long +|`0` + + +a| [[quarkus-log-handler-splunk_quarkus-log-handler-splunk-readTimeout]]`link:#quarkus-log-handler-splunk_quarkus-log-handler-splunk-readTimeout[quarkus.log.handler.splunk.readTimeout]` + + +[.description] +-- +Sets the default read timeout for new connections in milliseconds. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_HANDLER_SPLUNK_READTIMEOUT+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_READTIMEOUT+++` +endif::add-copy-button-to-env-var[] +-- a| +long +|`10000` + +a| [[quarkus-log-handler-splunk_quarkus-log-handler-splunk-writeTimeout]]`link:#quarkus-log-handler-splunk_quarkus-log-handler-splunk-writeTimeout[quarkus.log.handler.splunk.writeTimeout]` + + +[.description] +-- +Sets the default write timeout for new connections in milliseconds. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_HANDLER_SPLUNK_WRITETIMEOUT+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_WRITETIMEOUT+++` +endif::add-copy-button-to-env-var[] +-- a| +long +|`10000` + + +a| [[quarkus-log-handler-splunk_quarkus-log-handler-splunk-terminationTimeout]]`link:#quarkus-log-handler-splunk_quarkus-log-handler-splunk-terminationTimeout[quarkus.log.handler.splunk.terminationTimeout]` + + +[.description] +-- +Sets the default termination timeout during a flush in milliseconds. + +ifdef::add-copy-button-to-env-var[] +Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_HANDLER_SPLUNK_TERMINATIONTIMEOUT+++[] +endif::add-copy-button-to-env-var[] +ifndef::add-copy-button-to-env-var[] +Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_TERMINATIONTIMEOUT+++` +endif::add-copy-button-to-env-var[] +-- a| +long +|`0` + |=== ifndef::no-duration-note[] [NOTE] @@ -1083,5 +1172,4 @@ In other cases, the simplified format is translated to the `java.time.Duration` * If the value is a number followed by `h`, `m`, or `s`, it is prefixed with `PT`. * If the value is a number followed by `d`, it is prefixed with `P`. -==== -endif::no-duration-note[] + diff --git a/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkHandlerConfig.java b/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkHandlerConfig.java index 0df1232..8b4d12f 100644 --- a/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkHandlerConfig.java +++ b/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkHandlerConfig.java @@ -11,6 +11,8 @@ import java.util.function.BooleanSupplier; import java.util.logging.Level; +import com.splunk.logging.HttpEventCollectorSender; + import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; @@ -251,4 +253,33 @@ public enum SerializationFormat { FLAT } + /** + * Sets the default connect timeout for new connections in milliseconds. + */ + @ConfigItem(defaultValue = "3000") + public long connectTimeout = HttpEventCollectorSender.TimeoutSettings.DEFAULT_CONNECT_TIMEOUT; + + /** + * Sets the default timeout for complete calls in milliseconds. + */ + @ConfigItem(defaultValue = "0") + public long callTimeout = HttpEventCollectorSender.TimeoutSettings.DEFAULT_CALL_TIMEOUT; + + /** + * Sets the default read timeout for new connections in milliseconds. + */ + @ConfigItem(defaultValue = "10000") + public long readTimeout = HttpEventCollectorSender.TimeoutSettings.DEFAULT_READ_TIMEOUT; + + /** + * Sets the default write timeout for new connections in milliseconds. + */ + @ConfigItem(defaultValue = "10000") + public long writeTimeout = HttpEventCollectorSender.TimeoutSettings.DEFAULT_WRITE_TIMEOUT; + + /** + * Sets the default termination timeout during a flush in milliseconds. + */ + @ConfigItem(defaultValue = "0") + public long terminationTimeout = HttpEventCollectorSender.TimeoutSettings.DEFAULT_TERMINATION_TIMEOUT; } diff --git a/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkLogHandlerRecorder.java b/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkLogHandlerRecorder.java index dd5d556..9d7d591 100644 --- a/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkLogHandlerRecorder.java +++ b/runtime/src/main/java/io/quarkiverse/logging/splunk/SplunkLogHandlerRecorder.java @@ -83,6 +83,16 @@ static HttpEventCollectorSender createSender(SplunkHandlerConfig config) { if (config.raw || config.serialization == SplunkHandlerConfig.SerializationFormat.RAW) { type = "Raw"; } + + HttpEventCollectorSender.TimeoutSettings rto = null; + if ((config.connectTimeout != HttpEventCollectorSender.TimeoutSettings.DEFAULT_CONNECT_TIMEOUT) + || (config.callTimeout != HttpEventCollectorSender.TimeoutSettings.DEFAULT_CALL_TIMEOUT) || + (config.readTimeout != HttpEventCollectorSender.TimeoutSettings.DEFAULT_READ_TIMEOUT) + || (config.writeTimeout != HttpEventCollectorSender.TimeoutSettings.DEFAULT_WRITE_TIMEOUT) || + (config.terminationTimeout != HttpEventCollectorSender.TimeoutSettings.DEFAULT_TERMINATION_TIMEOUT)) { + rto = new HttpEventCollectorSender.TimeoutSettings(config.connectTimeout, config.callTimeout, + config.readTimeout, config.writeTimeout, config.terminationTimeout); + } // Timeout settings is not used and passing a null is correct regarding the code HttpEventCollectorSender sender = new HttpEventCollectorSender( config.url, @@ -93,7 +103,7 @@ static HttpEventCollectorSender createSender(SplunkHandlerConfig config) { config.batchSizeCount, config.batchSizeBytes, config.sendMode.name().toLowerCase(), - buildMetadata(config), null); + buildMetadata(config), rto); if (config.serialization == SplunkHandlerConfig.SerializationFormat.FLAT) { SplunkFlatEventSerializer serializer = new SplunkFlatEventSerializer(config.metadataSeverityFieldName); sender.setEventHeaderSerializer(serializer);