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

Dynamic logger ecs reconfig #1261

Merged
merged 80 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
2c11027
Tail files and notify FileChangeListener
felixbarny Apr 6, 2020
1ad5656
ApmServerLogShipper
felixbarny Apr 7, 2020
ddd3485
Use log4j2 and ecs-logging-java as opposed to simple-logger
felixbarny Apr 8, 2020
7677cd9
Merge remote-tracking branch 'origin/master' into log-shipper
felixbarny Apr 8, 2020
38b20b1
Set service.name and event.dataset in logs
felixbarny Apr 8, 2020
9a8f954
Store and restore persistent state about file position
felixbarny Apr 9, 2020
13b8a25
Store and restore persistent state about file position
felixbarny Apr 9, 2020
c23aee7
Set rollover policy to size 50M max 2
felixbarny Apr 9, 2020
60db443
Send file metadata
felixbarny Apr 9, 2020
52013bb
Ack/nak state
felixbarny Apr 11, 2020
350440e
Look up file by inode if available
felixbarny Apr 17, 2020
15bc635
Add log_file_max_size option
felixbarny Apr 17, 2020
225b389
No need to set service.name as it's sent in metadata
felixbarny Apr 17, 2020
eeb4aeb
When logging to sout, ship temp log file
felixbarny Apr 20, 2020
b7c162b
Merge remote-tracking branch 'origin/master' into log-shipper
felixbarny Apr 20, 2020
a2549ff
Fix tests
felixbarny Apr 22, 2020
adc6f9d
Add shader infrastructure and support for Logback
eyalkoren Apr 23, 2020
fd7eb75
Handling logging packages relocation
eyalkoren Apr 23, 2020
9c0f3ba
pom leftover
eyalkoren Apr 23, 2020
1f31115
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Jun 30, 2020
0c3f3bb
fix-merge
eyalkoren Jun 30, 2020
e7b39b7
Removing stale entries from configuration docs
eyalkoren Jun 30, 2020
023b38d
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Jul 5, 2020
4a4da40
Update configuration.asciidoc
eyalkoren Jul 5, 2020
fd3c98a
Add Logback ECS reformatting testing
eyalkoren Jul 5, 2020
955a595
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Jul 7, 2020
c6b5292
Add Log4j2
eyalkoren Jul 7, 2020
2abc2e3
Making Log4j2 instrumentation suitable for 2.10.0+
eyalkoren Jul 8, 2020
887cd58
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Jul 28, 2020
f024fe1
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Jul 30, 2020
902b859
Add support for log4j 1
eyalkoren Jul 30, 2020
75086b6
Updated configuration.asciidoc
eyalkoren Jul 30, 2020
8d1edad
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Aug 23, 2020
7eb64ba
Refactoring to Indy plugin and usage of new SDK APIs
eyalkoren Aug 23, 2020
66a1e0d
Splitting plugin to modules
eyalkoren Aug 24, 2020
32161b5
Fixing ECS shading
eyalkoren Sep 2, 2020
b071aa3
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Sep 13, 2020
c58a5ce
Updating agent versions
eyalkoren Sep 13, 2020
f00d6cc
Remove ThreadLocal delegator
eyalkoren Sep 14, 2020
5b79cf6
Adding config options and tests
eyalkoren Sep 14, 2020
40e0a7c
Updating configuration.asciidoc
eyalkoren Sep 16, 2020
60d8f36
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Sep 16, 2020
333ded8
Config option changes and tests
eyalkoren Sep 16, 2020
6a18309
Finalizing shade log rolling (disabled by default)
eyalkoren Sep 16, 2020
8c20c59
Fixing docs link
eyalkoren Sep 16, 2020
e9b1286
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Oct 18, 2020
6943fa4
Update version
eyalkoren Oct 18, 2020
eefb01b
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Feb 17, 2021
aaf629d
Updage module versions
eyalkoren Feb 17, 2021
ff786bd
Adjusting to new metadata API and fixing docs
eyalkoren Feb 17, 2021
ecd8b9b
Enhancing and enabling rolling file tests
eyalkoren Feb 17, 2021
3000133
Extending sleep time in Logback test
eyalkoren Feb 17, 2021
661243a
Extend sleep even further :(
eyalkoren Feb 18, 2021
3ab3fb9
Adding rolling-file-test javadoc
eyalkoren Feb 18, 2021
551c75f
Changing config options
eyalkoren Feb 21, 2021
dcf25fd
Adding documentation
eyalkoren Feb 22, 2021
81f7ed2
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Feb 22, 2021
18f4887
Adding legacy Logback testing
eyalkoren Feb 24, 2021
43bb909
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Feb 28, 2021
b2be2ea
Updating gRPC test app version
eyalkoren Mar 2, 2021
8cb9209
Adding dedicated IndyPluginClassLoaderParent
eyalkoren Mar 2, 2021
c7c21bd
Adding support for log4j2 2.6
eyalkoren Mar 2, 2021
9e51e7d
Adding to supported technologies
eyalkoren Mar 2, 2021
464ff4b
Setting service name
eyalkoren Mar 2, 2021
a682e11
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Mar 2, 2021
78dd727
Some enhancements to IndyPluginClassLoaderParent
eyalkoren Mar 2, 2021
27614da
Registering the CL as parallel capable
eyalkoren Mar 3, 2021
1ff28e4
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Mar 8, 2021
21274dd
Adding a line break
eyalkoren Mar 9, 2021
5055e7c
Trying referencing to ecs-logging docs
eyalkoren Mar 11, 2021
b54bbc8
Merge remote-tracking branch 'eyalkoren/dynamic-logger-ecs-reconfig' …
eyalkoren Mar 11, 2021
f41b9cb
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Mar 11, 2021
65a9136
Removing dependency of Utils in LoggingConfiguration
eyalkoren Mar 11, 2021
eb4135e
Remove in-context service name usage
eyalkoren Mar 11, 2021
d460449
Changing instrumentation groups
eyalkoren Mar 11, 2021
57d8aa6
Applying review suggestions
eyalkoren Mar 11, 2021
d9937c3
Fixing javadoc signature
eyalkoren Mar 11, 2021
aab2e17
Fix log correlation config validation
eyalkoren Mar 17, 2021
c6258c8
Merge remote-tracking branch 'upstream/master' into dynamic-logger-ec…
eyalkoren Mar 17, 2021
d4622aa
Adding to CHANGELOG
eyalkoren Mar 17, 2021
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
2 changes: 1 addition & 1 deletion apm-agent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j2-ecs-layout</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
eyalkoren marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>com.blogspot.mydailyjava</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void assertValid(Boolean value) {
.buildWithDefault(false);

@SuppressWarnings("unused")
public ConfigurationOption<ByteValue> logFileMaxSize = ByteValueConverter.byteOption()
public ConfigurationOption<ByteValue> logFileSize = ByteValueConverter.byteOption()
.key(LOG_FILE_SIZE_KEY)
.configurationCategory(LOGGING_CATEGORY)
.description("The size of the log file.\n" +
Expand Down Expand Up @@ -213,6 +213,10 @@ public boolean isLogCorrelationEnabled() {
return logCorrelationEnabled.get();
}

public long getLogFileSize() {
return logFileSize.get().getBytes();
}

public boolean isShipAgentLogs() {
return shipAgentLogs.get();
}
Expand Down
97 changes: 97 additions & 0 deletions apm-agent-plugins/apm-log-shader-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>apm-agent-plugins</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.17.1-SNAPSHOT</version>
</parent>

<artifactId>apm-log-shader-plugin</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir>
<version.ecs.logging>0.4.0</version.ecs.logging>
</properties>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.10.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>logback-ecs-encoder</artifactId>
<version>${version.ecs.logging}</version>
</dependency>
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j-ecs-layout</artifactId>
<version>${version.ecs.logging}</version>
</dependency>
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>log4j2-ecs-layout</artifactId>
<version>${version.ecs.logging}</version>
</dependency>
</dependencies>

<build>
<!-- Relocating ECS-logging and logging framework packages.
The co.elastic.logging package is relocated to a shaded package to be used only within this plugin.
The logging framework packages referenced by the plugin, as well as the ECS logging dependencies, are relocated
to temp packages so they can be relocated back to the original packages. If we wouldn't done that, the
framework packages would have been shaded during agent packaging. -->
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>co.elastic.apm:apm-log-shader-plugin</include>
</includes>
<includes>
<include>co.elastic.logging:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>co.elastic.logging</pattern>
<shadedPattern>co.elastic.apm.agent.shaded.logging.shader</shadedPattern>
</relocation>
<relocation>
<pattern>org.slf4j</pattern>
<shadedPattern>co.elastic.apm.agent.logshading.shaded.slf4j</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.logging</pattern>
<shadedPattern>co.elastic.apm.agent.logshading.shaded.apache.logging</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*-
* #%L
* Elastic APM Java agent
* %%
* Copyright (C) 2018 - 2020 Elastic and contributors
* %%
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
* #L%
*/
package co.elastic.apm.agent.log.shader;

import co.elastic.apm.agent.configuration.CoreConfiguration;
import co.elastic.apm.agent.impl.ElasticApmTracer;
import co.elastic.apm.agent.logging.LoggingConfiguration;
import com.blogspot.mydailyjava.weaklockfree.WeakConcurrentMap;

import javax.annotation.Nullable;

/**
* The abstract Log shading helper- loaded as part of the agent core (agent CL / bootstrap CL / System CL)
*
* @param <A> logging-framework-specific Appender type
*/
public abstract class AbstractLogShadingHelper<A> {

private static final Object NULL_APPENDER = new Object();

private final ElasticApmTracer tracer;
private final LoggingConfiguration loggingConfiguration;
private final String serviceName;

public AbstractLogShadingHelper(ElasticApmTracer tracer) {
this.tracer = tracer;
loggingConfiguration = tracer.getConfig(LoggingConfiguration.class);
serviceName = tracer.getConfig(CoreConfiguration.class).getServiceName();
}

private static final WeakConcurrentMap<Object, Object> appenderToShadeAppender = new WeakConcurrentMap.WithInlinedExpunction<Object, Object>();
felixbarny marked this conversation as resolved.
Show resolved Hide resolved

@Nullable
public A getOrCreateShadeAppenderFor(A originalAppender) {
if (isShadingAppender(originalAppender)) {
return null;
}

Object shadeAppender = appenderToShadeAppender.get(originalAppender);
if (shadeAppender == null) {
synchronized (appenderToShadeAppender) {
if (!appenderToShadeAppender.containsKey(originalAppender)) {
A createdAppender = createAndConfigureAppender(originalAppender);
appenderToShadeAppender.put(originalAppender, createdAppender != null ? createdAppender : NULL_APPENDER);
}
}
shadeAppender = appenderToShadeAppender.get(originalAppender);
}
return shadeAppender != NULL_APPENDER ? (A) shadeAppender : null;
}

public void stopShading(A originalAppender) {
synchronized (appenderToShadeAppender) {
Object shadeAppender = appenderToShadeAppender.remove(originalAppender);
if (shadeAppender != null) {
closeShadeAppender((A) shadeAppender);
}
}
}

/**
* Checks whether the given appender is a shading appender, so to avoid recursive shading
* @return true if the provide appender is a shading appender; false otherwise
*/
protected abstract boolean isShadingAppender(A appender);

@Nullable
protected abstract A createAndConfigureAppender(A originalAppender);

// todo: find more accurate service name
eyalkoren marked this conversation as resolved.
Show resolved Hide resolved
protected String getServiceName() {
return serviceName;
}

protected long getMaxLogFileSize() {
return loggingConfiguration.getLogFileSize();
}

protected abstract void closeShadeAppender(A shadeAppender);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*-
* #%L
* Elastic APM Java agent
* %%
* Copyright (C) 2018 - 2020 Elastic and contributors
* %%
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
* #L%
*/
package co.elastic.apm.agent.log.shader;

import co.elastic.apm.agent.bci.ElasticApmInstrumentation;

import java.util.ArrayList;
import java.util.Collection;

public abstract class AbstractLogShadingInstrumentation extends ElasticApmInstrumentation {

@Override
public Collection<String> getInstrumentationGroupNames() {
Collection<String> ret = new ArrayList<>();
ret.add("logging");
return ret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*-
* #%L
* Elastic APM Java agent
* %%
* Copyright (C) 2018 - 2020 Elastic and contributors
* %%
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you 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.
* #L%
*/
package co.elastic.apm.agent.log.shader;

import java.nio.file.Path;
import java.nio.file.Paths;

public class Utils {

static final String SHADE_LOGS_DIR_NAME = "shade_logs";

/**
* Computes a shade log file path based on a given log file. The shade log file will have the same name as the
* original log file and will be located in a subdirectory of the original file's parent directory.
* @param originalLogFile the log file to which a shade file path is required
* @return the shade log file path
*/
public static String computeShadeLogFilePath(String originalLogFile) {
Path originalFilePath = Paths.get(originalLogFile);
Path logFileName = originalFilePath.getFileName();
Path logFileDir = originalFilePath.getParent();
Path shadeDir;
if (logFileDir != null) {
shadeDir = logFileDir.resolve(SHADE_LOGS_DIR_NAME);
} else {
shadeDir = Paths.get(SHADE_LOGS_DIR_NAME);
}
return shadeDir.resolve(logFileName).toString();
}
}
Loading