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

[8.10] Add instrumentation API and native OpenTelemetry implementation (#588) #652

Merged
merged 1 commit into from
Aug 21, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
import javax.annotation.Nullable;
import javax.net.ssl.SSLException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -231,12 +231,8 @@ private String queryString(Request request, TransportOptions options) {
.entrySet()
.stream()
.map(e -> {
try {
return URLEncoder.encode(e.getKey(), "UTF-8") + "=" +
URLEncoder.encode(e.getValue(), "UTF-8");
} catch(UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
}
return URLEncoder.encode(e.getKey(), StandardCharsets.UTF_8) + "=" +
URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8);
})
.collect(Collectors.joining("&"));
}
Expand Down
40 changes: 26 additions & 14 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

import com.github.jk1.license.ProjectData
import com.github.jk1.license.render.ReportRenderer
import com.github.jk1.license.render.LicenseDataCollector
import com.github.jk1.license.render.ReportRenderer
import java.io.FileWriter

plugins {
Expand Down Expand Up @@ -53,8 +53,8 @@ tasks.getByName<ProcessResources>("processResources") {
if (name != "apis.json") {
// Only process main source-set resources (test files are large)
expand(
"version" to version,
"git_revision" to (if (rootProject.extra.has("gitHashFull")) rootProject.extra["gitHashFull"] else "unknown")
"version" to version,
"git_revision" to (if (rootProject.extra.has("gitHashFull")) rootProject.extra["gitHashFull"] else "unknown")
)
}
}
Expand All @@ -69,7 +69,7 @@ tasks.withType<Jar> {
if (rootProject.extra.has("gitHashFull")) {
val jar = this as Jar
jar.manifest.attributes["X-Git-Revision"] = rootProject.extra["gitHashFull"]
jar.manifest.attributes["X-Git-Commit-Time"] = rootProject .extra["gitCommitTime"]
jar.manifest.attributes["X-Git-Commit-Time"] = rootProject.extra["gitCommitTime"]
} else {
throw GradleException("No git information available")
}
Expand Down Expand Up @@ -154,7 +154,7 @@ publishing {
// are the same as the one used in the dependency section below.
val xPathFactory = javax.xml.xpath.XPathFactory.newInstance()
val depSelector = xPathFactory.newXPath()
.compile("/project/dependencies/dependency[groupId/text() = 'org.elasticsearch.client']")
.compile("/project/dependencies/dependency[groupId/text() = 'org.elasticsearch.client']")
val versionSelector = xPathFactory.newXPath().compile("version")

var foundVersion = false;
Expand Down Expand Up @@ -183,6 +183,7 @@ dependencies {
// the Java API client coexists with a 7.x HLRC work fine
val elasticsearchVersion = "7.17.7"
val jacksonVersion = "2.13.3"
val openTelemetryVersion = "1.29.0"

// Apache 2.0
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html
Expand All @@ -201,6 +202,13 @@ dependencies {
// https://github.com/eclipse-ee4j/parsson
api("org.eclipse.parsson:parsson:1.0.0")

// OpenTelemetry API for native instrumentation of the client.
// Apache 2.0
// https://github.com/open-telemetry/opentelemetry-java
implementation("io.opentelemetry", "opentelemetry-api", openTelemetryVersion)
// Use it once it's stable (see Instrumentation.java). Limited to tests for now.
testImplementation("io.opentelemetry", "opentelemetry-semconv", "$openTelemetryVersion-alpha")

// EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
// https://github.com/eclipse-ee4j/jsonb-api
compileOnly("jakarta.json.bind", "jakarta.json.bind-api", "2.0.0")
Expand Down Expand Up @@ -236,6 +244,9 @@ dependencies {
// https://www.testcontainers.org/
testImplementation("org.testcontainers", "testcontainers", "1.17.3")
testImplementation("org.testcontainers", "elasticsearch", "1.17.3")


testImplementation("io.opentelemetry", "opentelemetry-sdk", openTelemetryVersion)
}


Expand All @@ -247,17 +258,18 @@ licenseReport {
class SpdxReporter(val dest: File) : ReportRenderer {
// License names to their SPDX identifier
val spdxIds = mapOf(
"Apache License, Version 2.0" to "Apache-2.0",
"The Apache Software License, Version 2.0" to "Apache-2.0",
"BSD Zero Clause License" to "0BSD",
"Eclipse Public License 2.0" to "EPL-2.0",
"Eclipse Public License v. 2.0" to "EPL-2.0",
"Eclipse Public License - v 2.0" to "EPL-2.0",
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
"The Apache License, Version 2.0" to "Apache-2.0",
"Apache License, Version 2.0" to "Apache-2.0",
"The Apache Software License, Version 2.0" to "Apache-2.0",
"BSD Zero Clause License" to "0BSD",
"Eclipse Public License 2.0" to "EPL-2.0",
"Eclipse Public License v. 2.0" to "EPL-2.0",
"Eclipse Public License - v 2.0" to "EPL-2.0",
"GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
"COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
)

private fun quote(str: String) : String {
private fun quote(str: String): String {
return if (str.contains(',') || str.contains("\"")) {
"\"" + str.replace("\"", "\"\"") + "\""
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import jakarta.json.stream.JsonGenerator;
import java.lang.String;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -149,6 +151,21 @@ public AsyncSearchStatusRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _id = 1 << 0;

int propsSet = 0;

propsSet |= _id;

if (propsSet == (_id)) {
params.put("id", request.id);
}
return params;
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import jakarta.json.stream.JsonGenerator;
import java.lang.String;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -150,6 +152,21 @@ public DeleteAsyncSearchRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _id = 1 << 0;

int propsSet = 0;

propsSet |= _id;

if (propsSet == (_id)) {
params.put("id", request.id);
}
return params;
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ public GetAsyncSearchRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _id = 1 << 0;

int propsSet = 0;

propsSet |= _id;

if (propsSet == (_id)) {
params.put("id", request.id);
}
return params;
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2436,6 +2436,24 @@ protected static void setupSubmitRequestDeserializer(ObjectDeserializer<SubmitRe

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _index = 1 << 0;

int propsSet = 0;

if (ApiTypeHelper.isDefined(request.index()))
propsSet |= _index;

if (propsSet == 0) {
}
if (propsSet == (_index)) {
params.put("index", request.index.stream().map(v -> v).collect(Collectors.joining(",")));
}
return params;
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import jakarta.json.stream.JsonGenerator;
import java.lang.String;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -149,6 +151,21 @@ public DeleteAutoscalingPolicyRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _name = 1 << 0;

int propsSet = 0;

propsSet |= _name;

if (propsSet == (_name)) {
params.put("name", request.name);
}
return params;
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public GetAutoscalingCapacityRequest() {

},

// Path parameters
request -> {
return Collections.emptyMap();
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import jakarta.json.stream.JsonGenerator;
import java.lang.String;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -148,6 +150,21 @@ public GetAutoscalingPolicyRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _name = 1 << 0;

int propsSet = 0;

propsSet |= _name;

if (propsSet == (_name)) {
params.put("name", request.name);
}
return params;
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import jakarta.json.stream.JsonParser;
import java.lang.String;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -203,6 +205,21 @@ protected static JsonpDeserializer<PutAutoscalingPolicyRequest> createPutAutosca

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _name = 1 << 0;

int propsSet = 0;

propsSet |= _name;

if (propsSet == (_name)) {
params.put("name", request.name);
}
return params;
},

// Request parameters
request -> {
return Collections.emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ public AliasesRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _name = 1 << 0;

int propsSet = 0;

if (ApiTypeHelper.isDefined(request.name()))
propsSet |= _name;

if (propsSet == 0) {
}
if (propsSet == (_name)) {
params.put("name", request.name.stream().map(v -> v).collect(Collectors.joining(",")));
}
return params;
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ public AllocationRequest build() {

},

// Path parameters
request -> {
Map<String, String> params = new HashMap<>();
final int _nodeId = 1 << 0;

int propsSet = 0;

if (ApiTypeHelper.isDefined(request.nodeId()))
propsSet |= _nodeId;

if (propsSet == 0) {
}
if (propsSet == (_nodeId)) {
params.put("nodeId", request.nodeId.stream().map(v -> v).collect(Collectors.joining(",")));
}
return params;
},

// Request parameters
request -> {
Map<String, String> params = new HashMap<>();
Expand Down
Loading
Loading