codelibs/elasticsearch-cluster-runner

cluster-runner 7.16.3 causes NPE, can't find plugin

Opened this issue · 3 comments

2022-02-17 15:18:50,152 SUITE-MyTest-seed#[66F66F576B5EB0AF] ERROR Unable to locate plugin type for HeaderWarningAppender
2022-02-17 15:18:50,200 SUITE-MyTest-seed#[66F66F576B5EB0AF] ERROR Unable to locate plugin for HeaderWarningAppender
2022-02-17 15:18:50,200 SUITE-MyTest-seed#[66F66F576B5EB0AF] ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.config.AppendersPlugin for element Appenders: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:52)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:262)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1120)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1045)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:651)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:247)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:293)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:626)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:699)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:599)
at com.av.harness.elasticsearch.AbstractElasticsearchTestHarness.(AbstractElasticsearchTestHarness.java:46)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.carrotsearch.randomizedtesting.RandomizedRunner$2.run(RandomizedRunner.java:623)

2022-02-17 15:18:50,201 SUITE-MyTest-seed#[66F66F576B5EB0AF] ERROR Unable to locate appender "console" for logger config "root"
2022-02-17 15:18:50,201 SUITE-MyTest-seed#[66F66F576B5EB0AF] ERROR Unable to locate appender "header_warning" for logger config "org.elasticsearch.deprecation"

this is new behavior after changing from cluster runner 7.8.0 to 7.16.3.

Could you provide info to reproduce it?

`
for i in $(find . -type f | egrep -v '.idea/|.iml|.DS_Store'); do printf "\n\n ~~~[ %s ]~~~~~~~~~~ \n\n" $i; cat $i; done


<?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>

   <groupId>com.my</groupId>
   <artifactId>my-elasticsearch-testharness</artifactId>
   <version>2.2</version>

   <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

       <maven.compiler.source>1.8</maven.compiler.source>
       <maven.compiler.target>1.8</maven.compiler.target>

<!--        <elasticsearch.version>7.8.0</elasticsearch.version>-->
<!--        <embedded-es.version>7.8.0</embedded-es.version>-->
<!--        <cluster-runner.version>7.8.0.0</cluster-runner.version>-->
       <elasticsearch.version>7.16.3</elasticsearch.version>
       <embedded-es.version>7.16.3</embedded-es.version>
       <cluster-runner.version>7.16.3.0</cluster-runner.version>
       <log4j2.version>2.17.1</log4j2.version>
   </properties>

   <dependencies>
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>4.12</version>
           <exclusions>
               <exclusion>
                   <groupId>org.hamcrest</groupId>
                   <artifactId>hamcrest-core</artifactId>
               </exclusion>
           </exclusions>
       </dependency>
       <dependency>
           <groupId>org.elasticsearch.test</groupId>
           <artifactId>framework</artifactId>
           <version>${elasticsearch.version}</version>
       </dependency>
       <dependency>
           <groupId>org.codelibs</groupId>
           <artifactId>elasticsearch-cluster-runner</artifactId>
           <version>${cluster-runner.version}</version>
       </dependency>
       <dependency>
           <groupId>org.apache.logging.log4j</groupId>
           <artifactId>log4j-core</artifactId>
           <version>${log4j2.version}</version>
       </dependency>
       <dependency>
           <groupId>org.apache.logging.log4j</groupId>
           <artifactId>log4j-api</artifactId>
           <version>${log4j2.version}</version>
       </dependency>
       <dependency>
           <groupId>org.apache.logging.log4j</groupId>
           <artifactId>log4j-slf4j-impl</artifactId>
           <version>${log4j2.version}</version>
       </dependency>
   </dependencies>
   <!--  added specifically for elasticsearch-cluster-runner > 7.10.0.0 -->
   <!--  REF https://github.com/codelibs/elasticsearch-cluster-runner/tree/elasticsearch-cluster-runner-7.16.3.0 -->
   <repositories>
   	<repository>
   		<id>central</id>
   		<url>https://repo1.maven.org/maven2</url>
   		<releases>
   			<enabled>true</enabled>
   		</releases>
   		<snapshots>
   			<enabled>true</enabled>
   		</snapshots>
   	</repository>
   	<repository>
   		<id>codelibs.org</id>
   		<name>CodeLibs Repository</name>
   		<url>https://maven.codelibs.org/</url>
   	</repository>
   </repositories>
   
   <build>
       <pluginManagement>
           <plugins>
               <plugin>
                   <groupId>org.jacoco</groupId>
                   <artifactId>jacoco-maven-plugin</artifactId>
                   <version>0.8.7</version>
               </plugin>
           </plugins>
       </pluginManagement>
       <plugins>
       <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
           <executions>
               <execution>
                   <id>prepare-agent</id>
                   <goals>
                       <goal>prepare-agent</goal>
                   </goals>
               </execution>
               <execution>
                   <id>report</id>
                   <goals>
                       <goal>report</goal>
                   </goals>
               </execution>
           </executions>
       </plugin>
       </plugins>
   </build>
</project>


~~~[ ./src/test/resources/log4j2-test.xml ]~~~~~~~~~~ 

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
   <Appenders>
       <Console name="Console">
           <PatternLayout>
               <pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n</pattern>
           </PatternLayout>
       </Console>
   </Appenders>
   <Loggers>
       <Root level="${env:LOG_LEVEL:-ERROR}">
           <AppenderRef ref="Console"/>
       </Root>

       <Logger name="com.my" level="${env:MY_LOG_LEVEL:-TRACE}"/>
       <Logger name="com.carrotsearch" level="OFF"/>
       <Logger name="org.elasticsearch" level="WARN"/>
   </Loggers>
</Configuration>


~~~[ ./src/test/java/com/my/harness/elasticsearch/MyTest.java ]~~~~~~~~~~ 

package com.my.harness.elasticsearch;

import com.carrotsearch.randomizedtesting.RandomizedRunner;
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import junit.framework.TestSuite;
import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner;
import org.elasticsearch.common.settings.Settings;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;

@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
@RunWith(RandomizedRunner.class)
public class MyTest extends TestSuite {

   public static final Integer BASE_ES_PORT = 41091;
   public static final String CLUSTER_NAME = "my_cluster";

   ElasticsearchClusterRunner runner = new ElasticsearchClusterRunner();

   @Before
   public void before() throws IOException {
       // create runner instance
       String clusterName = CLUSTER_NAME + "_" + System.currentTimeMillis();
       ElasticsearchClusterRunner.Builder builder = new ElasticsearchClusterRunner.Builder() {

           @Override
           public void build(int i, Settings.Builder settingsBuilder) {
               settingsBuilder.put("http.cors.enabled", true);
               settingsBuilder.put("http.cors.allow-origin", "*");
//                settingsBuilder.put("node.master", true);
//                settingsBuilder.put("node.data", true);
//                settingsBuilder.put("node.ingest", true);
//                settingsBuilder.putList("discovery.seed_hosts", "127.0.0.1:41091", "127.0.0.1:41092");
               settingsBuilder.put("cluster.initial_master_nodes", "127.0.0.1");
           }
       };
       runner.setMaxHttpPort(41099);
       runner.onBuild(builder).build(newConfigs().clusterName(clusterName).numOfNode(1).baseHttpPort(BASE_ES_PORT));
   }

   @Test
   public void test() {
       System.out.println("pause");
   }

   @After
   public void after() throws IOException {
       runner.close();
       runner.clean();
   }
}

`

