From 49e66d9cbd0249e9dcb93e8086d6787970f82fa4 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Wed, 28 Jun 2023 17:23:00 -0400 Subject: [PATCH 01/12] fix:add hints for trace. --- .../trace/TraceRuntimeHints.java | 44 ++++++++++++++++++ .../resources/META-INF/spring/aot.factories | 2 + spring-cloud-gcp-samples/pom.xml | 2 + .../main/java/com/example/Application.java | 2 + .../java/com/example/SampleRuntimeHints.java | 36 +++++++++++++++ .../java/com/example/TestRuntimeHints.java | 45 +++++++++++++++++++ ...raceSampleApplicationIntegrationTests.java | 2 + 7 files changed, 133 insertions(+) create mode 100644 spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java create mode 100644 spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories create mode 100644 spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java create mode 100644 spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java new file mode 100644 index 0000000000..fcd2bccecd --- /dev/null +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java @@ -0,0 +1,44 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.google.cloud.spring.autoconfigure.trace; + +import com.google.protobuf.Value; +import io.micrometer.observation.aop.ObservedAspect; +import java.lang.reflect.Method; +import java.util.Arrays; +import org.aspectj.lang.ProceedingJoinPoint; +import org.springframework.aot.hint.ExecutableMode; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; +import org.springframework.util.ReflectionUtils; + +public class TraceRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + Method method = ReflectionUtils.findMethod(ObservedAspect.class, "observeMethod", ProceedingJoinPoint.class); + hints.reflection().registerMethod(method, ExecutableMode.INVOKE); + + // hints.reflection().registerTypes( + // Arrays.asList(TypeReference.of(Value.class), TypeReference.of(Value.Builder.class)), + // hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS, + // MemberCategory.INVOKE_DECLARED_METHODS)); + } +} diff --git a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories new file mode 100644 index 0000000000..3b9051016b --- /dev/null +++ b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar=\ +com.google.cloud.spring.autoconfigure.trace.TraceRuntimeHints \ No newline at end of file diff --git a/spring-cloud-gcp-samples/pom.xml b/spring-cloud-gcp-samples/pom.xml index 120ca1e5b2..74de63e696 100644 --- a/spring-cloud-gcp-samples/pom.xml +++ b/spring-cloud-gcp-samples/pom.xml @@ -90,6 +90,7 @@ native-sample-config spring-cloud-gcp-logging-sample + spring-cloud-gcp-trace-sample @@ -132,6 +133,7 @@ true + true diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/Application.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/Application.java index ad2f5be68b..bc2f75fb9e 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/Application.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/Application.java @@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.lang.NonNull; @@ -48,6 +49,7 @@ /** Sample spring boot application. */ @AutoConfiguration @SpringBootApplication +@ImportRuntimeHints(SampleRuntimeHints.class) public class Application implements WebMvcConfigurer { private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java new file mode 100644 index 0000000000..bc0f6c8e2e --- /dev/null +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import java.util.Arrays; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; + +public class SampleRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + + hints.reflection().registerTypes( + Arrays.asList(TypeReference.of(Application.class)), + hint -> hint.withMembers( + MemberCategory.INVOKE_PUBLIC_METHODS)); + + } +} diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java new file mode 100644 index 0000000000..0c6a38d4cd --- /dev/null +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example; + +import ch.qos.logback.classic.encoder.PatternLayoutEncoder; +import ch.qos.logback.core.ConsoleAppender; +import java.util.Arrays; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; + +public class TestRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + + hints + .reflection() + .registerTypes( + Arrays.asList( + TypeReference.of(ConsoleAppender.class), + TypeReference.of(PatternLayoutEncoder.class)), + hint -> + hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_METHODS)); + hints.resources().registerPattern("logback-test.xml"); + hints.resources().registerPattern("com/google/cloud/spring/logging/logback-appender.xml"); + } +} diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TraceSampleApplicationIntegrationTests.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TraceSampleApplicationIntegrationTests.java index e4a855e06e..7bfcb8b477 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TraceSampleApplicationIntegrationTests.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TraceSampleApplicationIntegrationTests.java @@ -60,6 +60,7 @@ import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -75,6 +76,7 @@ webEnvironment = WebEnvironment.RANDOM_PORT, classes = {Application.class}) @AutoConfigureObservability +@ImportRuntimeHints(TestRuntimeHints.class) class TraceSampleApplicationIntegrationTests { @DynamicPropertySource From f5e3893b84f201b91db44006e49da099c223436a Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Wed, 28 Jun 2023 17:35:36 -0400 Subject: [PATCH 02/12] fix: add test for trace runtime hints. --- .../trace/TraceRuntimeHintsTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java new file mode 100644 index 0000000000..5c2e85cc48 --- /dev/null +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.spring.autoconfigure.trace; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; + +import io.micrometer.observation.aop.ObservedAspect; +import org.junit.jupiter.api.Test; +import org.springframework.aot.hint.RuntimeHints; + +class TraceRuntimeHintsTest { + @Test + void registerObserveMethod() { + + RuntimeHints hints = new RuntimeHints(); + + TraceRuntimeHints registrar = new TraceRuntimeHints(); + registrar.registerHints(hints, null); + assertThat(hints).matches(reflection().onMethod(ObservedAspect.class, "observeMethod")); + } +} From 40ef15e31fd4d1cf9c85923f29215b75bdfcbb40 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Thu, 29 Jun 2023 12:24:04 -0400 Subject: [PATCH 03/12] chore: fix checkstyle and restructure. --- .../trace/{ => aot}/TraceRuntimeHints.java | 15 +++------------ .../resources/META-INF/spring/aot.factories | 2 +- .../trace/{ => aot}/TraceRuntimeHintsTest.java | 18 ++++++++---------- .../java/com/example/SampleRuntimeHints.java | 2 -- .../java/com/example/TestRuntimeHints.java | 1 - 5 files changed, 12 insertions(+), 26 deletions(-) rename spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/{ => aot}/TraceRuntimeHints.java (69%) rename spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/{ => aot}/TraceRuntimeHintsTest.java (73%) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java similarity index 69% rename from spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java rename to spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index fcd2bccecd..4317f98393 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -14,31 +14,22 @@ * limitations under the License. */ +package com.google.cloud.spring.autoconfigure.trace.aot; -package com.google.cloud.spring.autoconfigure.trace; - -import com.google.protobuf.Value; import io.micrometer.observation.aop.ObservedAspect; import java.lang.reflect.Method; -import java.util.Arrays; import org.aspectj.lang.ProceedingJoinPoint; import org.springframework.aot.hint.ExecutableMode; -import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeReference; import org.springframework.util.ReflectionUtils; public class TraceRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - Method method = ReflectionUtils.findMethod(ObservedAspect.class, "observeMethod", ProceedingJoinPoint.class); + Method method = ReflectionUtils.findMethod(ObservedAspect.class, + "observeMethod", ProceedingJoinPoint.class); hints.reflection().registerMethod(method, ExecutableMode.INVOKE); - - // hints.reflection().registerTypes( - // Arrays.asList(TypeReference.of(Value.class), TypeReference.of(Value.Builder.class)), - // hint -> hint.withMembers(MemberCategory.DECLARED_FIELDS, - // MemberCategory.INVOKE_DECLARED_METHODS)); } } diff --git a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories index 3b9051016b..c58fe35243 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories +++ b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories @@ -1,2 +1,2 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\ -com.google.cloud.spring.autoconfigure.trace.TraceRuntimeHints \ No newline at end of file +com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints \ No newline at end of file diff --git a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHintsTest.java similarity index 73% rename from spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java rename to spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHintsTest.java index 5c2e85cc48..77c5baed05 100644 --- a/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/TraceRuntimeHintsTest.java +++ b/spring-cloud-gcp-autoconfigure/src/test/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHintsTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.cloud.spring.autoconfigure.trace; +package com.google.cloud.spring.autoconfigure.trace.aot; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.springframework.aot.hint.predicate.RuntimeHintsPredicates.reflection; @@ -24,13 +24,11 @@ import org.springframework.aot.hint.RuntimeHints; class TraceRuntimeHintsTest { - @Test - void registerObserveMethod() { - - RuntimeHints hints = new RuntimeHints(); - - TraceRuntimeHints registrar = new TraceRuntimeHints(); - registrar.registerHints(hints, null); - assertThat(hints).matches(reflection().onMethod(ObservedAspect.class, "observeMethod")); - } + @Test + void registerObserveMethod() { + RuntimeHints hints = new RuntimeHints(); + TraceRuntimeHints registrar = new TraceRuntimeHints(); + registrar.registerHints(hints, null); + assertThat(hints).matches(reflection().onMethod(ObservedAspect.class, "observeMethod")); + } } diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java index bc0f6c8e2e..db46c7a87b 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java @@ -26,11 +26,9 @@ public class SampleRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints.reflection().registerTypes( Arrays.asList(TypeReference.of(Application.class)), hint -> hint.withMembers( MemberCategory.INVOKE_PUBLIC_METHODS)); - } } diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java index 0c6a38d4cd..dac8c7f9fe 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java @@ -28,7 +28,6 @@ public class TestRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints .reflection() .registerTypes( From 7e76412e56cd9fa378cd396cd2c5ceedb554b07e Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Wed, 19 Jul 2023 20:37:44 +0000 Subject: [PATCH 04/12] add runtime hints for trace starter --- .../trace/aot/TraceRuntimeHints.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index 4317f98393..4feca7121e 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -18,18 +18,32 @@ import io.micrometer.observation.aop.ObservedAspect; import java.lang.reflect.Method; +import java.util.Arrays; import org.aspectj.lang.ProceedingJoinPoint; import org.springframework.aot.hint.ExecutableMode; +import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; import org.springframework.util.ReflectionUtils; public class TraceRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - Method method = ReflectionUtils.findMethod(ObservedAspect.class, - "observeMethod", ProceedingJoinPoint.class); - hints.reflection().registerMethod(method, ExecutableMode.INVOKE); + Method method = + ReflectionUtils.findMethod( + ObservedAspect.class, "observeMethod", ProceedingJoinPoint.class); + hints + .reflection() + .registerMethod(method, ExecutableMode.INVOKE) + .registerTypes( + Arrays.asList( + TypeReference.of(com.google.protobuf.Value.class), + TypeReference.of(com.google.protobuf.Value.Builder.class)), + hint -> + hint.withMembers( + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, + MemberCategory.INVOKE_PUBLIC_METHODS)); } } From 837a16b3253bca1ddac41c46f9de3820a71af1a3 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Thu, 20 Jul 2023 17:32:11 +0000 Subject: [PATCH 05/12] avoid using ProceedingJointPoint in runtimehint --- .../autoconfigure/trace/aot/TraceRuntimeHints.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index 4feca7121e..08a90c42ac 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -17,28 +17,21 @@ package com.google.cloud.spring.autoconfigure.trace.aot; import io.micrometer.observation.aop.ObservedAspect; -import java.lang.reflect.Method; import java.util.Arrays; -import org.aspectj.lang.ProceedingJoinPoint; -import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.util.ReflectionUtils; public class TraceRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - Method method = - ReflectionUtils.findMethod( - ObservedAspect.class, "observeMethod", ProceedingJoinPoint.class); hints .reflection() - .registerMethod(method, ExecutableMode.INVOKE) .registerTypes( Arrays.asList( + TypeReference.of(ObservedAspect.class), TypeReference.of(com.google.protobuf.Value.class), TypeReference.of(com.google.protobuf.Value.Builder.class)), hint -> From 576e84f2be6083365eb5ee7c94f544b8fcaca2ed Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jul 2023 00:37:47 +0000 Subject: [PATCH 06/12] update to graalvm 22.3.2 --- .github/workflows/NativeTests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/NativeTests.yaml b/.github/workflows/NativeTests.yaml index 683e4856f8..cf669e10fb 100644 --- a/.github/workflows/NativeTests.yaml +++ b/.github/workflows/NativeTests.yaml @@ -71,7 +71,7 @@ jobs: same-branch-only: false - uses: graalvm/setup-graalvm@v1 with: - version: '22.3.0' + version: '22.3.2' java-version: '17' components: 'native-image' github-token: ${{ secrets.GITHUB_TOKEN }} From 9dec5056448fd96783aecbf3f71de1ec2f216857 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jul 2023 00:40:28 +0000 Subject: [PATCH 07/12] remove ObservedAspect configuration --- .../cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index 08a90c42ac..2ac5d893dd 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -16,7 +16,6 @@ package com.google.cloud.spring.autoconfigure.trace.aot; -import io.micrometer.observation.aop.ObservedAspect; import java.util.Arrays; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; @@ -31,7 +30,6 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { .reflection() .registerTypes( Arrays.asList( - TypeReference.of(ObservedAspect.class), TypeReference.of(com.google.protobuf.Value.class), TypeReference.of(com.google.protobuf.Value.Builder.class)), hint -> From bb478c79dbab17665794a8414af87882ddf211ca Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jul 2023 14:47:25 +0000 Subject: [PATCH 08/12] use ImportRuntimeHints instead of spring-aot properties file --- .../spring/autoconfigure/trace/aot/TraceRuntimeHints.java | 2 ++ .../trace/pubsub/TracePubSubAutoConfiguration.java | 3 +++ .../src/main/resources/META-INF/spring/aot.factories | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) delete mode 100644 spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index 2ac5d893dd..08a90c42ac 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -16,6 +16,7 @@ package com.google.cloud.spring.autoconfigure.trace.aot; +import io.micrometer.observation.aop.ObservedAspect; import java.util.Arrays; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; @@ -30,6 +31,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { .reflection() .registerTypes( Arrays.asList( + TypeReference.of(ObservedAspect.class), TypeReference.of(com.google.protobuf.Value.class), TypeReference.of(com.google.protobuf.Value.Builder.class)), hint -> diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java index a5b16aa97f..667b59dd69 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java @@ -20,6 +20,7 @@ import brave.messaging.MessagingTracing; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; +import com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints; import com.google.cloud.spring.pubsub.core.publisher.PublisherCustomizer; import com.google.cloud.spring.pubsub.support.PublisherFactory; import io.micrometer.observation.ObservationRegistry; @@ -34,6 +35,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -43,6 +45,7 @@ @ConditionalOnClass({PublisherFactory.class, MessagingTracing.class}) @AutoConfigureAfter({BraveAutoConfiguration.class}) @AutoConfigureBefore(GcpPubSubAutoConfiguration.class) +@ImportRuntimeHints(TraceRuntimeHints.class) class TracePubSubAutoConfiguration { @Bean diff --git a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories deleted file mode 100644 index c58fe35243..0000000000 --- a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.aot.hint.RuntimeHintsRegistrar=\ -com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints \ No newline at end of file From ec635d568e9008b14bc5e944db64ef0221b84aa6 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jul 2023 18:10:48 +0000 Subject: [PATCH 09/12] use aot-properties with package name --- .../trace/pubsub/TracePubSubAutoConfiguration.java | 3 --- .../aot.factories | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java index 667b59dd69..a5b16aa97f 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java @@ -20,7 +20,6 @@ import brave.messaging.MessagingTracing; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; -import com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints; import com.google.cloud.spring.pubsub.core.publisher.PublisherCustomizer; import com.google.cloud.spring.pubsub.support.PublisherFactory; import io.micrometer.observation.ObservationRegistry; @@ -35,7 +34,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -45,7 +43,6 @@ @ConditionalOnClass({PublisherFactory.class, MessagingTracing.class}) @AutoConfigureAfter({BraveAutoConfiguration.class}) @AutoConfigureBefore(GcpPubSubAutoConfiguration.class) -@ImportRuntimeHints(TraceRuntimeHints.class) class TracePubSubAutoConfiguration { @Bean diff --git a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories new file mode 100644 index 0000000000..c58fe35243 --- /dev/null +++ b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories @@ -0,0 +1,2 @@ +org.springframework.aot.hint.RuntimeHintsRegistrar=\ +com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints \ No newline at end of file From 0afd0efdac60948e0a6ac71f03adfe4c547e7106 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Fri, 21 Jul 2023 19:10:15 +0000 Subject: [PATCH 10/12] revert previous change; use ImportRuntimeHints --- .../trace/pubsub/TracePubSubAutoConfiguration.java | 3 +++ .../aot.factories | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java index a5b16aa97f..667b59dd69 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/pubsub/TracePubSubAutoConfiguration.java @@ -20,6 +20,7 @@ import brave.messaging.MessagingTracing; import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.spring.autoconfigure.pubsub.GcpPubSubAutoConfiguration; +import com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints; import com.google.cloud.spring.pubsub.core.publisher.PublisherCustomizer; import com.google.cloud.spring.pubsub.support.PublisherFactory; import io.micrometer.observation.ObservationRegistry; @@ -34,6 +35,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; @@ -43,6 +45,7 @@ @ConditionalOnClass({PublisherFactory.class, MessagingTracing.class}) @AutoConfigureAfter({BraveAutoConfiguration.class}) @AutoConfigureBefore(GcpPubSubAutoConfiguration.class) +@ImportRuntimeHints(TraceRuntimeHints.class) class TracePubSubAutoConfiguration { @Bean diff --git a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories b/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories deleted file mode 100644 index c58fe35243..0000000000 --- a/spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/com.google.cloud.spring.autoconfigure.trace.pubsub/aot.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.aot.hint.RuntimeHintsRegistrar=\ -com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints \ No newline at end of file From 236d250cf92e28ee80a2b1a85542dbb72191b088 Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Mon, 31 Jul 2023 22:36:32 +0000 Subject: [PATCH 11/12] move protobuf.Value config to test config --- .../spring/autoconfigure/trace/aot/TraceRuntimeHints.java | 5 +---- .../src/test/java/com/example/TestRuntimeHints.java | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java index 08a90c42ac..ed7575fe53 100644 --- a/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java +++ b/spring-cloud-gcp-autoconfigure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java @@ -30,10 +30,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { hints .reflection() .registerTypes( - Arrays.asList( - TypeReference.of(ObservedAspect.class), - TypeReference.of(com.google.protobuf.Value.class), - TypeReference.of(com.google.protobuf.Value.Builder.class)), + Arrays.asList(TypeReference.of(ObservedAspect.class)), hint -> hint.withMembers( MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java index dac8c7f9fe..c90f4d3ac5 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java @@ -33,7 +33,9 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { .registerTypes( Arrays.asList( TypeReference.of(ConsoleAppender.class), - TypeReference.of(PatternLayoutEncoder.class)), + TypeReference.of(PatternLayoutEncoder.class), + TypeReference.of(com.google.protobuf.Value.class), + TypeReference.of(com.google.protobuf.Value.Builder.class)), hint -> hint.withMembers( MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, From 399c586093651b0c30d91d57944603a991e3300d Mon Sep 17 00:00:00 2001 From: mpeddada1 Date: Tue, 1 Aug 2023 16:07:23 +0000 Subject: [PATCH 12/12] rebase branch with main; remove configs --- .../src/test/java/com/example/TestRuntimeHints.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java index c90f4d3ac5..dac8c7f9fe 100644 --- a/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java +++ b/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java @@ -33,9 +33,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { .registerTypes( Arrays.asList( TypeReference.of(ConsoleAppender.class), - TypeReference.of(PatternLayoutEncoder.class), - TypeReference.of(com.google.protobuf.Value.class), - TypeReference.of(com.google.protobuf.Value.Builder.class)), + TypeReference.of(PatternLayoutEncoder.class)), hint -> hint.withMembers( MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,