Skip to content

Commit

Permalink
Re #118: Initial stab at log4j/reload4j appender.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkowalcz committed Sep 3, 2023
1 parent bbbb5ef commit 4901f42
Show file tree
Hide file tree
Showing 17 changed files with 1,281 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void channelRead(ChannelHandlerContext ctx, Object object) {

monitoringModule.incrementHttpResponses();
if (msg.status().codeClass() != HttpStatusClass.SUCCESS) {
System.out.println(msg.content().toString(Charset.defaultCharset()));
monitoringModule.incrementHttpErrors(
msg.status().code(),
msg.content().toString(Charset.defaultCharset())
Expand Down
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<module>core</module>
<module>loki-protobuf</module>

<module>reload4j-appender</module>

<module>log4j2-appender</module>
<module>log4j2-appender-nodep</module>

Expand Down Expand Up @@ -58,11 +60,11 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<maven.compiler.testSource>9</maven.compiler.testSource>
<maven.compiler.testTarget>9</maven.compiler.testTarget>
<maven.compiler.testSource>11</maven.compiler.testSource>
<maven.compiler.testTarget>11</maven.compiler.testTarget>

<!--suppress UnresolvedMavenProperty -->
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
Expand Down
145 changes: 145 additions & 0 deletions reload4j-appender/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>pl.tkowalcz.tjahzi</groupId>
<artifactId>tjahzi-parent</artifactId>
<version>0.9.33-SNAPSHOT</version>
</parent>

<name>reload4j-appender</name>
<artifactId>reload4j-appender</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>pl.tkowalcz.tjahzi</groupId>
<artifactId>core</artifactId>
<version>0.9.33-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>ch.qos.reload4j</groupId>
<artifactId>reload4j</artifactId>
<version>1.2.25</version>
</dependency>

<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.1.17</version>
<scope>provided</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.code.java-allocation-instrumenter</groupId>
<artifactId>java-allocation-instrumenter</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.15.0</version>
<scope>test</scope>
</dependency>

<!-- Testcontainers -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>nginx</artifactId>
<version>1.14.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dns-cache-manipulator</artifactId>
<version>1.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>allocation-profiling</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0/java-allocation-instrumenter-3.3.0.jar"
</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.java-allocation-instrumenter</groupId>
<artifactId>java-allocation-instrumenter</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package pl.tkowalcz.tjahzi.reload4j;

import org.apache.log4j.helpers.LogLog;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;

public class CommaDelimitedListParser {

public static <T> List<T> parseString(
String commaDelimitedList,
BiFunction<String, String, T> converter) {
if (commaDelimitedList == null || commaDelimitedList.trim().isEmpty()) {
return Collections.emptyList();
}

ArrayList<T> result = new ArrayList<>();
String[] keyValuePairs = commaDelimitedList.split(",");
for (String keyValuePair : keyValuePairs) {
String[] keyAndValue = keyValuePair.split(":", 2);

if (keyAndValue.length != 2) {
LogLog.warn("Invalid key-value pair format: " + keyValuePair);
continue;
}

String key = keyAndValue[0].trim();
String value = keyAndValue[1].trim();

if (key.isEmpty() || value.isEmpty()) {
LogLog.warn("Key or value cannot be empty: " + keyValuePair);
continue;
}

result.add(converter.apply(key, value));
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.tkowalcz.tjahzi.reload4j;

public class Header {

private String name;
private String value;

public Header(String name, String value) {
this.name = name;
this.value = value;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pl.tkowalcz.tjahzi.reload4j;

import java.util.regex.Pattern;

public class Label {

private static final Pattern LABEL_NAME_PATTER = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*");

private String name;
private String value;

public static Label createLabel(String name, String value) {
Label result = new Label();
result.setName(name);
result.setValue(value);

return result;
}

public boolean hasValidName() {
return hasValidName(getName());
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public static boolean hasValidName(String label) {
return LABEL_NAME_PATTER.matcher(label).matches();
}
}
Loading

0 comments on commit 4901f42

Please sign in to comment.