Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayanesh authored Sep 21, 2023
2 parents fc03175 + 6e7f955 commit fb8d394
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion benchmark-overhead-jmh/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

dependencies {
jmhImplementation("org.springframework.boot:spring-boot-starter-web:3.1.3")
jmhImplementation("org.springframework.boot:spring-boot-starter-web:3.1.4")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ abstract class NettyAlignmentRule : ComponentMetadataRule {
with(ctx.details) {
if (id.group == "io.netty" && id.name != "netty") {
if (id.version.startsWith("4.1.")) {
belongsTo("io.netty:netty-bom:4.1.97.Final", false)
belongsTo("io.netty:netty-bom:4.1.98.Final", false)
} else if (id.version.startsWith("4.0.")) {
belongsTo("io.netty:netty-bom:4.0.56.Final", false)
}
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ val DEPENDENCIES = listOf(
"org.junit-pioneer:junit-pioneer:1.9.1",
"org.objenesis:objenesis:3.3",
// Note that this is only referenced as "org.springframework.boot" in build files, not the artifact name.
"org.springframework.boot:spring-boot-dependencies:2.7.15",
"org.springframework.boot:spring-boot-dependencies:2.7.16",
"javax.validation:validation-api:2.0.1.Final",
"org.snakeyaml:snakeyaml-engine:2.7"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.instrumentation.spring.resources;

import static java.util.logging.Level.FINE;
import static java.util.logging.Level.FINER;

import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
Expand All @@ -20,7 +21,6 @@
import java.util.Properties;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -69,7 +69,7 @@ public SpringBootServiceNameDetector() {
@Override
public Resource createResource(ConfigProperties config) {

logger.log(Level.FINER, "Performing Spring Boot service name auto-detection...");
logger.log(FINER, "Performing Spring Boot service name auto-detection...");
// Note: The order should be consistent with the order of Spring matching, but noting
// that we have "first one wins" while Spring has "last one wins".
// The docs for Spring are here:
Expand All @@ -80,8 +80,10 @@ public Resource createResource(ConfigProperties config) {
this::findBySystemProperties,
this::findByEnvironmentVariable,
this::findByCurrentDirectoryApplicationProperties,
this::findByCurrentDirectoryApplicationYml,
this::findByCurrentDirectoryApplicationYaml,
this::findByClasspathApplicationProperties,
this::findByClasspathApplicationYml,
this::findByClasspathApplicationYaml);
return finders
.map(Supplier::get)
Expand Down Expand Up @@ -115,24 +117,22 @@ public int order() {
@Nullable
private String findByEnvironmentVariable() {
String result = system.getenv("SPRING_APPLICATION_NAME");
logger.log(Level.FINER, "Checking for SPRING_APPLICATION_NAME in env: {0}", result);
logger.log(FINER, "Checking for SPRING_APPLICATION_NAME in env: {0}", result);
return result;
}

@Nullable
private String findBySystemProperties() {
String result = system.getProperty("spring.application.name");
logger.log(Level.FINER, "Checking for spring.application.name system property: {0}", result);
logger.log(FINER, "Checking for spring.application.name system property: {0}", result);
return result;
}

@Nullable
private String findByClasspathApplicationProperties() {
String result = readNameFromAppProperties();
logger.log(
Level.FINER,
"Checking for spring.application.name in application.properties file: {0}",
result);
FINER, "Checking for spring.application.name in application.properties file: {0}", result);
return result;
}

Expand All @@ -144,27 +144,49 @@ private String findByCurrentDirectoryApplicationProperties() {
} catch (Exception e) {
// expected to fail sometimes
}
logger.log(Level.FINER, "Checking application.properties in current dir: {0}", result);
logger.log(FINER, "Checking application.properties in current dir: {0}", result);
return result;
}

@Nullable
private String findByClasspathApplicationYml() {
return findByClasspathYamlFile("application.yml");
}

@Nullable
private String findByClasspathApplicationYaml() {
String result =
loadFromClasspath("application.yml", SpringBootServiceNameDetector::parseNameFromYaml);
logger.log(Level.FINER, "Checking application.yml in classpath: {0}", result);
return findByClasspathYamlFile("application.yaml");
}

private String findByClasspathYamlFile(String fileName) {
String result = loadFromClasspath(fileName, SpringBootServiceNameDetector::parseNameFromYaml);
if (logger.isLoggable(FINER)) {
logger.log(FINER, "Checking {0} in classpath: {1}", new Object[] {fileName, result});
}
return result;
}

@Nullable
private String findByCurrentDirectoryApplicationYml() {
return findByCurrentDirectoryYamlFile("application.yml");
}

@Nullable
private String findByCurrentDirectoryApplicationYaml() {
return findByCurrentDirectoryYamlFile("application.yaml");
}

@Nullable
private String findByCurrentDirectoryYamlFile(String fileName) {
String result = null;
try (InputStream in = system.openFile("application.yml")) {
try (InputStream in = system.openFile(fileName)) {
result = parseNameFromYaml(in);
} catch (Exception e) {
// expected to fail sometimes
}
logger.log(Level.FINER, "Checking application.yml in current dir: {0}", result);
if (logger.isLoggable(FINER)) {
logger.log(FINER, "Checking {0} in current dir: {1}", new Object[] {fileName, result});
}
return result;
}

Expand Down Expand Up @@ -199,7 +221,7 @@ private String findByCommandlineArgument() {
String javaCommand = system.getProperty("sun.java.command");
result = parseNameFromCommandLine(javaCommand);
}
logger.log(Level.FINER, "Checking application commandline args: {0}", result);
logger.log(FINER, "Checking application commandline args: {0}", result);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

Expand Down Expand Up @@ -66,33 +68,35 @@ void propertiesFileInCurrentDir() throws Exception {
}
}

@Test
void classpathApplicationYaml() {
when(system.openClasspathResource(APPLICATION_YML))
.thenReturn(openClasspathResource(APPLICATION_YML));
@ParameterizedTest
@ValueSource(strings = {"application.yaml", APPLICATION_YML})
void classpathApplicationYaml(String fileName) {
when(system.openClasspathResource(fileName)).thenReturn(openClasspathResource(APPLICATION_YML));
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system);
Resource result = guesser.createResource(config);
expectServiceName(result, "cat-store");
}

@Test
void classpathApplicationYamlContainingMultipleYamlDefinitions() {
when(system.openClasspathResource(APPLICATION_YML))
@ParameterizedTest
@ValueSource(strings = {"application.yaml", APPLICATION_YML})
void classpathApplicationYamlContainingMultipleYamlDefinitions(String fileName) {
when(system.openClasspathResource(fileName))
.thenReturn(
ClassLoader.getSystemClassLoader().getResourceAsStream("application-multi.yml"));
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system);
Resource result = guesser.createResource(config);
expectServiceName(result, "cat-store");
}

@Test
void yamlFileInCurrentDir() throws Exception {
Path yamlPath = Paths.get(APPLICATION_YML);
@ParameterizedTest
@ValueSource(strings = {"application.yaml", APPLICATION_YML})
void yamlFileInCurrentDir(String fileName) throws Exception {
Path yamlPath = Paths.get(fileName);
try {
URL url = getClass().getClassLoader().getResource(APPLICATION_YML);
String content = readString(Paths.get(url.toURI()));
writeString(yamlPath, content);
when(system.openFile(APPLICATION_YML)).thenCallRealMethod();
when(system.openFile(fileName)).thenCallRealMethod();
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system);
Resource result = guesser.createResource(config);
expectServiceName(result, "cat-store");
Expand All @@ -117,7 +121,7 @@ void getFromCommandlineArgsWithProcessHandle() throws Exception {
}

@Test
void getFromCommandlineArgsWithSystemProperty() throws Exception {
void getFromCommandlineArgsWithSystemProperty() {
when(system.getProperty("sun.java.command"))
.thenReturn("/bin/java sweet-spring.jar --spring.application.name=bullpen --quiet=never");
SpringBootServiceNameDetector guesser = new SpringBootServiceNameDetector(system);
Expand Down
2 changes: 1 addition & 1 deletion smoke-tests-otel-starter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("otel.java-conventions")
id("org.springframework.boot") version "3.1.3"
id("org.springframework.boot") version "3.1.4"
id("org.graalvm.buildtools.native")
}

Expand Down
4 changes: 2 additions & 2 deletions smoke-tests/images/spring-boot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
id("otel.java-conventions")

id("com.google.cloud.tools.jib")
id("org.springframework.boot") version "2.7.15"
id("org.springframework.boot") version "2.7.16"
}

dependencies {
implementation(platform("io.opentelemetry:opentelemetry-bom:1.0.0"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.7.15"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.7.16"))

implementation("io.opentelemetry:opentelemetry-api")
implementation(project(":instrumentation-annotations"))
Expand Down

0 comments on commit fb8d394

Please sign in to comment.