Skip to content

Commit

Permalink
Support named handlers #156
Browse files Browse the repository at this point in the history
  • Loading branch information
treivize committed Oct 5, 2023
1 parent bd7c8ba commit c130d12
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.LogHandlerBuildItem;
import io.quarkus.deployment.builditem.NamedLogHandlersBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;

class LoggingSplunkProcessor {
Expand All @@ -29,6 +30,12 @@ LogHandlerBuildItem logHandler(SplunkLogHandlerRecorder recorder, SplunkConfig c
return new LogHandlerBuildItem(recorder.initializeHandler(config));
}

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
NamedLogHandlersBuildItem logNamedHandlers(SplunkLogHandlerRecorder recorder, SplunkConfig config) {
return new NamedLogHandlersBuildItem(recorder.initializeHandlers(config));
}

@BuildStep
ExtensionSslNativeSupportBuildItem enableSSL() {
// Enable SSL support by default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (c) 2023 Amadeus s.a.s.
Contributor(s): Kevin Viet, Romain Quinio, Yohann Puyhaubert (Amadeus s.a.s.)
*/
package io.quarkiverse.logging.splunk;

import io.quarkus.test.QuarkusUnitTest;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.mockserver.model.JsonBody.json;

class LoggingSplunkNamedHandlerConfigTest extends AbstractMockServerTest {

@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.withConfigurationResource("application-splunk-logging-named-handler.properties")
.withConfigurationResource("mock-server.properties")
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));

static final Logger logger = Logger.getLogger(LoggingSplunkNamedHandlerConfigTest.class);

static final Logger monitoringLogger = Logger.getLogger("monitoring");

@Test
void indexWithDefaultLoggerAndNamedLogger() {
logger.warn("hello splunk");
monitoringLogger.info("{\"key\":\"value\"}");
awaitMockServer();
httpServer.verify(requestToJsonEndpoint()
.withBody(json("{ index: 'mylogindex'}"))
.withHeader("Authorization", "Splunk 12345678-1234-1234-1234-1234567890AB"));
httpServer.verify(requestToJsonEndpoint()
.withBody(json("{ index: 'mystatsindex'}"))
.withHeader("Authorization", "Splunk 12345678-0000-0000-0000-1234567890AB"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
quarkus.log.handler.splunk.enabled=true
quarkus.log.handler.splunk.token=12345678-1234-1234-1234-1234567890AB
quarkus.log.handler.splunk.level=WARN
quarkus.log.handler.splunk.format=%s%e
quarkus.log.handler.splunk.metadata-index=mylogindex
quarkus.log.handler.splunk."MONITORING".enable=true
quarkus.log.handler.splunk."MONITORING".token=12345678-0000-0000-0000-1234567890AB
quarkus.log.handler.splunk."MONITORING".level=INFO
quarkus.log.handler.splunk."MONITORING".metadata-index=mystatsindex
quarkus.log.category."monitoring".handlers=MONITORING
quarkus.log.category."monitoring".level=INFO
101 changes: 70 additions & 31 deletions docs/modules/ROOT/pages/includes/quarkus-log-handler-splunk.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`true`


Expand All @@ -39,15 +39,15 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_LEVEL+++`
endif::add-copy-button-to-env-var[]
--|link:https://docs.jboss.org/jbossas/javadoc/7.1.2.Final/org/jboss/logmanager/Level.html[Level]

|`ALL`


a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.url]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.url[quarkus.log.handler.splunk.url]`

[.description]
--
Splunk HEC endpoint base url.
Splunk HEC endpoint base url.
With raw events, the endpoint targeted is /services/collector/raw. With flat or nested JSON events, the endpoint targeted is /services/collector/event/1.0.

ifdef::add-copy-button-to-env-var[]
Expand All @@ -56,7 +56,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_URL+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|`https://localhost:8088/`


Expand All @@ -72,7 +72,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_DISABLE_CERTIFICATE_VALIDATION+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`false`


Expand All @@ -88,15 +88,15 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_TOKEN+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|


a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.send-mode]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.send-mode[quarkus.log.handler.splunk.send-mode]`

[.description]
--
The strategy to send events to HEC.
The strategy to send events to HEC.
In sequential mode, there is only one HTTP connection to HEC and the order of events is preserved, but performance is lower. In parallel mode, event batches are sent asynchronously over multiple HTTP connections, and events with the same timestamp (that has 1 millisecond resolution) may be indexed out of order by Splunk.

ifdef::add-copy-button-to-env-var[]
Expand All @@ -106,7 +106,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_SEND_MODE+++`
endif::add-copy-button-to-env-var[]
-- a|
`sequential`, `parallel`
`sequential`, `parallel`
|`sequential`


Expand All @@ -122,7 +122,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_CHANNEL+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|


Expand Down Expand Up @@ -155,7 +155,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_BATCH_SIZE_COUNT+++`
endif::add-copy-button-to-env-var[]
--|long
--|long
|`10`


Expand All @@ -171,7 +171,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_BATCH_SIZE_BYTES+++`
endif::add-copy-button-to-env-var[]
--|long
--|long
|`10`


Expand All @@ -187,15 +187,15 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_MAX_RETRIES+++`
endif::add-copy-button-to-env-var[]
--|long
--|long
|`0`


a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.format]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.format[quarkus.log.handler.splunk.format]`

[.description]
--
The log format, defining which metadata are inlined inside the log main payload.
The log format, defining which metadata are inlined inside the log main payload.
Specific metadata (hostname, category, thread name, ...), as well as MDC key/value map, can also be sent in a structured way.

ifdef::add-copy-button-to-env-var[]
Expand All @@ -204,7 +204,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_FORMAT+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|`%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n`


Expand All @@ -220,7 +220,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_INCLUDE_EXCEPTION+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`false`


Expand All @@ -236,7 +236,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_INCLUDE_LOGGER_NAME+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`false`


Expand All @@ -252,7 +252,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_INCLUDE_THREAD_NAME+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`false`


Expand All @@ -268,7 +268,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_HOST+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|


Expand All @@ -284,15 +284,15 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_SOURCE+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|


a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.metadata-source-type]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.metadata-source-type[quarkus.log.handler.splunk.metadata-source-type]`

[.description]
--
The optional format of the events, to enable some parsing on Splunk side. https://docs.splunk.com/Documentation/Splunk/latest/Data/FormateventsforHTTPEventCollector++#++Event_metadata
The optional format of the events, to enable some parsing on Splunk side. https://docs.splunk.com/Documentation/Splunk/latest/Data/FormateventsforHTTPEventCollector++#++Event_metadata
A given source type may have indexed fields extraction enabled, which is the case of the built-in _json used for nested serialization.
ifdef::add-copy-button-to-env-var[]
Expand All @@ -301,7 +301,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_SOURCE_TYPE+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|
Expand All @@ -317,7 +317,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_INDEX+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|
Expand All @@ -333,17 +333,17 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_SEVERITY_FIELD_NAME+++`
endif::add-copy-button-to-env-var[]
--|string
--|string
|`severity`
a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.serialization]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.serialization[quarkus.log.handler.splunk.serialization]`
[.description]
--
The format of the payload.
- With raw serialization, the log message is sent 'as is' in the HTTP body. Metadata can only be common to a whole batch and are sent via HTTP parameters.
- With nested serialization, the log message is sent into a 'message' field of a JSON structure which also contains dynamic metadata.
The format of the payload.
- With raw serialization, the log message is sent 'as is' in the HTTP body. Metadata can only be common to a whole batch and are sent via HTTP parameters.
- With nested serialization, the log message is sent into a 'message' field of a JSON structure which also contains dynamic metadata.
- With flat serialization, the log message is sent into the root 'event' field. Dynamic metadata is sent via the 'fields' root object.
ifdef::add-copy-button-to-env-var[]
Expand All @@ -353,7 +353,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_SERIALIZATION+++`
endif::add-copy-button-to-env-var[]
-- a|
`raw`, `nested`, `flat`
`raw`, `nested`, `flat`
|`nested`
Expand All @@ -369,7 +369,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_ASYNC+++`
endif::add-copy-button-to-env-var[]
--|boolean
--|boolean
|`false`
Expand All @@ -385,7 +385,7 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_ASYNC_QUEUE_LENGTH+++`
endif::add-copy-button-to-env-var[]
--|int
--|int
|`512`
Expand All @@ -402,7 +402,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_ASYNC_OVERFLOW+++`
endif::add-copy-button-to-env-var[]
-- a|
`block`, `discard`
`block`, `discard`
|`block`
Expand All @@ -418,10 +418,49 @@ endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_LOG_HANDLER_SPLUNK_METADATA_FIELDS+++`
endif::add-copy-button-to-env-var[]
--|`Map<String,String>`
--|`Map<String,String>`
|
|===
*Named handlers configuration*
Named handlers configuration allows to specify several Splunk handlers on the same quarkus application and next use quarkus built-in
logging category management to determine which handler to use (`link:https://quarkus.io/guides/logging#quarkus-log-logging-log-config_quarkus.log.categories-logging-categories:[link]`)).
On top of the named handler configuration, you will have to associate your handler with this kind of configuration line:
`quarkus.log.category."my.category.for.custom.logging".handlers=CUSTOM_HANDLER`
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===
h|[[quarkus-log-handler-splunk_named_handlers_configuration]]link:#quarkus-log-handler-splunk_named_handlers_configuration[Named handlers configuration property]
h|Type
h|Default
a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.CUSTOM_HANDLER]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.CUSTOM_HANDLER[quarkus.log.handler.splunk."CUSTOM_HANDLER".enable]`
[.description]
--
Determine whether to enable the handler with the custom name CUSTOM_HANDLER.
--|boolean
|`false`
a| [[quarkus-log-handler-splunk_quarkus.log.handler.splunk.CUSTOM_HANDLER.xxxxxx]]`link:#quarkus-log-handler-splunk_quarkus.log.handler.splunk.CUSTOM_HANDLER.xxxxxx[quarkus.log.handler.splunk."CUSTOM_HANDLER".xxxxxx]`
[.description]
--
Any of the above property can be overridden at named handler level to customize the new Splunk handler.
--|Parent property type
|Default on parent property value/default value
|===
ifndef::no-duration-note[]
[NOTE]
[id='duration-note-anchor-{summaryTableId}']
Expand Down
4 changes: 2 additions & 2 deletions integration-test/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
quarkus.log.handler.splunk.url=https://localhost:8099
quarkus.log.handler.splunk.index=main
quarkus.log.handler.splunk.metadata-index=main
quarkus.log.handler.splunk.token=29fe2838-cab6-4d17-a392-37b7b8f41f75
quarkus.log.handler.splunk.batch-interval=1s
quarkus.log.handler.splunk.disable-certificate-validation=true
quarkus.log.console.enable=true
quarkus.log.handler.splunk.serialization=nested
quarkus.log.handler.splunk.serialization=nested
Loading

0 comments on commit c130d12

Please sign in to comment.