Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 96 additions & 63 deletions log4j-layout-template-json-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,30 @@
</parent>

<artifactId>log4j-layout-template-json-test</artifactId>
<name>Tests for the JSON Template Layout of Apache Log4j</name>

<name>Apache Log4j JSON Template Layout tests</name>

<properties>

<log4j.docgen.skip>true</log4j.docgen.skip>
<log4jParentDir>${basedir}/..</log4jParentDir>
<bnd.baseline.skip>true</bnd.baseline.skip>
<maven.deploy.skip>true</maven.deploy.skip>
<sign.skip>true</sign.skip>

<!--
~ OSGi and JPMS options
-->
<bnd-module-name>org.apache.logging.log4j.layout.template.json.test</bnd-module-name>
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>

<!-- `elastic.version` is used for two purposes:

1. `co.elastic.clients:elasticsearch-java` version
2. The Docker image version of the ELK-stack

As of 2024-09-16, these all (Maven artifacts and Elastic products) get released with the same version. -->
<elastic.version>8.15.1</elastic.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -78,8 +91,9 @@
</dependency>

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>${elastic.version}</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -107,34 +121,11 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j2-ecs-layout</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>

<!-- Disable ITs, which are Docker-dependent, by default. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -159,15 +150,29 @@

<id>docker</id>

<!--
~ Only the `ubuntu` CI runners have access to Docker
-->
<activation>
<activeByDefault>false</activeByDefault>
<os>
<family>linux</family>
</os>
<property>
<name>env.CI</name>
<value>true</value>
</property>
</activation>

<properties>
<elastic.version>8.10.2</elastic.version>

<!-- Suppress `docker-maven-plugin` output -->
<docker.showLogs>false</docker.showLogs>
<docker.verbose>false</docker.verbose>

<!-- `docker run elasticsearch:<TAG>` exists with code 137 due to insufficient memory.
We limit the used JVM memory to avoid this OOM failure. -->
<elastic.java-opts>-Xms750m -Xmx750m</elastic.java-opts>
<elastic.javaOpts>-Xms750m -Xmx750m</elastic.javaOpts>

</properties>

<build>
Expand All @@ -177,7 +182,6 @@
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<verbose>all</verbose>
<startParallel>true</startParallel>
<autoCreateCustomNetworks>true</autoCreateCustomNetworks>
<images>
Expand All @@ -188,10 +192,11 @@
<env>
<discovery.type>single-node</discovery.type>
<xpack.security.enabled>false</xpack.security.enabled>
<ES_JAVA_OPTS>${elastic.java-opts}</ES_JAVA_OPTS>
<ES_JAVA_OPTS>${elastic.javaOpts}</ES_JAVA_OPTS>
</env>
<ports>
<port>9200:9200</port>
<!-- Binds an ephemeral port to the `elasticsearch.port` Maven property. -->
<port>localhost:elasticsearch.port:9200</port>
</ports>
<network>
<mode>custom</mode>
Expand All @@ -203,7 +208,11 @@
<color>cyan</color>
</log>
<wait>
<log>recovered \[0\] indices into cluster_state</log>
<tcp>
<ports>
<port>9200</port>
</ports>
</tcp>
<time>60000</time>
</wait>
</run>
Expand All @@ -221,11 +230,13 @@
<alias>logstash</alias>
</network>
<env>
<LS_JAVA_OPTS>${elastic.java-opts}</LS_JAVA_OPTS>
<LS_JAVA_OPTS>${elastic.javaOpts}</LS_JAVA_OPTS>
</env>
<ports>
<port>12222:12222</port>
<port>12345:12345</port>
<!-- Binds an ephemeral port to the `logstash.gelf.port` Maven property. -->
<port>localhost:logstash.gelf.port:12222</port>
<!-- Binds an ephemeral port to the `logstash.tcp.port` Maven property. -->
<port>localhost:logstash.tcp.port:12345</port>
</ports>
<log>
<prefix>[LS]</prefix>
Expand All @@ -237,54 +248,71 @@
<arg>--pipeline.batch.size</arg>
<arg>1</arg>
<arg>-e</arg>
<arg>input {
<arg><![CDATA[

input {

# Documentation: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-gelf.html
gelf {
host =&gt; "logstash"
use_tcp =&gt; true
use_udp =&gt; false
port =&gt; 12222
type =&gt; "gelf"
host => "logstash"
use_tcp => true
use_udp => false
port => 12222
type => "gelf"
}

# Documentation: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-tcp.html
tcp {
port =&gt; 12345
codec =&gt; json
type =&gt; "tcp"
port => 12345
codec => json
type => "tcp"
}

}

filter {
if [type] == "gelf" {
# These are GELF/Syslog logging levels as defined in RFC 3164.
# Map the integer level to its human readable format.
# Map the integer level to its human-readable format.
# Documentation: https://www.elastic.co/guide/en/logstash/current/plugins-filters-translate.html
translate {
field =&gt; "[level]"
destination =&gt; "[levelName]"
dictionary =&gt; {
"0" =&gt; "EMERG"
"1" =&gt; "ALERT"
"2" =&gt; "CRITICAL"
"3" =&gt; "ERROR"
"4" =&gt; "WARN"
"5" =&gt; "NOTICE"
"6" =&gt; "INFO"
"7" =&gt; "DEBUG"
source => "[level]"
target => "[levelName]"
dictionary => {
"0" => "EMERG"
"1" => "ALERT"
"2" => "CRITICAL"
"3" => "ERROR"
"4" => "WARN"
"5" => "NOTICE"
"6" => "INFO"
"7" => "DEBUG"
}
}
}
}

# Documentation: https://www.elastic.co/guide/en/logstash/current/plugins-filters-elasticsearch.html
output {
# (Un)comment for debugging purposes
# stdout { codec =&gt; rubydebug }
# stdout { codec => rubydebug }
elasticsearch {
hosts =&gt; ["http://elasticsearch:9200"]
index =&gt; "log4j"
hosts => ["http://elasticsearch:9200"]
index => "log4j"
}
}</arg>
}

]]></arg>
</exec>
</entrypoint>
<wait>
<log>Successfully started Logstash API endpoint</log>
<tcp>
<host>localhost</host>
<ports>
<port>12222</port>
<port>12345</port>
</ports>
</tcp>
<time>60000</time>
</wait>
</run>
Expand Down Expand Up @@ -316,6 +344,11 @@
<includes>
<include>**/*IT.java</include>
</includes>
<systemPropertyVariables>
<log4j.elasticsearch.port>${elasticsearch.port}</log4j.elasticsearch.port>
<log4j.logstash.gelf.port>${logstash.gelf.port}</log4j.logstash.gelf.port>
<log4j.logstash.tcp.port>${logstash.tcp.port}</log4j.logstash.tcp.port>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
Expand Down

This file was deleted.

Loading