Skip to content

Commit

Permalink
feature-#34 parallel logging (#42)
Browse files Browse the repository at this point in the history
* initial refactoring for feature-#34

* enhance test cases

* change overlapping port

* make refactored classes final

* remove unused import from RlpLogbackAppender

* add licenses

* add locking to ensure configurations are set

* update readme

* change to use AtomicReference and new immutable decorateable RelpAppender implementations

* improve test assertion for threadedTest so that it ensures all messages were sent

* update assertion message to proper grammar in RlpLogbackAppenderTest

* remove extra curly bracket from Hostname default err message

* add parentheses for readability in RlpLogbackAppender maxIdleEnabled

* update README.adoc to include defaults

* enable rebind as default
  • Loading branch information
kortemik authored Dec 2, 2024
1 parent 73342f0 commit 5c610f6
Show file tree
Hide file tree
Showing 19 changed files with 981 additions and 565 deletions.
56 changes: 48 additions & 8 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,48 +1,88 @@
image::https://scan.coverity.com/projects/22709/badge.svg[link=https://scan.coverity.com/projects/jla_01]

= Relp Logging plugin for Logback
== RELP Logging plugin for Logback

See link:https://github.com/teragrep/jla_01/blob/master/src/main/resources/logback.example.xml[logback.example.xml] for example config

== Parameters

|===
|Parameter |Description
|Parameter |Description | Default

|`relpHostAddress`
|Connection destination address
|127.0.0.1

|`relpPort`
|Connection destination port
|601

|`enableEventId48577`
|Enables structured data containing uuid and source information
|true

|`appName`
|Stream application identifier. Maximum length of 48 characters, limited by RFC5424
|jla-01

|`hostname`
|Stream host identifier. Maximum length of 255 characters, limited by RFC5424
|localhost.localdomain

|`connectionTimeout`
|Time to wait before timing out connection
|Time to wait before timing out connection in milliseconds
|2500

|`reconnectInterval`
|Time to wait between re-connection attempts
|Time to wait between re-connection attempts in milliseconds
|500

|`writeTimeout`
|Time to wait for destination to accept data
|Time to wait for destination to accept data in milliseconds
|1500

|`readTimeout`
|Time to wait for destination to acknowledge sent data (low values cause duplicates)
|Time to wait for destination to acknowledge sent data (low values cause duplicates) in milliseconds
|1500

|`keepAlive`
|Enables sending alive packets. Default true.
|Enables sending alive packets.
|true

|`reconnectIfNoMessagesInterval`
|Reconnects before sending message if at least X milliseconds have passed since last message. Default 150000, set to 0 to turn off automatic reconnections.
|Reconnects before sending message if at least X milliseconds have passed since last message. Set to 0 to turn off automatic reconnections.
|150000

|`connectOnStart`
|Start one connection initially at appender start. Allows detection of configuration mistakes early.
|false

|`rebindEnabled`
|Rebind RELP connection after `rebindAmount` of records.
|true

|`rebindAmount`
|Rebind after this amount of records sent if `rebindEnabled` is set.
|100000

|`synchronizedAccess`
|Allows only one thread at a time to append, therefore uses only one connection.
|false

|`useTLS`
|Use TLS instead of a plain text connection.
|false

|`keystorePath`
|Path to Java keystore that includes the CA certificate for the TLS connection
|/unset/path/to/keystore

|`keystorePassword`
|Keystore password for the keystore defined in `keystorePath`
|
|===


== jboss-module

