diff --git a/scavenger-agent-java/src/main/java/com/navercorp/scavenger/javaagent/collecting/MethodRegistry.java b/scavenger-agent-java/src/main/java/com/navercorp/scavenger/javaagent/collecting/MethodRegistry.java index dab8e59d..a6990cf7 100644 --- a/scavenger-agent-java/src/main/java/com/navercorp/scavenger/javaagent/collecting/MethodRegistry.java +++ b/scavenger-agent-java/src/main/java/com/navercorp/scavenger/javaagent/collecting/MethodRegistry.java @@ -7,7 +7,6 @@ import lombok.Getter; import com.navercorp.scavenger.util.HashGenerator; -import com.navercorp.scavenger.util.Signatures; public class MethodRegistry { public static final String SYNTHETIC_SIGNATURE_HASH = ""; @@ -15,11 +14,13 @@ public class MethodRegistry { @Getter private final Map byteBuddySignatureToHash = new ConcurrentHashMap<>(); + private static final Pattern SYNTHETIC_SIGNATURE_PATTERN = Pattern.compile(".*\\$\\$(Enhancer|FastClass)BySpringCGLIB\\$\\$.*"); + public String getHash(String byteBuddySignature, boolean legacyCompatibilityMode) { String hash = this.byteBuddySignatureToHash.get(byteBuddySignature); if (hash == null) { - if (Signatures.containsSyntheticPattern(byteBuddySignature)) { + if (SYNTHETIC_SIGNATURE_PATTERN.matcher(byteBuddySignature).matches()) { hash = SYNTHETIC_SIGNATURE_HASH; } else { String signature = extractSignature(byteBuddySignature); diff --git a/scavenger-collector/src/main/kotlin/com/navercorp/scavenger/model/Publication.kt b/scavenger-collector/src/main/kotlin/com/navercorp/scavenger/model/Publication.kt index bd95a7d1..87e5969f 100644 --- a/scavenger-collector/src/main/kotlin/com/navercorp/scavenger/model/Publication.kt +++ b/scavenger-collector/src/main/kotlin/com/navercorp/scavenger/model/Publication.kt @@ -6,12 +6,12 @@ import com.navercorp.scavenger.dto.CommonImportResultDto import com.navercorp.scavenger.dto.InvocationImportDto import com.navercorp.scavenger.exception.UnknownPublicationException import com.navercorp.scavenger.util.HashGenerator -import com.navercorp.scavenger.util.Signatures import io.codekvast.javaagent.model.v4.CodeBasePublication4 import io.codekvast.javaagent.model.v4.CommonPublicationData4 import io.codekvast.javaagent.model.v4.InvocationDataPublication4 import java.io.InputStream import java.io.ObjectInputStream +import java.util.regex.Pattern sealed interface Publication { fun getCommonImportDto(customerId: Long): CommonImportDto @@ -107,7 +107,7 @@ sealed class LegacyPublication private constructor(val commonData: CommonPublica override fun getCodeBaseImportDto(commonImportResultDto: CommonImportResultDto): CodeBaseImportDto = with(commonImportResultDto) { val entries = pub.entries - .filterNot { Signatures.containsSyntheticPattern(it.signature) } + .filterNot { syntheticSignaturePattern.matcher(it.signature).matches() } .map { CodeBaseImportDto.CodeBaseEntry( declaringType = it.methodSignature.declaringType, @@ -140,13 +140,17 @@ sealed class LegacyPublication private constructor(val commonData: CommonPublica applicationId = applicationId, environmentId = environmentId, invocations = pub.invocations - .filterNot { Signatures.containsSyntheticPattern(it) } + .filterNot { syntheticSignaturePattern.matcher(it).matches() } .map { HashGenerator.Md5.from(it) } .sorted(), invokedAtMillis = pub.recordingIntervalStartedAtMillis, ) } } + + companion object { + val syntheticSignaturePattern: Pattern = Pattern.compile(".*\\.\\.(Enhancer|FastClass)BySpringCGLIB\\.\\..*") + } } fun InputStream.toLegacyPublication(): LegacyPublication { diff --git a/scavenger-model/build.gradle.kts b/scavenger-model/build.gradle.kts index 94be0519..55daaf3f 100644 --- a/scavenger-model/build.gradle.kts +++ b/scavenger-model/build.gradle.kts @@ -22,10 +22,6 @@ dependencies { implementation("io.grpc:grpc-kotlin-stub:${property("grpcKotlinVersion")}") implementation("io.grpc:grpc-protobuf:${property("grpcVersion")}") implementation("javax.annotation:javax.annotation-api:1.3.2") - - testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2") - testImplementation("org.assertj:assertj-core:3.22.0") } tasks.withType { diff --git a/scavenger-model/src/main/java/com/navercorp/scavenger/util/Signatures.java b/scavenger-model/src/main/java/com/navercorp/scavenger/util/Signatures.java deleted file mode 100644 index 29d24f56..00000000 --- a/scavenger-model/src/main/java/com/navercorp/scavenger/util/Signatures.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.navercorp.scavenger.util; - -import java.util.regex.Pattern; - -public final class Signatures { - - private static final Pattern SYNTHETIC_SIGNATURE_PATTERN = Pattern.compile(".*\\$\\$(Enhancer|FastClass)BySpringCGLIB\\$\\$.*"); - - private Signatures() { - // utility class - } - - public static boolean containsSyntheticPattern(String signature) { - return SYNTHETIC_SIGNATURE_PATTERN.matcher(signature).matches(); - } -} diff --git a/scavenger-model/src/test/java/com/navercorp/scavenger/util/SignaturesTest.java b/scavenger-model/src/test/java/com/navercorp/scavenger/util/SignaturesTest.java deleted file mode 100644 index e0c5b9df..00000000 --- a/scavenger-model/src/test/java/com/navercorp/scavenger/util/SignaturesTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.navercorp.scavenger.util; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; - -class SignaturesTest { - - @Test - void returnsTrueIfSignatureContainsEnhancerBySpringCGLIB() { - // given - String signature = "TestClass$$EnhancerBySpringCGLIB$$hash.testMethod()"; - - // when - boolean actual = Signatures.containsSyntheticPattern(signature); - - // then - assertThat(actual).isTrue(); - } - - @Test - void returnsTrueIfSignatureContainsFastClassBySpringCGLIB() { - // given - String signature = "TestClass$$FastClassBySpringCGLIB$$hash.testMethod()"; - - // when - boolean actual = Signatures.containsSyntheticPattern(signature); - - // then - assertThat(actual).isTrue(); - } - - @Test - void returnsFalseIfDoesNotContainsPattern() { - // given - String signature = "TestClass$hash.testMethod()"; - - // when - boolean actual = Signatures.containsSyntheticPattern(signature); - - // then - assertThat(actual).isFalse(); - } -}