Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for elasticsearch7 #2514

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ These are the supported libraries and frameworks:
| [Cassandra Driver](https://github.com/datastax/java-driver) | 3.0+ |
| [Couchbase Client](https://github.com/couchbase/couchbase-java-client) | 2.0+ (not including 3.x yet) |
| [Dropwizard Views](https://www.dropwizard.io/en/latest/manual/views.html) | 0.7+ |
| [Elasticsearch API](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html) | 5.0+ (not including 7.x yet) |
| [Elasticsearch API](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html) | 5.0+ |
| [Elasticsearch REST Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html) | 5.0+ |
| [Finatra](https://github.com/twitter/finatra) | 2.9+ |
| [Geode Client](https://geode.apache.org/) | 1.4+ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ muzzle {
pass {
group = "org.elasticsearch.client"
module = "transport"
versions = "[6.0.0,7.0.0)"
versions = "[6.0.0,)"
}
pass {
group = "org.elasticsearch"
module = "elasticsearch"
versions = "[6.0.0,7.0.0)"
versions = "[6.0.0,)"
}
fail {
group = "org.elasticsearch.client"
Expand Down Expand Up @@ -37,10 +37,6 @@ dependencies {

testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'

// Limit tests to <6.5 as the latest versions have a breaking change for the tests.
latestDepTestLibrary group: 'org.elasticsearch.plugin', name: 'transport-netty4-client', version: '(6.1,6.5)'
latestDepTestLibrary group: 'org.elasticsearch.client', name: 'transport', version: '(6.1,6.5)'
}

tasks.withType(Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.google.auto.service.AutoService;
Expand All @@ -24,7 +25,6 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionResponse;
Expand Down Expand Up @@ -57,7 +57,12 @@ public Map<? extends ElementMatcher<? super MethodDescription>, String> transfor
return singletonMap(
isMethod()
.and(named("execute"))
.and(takesArgument(0, named("org.elasticsearch.action.Action")))
.and(
takesArgument(
0,
namedOneOf(
"org.elasticsearch.action.Action",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of change happened on minor version 6.5? Geez

"org.elasticsearch.action.ActionType")))
.and(takesArgument(1, named("org.elasticsearch.action.ActionRequest")))
.and(takesArgument(2, named("org.elasticsearch.action.ActionListener"))),
Elasticsearch6TransportClientInstrumentationModule.class.getName()
Expand All @@ -69,7 +74,7 @@ public static class Elasticsearch6TransportClientAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.Argument(0) Action action,
@Advice.Argument(0) Object action,
@Advice.Argument(1) ActionRequest actionRequest,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequ
import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin
import spock.lang.Shared

class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
Expand Down Expand Up @@ -44,7 +42,7 @@ class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.put("discovery.type", "single-node")
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode = NodeFactory.newNode(settings)
testNode.start()
runUnderTrace("setup") {
// this may potentially create multiple requests and therefore multiple spans, so we wrap this call
Expand Down Expand Up @@ -103,7 +101,7 @@ class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
name "GetAction"
kind CLIENT
errored true
errorEvent IndexNotFoundException, "no such index"
errorEvent IndexNotFoundException, ~/no such index( \[invalid-index\])?/
attributes {
"${SemanticAttributes.DB_SYSTEM.key}" "elasticsearch"
"${SemanticAttributes.DB_OPERATION.key}" "GetAction"
Expand Down Expand Up @@ -205,13 +203,13 @@ class Elasticsearch6NodeClientTest extends AgentInstrumentationSpecification {
}
}
span(1) {
name "PutMappingAction"
name ~/(Auto)?PutMappingAction/
kind CLIENT
childOf span(0)
attributes {
"${SemanticAttributes.DB_SYSTEM.key}" "elasticsearch"
"${SemanticAttributes.DB_OPERATION.key}" "PutMappingAction"
"elasticsearch.action" "PutMappingAction"
"${SemanticAttributes.DB_OPERATION.key}" ~/(Auto)?PutMappingAction/
"elasticsearch.action" ~/(Auto)?PutMappingAction/
"elasticsearch.request" "PutMappingRequest"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import org.elasticsearch.common.io.FileSystemUtils
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.TransportAddress
import org.elasticsearch.index.IndexNotFoundException
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin
import org.elasticsearch.transport.RemoteTransportException
import org.elasticsearch.transport.TransportService
import org.elasticsearch.transport.client.PreBuiltTransportClient
Expand Down Expand Up @@ -49,7 +47,7 @@ class Elasticsearch6TransportClientTest extends AgentInstrumentationSpecificatio
.put(CLUSTER_NAME_SETTING.getKey(), clusterName)
.put("discovery.type", "single-node")
.build()
testNode = new Node(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
testNode = NodeFactory.newNode(settings)
testNode.start()
tcpPublishAddress = testNode.injector().getInstance(TransportService).boundAddress().publishAddress()

Expand Down Expand Up @@ -221,12 +219,12 @@ class Elasticsearch6TransportClientTest extends AgentInstrumentationSpecificatio
}
trace(2, 1) {
span(0) {
name "PutMappingAction"
name ~/(Auto)?PutMappingAction/
kind CLIENT
attributes {
"${SemanticAttributes.DB_SYSTEM.key}" "elasticsearch"
"${SemanticAttributes.DB_OPERATION.key}" "PutMappingAction"
"elasticsearch.action" "PutMappingAction"
"${SemanticAttributes.DB_OPERATION.key}" ~/(Auto)?PutMappingAction/
"elasticsearch.action" ~/(Auto)?PutMappingAction/
"elasticsearch.request" "PutMappingRequest"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import org.elasticsearch.common.settings.Settings
import org.elasticsearch.node.InternalSettingsPreparer
import org.elasticsearch.node.Node
import org.elasticsearch.transport.Netty4Plugin

class NodeFactory {
static Node newNode(Settings settings) {
def version = org.elasticsearch.Version.CURRENT
if (version.major >= 7) {
return new NodeV7(settings)
} else if (version.major == 6 && version.minor >= 5) {
return new NodeV65(settings)
}
return new NodeV6(settings)
}

static class NodeV6 extends Node {
NodeV6(Settings settings) {
super(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin])
}

protected void registerDerivedNodeNameWithLogger(String s) {
}
}

static class NodeV65 extends Node {
NodeV65(Settings settings) {
super(InternalSettingsPreparer.prepareEnvironment(settings, null), [Netty4Plugin], true)
}

protected void registerDerivedNodeNameWithLogger(String s) {
}
}

static class NodeV7 extends Node {
NodeV7(Settings settings) {
super(InternalSettingsPreparer.prepareEnvironment(settings, Collections.emptyMap(), null, { "default node name" }), [Netty4Plugin], true)
}

protected void registerDerivedNodeNameWithLogger(String s) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import java.net.InetSocketAddress;
import org.elasticsearch.action.Action;

public class ElasticsearchTransportClientTracer
extends DatabaseClientTracer<Void, Action<?, ?, ?>, String> {
public class ElasticsearchTransportClientTracer extends DatabaseClientTracer<Void, Object, String> {

private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES =
Config.get()
Expand All @@ -36,7 +34,7 @@ public void onRequest(Context context, Class<?> action, Class<?> request) {
}

@Override
protected String sanitizeStatement(Action<?, ?, ?> action) {
protected String sanitizeStatement(Object action) {
return action.getClass().getSimpleName();
}

Expand All @@ -51,7 +49,7 @@ protected InetSocketAddress peerAddress(Void connection) {
}

@Override
protected String dbOperation(Void connection, Action<?, ?, ?> action, String operation) {
protected String dbOperation(Void connection, Object action, String operation) {
return operation;
}

Expand Down