These instructions are untested but should work none the less.
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/teragrep/jla_01/IRelpAppenderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ Reliable Event Logging Protocol (RELP) Logback plugin
public interface IRelpAppenderConfig<E> {
void setEncoder(LayoutWrappingEncoder<E> encoder);

void setSender(RelpConnection sender);

void setRelpPort(int relpPort);

void setEnableEventId48577(Boolean enableEventId48577);
Expand Down Expand Up @@ -60,4 +58,12 @@ public interface IRelpAppenderConfig<E> {
void setKeystorePassword(String keystorePassword);

void setTlsProtocol(String tlsProtocol);

void setConnectOnStart(boolean connectOnStart);

void setRebindEnabled(boolean rebindEnabled);

void setRebindAmount(int rebindAmount);

void setSynchronizedAccess(boolean synchronizedAccess);
}
82 changes: 0 additions & 82 deletions src/main/java/com/teragrep/jla_01/LoggingEventConverter.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/com/teragrep/jla_01/RelpAppender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Reliable Event Logging Protocol (RELP) Logback plugin
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.jla_01;

import com.teragrep.rlp_01.pool.Stubable;

public interface RelpAppender<E> extends Stubable {

void append(E iLoggingEvent);
void stop();
}
73 changes: 73 additions & 0 deletions src/main/java/com/teragrep/jla_01/RelpAppenderImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Reliable Event Logging Protocol (RELP) Logback plugin
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.jla_01;

import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import com.teragrep.jla_01.syslog.*;
import com.teragrep.rlp_01.client.IManagedRelpConnection;
import com.teragrep.rlp_01.pool.Pool;

import java.nio.charset.StandardCharsets;

public final class RelpAppenderImpl<E> implements RelpAppender<E> {

private final Pool<IManagedRelpConnection> relpConnectionPool;
private final String hostname;
private final String appName;
private final String originalHostname;
private final boolean enableEventId48577;
private final LayoutWrappingEncoder<E> encoder;

public RelpAppenderImpl(Pool<IManagedRelpConnection> relpConnectionPool, String hostname, String appName, String originalHostname, boolean enableEventId48577, LayoutWrappingEncoder<E> encoder) {
this.relpConnectionPool = relpConnectionPool;
this.hostname = hostname;
this.appName = appName;
this.originalHostname = originalHostname;
this.enableEventId48577 = enableEventId48577;
this.encoder = encoder;
}

@Override
public void append(E iLoggingEvent) {
{
SyslogRecord syslogRecord = new SyslogRecordConfigured(hostname, appName);
syslogRecord = new SyslogRecordTimestamp(syslogRecord);
syslogRecord = new SyslogRecordOrigin(syslogRecord, originalHostname);
if (enableEventId48577) {
syslogRecord = new SyslogRecordEventID(syslogRecord, originalHostname);
}

//syslogRecord = new SyslogRecordMDC(syslogRecord, new HashMap<>());

String payload = encoder.getLayout().doLayout(iLoggingEvent);
syslogRecord = new SyslogRecordPayload(syslogRecord, payload);

IManagedRelpConnection connection = relpConnectionPool.get();

connection.ensureSent(syslogRecord.getRecord().toRfc5424SyslogMessage().getBytes(StandardCharsets.UTF_8));
relpConnectionPool.offer(connection);
}
}

@Override
public void stop() {
relpConnectionPool.close();
}

@Override
public boolean isStub() {
return false;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/teragrep/jla_01/RelpAppenderStub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Reliable Event Logging Protocol (RELP) Logback plugin
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.jla_01;

public final class RelpAppenderStub<E> implements RelpAppender<E> {
@Override
public void append(E iLoggingEvent) {
throw new UnsupportedOperationException("RelpAppenderStub does not support this. Perhaps appender is not started yet.");
}

@Override
public void stop() {
throw new UnsupportedOperationException("RelpAppenderStub does not support this. Perhaps appender is not started yet.");
}

@Override
public boolean isStub() {
return true;
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/teragrep/jla_01/RelpAppenderSynchronized.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Reliable Event Logging Protocol (RELP) Logback plugin
Copyright (C) 2021-2024 Suomen Kanuuna Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.teragrep.jla_01;

public final class RelpAppenderSynchronized<E> implements RelpAppender<E> {

private final RelpAppender<E> appender;

public RelpAppenderSynchronized(RelpAppender<E> relpAppender) {
this.appender = relpAppender;
}

@Override
public synchronized void append(E iLoggingEvent) {
appender.append(iLoggingEvent);
}

@Override
public void stop() {
appender.stop();
}

@Override
public boolean isStub() {
return false;
}
}
Loading

0 comments on commit 5c610f6

Please sign in to comment.