difference between elasticsearch-7.16.3/config/log4j.properties (1st set) and your embedded log4j.properties (2nd set), for the block that appears relevant to the stack trace above (around the context of HeaderWarningAppender)

diff <(cat -n log4j2.properties | head -78 | tail -19) <(cat -n __elasticsearch-cluster-runner-7163-log4j2.properties | head -78 | tail -19)

x-opaque line not covered in cluster-runner log4j2.props (at least in this block)
ESJsonLayout vs ECSJsonLayout (lines 64, at least in this block)
data.set vs type_name (line 65/66, at least in this block)

  60        ######## Deprecation JSON #######################
  61        appender.deprecation_rolling.type = RollingFile
  62        appender.deprecation_rolling.name = deprecation_rolling
  63        appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.json
  64        appender.deprecation_rolling.layout.type = ESJsonLayout
  65        appender.deprecation_rolling.layout.type_name = deprecation.elasticsearch
  66        appender.deprecation_rolling.layout.esmessagefields=x-opaque-id,key,category,elasticsearch.elastic_product_origin ### not represented in cluster-runner log4j2.props
  67        appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter
  68
  69        appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.json.gz
  70        appender.deprecation_rolling.policies.type = Policies
  71        appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy
  72        appender.deprecation_rolling.policies.size.size = 1GB
  73        appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
  74        appender.deprecation_rolling.strategy.max = 4
  75
  76        appender.header_warning.type = HeaderWarningAppender
  77        appender.header_warning.name = header_warning
  78        #################################################


  60        ######## Deprecation JSON #######################
  61        appender.deprecation_rolling.type = RollingFile
  62        appender.deprecation_rolling.name = deprecation_rolling
  63        appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.json
  64        appender.deprecation_rolling.layout.type = ECSJsonLayout  ### vs ESJsonLayout (no C)
  65        # Intentionally follows a different pattern to above
  66        appender.deprecation_rolling.layout.dataset = deprecation.elasticsearch  ### vs. type_name
  67        appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter
  68
  69        appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.json.gz
  70        appender.deprecation_rolling.policies.type = Policies
  71        appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy
  72        appender.deprecation_rolling.policies.size.size = 1GB
  73        appender.deprecation_rolling.strategy.type = DefaultRolloverStrategy
  74        appender.deprecation_rolling.strategy.max = 4
  75
  76        appender.header_warning.type = HeaderWarningAppender
  77        appender.header_warning.name = header_warning
  78        #################################################