Merge pull request #506 from DataDog/tyler/es-tlc
Remove elasticsearch.request.description
This commit is contained in:
commit
21f4806d08
|
@ -14,9 +14,7 @@ testJava8Only += '**/*Test.class'
|
||||||
apply plugin: 'org.unbroken-dome.test-sets'
|
apply plugin: 'org.unbroken-dome.test-sets'
|
||||||
|
|
||||||
testSets {
|
testSets {
|
||||||
latestDepTest {
|
latestDepTest
|
||||||
dirName = 'test'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -43,6 +41,6 @@ dependencies {
|
||||||
testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
|
testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
|
||||||
testCompile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
|
testCompile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
|
||||||
|
|
||||||
latestDepTestCompile group: 'org.elasticsearch', name: 'elasticsearch', version: '2.+'
|
latestDepTestCompile group: 'org.elasticsearch', name: 'elasticsearch', version: '2.4.6'
|
||||||
latestDepTestCompile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '2.+'
|
latestDepTestCompile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '2.1.15.RELEASE'
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,293 @@
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
import org.elasticsearch.index.IndexNotFoundException
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
|
import org.elasticsearch.node.NodeBuilder
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
|
class Elasticsearch2NodeClientTest extends AgentTestRunner {
|
||||||
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
int httpPort
|
||||||
|
@Shared
|
||||||
|
int tcpPort
|
||||||
|
@Shared
|
||||||
|
Node testNode
|
||||||
|
@Shared
|
||||||
|
File esWorkingDir
|
||||||
|
|
||||||
|
def client = testNode.client()
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.randomOpenPort()
|
||||||
|
|
||||||
|
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
|
||||||
|
esWorkingDir.deleteOnExit()
|
||||||
|
println "ES work dir: $esWorkingDir"
|
||||||
|
|
||||||
|
def settings = Settings.builder()
|
||||||
|
.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.start()
|
||||||
|
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.
|
||||||
|
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch status"() {
|
||||||
|
setup:
|
||||||
|
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
||||||
|
|
||||||
|
def status = result.get().status
|
||||||
|
|
||||||
|
expect:
|
||||||
|
status.name() == "GREEN"
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags IndexNotFoundException, "no such index"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
setup:
|
||||||
|
assert TEST_WRITER == []
|
||||||
|
def indexResult = client.admin().indices().prepareCreate(indexName).get()
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
expect:
|
||||||
|
indexResult.acknowledged
|
||||||
|
TEST_WRITER.size() == 1
|
||||||
|
|
||||||
|
when:
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
def emptyResult = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!emptyResult.isExists()
|
||||||
|
emptyResult.id == id
|
||||||
|
emptyResult.type == indexType
|
||||||
|
emptyResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def createResult = client.prepareIndex(indexName, indexType, id).setSource([:]).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
createResult.id == id
|
||||||
|
createResult.type == indexType
|
||||||
|
createResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.isExists()
|
||||||
|
result.id == id
|
||||||
|
result.type == indexType
|
||||||
|
result.index == indexName
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 6) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version"(-1)
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,322 @@
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
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.index.IndexNotFoundException
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
|
import org.elasticsearch.node.NodeBuilder
|
||||||
|
import org.elasticsearch.transport.RemoteTransportException
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
|
class Elasticsearch2TransportClientTest extends AgentTestRunner {
|
||||||
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
int httpPort
|
||||||
|
@Shared
|
||||||
|
int tcpPort
|
||||||
|
@Shared
|
||||||
|
Node testNode
|
||||||
|
@Shared
|
||||||
|
File esWorkingDir
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
TransportClient client
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.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)
|
||||||
|
.build()
|
||||||
|
testNode = NodeBuilder.newInstance().clusterName("test-cluster").settings(settings).build()
|
||||||
|
testNode.start()
|
||||||
|
|
||||||
|
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")
|
||||||
|
.build()
|
||||||
|
).build()
|
||||||
|
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
|
||||||
|
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.
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch status"() {
|
||||||
|
setup:
|
||||||
|
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
||||||
|
|
||||||
|
def status = result.get().status
|
||||||
|
|
||||||
|
expect:
|
||||||
|
status.name() == "GREEN"
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags RemoteTransportException, String
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
setup:
|
||||||
|
assert TEST_WRITER == []
|
||||||
|
def indexResult = client.admin().indices().prepareCreate(indexName).get()
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
expect:
|
||||||
|
indexResult.acknowledged
|
||||||
|
TEST_WRITER.size() == 1
|
||||||
|
|
||||||
|
when:
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
def emptyResult = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!emptyResult.isExists()
|
||||||
|
emptyResult.id == id
|
||||||
|
emptyResult.type == indexType
|
||||||
|
emptyResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def createResult = client.prepareIndex(indexName, indexType, id).setSource([:]).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
createResult.id == id
|
||||||
|
createResult.type == indexType
|
||||||
|
createResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.isExists()
|
||||||
|
result.id == id
|
||||||
|
result.type == indexType
|
||||||
|
result.index == indexName
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 6) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version"(-1)
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
import org.elasticsearch.node.NodeBuilder
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.ComponentScan
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableElasticsearchRepositories(basePackages = "springdata")
|
||||||
|
@ComponentScan(basePackages = "springdata")
|
||||||
|
class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
NodeBuilder nodeBuilder() {
|
||||||
|
return new NodeBuilder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ElasticsearchOperations elasticsearchTemplate() {
|
||||||
|
|
||||||
|
def tmpDir = File.createTempFile("test-es-working-dir-", "")
|
||||||
|
tmpDir.delete()
|
||||||
|
tmpDir.mkdir()
|
||||||
|
tmpDir.deleteOnExit()
|
||||||
|
|
||||||
|
System.addShutdownHook {
|
||||||
|
if (tmpDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(tmpDir.toPath())
|
||||||
|
tmpDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final Settings.Builder elasticsearchSettings =
|
||||||
|
Settings.settingsBuilder()
|
||||||
|
.put("http.enabled", "false")
|
||||||
|
.put("path.data", tmpDir.toString())
|
||||||
|
.put("path.home", tmpDir.toString())
|
||||||
|
|
||||||
|
println "ES work dir: $tmpDir"
|
||||||
|
|
||||||
|
return new ElasticsearchTemplate(nodeBuilder().local(true)
|
||||||
|
.settings(elasticsearchSettings.build()).node().client())
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import groovy.transform.EqualsAndHashCode
|
||||||
|
import org.springframework.data.annotation.Id
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Document
|
||||||
|
|
||||||
|
@Document(indexName = "test-index")
|
||||||
|
@EqualsAndHashCode
|
||||||
|
class Doc {
|
||||||
|
@Id
|
||||||
|
private String id = "1"
|
||||||
|
private String data = "some data"
|
||||||
|
|
||||||
|
String getId() {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
void setId(String id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
|
||||||
|
String getData() {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
void setData(String data) {
|
||||||
|
this.data = data
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||||
|
|
||||||
|
interface DocRepository extends ElasticsearchRepository<Doc, String> {}
|
|
@ -0,0 +1,293 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.springframework.context.ApplicationContext
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
class Elasticsearch2SpringRepositoryTest extends AgentTestRunner {
|
||||||
|
@Shared
|
||||||
|
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config)
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
DocRepository repo = applicationContext.getBean(DocRepository)
|
||||||
|
|
||||||
|
def setup() {
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
runUnderTrace("delete") {
|
||||||
|
repo.deleteAll()
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test empty repo"() {
|
||||||
|
when:
|
||||||
|
def result = repo.findAll()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!result.iterator().hasNext()
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored false
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test CRUD"() {
|
||||||
|
when:
|
||||||
|
def doc = new Doc()
|
||||||
|
|
||||||
|
then:
|
||||||
|
repo.index(doc) == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 3) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
and:
|
||||||
|
repo.findOne("1") == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" "doc"
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
when:
|
||||||
|
doc.data = "other data"
|
||||||
|
|
||||||
|
then:
|
||||||
|
repo.index(doc) == doc
|
||||||
|
repo.findOne("1") == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 3) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" "doc"
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 2
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
when:
|
||||||
|
repo.delete("1")
|
||||||
|
|
||||||
|
then:
|
||||||
|
!repo.findAll().iterator().hasNext()
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 3) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "DeleteAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "DeleteAction"
|
||||||
|
"elasticsearch.request" "DeleteRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,349 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.elasticsearch.action.search.SearchResponse
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
import org.elasticsearch.index.IndexNotFoundException
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
|
import org.elasticsearch.node.NodeBuilder
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.nested.InternalNested
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate
|
||||||
|
import org.springframework.data.elasticsearch.core.ResultsExtractor
|
||||||
|
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
|
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
|
||||||
|
ElasticsearchTemplate template
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.randomOpenPort()
|
||||||
|
|
||||||
|
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
|
||||||
|
esWorkingDir.deleteOnExit()
|
||||||
|
println "ES work dir: $esWorkingDir"
|
||||||
|
|
||||||
|
def settings = Settings.builder()
|
||||||
|
.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.start()
|
||||||
|
|
||||||
|
template = new ElasticsearchTemplate(testNode.client())
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
template.refresh(indexName)
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags IndexNotFoundException, "no such index"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
expect:
|
||||||
|
template.createIndex(indexName)
|
||||||
|
template.getClient().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
|
||||||
|
when:
|
||||||
|
NativeSearchQuery query = new NativeSearchQueryBuilder()
|
||||||
|
.withIndices(indexName)
|
||||||
|
.withTypes(indexType)
|
||||||
|
.withIds([id])
|
||||||
|
.build()
|
||||||
|
|
||||||
|
then:
|
||||||
|
template.queryForIds(query) == []
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc())
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withType(indexType)
|
||||||
|
.withId(id)
|
||||||
|
.build())
|
||||||
|
template.refresh(Doc)
|
||||||
|
|
||||||
|
then:
|
||||||
|
result == id
|
||||||
|
template.queryForList(query, Doc) == [new Doc()]
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 7) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(6, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test results extractor"() {
|
||||||
|
setup:
|
||||||
|
template.createIndex(indexName)
|
||||||
|
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc(id: 1, data: "doc a"))
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withId("a")
|
||||||
|
.build())
|
||||||
|
template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc(id: 2, data: "doc b"))
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withId("b")
|
||||||
|
.build())
|
||||||
|
template.refresh(indexName)
|
||||||
|
TEST_WRITER.waitForTraces(6)
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
and:
|
||||||
|
def query = new NativeSearchQueryBuilder().withIndices(indexName).build()
|
||||||
|
def hits = new AtomicLong()
|
||||||
|
List<Map<String, Object>> results = []
|
||||||
|
def bucketTags = [:]
|
||||||
|
|
||||||
|
when:
|
||||||
|
template.query(query, new ResultsExtractor<Doc>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Doc extract(SearchResponse response) {
|
||||||
|
hits.addAndGet(response.getHits().totalHits())
|
||||||
|
results.addAll(response.hits.collect { it.source })
|
||||||
|
if (response.getAggregations() != null) {
|
||||||
|
InternalNested internalNested = response.getAggregations().get("tag")
|
||||||
|
if (internalNested != null) {
|
||||||
|
Terms terms = internalNested.getAggregations().get("count_agg")
|
||||||
|
Collection<Terms.Bucket> buckets = terms.getBuckets()
|
||||||
|
for (Terms.Bucket bucket : buckets) {
|
||||||
|
bucketTags.put(Integer.valueOf(bucket.getKeyAsString()), bucket.getDocCount())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
then:
|
||||||
|
hits.get() == 2
|
||||||
|
results[0] == [id: "2", data: "doc b"]
|
||||||
|
results[1] == [id: "1", data: "doc a"]
|
||||||
|
bucketTags == [:]
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index-extract"
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import spock.lang.Shared
|
||||||
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch2NodeClientTest extends AgentTestRunner {
|
class Elasticsearch2NodeClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -63,6 +62,7 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch status"() {
|
def "test elasticsearch status"() {
|
||||||
setup:
|
setup:
|
||||||
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
||||||
|
@ -92,6 +92,7 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
|
@ -18,7 +18,6 @@ import spock.lang.Shared
|
||||||
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch2TransportClientTest extends AgentTestRunner {
|
class Elasticsearch2TransportClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -74,6 +73,7 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch status"() {
|
def "test elasticsearch status"() {
|
||||||
setup:
|
setup:
|
||||||
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
def result = client.admin().cluster().health(new ClusterHealthRequest(new String[0]))
|
||||||
|
@ -106,6 +106,7 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.springframework.context.ApplicationContext
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||||
import spock.lang.Shared
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
@RetryOnFailure
|
@RetryOnFailure
|
||||||
|
@ -20,8 +21,11 @@ class Elasticsearch2SpringRepositoryTest extends AgentTestRunner {
|
||||||
DocRepository repo = applicationContext.getBean(DocRepository)
|
DocRepository repo = applicationContext.getBean(DocRepository)
|
||||||
|
|
||||||
def setup() {
|
def setup() {
|
||||||
repo.deleteAll()
|
TEST_WRITER.clear()
|
||||||
TEST_WRITER.waitForTraces(4)
|
runUnderTrace("delete") {
|
||||||
|
repo.deleteAll()
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
TEST_WRITER.clear()
|
TEST_WRITER.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
|
class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -70,6 +69,7 @@ class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
template.refresh(indexName)
|
template.refresh(indexName)
|
||||||
|
|
|
@ -17,6 +17,14 @@ apply from: "${rootDir}/gradle/java.gradle"
|
||||||
|
|
||||||
testJava8Minimum += '**/*Test.class'
|
testJava8Minimum += '**/*Test.class'
|
||||||
|
|
||||||
|
apply plugin: 'org.unbroken-dome.test-sets'
|
||||||
|
|
||||||
|
testSets {
|
||||||
|
latestDepTest {
|
||||||
|
dirName = 'test'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0'
|
compileOnly group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0'
|
||||||
|
|
||||||
|
@ -34,4 +42,11 @@ dependencies {
|
||||||
|
|
||||||
testCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.3.0'
|
testCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.3.0'
|
||||||
testCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0'
|
testCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0'
|
||||||
|
|
||||||
|
// Unfortunately this will bump the transport version up to 5.5.0.
|
||||||
|
testCompile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.0.0.RELEASE'
|
||||||
|
|
||||||
|
latestDepTestCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.+'
|
||||||
|
latestDepTestCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.+'
|
||||||
|
latestDepTestCompile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '3.+'
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,6 @@ public class TransportActionListener<T extends ActionResponse> implements Action
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRequest(final ActionRequest request) {
|
private void onRequest(final ActionRequest request) {
|
||||||
if (request != null) {
|
|
||||||
span.setTag("elasticsearch.request.description", request.getDescription());
|
|
||||||
}
|
|
||||||
if (request instanceof IndicesRequest) {
|
if (request instanceof IndicesRequest) {
|
||||||
final IndicesRequest req = (IndicesRequest) request;
|
final IndicesRequest req = (IndicesRequest) request;
|
||||||
if (req.indices() != null) {
|
if (req.indices() != null) {
|
||||||
|
|
|
@ -9,8 +9,8 @@ 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
|
||||||
import org.elasticsearch.index.IndexNotFoundException
|
import org.elasticsearch.index.IndexNotFoundException
|
||||||
import org.elasticsearch.node.Node
|
|
||||||
import org.elasticsearch.node.InternalSettingsPreparer
|
import org.elasticsearch.node.InternalSettingsPreparer
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
import org.elasticsearch.transport.Netty3Plugin
|
import org.elasticsearch.transport.Netty3Plugin
|
||||||
import spock.lang.Shared
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch53NodeClientTest extends AgentTestRunner {
|
class Elasticsearch53NodeClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -69,6 +68,7 @@ class Elasticsearch53NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch status"() {
|
def "test elasticsearch status"() {
|
||||||
setup:
|
setup:
|
||||||
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
||||||
|
@ -98,6 +98,7 @@ class Elasticsearch53NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
@ -133,4 +134,171 @@ class Elasticsearch53NodeClientTest extends AgentTestRunner {
|
||||||
indexType = "test-type"
|
indexType = "test-type"
|
||||||
id = "1"
|
id = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
setup:
|
||||||
|
assert TEST_WRITER == []
|
||||||
|
def indexResult = client.admin().indices().prepareCreate(indexName).get()
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
expect:
|
||||||
|
indexResult.acknowledged
|
||||||
|
TEST_WRITER.size() == 1
|
||||||
|
|
||||||
|
when:
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
def emptyResult = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!emptyResult.isExists()
|
||||||
|
emptyResult.id == id
|
||||||
|
emptyResult.type == indexType
|
||||||
|
emptyResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def createResult = client.prepareIndex(indexName, indexType, id).setSource([:]).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
createResult.id == id
|
||||||
|
createResult.type == indexType
|
||||||
|
createResult.index == indexName
|
||||||
|
createResult.status().status == 201
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.isExists()
|
||||||
|
result.id == id
|
||||||
|
result.type == indexType
|
||||||
|
result.index == indexName
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 6) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version"(-1)
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
"elasticsearch.request.write.version"(-3)
|
||||||
|
"elasticsearch.response.status" 201
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ import org.elasticsearch.common.settings.Settings
|
||||||
import org.elasticsearch.common.transport.InetSocketTransportAddress
|
import org.elasticsearch.common.transport.InetSocketTransportAddress
|
||||||
import org.elasticsearch.env.Environment
|
import org.elasticsearch.env.Environment
|
||||||
import org.elasticsearch.index.IndexNotFoundException
|
import org.elasticsearch.index.IndexNotFoundException
|
||||||
import org.elasticsearch.node.Node
|
|
||||||
import org.elasticsearch.node.InternalSettingsPreparer
|
import org.elasticsearch.node.InternalSettingsPreparer
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
import org.elasticsearch.transport.Netty3Plugin
|
import org.elasticsearch.transport.Netty3Plugin
|
||||||
import org.elasticsearch.transport.RemoteTransportException
|
import org.elasticsearch.transport.RemoteTransportException
|
||||||
import org.elasticsearch.transport.client.PreBuiltTransportClient
|
import org.elasticsearch.transport.client.PreBuiltTransportClient
|
||||||
|
@ -22,7 +22,6 @@ import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch53TransportClientTest extends AgentTestRunner {
|
class Elasticsearch53TransportClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -113,6 +112,7 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
@ -276,7 +276,6 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.shard.replication.total" 2
|
"elasticsearch.shard.replication.total" 2
|
||||||
"elasticsearch.shard.replication.successful" 1
|
"elasticsearch.shard.replication.successful" 1
|
||||||
"elasticsearch.shard.replication.failed" 0
|
"elasticsearch.shard.replication.failed" 0
|
||||||
"elasticsearch.request.description" "index {[$indexName][$indexType][1], source[{}]}"
|
|
||||||
defaultTags()
|
defaultTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
import org.elasticsearch.env.Environment
|
||||||
|
import org.elasticsearch.node.InternalSettingsPreparer
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
|
import org.elasticsearch.transport.Netty3Plugin
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.ComponentScan
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableElasticsearchRepositories(basePackages = "springdata")
|
||||||
|
@ComponentScan(basePackages = "springdata")
|
||||||
|
class Config {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
NodeBuilder nodeBuilder() {
|
||||||
|
return new NodeBuilder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ElasticsearchOperations elasticsearchTemplate() {
|
||||||
|
def tmpDir = File.createTempFile("test-es-working-dir-", "")
|
||||||
|
tmpDir.delete()
|
||||||
|
tmpDir.mkdir()
|
||||||
|
tmpDir.deleteOnExit()
|
||||||
|
|
||||||
|
System.addShutdownHook {
|
||||||
|
if (tmpDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(tmpDir.toPath())
|
||||||
|
tmpDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def settings = Settings.builder()
|
||||||
|
.put("http.enabled", "false")
|
||||||
|
.put("path.data", tmpDir.toString())
|
||||||
|
.put("path.home", tmpDir.toString())
|
||||||
|
.put("thread_pool.listener.size", 1)
|
||||||
|
.put("transport.type", "netty3")
|
||||||
|
.put("http.type", "netty3")
|
||||||
|
.build()
|
||||||
|
|
||||||
|
println "ES work dir: $tmpDir"
|
||||||
|
|
||||||
|
return new ElasticsearchTemplate(new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin]).start().client())
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import groovy.transform.EqualsAndHashCode
|
||||||
|
import org.springframework.data.annotation.Id
|
||||||
|
import org.springframework.data.elasticsearch.annotations.Document
|
||||||
|
|
||||||
|
@Document(indexName = "test-index")
|
||||||
|
@EqualsAndHashCode
|
||||||
|
class Doc {
|
||||||
|
@Id
|
||||||
|
private String id = "1"
|
||||||
|
private String data = "some data"
|
||||||
|
|
||||||
|
String getId() {
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
void setId(String id) {
|
||||||
|
this.id = id
|
||||||
|
}
|
||||||
|
|
||||||
|
String getData() {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
void setData(String data) {
|
||||||
|
this.data = data
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||||
|
|
||||||
|
interface DocRepository extends ElasticsearchRepository<Doc, String> {}
|
|
@ -0,0 +1,291 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.springframework.context.ApplicationContext
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
class Elasticsearch53SpringRepositoryTest extends AgentTestRunner {
|
||||||
|
@Shared
|
||||||
|
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config)
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
DocRepository repo = applicationContext.getBean(DocRepository)
|
||||||
|
|
||||||
|
def setup() {
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
runUnderTrace("delete") {
|
||||||
|
repo.deleteAll()
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test empty repo"() {
|
||||||
|
when:
|
||||||
|
def result = repo.findAll()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!result.iterator().hasNext()
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored false
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test CRUD"() {
|
||||||
|
when:
|
||||||
|
def doc = new Doc()
|
||||||
|
|
||||||
|
then:
|
||||||
|
repo.index(doc) == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 2) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
"elasticsearch.request.write.version"(-3)
|
||||||
|
"elasticsearch.response.status" 201
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
and:
|
||||||
|
repo.findById("1").get() == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" "doc"
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 3
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
when:
|
||||||
|
doc.data = "other data"
|
||||||
|
|
||||||
|
then:
|
||||||
|
repo.index(doc) == doc
|
||||||
|
repo.findById("1").get() == doc
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 3) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
"elasticsearch.request.write.version"(-3)
|
||||||
|
"elasticsearch.response.status" 200
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" "doc"
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 4
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
when:
|
||||||
|
repo.deleteById("1")
|
||||||
|
|
||||||
|
then:
|
||||||
|
!repo.findAll().iterator().hasNext()
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 3) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "DeleteAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "DeleteAction"
|
||||||
|
"elasticsearch.request" "DeleteRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" "doc"
|
||||||
|
"elasticsearch.request.write.version"(-3)
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" "doc"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,366 @@
|
||||||
|
package springdata
|
||||||
|
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.elasticsearch.action.search.SearchResponse
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
import org.elasticsearch.env.Environment
|
||||||
|
import org.elasticsearch.index.IndexNotFoundException
|
||||||
|
import org.elasticsearch.node.InternalSettingsPreparer
|
||||||
|
import org.elasticsearch.node.Node
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.nested.InternalNested
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms
|
||||||
|
import org.elasticsearch.transport.Netty3Plugin
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate
|
||||||
|
import org.springframework.data.elasticsearch.core.ResultsExtractor
|
||||||
|
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery
|
||||||
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
|
class Elasticsearch53SpringTemplateTest extends AgentTestRunner {
|
||||||
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
int httpPort
|
||||||
|
@Shared
|
||||||
|
int tcpPort
|
||||||
|
@Shared
|
||||||
|
Node testNode
|
||||||
|
@Shared
|
||||||
|
File esWorkingDir
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
ElasticsearchTemplate template
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.randomOpenPort()
|
||||||
|
|
||||||
|
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
|
||||||
|
esWorkingDir.deleteOnExit()
|
||||||
|
println "ES work dir: $esWorkingDir"
|
||||||
|
|
||||||
|
def settings = Settings.builder()
|
||||||
|
.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")
|
||||||
|
.build()
|
||||||
|
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
|
||||||
|
testNode.start()
|
||||||
|
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.
|
||||||
|
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
template = new ElasticsearchTemplate(testNode.client())
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
template.refresh(indexName)
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags IndexNotFoundException, "no such index"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
expect:
|
||||||
|
template.createIndex(indexName)
|
||||||
|
template.getClient().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
|
||||||
|
when:
|
||||||
|
NativeSearchQuery query = new NativeSearchQueryBuilder()
|
||||||
|
.withIndices(indexName)
|
||||||
|
.withTypes(indexType)
|
||||||
|
.withIds([id])
|
||||||
|
.build()
|
||||||
|
|
||||||
|
then:
|
||||||
|
template.queryForIds(query) == []
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc())
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withType(indexType)
|
||||||
|
.withId(id)
|
||||||
|
.build())
|
||||||
|
template.refresh(Doc)
|
||||||
|
|
||||||
|
then:
|
||||||
|
result == id
|
||||||
|
template.queryForList(query, Doc) == [new Doc()]
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 7) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
"elasticsearch.request.write.version"(-3)
|
||||||
|
"elasticsearch.response.status" 201
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "RefreshAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "RefreshAction"
|
||||||
|
"elasticsearch.request" "RefreshRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.shard.broadcast.failed" 0
|
||||||
|
"elasticsearch.shard.broadcast.successful" 5
|
||||||
|
"elasticsearch.shard.broadcast.total" 10
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(6, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.search.types" indexType
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test results extractor"() {
|
||||||
|
setup:
|
||||||
|
template.createIndex(indexName)
|
||||||
|
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc(id: 1, data: "doc a"))
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withId("a")
|
||||||
|
.build())
|
||||||
|
template.index(IndexQueryBuilder.newInstance()
|
||||||
|
.withObject(new Doc(id: 2, data: "doc b"))
|
||||||
|
.withIndexName(indexName)
|
||||||
|
.withId("b")
|
||||||
|
.build())
|
||||||
|
template.refresh(indexName)
|
||||||
|
TEST_WRITER.waitForTraces(6)
|
||||||
|
TEST_WRITER.clear()
|
||||||
|
|
||||||
|
and:
|
||||||
|
def query = new NativeSearchQueryBuilder().withIndices(indexName).build()
|
||||||
|
def hits = new AtomicLong()
|
||||||
|
List<Map<String, Object>> results = []
|
||||||
|
def bucketTags = [:]
|
||||||
|
|
||||||
|
when:
|
||||||
|
template.query(query, new ResultsExtractor<Doc>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Doc extract(SearchResponse response) {
|
||||||
|
hits.addAndGet(response.getHits().totalHits())
|
||||||
|
results.addAll(response.hits.collect { it.source })
|
||||||
|
if (response.getAggregations() != null) {
|
||||||
|
InternalNested internalNested = response.getAggregations().get("tag")
|
||||||
|
if (internalNested != null) {
|
||||||
|
Terms terms = internalNested.getAggregations().get("count_agg")
|
||||||
|
Collection<Terms.Bucket> buckets = terms.getBuckets()
|
||||||
|
for (Terms.Bucket bucket : buckets) {
|
||||||
|
bucketTags.put(Integer.valueOf(bucket.getKeyAsString()), bucket.getDocCount())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
then:
|
||||||
|
hits.get() == 2
|
||||||
|
results[0] == [id: "2", data: "doc b"]
|
||||||
|
results[1] == [id: "1", data: "doc a"]
|
||||||
|
bucketTags == [:]
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "SearchAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "SearchAction"
|
||||||
|
"elasticsearch.request" "SearchRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index-extract"
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,6 @@ dependencies {
|
||||||
testCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.0.0'
|
testCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.0.0'
|
||||||
testCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.0.0'
|
testCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.0.0'
|
||||||
|
|
||||||
latestDepTestCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '+'
|
latestDepTestCompile group: 'org.elasticsearch.plugin', name: 'transport-netty3-client', version: '5.2.+'
|
||||||
latestDepTestCompile group: 'org.elasticsearch.client', name: 'transport', version: '+'
|
latestDepTestCompile group: 'org.elasticsearch.client', name: 'transport', version: '5.2.+'
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,303 @@
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest
|
||||||
|
import org.elasticsearch.common.io.FileSystemUtils
|
||||||
|
import org.elasticsearch.common.settings.Settings
|
||||||
|
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 spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
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
|
||||||
|
|
||||||
|
def client = testNode.client()
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.randomOpenPort()
|
||||||
|
|
||||||
|
esWorkingDir = File.createTempDir("test-es-working-dir-", "")
|
||||||
|
esWorkingDir.deleteOnExit()
|
||||||
|
println "ES work dir: $esWorkingDir"
|
||||||
|
|
||||||
|
def settings = Settings.builder()
|
||||||
|
.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")
|
||||||
|
.build()
|
||||||
|
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
|
||||||
|
testNode.start()
|
||||||
|
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.
|
||||||
|
testNode.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch status"() {
|
||||||
|
setup:
|
||||||
|
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
||||||
|
|
||||||
|
def status = result.get().status
|
||||||
|
|
||||||
|
expect:
|
||||||
|
status.name() == "GREEN"
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags IndexNotFoundException, "no such index"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
setup:
|
||||||
|
assert TEST_WRITER == []
|
||||||
|
def indexResult = client.admin().indices().prepareCreate(indexName).get()
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
expect:
|
||||||
|
indexResult.acknowledged
|
||||||
|
TEST_WRITER.size() == 1
|
||||||
|
|
||||||
|
when:
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
def emptyResult = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!emptyResult.isExists()
|
||||||
|
emptyResult.id == id
|
||||||
|
emptyResult.type == indexType
|
||||||
|
emptyResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def createResult = client.prepareIndex(indexName, indexType, id).setSource([:]).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
createResult.id == id
|
||||||
|
createResult.type == indexType
|
||||||
|
createResult.index == indexName
|
||||||
|
createResult.status().status == 201
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.isExists()
|
||||||
|
result.id == id
|
||||||
|
result.type == indexType
|
||||||
|
result.index == indexName
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[3][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = TEST_WRITER[4]
|
||||||
|
TEST_WRITER[4] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 6) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version"(-1)
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
"elasticsearch.response.status" 201
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(5, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,313 @@
|
||||||
|
import com.anotherchrisberry.spock.extensions.retry.RetryOnFailure
|
||||||
|
import datadog.trace.agent.test.AgentTestRunner
|
||||||
|
import datadog.trace.agent.test.TestUtils
|
||||||
|
import datadog.trace.api.DDSpanTypes
|
||||||
|
import datadog.trace.api.DDTags
|
||||||
|
import io.opentracing.tag.Tags
|
||||||
|
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.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.client.PreBuiltTransportClient
|
||||||
|
import spock.lang.Shared
|
||||||
|
|
||||||
|
import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
|
class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
int httpPort
|
||||||
|
@Shared
|
||||||
|
int tcpPort
|
||||||
|
@Shared
|
||||||
|
Node testNode
|
||||||
|
@Shared
|
||||||
|
File esWorkingDir
|
||||||
|
|
||||||
|
@Shared
|
||||||
|
TransportClient client
|
||||||
|
|
||||||
|
def setupSpec() {
|
||||||
|
httpPort = TestUtils.randomOpenPort()
|
||||||
|
tcpPort = TestUtils.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("transport.type", "netty3")
|
||||||
|
.put("http.type", "netty3")
|
||||||
|
.put(CLUSTER_NAME_SETTING.getKey(), "test-cluster")
|
||||||
|
.build()
|
||||||
|
testNode = new Node(new Environment(InternalSettingsPreparer.prepareSettings(settings)), [Netty3Plugin])
|
||||||
|
testNode.start()
|
||||||
|
|
||||||
|
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")
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), tcpPort))
|
||||||
|
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.
|
||||||
|
client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(TIMEOUT)
|
||||||
|
}
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
def cleanupSpec() {
|
||||||
|
testNode?.close()
|
||||||
|
if (esWorkingDir != null) {
|
||||||
|
FileSystemUtils.deleteSubDirectories(esWorkingDir.toPath())
|
||||||
|
esWorkingDir.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch status"() {
|
||||||
|
setup:
|
||||||
|
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
||||||
|
|
||||||
|
def status = result.get().status
|
||||||
|
|
||||||
|
expect:
|
||||||
|
status.name() == "GREEN"
|
||||||
|
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "ClusterHealthAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
"elasticsearch.request" "ClusterHealthRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
|
def "test elasticsearch error"() {
|
||||||
|
when:
|
||||||
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
thrown IndexNotFoundException
|
||||||
|
|
||||||
|
and:
|
||||||
|
assertTraces(TEST_WRITER, 1) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
errored true
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
errorTags RemoteTransportException, String
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "invalid-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
def "test elasticsearch get"() {
|
||||||
|
setup:
|
||||||
|
assert TEST_WRITER == []
|
||||||
|
def indexResult = client.admin().indices().prepareCreate(indexName).get()
|
||||||
|
TEST_WRITER.waitForTraces(1)
|
||||||
|
|
||||||
|
expect:
|
||||||
|
indexResult.acknowledged
|
||||||
|
TEST_WRITER.size() == 1
|
||||||
|
|
||||||
|
when:
|
||||||
|
def emptyResult = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
!emptyResult.isExists()
|
||||||
|
emptyResult.id == id
|
||||||
|
emptyResult.type == indexType
|
||||||
|
emptyResult.index == indexName
|
||||||
|
|
||||||
|
when:
|
||||||
|
def createResult = client.prepareIndex(indexName, indexType, id).setSource([:]).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
createResult.id == id
|
||||||
|
createResult.type == indexType
|
||||||
|
createResult.index == indexName
|
||||||
|
createResult.status().status == 201
|
||||||
|
|
||||||
|
when:
|
||||||
|
def result = client.prepareGet(indexName, indexType, id).get()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.isExists()
|
||||||
|
result.id == id
|
||||||
|
result.type == indexType
|
||||||
|
result.index == indexName
|
||||||
|
|
||||||
|
and:
|
||||||
|
// IndexAction and PutMappingAction run in separate threads and order in which
|
||||||
|
// these spans are closed is not defined. So we force the order if it is wrong.
|
||||||
|
if (TEST_WRITER[2][0].resourceName == "IndexAction") {
|
||||||
|
def tmp = TEST_WRITER[2]
|
||||||
|
TEST_WRITER[2] = TEST_WRITER[3]
|
||||||
|
TEST_WRITER[3] = tmp
|
||||||
|
}
|
||||||
|
assertTraces(TEST_WRITER, 5) {
|
||||||
|
trace(0, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "CreateIndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(1, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version"(-1)
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(2, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "PutMappingAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"elasticsearch.action" "PutMappingAction"
|
||||||
|
"elasticsearch.request" "PutMappingRequest"
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(3, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "IndexAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "IndexAction"
|
||||||
|
"elasticsearch.request" "IndexRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.request.write.type" indexType
|
||||||
|
"elasticsearch.response.status" 201
|
||||||
|
"elasticsearch.shard.replication.total" 2
|
||||||
|
"elasticsearch.shard.replication.successful" 1
|
||||||
|
"elasticsearch.shard.replication.failed" 0
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trace(4, 1) {
|
||||||
|
span(0) {
|
||||||
|
serviceName "elasticsearch"
|
||||||
|
resourceName "GetAction"
|
||||||
|
operationName "elasticsearch.query"
|
||||||
|
spanType DDSpanTypes.ELASTICSEARCH
|
||||||
|
tags {
|
||||||
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
|
"$Tags.PEER_HOSTNAME.key" "localhost"
|
||||||
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
|
"elasticsearch.action" "GetAction"
|
||||||
|
"elasticsearch.request" "GetRequest"
|
||||||
|
"elasticsearch.request.indices" indexName
|
||||||
|
"elasticsearch.type" indexType
|
||||||
|
"elasticsearch.id" "1"
|
||||||
|
"elasticsearch.version" 1
|
||||||
|
defaultTags()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
where:
|
||||||
|
indexName = "test-index"
|
||||||
|
indexType = "test-type"
|
||||||
|
id = "1"
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,9 +32,6 @@ public class TransportActionListener<T extends ActionResponse> implements Action
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRequest(final ActionRequest request) {
|
private void onRequest(final ActionRequest request) {
|
||||||
if (request != null) {
|
|
||||||
span.setTag("elasticsearch.request.description", request.getDescription());
|
|
||||||
}
|
|
||||||
if (request instanceof IndicesRequest) {
|
if (request instanceof IndicesRequest) {
|
||||||
final IndicesRequest req = (IndicesRequest) request;
|
final IndicesRequest req = (IndicesRequest) request;
|
||||||
if (req.indices() != null) {
|
if (req.indices() != null) {
|
||||||
|
|
|
@ -18,7 +18,6 @@ import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch5NodeClientTest extends AgentTestRunner {
|
class Elasticsearch5NodeClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -69,6 +68,7 @@ class Elasticsearch5NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch status"() {
|
def "test elasticsearch status"() {
|
||||||
setup:
|
setup:
|
||||||
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
||||||
|
@ -98,6 +98,7 @@ class Elasticsearch5NodeClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
@ -268,7 +269,6 @@ class Elasticsearch5NodeClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.shard.replication.total" 2
|
"elasticsearch.shard.replication.total" 2
|
||||||
"elasticsearch.shard.replication.successful" 1
|
"elasticsearch.shard.replication.successful" 1
|
||||||
"elasticsearch.shard.replication.failed" 0
|
"elasticsearch.shard.replication.failed" 0
|
||||||
"elasticsearch.request.description" "index {[test-index][test-type][1], source[{}]}"
|
|
||||||
defaultTags()
|
defaultTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import static datadog.trace.agent.test.TestUtils.runUnderTrace
|
||||||
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
import static datadog.trace.agent.test.asserts.ListWriterAssert.assertTraces
|
||||||
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
import static org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING
|
||||||
|
|
||||||
@RetryOnFailure
|
|
||||||
class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
public static final long TIMEOUT = 10000; // 10 seconds
|
public static final long TIMEOUT = 10000; // 10 seconds
|
||||||
|
|
||||||
|
@ -81,6 +80,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch status"() {
|
def "test elasticsearch status"() {
|
||||||
setup:
|
setup:
|
||||||
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
def result = client.admin().cluster().health(new ClusterHealthRequest())
|
||||||
|
@ -101,7 +101,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"$Tags.COMPONENT.key" "elasticsearch-java"
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
"$Tags.PEER_HOSTNAME.key" "127.0.0.1"
|
"$Tags.PEER_HOSTNAME.key" String
|
||||||
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
"$Tags.PEER_PORT.key" tcpPort
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
"elasticsearch.action" "ClusterHealthAction"
|
"elasticsearch.action" "ClusterHealthAction"
|
||||||
|
@ -113,6 +113,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RetryOnFailure
|
||||||
def "test elasticsearch error"() {
|
def "test elasticsearch error"() {
|
||||||
when:
|
when:
|
||||||
client.prepareGet(indexName, indexType, id).get()
|
client.prepareGet(indexName, indexType, id).get()
|
||||||
|
@ -208,7 +209,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.action" "CreateIndexAction"
|
"elasticsearch.action" "CreateIndexAction"
|
||||||
"elasticsearch.request" "CreateIndexRequest"
|
"elasticsearch.request" "CreateIndexRequest"
|
||||||
"elasticsearch.request.indices" indexName
|
"elasticsearch.request.indices" indexName
|
||||||
"$Tags.PEER_HOSTNAME.key" "127.0.0.1"
|
"$Tags.PEER_HOSTNAME.key" String
|
||||||
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
"$Tags.PEER_PORT.key" tcpPort
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
defaultTags()
|
defaultTags()
|
||||||
|
@ -225,7 +226,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"$Tags.COMPONENT.key" "elasticsearch-java"
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
"$Tags.PEER_HOSTNAME.key" "127.0.0.1"
|
"$Tags.PEER_HOSTNAME.key" String
|
||||||
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
"$Tags.PEER_PORT.key" tcpPort
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
"elasticsearch.action" "GetAction"
|
"elasticsearch.action" "GetAction"
|
||||||
|
@ -264,7 +265,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"$Tags.COMPONENT.key" "elasticsearch-java"
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
"$Tags.PEER_HOSTNAME.key" "127.0.0.1"
|
"$Tags.PEER_HOSTNAME.key" String
|
||||||
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
"$Tags.PEER_PORT.key" tcpPort
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
"elasticsearch.action" "IndexAction"
|
"elasticsearch.action" "IndexAction"
|
||||||
|
@ -275,7 +276,6 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.shard.replication.total" 2
|
"elasticsearch.shard.replication.total" 2
|
||||||
"elasticsearch.shard.replication.successful" 1
|
"elasticsearch.shard.replication.successful" 1
|
||||||
"elasticsearch.shard.replication.failed" 0
|
"elasticsearch.shard.replication.failed" 0
|
||||||
"elasticsearch.request.description" "index {[test-index][test-type][1], source[{}]}"
|
|
||||||
defaultTags()
|
defaultTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
|
||||||
"$Tags.COMPONENT.key" "elasticsearch-java"
|
"$Tags.COMPONENT.key" "elasticsearch-java"
|
||||||
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
"$Tags.SPAN_KIND.key" Tags.SPAN_KIND_CLIENT
|
||||||
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
"$DDTags.SPAN_TYPE" DDSpanTypes.ELASTICSEARCH
|
||||||
"$Tags.PEER_HOSTNAME.key" "127.0.0.1"
|
"$Tags.PEER_HOSTNAME.key" String
|
||||||
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
"$Tags.PEER_HOST_IPV4.key" "127.0.0.1"
|
||||||
"$Tags.PEER_PORT.key" tcpPort
|
"$Tags.PEER_PORT.key" tcpPort
|
||||||
"elasticsearch.action" "GetAction"
|
"elasticsearch.action" "GetAction"
|
||||||
|
|
|
@ -36,9 +36,6 @@ public class TransportActionListener<T extends ActionResponse> implements Action
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onRequest(final ActionRequest request) {
|
private void onRequest(final ActionRequest request) {
|
||||||
if (request != null) {
|
|
||||||
span.setTag("elasticsearch.request.description", request.getDescription());
|
|
||||||
}
|
|
||||||
if (request instanceof IndicesRequest) {
|
if (request instanceof IndicesRequest) {
|
||||||
final IndicesRequest req = (IndicesRequest) request;
|
final IndicesRequest req = (IndicesRequest) request;
|
||||||
if (req.indices() != null) {
|
if (req.indices() != null) {
|
||||||
|
|
|
@ -249,7 +249,6 @@ class Elasticsearch6NodeClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.shard.replication.total" 2
|
"elasticsearch.shard.replication.total" 2
|
||||||
"elasticsearch.shard.replication.successful" 1
|
"elasticsearch.shard.replication.successful" 1
|
||||||
"elasticsearch.shard.replication.failed" 0
|
"elasticsearch.shard.replication.failed" 0
|
||||||
"elasticsearch.request.description" "index {[test-index][test-type][1], source[{}]}"
|
|
||||||
defaultTags()
|
defaultTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,7 +273,6 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
|
||||||
"elasticsearch.shard.replication.total" 2
|
"elasticsearch.shard.replication.total" 2
|
||||||
"elasticsearch.shard.replication.successful" 1
|
"elasticsearch.shard.replication.successful" 1
|
||||||
"elasticsearch.shard.replication.failed" 0
|
"elasticsearch.shard.replication.failed" 0
|
||||||
"elasticsearch.request.description" "index {[test-index][test-type][1], source[{}]}"
|
|
||||||
defaultTags()
|
defaultTags()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue