Imporve stability of elasticsearch tests (#2170)
This commit is contained in:
parent
575a71f316
commit
89fd887c74
|
@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
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.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
import org.elasticsearch.common.settings.Settings
|
||||||
import org.elasticsearch.env.Environment
|
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
|
// 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.
|
// into a top level trace to get exactly one trace in the result.
|
||||||
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
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)
|
testWriter.waitForTraces(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
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.client.transport.TransportClient
|
||||||
import org.elasticsearch.common.io.FileSystemUtils
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
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
|
// 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.
|
// into a top level trace to get exactly one trace in the result.
|
||||||
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
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)
|
testWriter.waitForTraces(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package springdata
|
package springdata
|
||||||
|
|
||||||
|
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
|
||||||
import org.elasticsearch.common.io.FileSystemUtils
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
import org.elasticsearch.common.settings.Settings
|
||||||
import org.elasticsearch.env.Environment
|
import org.elasticsearch.env.Environment
|
||||||
|
@ -28,8 +29,8 @@ class Config {
|
||||||
return new NodeBuilder()
|
return new NodeBuilder()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean(destroyMethod = "close")
|
||||||
ElasticsearchOperations elasticsearchTemplate() {
|
Node elasticSearchNode() {
|
||||||
def tmpDir = File.createTempFile("test-es-working-dir-", "")
|
def tmpDir = File.createTempFile("test-es-working-dir-", "")
|
||||||
tmpDir.delete()
|
tmpDir.delete()
|
||||||
tmpDir.mkdir()
|
tmpDir.mkdir()
|
||||||
|
@ -53,6 +54,16 @@ class Config {
|
||||||
|
|
||||||
println "ES work dir: $tmpDir"
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,26 +23,34 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat
|
||||||
// To change the timing without adding ugly checks everywhere -
|
// To change the timing without adding ugly checks everywhere -
|
||||||
// use a dynamic proxy. There's probably a more "groovy" way to do this.
|
// use a dynamic proxy. There's probably a more "groovy" way to do this.
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
LazyProxyInvoker lazyProxyInvoker = new LazyProxyInvoker()
|
||||||
|
|
||||||
@Shared
|
@Shared
|
||||||
DocRepository repo = Proxy.newProxyInstance(
|
DocRepository repo = Proxy.newProxyInstance(
|
||||||
getClass().getClassLoader(),
|
getClass().getClassLoader(),
|
||||||
[DocRepository] as Class[],
|
[DocRepository] as Class[],
|
||||||
new LazyProxyInvoker())
|
lazyProxyInvoker)
|
||||||
|
|
||||||
static class LazyProxyInvoker implements InvocationHandler {
|
static class LazyProxyInvoker implements InvocationHandler {
|
||||||
def repo
|
def repo
|
||||||
|
def applicationContext
|
||||||
|
|
||||||
DocRepository getOrCreateRepository() {
|
DocRepository getOrCreateRepository() {
|
||||||
if (repo != null) {
|
if (repo != null) {
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
def applicationContext = new AnnotationConfigApplicationContext(Config)
|
applicationContext = new AnnotationConfigApplicationContext(Config)
|
||||||
repo = applicationContext.getBean(DocRepository)
|
repo = applicationContext.getBean(DocRepository)
|
||||||
|
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
applicationContext.close()
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
return method.invoke(getOrCreateRepository(), args)
|
return method.invoke(getOrCreateRepository(), args)
|
||||||
|
@ -59,6 +67,10 @@ class Elasticsearch53SpringRepositoryTest extends AgentInstrumentationSpecificat
|
||||||
testWriter.clear()
|
testWriter.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
lazyProxyInvoker.close()
|
||||||
|
}
|
||||||
|
|
||||||
def "test empty repo"() {
|
def "test empty repo"() {
|
||||||
when:
|
when:
|
||||||
def result = repo.findAll()
|
def result = repo.findAll()
|
||||||
|
|
|
@ -12,6 +12,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest
|
||||||
import org.elasticsearch.action.search.SearchResponse
|
import org.elasticsearch.action.search.SearchResponse
|
||||||
import org.elasticsearch.common.io.FileSystemUtils
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
@ -32,11 +33,6 @@ import spock.lang.Shared
|
||||||
class Elasticsearch53SpringTemplateTest extends AgentInstrumentationSpecification {
|
class Elasticsearch53SpringTemplateTest extends AgentInstrumentationSpecification {
|
||||||
public static final long TIMEOUT = 10000 // 10 seconds
|
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
|
@Shared
|
||||||
Node testNode
|
Node testNode
|
||||||
@Shared
|
@Shared
|
||||||
|
@ -67,6 +63,8 @@ class Elasticsearch53SpringTemplateTest extends AgentInstrumentationSpecificatio
|
||||||
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
|
// 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.
|
// into a top level trace to get exactly one trace in the result.
|
||||||
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
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)
|
testWriter.waitForTraces(1)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
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.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
import org.elasticsearch.common.settings.Settings
|
||||||
import org.elasticsearch.index.IndexNotFoundException
|
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
|
// 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.
|
// into a top level trace to get exactly one trace in the result.
|
||||||
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
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)
|
testWriter.waitForTraces(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
|
||||||
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
|
||||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
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.client.transport.TransportClient
|
||||||
import org.elasticsearch.common.io.FileSystemUtils
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
import org.elasticsearch.common.settings.Settings
|
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
|
// 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.
|
// into a top level trace to get exactly one trace in the result.
|
||||||
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
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)
|
testWriter.waitForTraces(1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue