Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-#34 parallel logging #42

Merged
merged 15 commits into from
Dec 2, 2024
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
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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name ending in -er

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the naming is to reflect the UnsynchronizedAppenderBase naming


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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableEventId48577 boolean seems to configure the behaviour of this method here, so there seems to be use cases where sometimes you want the eventId, sometimes you don't.
Should this be separated into a different object, so that you have RelpAppenders that include the eventId and RelpAppenders that don't include it, to make it more obvious when the eventId will be appended, and when it's omitted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create an issue about this

syslogRecord = new SyslogRecordEventID(syslogRecord, originalHostname);
}

//syslogRecord = new SyslogRecordMDC(syslogRecord, new HashMap<>());
StrongestNumber9 marked this conversation as resolved.
Show resolved Hide resolved

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