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 Java8 support #353

Merged
merged 16 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ subprojects {
group = "com.google.cloud.opentelemetry"
// Note: Version now comes from nebula plugin

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
mavenLocal()
Expand All @@ -103,6 +100,15 @@ subprojects {
archivesBaseName = "${project.name}"
}

// Support for some higher language versions can only be achieved using Toolchains.
// Compatibility matrix at https://docs.gradle.org/current/userguide/compatibility.html#java
// See https://docs.gradle.org/current/userguide/toolchains.html#toolchains
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}

// Include license check and auto-format support.
spotless {
java {
Expand Down Expand Up @@ -234,12 +240,6 @@ subprojects {
archives javadocJar, sourcesJar
}

javadoc {
Copy link
Contributor Author

@psx95 psx95 Jun 22, 2024

Choose a reason for hiding this comment

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

Minimum JDK version required for building this project is JDK 11, html5 is default and is no longer required.

if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

java {
withJavadocJar()
withSourcesJar()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources-support/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ dependencies {
testRuntimeOnly(testLibraries.junit5_runtime)
}

afterEvaluate {
tasks.named("compileJava"){
options.release = 8
}
}

test {
// required for discovering JUnit 5 tests
useJUnitPlatform()
Expand Down
6 changes: 0 additions & 6 deletions detectors/resources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
description = 'Google Cloud resource provider for OpenTelemetry'

afterEvaluate {
tasks.named("compileJava"){
options.release = 8
}
}

dependencies {
implementation(libraries.opentelemetry_api)
implementation(libraries.opentelemetry_sdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import com.google.cloud.opentelemetry.detection.DetectedPlatform;
import com.google.cloud.opentelemetry.detection.GCPPlatformDetector;
Expand All @@ -37,7 +38,7 @@ public class GCPResourceTest {
private static final String DUMMY_PROJECT_ID = "google-pid";
private final ConfigProperties mockConfigProps = Mockito.mock(ConfigProperties.class);
private final Map<String, String> mockGKECommonAttributes =
new HashMap<>() {
new HashMap<String, String>() {
{
put(GKE_CLUSTER_NAME, "gke-cluster");
put(GKE_HOST_ID, "host1");
Expand All @@ -47,7 +48,7 @@ public class GCPResourceTest {
// Mock Platforms
private DetectedPlatform generateMockGCEPlatform() {
Map<String, String> mockAttributes =
new HashMap<>() {
new HashMap<String, String>() {
{
put(GCE_CLOUD_REGION, "australia-southeast1");
put(GCE_AVAILABILITY_ZONE, "australia-southeast1-b");
Expand Down Expand Up @@ -92,7 +93,7 @@ private DetectedPlatform generateMockServerlessPlatform(
throw new IllegalArgumentException();
}
Map<String, String> mockAttributes =
new HashMap<>() {
new HashMap<String, String>() {
{
put(SERVERLESS_COMPUTE_NAME, "serverless-app");
put(SERVERLESS_COMPUTE_REVISION, "v2");
Expand All @@ -110,7 +111,7 @@ private DetectedPlatform generateMockServerlessPlatform(

private DetectedPlatform generateMockGAEPlatform() {
Map<String, String> mockAttributes =
new HashMap<>() {
new HashMap<String, String>() {
{
put(GAE_MODULE_NAME, "gae-app");
put(GAE_APP_VERSION, "v1");
Expand All @@ -129,7 +130,7 @@ private DetectedPlatform generateMockGAEPlatform() {

private DetectedPlatform generateMockUnknownPlatform() {
Map<String, String> mockAttributes =
new HashMap<>() {
new HashMap<String, String>() {
{
put(GCE_INSTANCE_ID, "instance-id");
put(GCE_CLOUD_REGION, "australia-southeast1");
Expand Down Expand Up @@ -385,8 +386,12 @@ public void testUnknownPlatformResourceAttributesMapping() {
public void findsWithServiceLoader() {
ServiceLoader<ResourceProvider> services =
ServiceLoader.load(ResourceProvider.class, getClass().getClassLoader());
assertTrue(
services.stream().anyMatch(provider -> provider.type().equals(GCPResource.class)),
"Could not load GCP Resource detector using serviceloader, found: " + services);
while (services.iterator().hasNext()) {
ResourceProvider provider = services.iterator().next();
if (provider instanceof GCPResource) {
return;
}
}
fail("Could not load GCP Resource detector using serviceloader");
}
}
5 changes: 5 additions & 0 deletions e2e-test-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ application {
mainClass.set('com.google.cloud.opentelemetry.endtoend.Server')
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
description = 'End-To-End integration testing server'

shadowJar {
Expand Down
6 changes: 6 additions & 0 deletions examples/otlp-spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ repositories {
mavenCentral()
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

dependencies {
implementation(libraries.opentelemetry_api)
implementation(libraries.opentelemetry_sdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -167,7 +167,7 @@ private Attributes instrumentationLibraryLabels(
instrumentationScopeInfo.getName())
.put(
AttributeKey.stringKey(LABEL_INSTRUMENTATION_VERSION),
Objects.requireNonNullElse(instrumentationScopeInfo.getVersion(), ""))
Optional.ofNullable(instrumentationScopeInfo.getVersion()).orElse(""))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryData;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -419,7 +421,8 @@ public void testExportWithNonSupportedMetricTypeReturnsFailure() {
public void testExportWithMonitoredResourceMappingSucceeds() {
MonitoredResourceDescription monitoredResourceDescription =
new MonitoredResourceDescription(
"custom_mr_instance", Set.of("service_instance_id", "host_id", "location"));
"custom_mr_instance",
new HashSet<>(Arrays.asList("service_instance_id", "host_id", "location")));

// controls which resource attributes end up in metric labels
Predicate<AttributeKey<?>> customAttributesFilter =
Expand Down Expand Up @@ -618,7 +621,8 @@ public void testExportWithMonitoredResourceMappingSucceeds_NoMRLabels() {
public void testExportWithMonitoredResourceMappingSucceeds_NoResourceLabels() {
MonitoredResourceDescription monitoredResourceDescription =
new MonitoredResourceDescription(
"custom_mr_instance", Set.of("service_instance_id", "host_id", "location"));
"custom_mr_instance",
new HashSet<>(Arrays.asList("service_instance_id", "host_id", "location")));

// controls which resource attributes end up in metric labels
Predicate<AttributeKey<?>> customAttributesFilter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import com.google.cloud.opentelemetry.metric.MetricConfiguration.Builder;
import io.opentelemetry.api.common.AttributeKey;
import java.time.Duration;
import java.util.Arrays;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;
import java.util.function.Predicate;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -61,7 +62,8 @@ public void testDefaultConfigurationSucceeds() {
public void testSetAllConfigurationFieldsSucceeds() {
Predicate<AttributeKey<?>> allowAllPredicate = attributeKey -> true;
MonitoredResourceDescription customMRMapping =
new MonitoredResourceDescription("custom_mr", Set.of("instance_id", "foo_bar", "host_id"));
new MonitoredResourceDescription(
"custom_mr", new HashSet<>(Arrays.asList("instance_id", "foo_bar", "host_id")));

MetricConfiguration configuration =
MetricConfiguration.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.opentelemetry.trace;

import static com.google.api.client.util.Preconditions.checkNotNull;
import static java.util.AbstractMap.SimpleEntry;

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
Expand All @@ -40,6 +41,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* This class encapsulates internal implementation details for exporting spans to Google Cloud
Expand All @@ -53,7 +56,10 @@ class InternalTraceExporter implements SpanExporter {
private final TraceTranslator translator;

private static final Map<String, String> HEADERS =
Map.of("User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION);
Stream.of(
psx95 marked this conversation as resolved.
Show resolved Hide resolved
new SimpleEntry<>(
"User-Agent", "opentelemetry-operations-java/" + TraceVersions.EXPORTER_VERSION))
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
private static final HeaderProvider HEADER_PROVIDER = () -> HEADERS;

private static InternalTraceExporter createWithClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurablePropagatorProvider;
import java.util.Map;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -33,19 +37,20 @@ public class AutoConfigureTest {
public void findsWithServiceLoader() {
ServiceLoader<ConfigurablePropagatorProvider> services =
ServiceLoader.load(ConfigurablePropagatorProvider.class, getClass().getClassLoader());

List<ConfigurablePropagatorProvider> servicesList = new ArrayList<>();
services.iterator().forEachRemaining(servicesList::add);

assertTrue(
"Could not load gcp_oneway propagator using serviceloader, found: " + services,
services.stream()
servicesList.stream()
.anyMatch(
provider ->
provider.type().equals(OneWayXCloudTraceConfigurablePropagatorProvider.class)));
provider -> (provider instanceof OneWayXCloudTraceConfigurablePropagatorProvider)));

assertTrue(
"Could not load gcp propagator using serviceloader, found: " + services,
services.stream()
.anyMatch(
provider ->
provider.type().equals(XCloudTraceConfigurablePropagatorProvider.class)));
servicesList.stream()
.anyMatch(provider -> (provider instanceof XCloudTraceConfigurablePropagatorProvider)));
}

@Test
Expand All @@ -64,15 +69,12 @@ private static ContextPropagators findsWithAutoConfigure(String propagator) {
.disableShutdownHook()
.addPropertiesSupplier(
() ->
Map.of(
"otel.propagators",
propagator,
"otel.traces.exporter",
"none",
"otel.metrics.exporter",
"none",
"otel.logs.exporter",
"none"))
Stream.of(
new SimpleEntry<>("otel.propagators", propagator),
new SimpleEntry<>("otel.traces.exporter", "none"),
new SimpleEntry<>("otel.metrics.exporter", "none"),
new SimpleEntry<>("otel.logs.exporter", "none"))
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)))
.build();
return sdk.getOpenTelemetrySdk().getPropagators();
}
Expand Down
Loading
Loading