Skip to content

Commit 2ae0ed8

Browse files
committed
Copilot code review test
1 parent 229264c commit 2ae0ed8

File tree

176 files changed

+489
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+489
-413
lines changed

aws-resources/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ description = "OpenTelemetry AWS Resources Support"
88
otelJava.moduleName.set("io.opentelemetry.contrib.aws.resource")
99

1010
dependencies {
11+
annotationProcessor("com.google.auto.service:auto-service")
12+
compileOnly("com.google.auto.service:auto-service")
13+
1114
api("io.opentelemetry:opentelemetry-api")
1215
compileOnly("io.opentelemetry:opentelemetry-api-incubator")
1316
api("io.opentelemetry:opentelemetry-sdk")
@@ -23,6 +26,7 @@ dependencies {
2326
testImplementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
2427
testImplementation("io.opentelemetry:opentelemetry-api-incubator")
2528
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
29+
testImplementation("com.google.auto.service:auto-service")
2630

2731
testImplementation("com.linecorp.armeria:armeria-junit5")
2832
testRuntimeOnly("org.bouncycastle:bcpkix-jdk15on")

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/BeanstalkResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.SERVICE_INSTANCE_ID;
1313
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.SERVICE_NAMESPACE;
1414
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_VERSION;
15+
import static java.util.logging.Level.WARNING;
1516

1617
import com.fasterxml.jackson.core.JsonFactory;
1718
import com.fasterxml.jackson.core.JsonParser;
@@ -22,7 +23,6 @@
2223
import io.opentelemetry.semconv.SchemaUrls;
2324
import java.io.File;
2425
import java.io.IOException;
25-
import java.util.logging.Level;
2626
import java.util.logging.Logger;
2727

2828
/**
@@ -65,7 +65,7 @@ static Resource buildResource(String configPath) {
6565
parser.nextToken();
6666

6767
if (!parser.isExpectedStartObjectToken()) {
68-
logger.log(Level.WARNING, "Invalid Beanstalk config: ", configPath);
68+
logger.log(WARNING, "Invalid Beanstalk config: ", configPath);
6969
return Resource.create(attrBuilders.build(), SchemaUrls.V1_25_0);
7070
}
7171

@@ -87,7 +87,7 @@ static Resource buildResource(String configPath) {
8787
}
8888
}
8989
} catch (IOException e) {
90-
logger.log(Level.WARNING, "Could not parse Beanstalk config.", e);
90+
logger.log(WARNING, "Could not parse Beanstalk config.", e);
9191
return Resource.empty();
9292
}
9393

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/BeanstalkResourceProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import com.google.auto.service.AutoService;
89
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
910
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
1011
import io.opentelemetry.sdk.resources.Resource;
1112

1213
/** {@link ResourceProvider} for automatically configuring {@link BeanstalkResource}. */
14+
@AutoService(ResourceProvider.class)
1315
public final class BeanstalkResourceProvider extends CloudResourceProvider {
1416
@Override
1517
public Resource createResource(ConfigProperties config) {

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/DockerHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import static java.util.logging.Level.WARNING;
9+
810
import java.io.BufferedReader;
911
import java.io.FileNotFoundException;
1012
import java.io.FileReader;
1113
import java.io.IOException;
12-
import java.util.logging.Level;
1314
import java.util.logging.Logger;
1415

1516
class DockerHelper {
@@ -44,9 +45,9 @@ public String getContainerId() {
4445
}
4546
}
4647
} catch (FileNotFoundException e) {
47-
logger.log(Level.WARNING, "Failed to read container id, cgroup file does not exist.");
48+
logger.log(WARNING, "Failed to read container id, cgroup file does not exist.");
4849
} catch (IOException e) {
49-
logger.log(Level.WARNING, "Unable to read container id: " + e.getMessage());
50+
logger.log(WARNING, "Unable to read container id: " + e.getMessage());
5051
}
5152

5253
return "";

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/Ec2Resource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_IMAGE_ID;
1616
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_NAME;
1717
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.HOST_TYPE;
18+
import static java.util.logging.Level.WARNING;
1819

1920
import com.fasterxml.jackson.core.JsonFactory;
2021
import com.fasterxml.jackson.core.JsonParser;
@@ -28,7 +29,6 @@
2829
import java.net.URL;
2930
import java.util.HashMap;
3031
import java.util.Map;
31-
import java.util.logging.Level;
3232
import java.util.logging.Logger;
3333

3434
/**
@@ -125,7 +125,7 @@ static Resource buildResource(String endpoint) {
125125
}
126126
}
127127
} catch (IOException e) {
128-
logger.log(Level.WARNING, "Could not parse identity document, resource not filled.", e);
128+
logger.log(WARNING, "Could not parse identity document, resource not filled.", e);
129129
return Resource.empty();
130130
}
131131

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/Ec2ResourceProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import com.google.auto.service.AutoService;
89
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
910
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
1011
import io.opentelemetry.sdk.resources.Resource;
1112

1213
/** {@link ResourceProvider} for automatically configuring {@link Ec2Resource}. */
14+
@AutoService(ResourceProvider.class)
1315
public final class Ec2ResourceProvider extends CloudResourceProvider {
1416
@Override
1517
public Resource createResource(ConfigProperties config) {

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EcsResource.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CONTAINER_NAME;
2727
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudPlatformIncubatingValues.AWS_ECS;
2828
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudProviderIncubatingValues.AWS;
29+
import static java.util.Collections.emptyMap;
30+
import static java.util.Collections.singletonList;
31+
import static java.util.logging.Level.WARNING;
2932

3033
import com.fasterxml.jackson.core.JsonFactory;
3134
import com.fasterxml.jackson.core.JsonParser;
@@ -35,11 +38,9 @@
3538
import io.opentelemetry.sdk.resources.Resource;
3639
import io.opentelemetry.semconv.SchemaUrls;
3740
import java.io.IOException;
38-
import java.util.Collections;
3941
import java.util.Locale;
4042
import java.util.Map;
4143
import java.util.Optional;
42-
import java.util.logging.Level;
4344
import java.util.logging.Logger;
4445
import java.util.regex.Matcher;
4546
import java.util.regex.Pattern;
@@ -88,7 +89,7 @@ static Resource buildResource(Map<String, String> sysEnv, SimpleHttpClient httpC
8889

8990
static void fetchMetadata(
9091
SimpleHttpClient httpClient, String url, AttributesBuilder attrBuilders) {
91-
String json = httpClient.fetchString("GET", url, Collections.emptyMap(), null);
92+
String json = httpClient.fetchString("GET", url, emptyMap(), null);
9293
if (json.isEmpty()) {
9394
return;
9495
}
@@ -103,17 +104,17 @@ static void fetchMetadata(
103104
.getLogGroupArn()
104105
.ifPresent(
105106
logGroupArn -> {
106-
attrBuilders.put(AWS_LOG_GROUP_ARNS, Collections.singletonList(logGroupArn));
107+
attrBuilders.put(AWS_LOG_GROUP_ARNS, singletonList(logGroupArn));
107108
});
108109

109110
logArnBuilder
110111
.getLogStreamArn()
111112
.ifPresent(
112113
logStreamArn -> {
113-
attrBuilders.put(AWS_LOG_STREAM_ARNS, Collections.singletonList(logStreamArn));
114+
attrBuilders.put(AWS_LOG_STREAM_ARNS, singletonList(logStreamArn));
114115
});
115116
} catch (IOException e) {
116-
logger.log(Level.WARNING, "Can't get ECS metadata", e);
117+
logger.log(WARNING, "Can't get ECS metadata", e);
117118
}
118119
}
119120

@@ -156,7 +157,7 @@ static void parseResponse(
156157
JsonParser parser, AttributesBuilder attrBuilders, LogArnBuilder logArnBuilder)
157158
throws IOException {
158159
if (!parser.isExpectedStartObjectToken()) {
159-
logger.log(Level.WARNING, "Couldn't parse ECS metadata, invalid JSON");
160+
logger.log(WARNING, "Couldn't parse ECS metadata, invalid JSON");
160161
return;
161162
}
162163

@@ -339,7 +340,7 @@ static DockerImage parse(@Nullable String image) {
339340
}
340341
Matcher matcher = imagePattern.matcher(image);
341342
if (!matcher.matches()) {
342-
logger.log(Level.WARNING, "Couldn't parse image '" + image + "'");
343+
logger.log(WARNING, "Couldn't parse image '" + image + "'");
343344
return null;
344345
}
345346
String repository = matcher.group("repository");

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EcsResourceProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import com.google.auto.service.AutoService;
89
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
910
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
1011
import io.opentelemetry.sdk.resources.Resource;
1112

1213
/** {@link ResourceProvider} for automatically configuring {@link EcsResource}. */
14+
@AutoService(ResourceProvider.class)
1315
public final class EcsResourceProvider extends CloudResourceProvider {
1416
@Override
1517
public Resource createResource(ConfigProperties config) {

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EksResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS;
1212
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.CloudProviderIncubatingValues.AWS;
1313
import static io.opentelemetry.contrib.aws.resource.IncubatingAttributes.K8S_CLUSTER_NAME;
14+
import static java.util.logging.Level.FINE;
15+
import static java.util.logging.Level.WARNING;
1416

1517
import com.fasterxml.jackson.core.JsonFactory;
1618
import com.fasterxml.jackson.core.JsonParser;
@@ -26,7 +28,6 @@
2628
import java.nio.file.Paths;
2729
import java.util.HashMap;
2830
import java.util.Map;
29-
import java.util.logging.Level;
3031
import java.util.logging.Logger;
3132

3233
/**
@@ -91,7 +92,7 @@ static Resource buildResource(
9192
private static boolean isEks(
9293
String k8sTokenPath, String k8sKeystorePath, SimpleHttpClient httpClient) {
9394
if (!isK8s(k8sTokenPath, k8sKeystorePath)) {
94-
logger.log(Level.FINE, "Not running on k8s.");
95+
logger.log(FINE, "Not running on k8s.");
9596
return false;
9697
}
9798

@@ -145,7 +146,7 @@ private static String getClusterName(SimpleHttpClient httpClient) {
145146
}
146147
}
147148
} catch (IOException e) {
148-
logger.log(Level.WARNING, "Can't get cluster name on EKS.", e);
149+
logger.log(WARNING, "Can't get cluster name on EKS.", e);
149150
}
150151
return "";
151152
}
@@ -156,7 +157,7 @@ private static String getK8sCredHeader() {
156157
new String(Files.readAllBytes(Paths.get(K8S_TOKEN_PATH)), StandardCharsets.UTF_8);
157158
return "Bearer " + content;
158159
} catch (IOException e) {
159-
logger.log(Level.WARNING, "Unable to load K8s client token.", e);
160+
logger.log(WARNING, "Unable to load K8s client token.", e);
160161
}
161162
return "";
162163
}

aws-resources/src/main/java/io/opentelemetry/contrib/aws/resource/EksResourceProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
package io.opentelemetry.contrib.aws.resource;
77

8+
import com.google.auto.service.AutoService;
89
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
910
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider;
1011
import io.opentelemetry.sdk.resources.Resource;
1112

1213
/** {@link ResourceProvider} for automatically configuring {@link EksResource}. */
14+
@AutoService(ResourceProvider.class)
1315
public final class EksResourceProvider extends CloudResourceProvider {
1416
@Override
1517
public Resource createResource(ConfigProperties config) {

0 commit comments

Comments
 (0)