Imporve stability of elasticsearch tests
MODIFY
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53NodeClientTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53NodeClientTest.groovy
@@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.env.Environment
@@ -51,6 +52,8 @@ class Elasticsearch53NodeClientTest extends AgentInstrumentationSpecification {
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
// into a top level trace to get exactly one trace in the result.
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ testNode.client().admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
}
testWriter.waitForTraces(1)
}

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/Elasticsearch53TransportClientTest.groovy
@@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@@ -68,6 +69,8 @@ class Elasticsearch53TransportClientTest extends AgentInstrumentationSpecificati
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
// into a top level trace to get exactly one trace in the result.
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ client.admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
}
testWriter.waitForTraces(1)
}

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Config.groovy
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Config.groovy
package springdata
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.env.Environment
@@ -28,8 +29,8 @@ class Config {
return new NodeBuilder()
}
- @Bean
- ElasticsearchOperations elasticsearchTemplate() {
+ @Bean(destroyMethod = "close")
+ Node elasticSearchNode() {
def tmpDir = File.createTempFile("test-es-working-dir-", "")
tmpDir.delete()
tmpDir.mkdir()
@@ -53,6 +54,16 @@ class Config {
println "ES work dir: $tmpDir"
- return new ElasticsearchTemplate(new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin]).start().client())
+ def testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
+ testNode.start()
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ testNode.client().admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
+
+ return testNode
+ }
+
+ @Bean
+ ElasticsearchOperations elasticsearchTemplate(Node node) {
+ return new ElasticsearchTemplate(node.client())
}
}

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringRepositoryTest.groovy
@@ -23,26 +23,34 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat
// To change the timing without adding ugly checks everywhere -
// use a dynamic proxy. There's probably a more "groovy" way to do this.
+ @Shared
+ LazyProxyInvoker lazyProxyInvoker = new LazyProxyInvoker()
+
@Shared
DocRepository repo = Proxy.newProxyInstance(
getClass().getClassLoader(),
[DocRepository] as Class[],
- new LazyProxyInvoker())
+ lazyProxyInvoker)
static class LazyProxyInvoker implements InvocationHandler {
def repo
+ def applicationContext
DocRepository getOrCreateRepository() {
if (repo != null) {
return repo
}
- def applicationContext = new AnnotationConfigApplicationContext(Config)
+ applicationContext = new AnnotationConfigApplicationContext(Config)
repo = applicationContext.getBean(DocRepository)
return repo
}
+ void close() {
+ applicationContext.close()
+ }
+
@Override
Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return method.invoke(getOrCreateRepository(), args)
@@ -59,6 +67,10 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat
testWriter.clear()
}
+ def cleanupSpec() {
+ lazyProxyInvoker.close()
+ }
+
def "test empty repo"() {
when:
def result = repo.findAll()

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringTemplateTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-5.3/javaagent/src/test/groovy/springdata/Elasticsearch53SpringTemplateTest.groovy
@@ -12,6 +12,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import java.util.concurrent.atomic.AtomicLong
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.action.search.SearchResponse
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@@ -32,11 +33,6 @@ import spock.lang.Shared
class Elasticsearch53SpringTemplateTest extends AgentInstrumentationSpecification {
public static final long TIMEOUT = 10000 // 10 seconds
- // Some ES actions are not caused by clients and seem to just happen from time to time.
- // We will just ignore these actions in traces.
- // TODO: check if other ES tests need this protection and potentially pull this into global class
- public static final Set<String> IGNORED_ACTIONS = ["NodesStatsAction", "IndicesStatsAction"] as Set
-
@Shared
Node testNode
@Shared
@@ -67,6 +63,8 @@ class Elasticsearch53SpringTemplateTest extends AgentInstrumentationSpecificatio
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
// into a top level trace to get exactly one trace in the result.
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ testNode.client().admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
}
testWriter.waitForTraces(1)

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6NodeClientTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6NodeClientTest.groovy
@@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.index.IndexNotFoundException
@@ -48,6 +49,8 @@ class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
// into a top level trace to get exactly one trace in the result.
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ testNode.client().admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
}
testWriter.waitForTraces(1)
}

MODIFY
instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy
instrumentation/elasticsearch/elasticsearch-transport-6.0/javaagent/src/test/groovy/Elasticsearch6TransportClientTest.groovy
@@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
+import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@@ -63,6 +64,8 @@ class Elasticsearch6TransportClientTest extends AgentInstrumentationSpecificatio
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
// into a top level trace to get exactly one trace in the result.
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
+ // disable periodic refresh in InternalClusterInfoService as it creates spans that tests don't expect
+ client.admin().cluster().updateSettings(new ClusterUpdateSettingsRequest().transientSettings(["cluster.routing.allocation.disk.threshold_enabled": false]))
}
testWriter.waitForTraces(1)
}

Imporve stability of elasticsearch tests (#2170)