Fix elasticsearch test flakiness (DataDog/dd-trace-java#1513)

This commit is contained in:
Richard Startin 2020-06-02 08:03:45 +01:00 committed by Trask Stalnaker
parent 1b29184e7c
commit c61034c945
17 changed files with 226 additions and 369 deletions

View File

@ -18,7 +18,6 @@ import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecor
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.apache.http.HttpHost
import org.apache.http.client.config.RequestConfig
import org.apache.http.util.EntityUtils
@ -27,6 +26,8 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.http.HttpServerTransport
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin
@ -37,26 +38,18 @@ import static io.opentelemetry.trace.Span.Kind.INTERNAL
class Elasticsearch6RestClientTest extends AgentTestRunner {
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress httpTransportAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
RestClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -64,14 +57,13 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("cluster.name", "test-cluster")
.put("cluster.name", clusterName)
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode.start()
httpTransportAddress = testNode.injector().getInstance(HttpServerTransport).boundAddress().publishAddress()
client = RestClient.builder(new HttpHost("localhost", httpPort))
client = RestClient.builder(new HttpHost(httpTransportAddress.address, httpTransportAddress.port))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
@ -107,8 +99,8 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
spanKind INTERNAL
parent()
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_PORT" httpPort
"$MoreTags.NET_PEER_NAME" httpTransportAddress.address
"$MoreTags.NET_PEER_PORT" httpTransportAddress.port
"$Tags.HTTP_URL" "_cluster/health"
"$Tags.HTTP_METHOD" "GET"
"$Tags.DB_TYPE" "elasticsearch"

View File

@ -18,7 +18,6 @@ import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecor
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.apache.http.HttpHost
import org.apache.http.client.config.RequestConfig
import org.apache.http.util.EntityUtils
@ -27,7 +26,9 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.env.Environment
import org.elasticsearch.http.HttpServerTransport
import org.elasticsearch.node.Node
import org.elasticsearch.node.internal.InternalSettingsPreparer
import org.elasticsearch.transport.Netty3Plugin
@ -39,26 +40,18 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
class Elasticsearch5RestClientTest extends AgentTestRunner {
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress httpTransportAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
static RestClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -66,16 +59,15 @@ class Elasticsearch5RestClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()
httpTransportAddress = testNode.injector().getInstance(HttpServerTransport).boundAddress().publishAddress()
client = RestClient.builder(new HttpHost("localhost", httpPort))
client = RestClient.builder(new HttpHost(httpTransportAddress.address, httpTransportAddress.port))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
@ -111,8 +103,8 @@ class Elasticsearch5RestClientTest extends AgentTestRunner {
spanKind INTERNAL
parent()
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_PORT" httpPort
"$MoreTags.NET_PEER_NAME" httpTransportAddress.address
"$MoreTags.NET_PEER_PORT" httpTransportAddress.port
"$Tags.HTTP_URL" "_cluster/health"
"$Tags.HTTP_METHOD" "GET"
"$Tags.DB_TYPE" "elasticsearch"

View File

@ -18,7 +18,6 @@ import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecor
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.apache.http.HttpHost
import org.apache.http.client.config.RequestConfig
import org.apache.http.util.EntityUtils
@ -28,7 +27,9 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.env.Environment
import org.elasticsearch.http.HttpServerTransport
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.plugins.Plugin
@ -39,10 +40,9 @@ import static io.opentelemetry.trace.Span.Kind.CLIENT
import static io.opentelemetry.trace.Span.Kind.INTERNAL
class Elasticsearch6RestClientTest extends AgentTestRunner {
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress httpTransportAddress
@Shared
Node testNode
@Shared
@ -50,16 +50,10 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
@Shared
RestClient client
@Shared
String clusterName = UUID.randomUUID().toString()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -67,14 +61,13 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("cluster.name", "test-cluster")
.put("cluster.name", clusterName)
.build()
testNode = new TestNode(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode.start()
httpTransportAddress = testNode.injector().getInstance(HttpServerTransport).boundAddress().publishAddress()
client = RestClient.builder(new HttpHost("localhost", httpPort))
client = RestClient.builder(new HttpHost(httpTransportAddress.address, httpTransportAddress.port))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
@ -111,8 +104,8 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
spanKind INTERNAL
parent()
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_PORT" httpPort
"$MoreTags.NET_PEER_NAME" httpTransportAddress.address
"$MoreTags.NET_PEER_PORT" httpTransportAddress.port
"$Tags.HTTP_URL" "_cluster/health"
"$Tags.HTTP_METHOD" "GET"
"$Tags.DB_TYPE" "elasticsearch"

View File

@ -18,7 +18,6 @@ import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecor
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.apache.http.HttpHost
import org.apache.http.client.config.RequestConfig
import org.apache.http.util.EntityUtils
@ -27,6 +26,8 @@ import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.http.HttpServerTransport
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin
@ -37,26 +38,18 @@ import static io.opentelemetry.trace.Span.Kind.INTERNAL
class Elasticsearch6RestClientTest extends AgentTestRunner {
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress httpTransportAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
RestClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -64,14 +57,13 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("cluster.name", "test-cluster")
.put("cluster.name", clusterName)
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode.start()
httpTransportAddress = testNode.injector().getInstance(HttpServerTransport).boundAddress().publishAddress()
client = RestClient.builder(new HttpHost("localhost", httpPort))
client = RestClient.builder(new HttpHost(httpTransportAddress.address, httpTransportAddress.port))
.setMaxRetryTimeoutMillis(Integer.MAX_VALUE)
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
@ -107,8 +99,8 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
spanKind INTERNAL
parent()
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_PORT" httpPort
"$MoreTags.NET_PEER_NAME" httpTransportAddress.address
"$MoreTags.NET_PEER_PORT" httpTransportAddress.port
"$Tags.HTTP_URL" "_cluster/health"
"$Tags.HTTP_METHOD" "GET"
"$Tags.DB_TYPE" "elasticsearch"

View File

@ -15,13 +15,14 @@
*/
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.Node
import org.elasticsearch.node.NodeBuilder
import org.elasticsearch.transport.TransportService
import spock.lang.Shared
import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderTrace
@ -31,25 +32,17 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
def client = testNode.client()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -59,11 +52,10 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().local(true).clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().local(true).clusterName(clusterName).settings(settings).build()
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
runUnderTrace("setup") {
// 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.

View File

@ -16,16 +16,17 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.Node
import org.elasticsearch.node.NodeBuilder
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import spock.lang.Shared
import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderTrace
@ -35,26 +36,18 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
TransportClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -62,20 +55,20 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().clusterName(clusterName).settings(settings).build()
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
client = TransportClient.builder().settings(
Settings.builder()
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("cluster.name", "test-cluster")
.put("cluster.name", clusterName)
.build()
).build()
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
client.addTransportAddress(tcpPublishAddress)
runUnderTrace("setup") {
// 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.
@ -107,9 +100,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -119,6 +112,36 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
}
}
def "test elasticsearch stats"() {
setup:
def result = client.admin().cluster().clusterStats(new ClusterStatsRequest(new String[0]))
def status = result.get().status
def failures = result.get().failures()
expect:
status.name() == "GREEN"
failures == null
assertTraces(1) {
trace(0, 1) {
span(0) {
operationName "ClusterStatsAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterStatsAction"
"elasticsearch.request" "ClusterStatsRequest"
"elasticsearch.node.cluster.name" clusterName
}
}
}
}
}
def "test elasticsearch error"() {
when:
client.prepareGet(indexName, indexType, id).get()
@ -202,9 +225,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "CreateIndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "CreateIndexAction"
"elasticsearch.request" "CreateIndexRequest"
@ -217,9 +240,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -231,9 +254,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"
@ -261,9 +284,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "IndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "IndexAction"
"elasticsearch.request" "IndexRequest"
@ -277,9 +300,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"

View File

@ -17,7 +17,6 @@ package springdata
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.search.SearchResponse
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -40,27 +39,17 @@ import static io.opentelemetry.trace.Span.Kind.CLIENT
class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
ElasticsearchTemplate template
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -70,10 +59,8 @@ class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().local(true).clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().local(true).clusterName(clusterName).settings(settings).build()
testNode.start()
template = new ElasticsearchTemplate(testNode.client())

View File

@ -16,7 +16,6 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -31,26 +30,16 @@ import static io.opentelemetry.trace.Span.Kind.CLIENT
class Elasticsearch2NodeClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
def client = testNode.client()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -60,10 +49,8 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().local(true).clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().local(true).clusterName(clusterName).settings(settings).build()
testNode.start()
runUnderTrace("setup") {
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call

View File

@ -16,17 +16,17 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.Node
import org.elasticsearch.node.NodeBuilder
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import spock.lang.Shared
import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderTrace
@ -36,26 +36,18 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
TransportClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -63,20 +55,19 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().clusterName(clusterName).settings(settings).build()
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
client = TransportClient.builder().settings(
Settings.builder()
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("cluster.name", "test-cluster")
.put("cluster.name", clusterName)
.build()
).build()
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
client.addTransportAddress(tcpPublishAddress)
runUnderTrace("setup") {
// 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.
@ -108,9 +99,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -136,13 +127,13 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
span(0) {
operationName "ClusterStatsAction"
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterStatsAction"
"elasticsearch.request" "ClusterStatsRequest"
"elasticsearch.node.cluster.name" "test-cluster"
"elasticsearch.node.cluster.name" clusterName
}
}
}
@ -232,9 +223,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "CreateIndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "CreateIndexAction"
"elasticsearch.request" "CreateIndexRequest"
@ -247,9 +238,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -261,9 +252,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"
@ -291,9 +282,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "IndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "IndexAction"
"elasticsearch.request" "IndexRequest"
@ -307,9 +298,9 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "127.0.0.1"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"

View File

@ -18,7 +18,6 @@ package springdata
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.search.SearchResponse
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -41,27 +40,17 @@ import static io.opentelemetry.trace.Span.Kind.CLIENT
class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
ElasticsearchTemplate template
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -71,10 +60,8 @@ class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("threadpool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.build()
testNode = NodeBuilder.newInstance().local(true).clusterName("test-cluster").settings(settings).build()
testNode = NodeBuilder.newInstance().local(true).clusterName(clusterName).settings(settings).build()
testNode.start()
template = new ElasticsearchTemplate(testNode.client())

View File

@ -15,7 +15,6 @@
*/
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -33,26 +32,16 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
class Elasticsearch5NodeClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
def client = testNode.client()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -62,11 +51,9 @@ class Elasticsearch5NodeClientTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()

View File

@ -16,18 +16,18 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.env.Environment
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.Node
import org.elasticsearch.node.internal.InternalSettingsPreparer
import org.elasticsearch.transport.Netty3Plugin
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import org.elasticsearch.transport.client.PreBuiltTransportClient
import spock.lang.Shared
@ -39,26 +39,18 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
TransportClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -66,23 +58,22 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
client = new PreBuiltTransportClient(
Settings.builder()
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
)
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
client.addTransportAddress(tcpPublishAddress)
runUnderTrace("setup") {
// 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.
@ -114,9 +105,9 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" String
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -209,9 +200,9 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
operationName "CreateIndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" String
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "CreateIndexAction"
"elasticsearch.request" "CreateIndexRequest"
@ -224,9 +215,9 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" String
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"
@ -253,9 +244,9 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
operationName "IndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" String
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "IndexAction"
"elasticsearch.request" "IndexRequest"
@ -273,9 +264,9 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" String
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"

View File

@ -15,7 +15,6 @@
*/
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -33,26 +32,16 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
class Elasticsearch53NodeClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
def client = testNode.client()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -62,11 +51,9 @@ class Elasticsearch53NodeClientTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()

View File

@ -16,18 +16,18 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.env.Environment
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty3Plugin
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import org.elasticsearch.transport.client.PreBuiltTransportClient
import spock.lang.Shared
@ -39,9 +39,8 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
@ -49,16 +48,10 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
@Shared
TransportClient client
@Shared
String clusterName = UUID.randomUUID().toString()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -66,23 +59,22 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
client = new PreBuiltTransportClient(
Settings.builder()
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
)
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
client.addTransportAddress(tcpPublishAddress)
runUnderTrace("setup") {
// 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.
@ -114,9 +106,9 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
operationName "ClusterHealthAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -209,9 +201,9 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
operationName "CreateIndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "CreateIndexAction"
"elasticsearch.request" "CreateIndexRequest"
@ -224,9 +216,9 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"
@ -253,9 +245,9 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
operationName "IndexAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "IndexAction"
"elasticsearch.request" "IndexRequest"
@ -274,9 +266,9 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
operationName "GetAction"
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_NAME" tcpPublishAddress.host
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"

View File

@ -18,7 +18,6 @@ package springdata
import com.google.common.collect.ImmutableSet
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.search.SearchResponse
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -50,27 +49,17 @@ class Elasticsearch53SpringTemplateTest extends AgentTestRunner {
// TODO: check if other ES tests need this protection and potentially pull this into global class
public static final Set<String> IGNORED_ACTIONS = ImmutableSet.of("NodesStatsAction", "IndicesStatsAction")
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
ElasticsearchTemplate template
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -80,11 +69,9 @@ class Elasticsearch53SpringTemplateTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put("transport.type", "netty3")
.put("http.type", "netty3")
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
testNode.start()

View File

@ -15,7 +15,6 @@
*/
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
@ -32,26 +31,16 @@ import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
class Elasticsearch6NodeClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
def client = testNode.client()
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
@ -61,9 +50,7 @@ class Elasticsearch6NodeClientTest extends AgentTestRunner {
.put("path.home", esWorkingDir.path)
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode.start()

View File

@ -16,7 +16,6 @@
import io.opentelemetry.auto.instrumentation.api.MoreTags
import io.opentelemetry.auto.instrumentation.api.Tags
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.PortUtils
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.io.FileSystemUtils
@ -27,6 +26,7 @@ import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import org.elasticsearch.transport.client.PreBuiltTransportClient
import spock.lang.Shared
@ -38,48 +38,38 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
public static final long TIMEOUT = 10000; // 10 seconds
@Shared
int httpPort
@Shared
int tcpPort
TransportAddress tcpPublishAddress
@Shared
Node testNode
@Shared
File esWorkingDir
@Shared
String clusterName = UUID.randomUUID().toString()
@Shared
TransportClient client
def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}
def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
esWorkingDir.deleteOnExit()
println "ES work dir: $esWorkingDir"
def settings = Settings.builder()
.put("path.home", esWorkingDir.path)
.put("http.port", httpPort)
.put("transport.tcp.port", tcpPort)
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()
client = new PreBuiltTransportClient(
Settings.builder()
// Since we use listeners to close spans this should make our span closing deterministic which is good for tests
.put("thread_pool.listener.size", 1)
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.build()
)
client.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), tcpPort))
client.addTransportAddress(tcpPublishAddress)
runUnderTrace("setup") {
// 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.
@ -112,8 +102,8 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "ClusterHealthAction"
"elasticsearch.request" "ClusterHealthRequest"
@ -207,8 +197,8 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "CreateIndexAction"
"elasticsearch.request" "CreateIndexRequest"
@ -222,8 +212,8 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"
@ -251,8 +241,8 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "IndexAction"
"elasticsearch.request" "IndexRequest"
@ -272,8 +262,8 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
spanKind CLIENT
tags {
"$MoreTags.NET_PEER_NAME" "localhost"
"$MoreTags.NET_PEER_IP" "127.0.0.1"
"$MoreTags.NET_PEER_PORT" tcpPort
"$MoreTags.NET_PEER_IP" tcpPublishAddress.address
"$MoreTags.NET_PEER_PORT" tcpPublishAddress.port
"$Tags.DB_TYPE" "elasticsearch"
"elasticsearch.action" "GetAction"
"elasticsearch.request" "GetRequest"