-
Notifications
You must be signed in to change notification settings - Fork 315
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
fix: add runtime hints for trace #1990
Merged
Merged
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
49e66d9
fix:add hints for trace.
zhumin8 f5e3893
fix: add test for trace runtime hints.
zhumin8 40ef15e
chore: fix checkstyle and restructure.
zhumin8 c6d5346
Merge branch 'main' into trace-hints-2
mpeddada1 7e76412
add runtime hints for trace starter
mpeddada1 837a16b
avoid using ProceedingJointPoint in runtimehint
mpeddada1 576e84f
update to graalvm 22.3.2
mpeddada1 9dec505
remove ObservedAspect configuration
mpeddada1 bb478c7
use ImportRuntimeHints instead of spring-aot properties file
mpeddada1 ec635d5
use aot-properties with package name
mpeddada1 0afd0ef
revert previous change; use ImportRuntimeHints
mpeddada1 236d250
move protobuf.Value config to test config
mpeddada1 d18985f
Merge branch 'main' of github.com:GoogleCloudPlatform/spring-cloud-gc…
mpeddada1 399c586
rebase branch with main; remove configs
mpeddada1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...gure/src/main/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.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(com.google.protobuf.Value.class), | ||
TypeReference.of(com.google.protobuf.Value.Builder.class)), | ||
hint -> | ||
hint.withMembers( | ||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, | ||
MemberCategory.INVOKE_PUBLIC_METHODS)); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
spring-cloud-gcp-autoconfigure/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ | ||
com.google.cloud.spring.autoconfigure.trace.aot.TraceRuntimeHints |
34 changes: 34 additions & 0 deletions
34
.../src/test/java/com/google/cloud/spring/autoconfigure/trace/aot/TraceRuntimeHintsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.aot; | ||
|
||
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...p-samples/spring-cloud-gcp-trace-sample/src/main/java/com/example/SampleRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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)); | ||
} | ||
} | ||
Comment on lines
+26
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this configuration, the sample test results in:
|
44 changes: 44 additions & 0 deletions
44
...gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TestRuntimeHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two configurations may be removed after the static jsons are generated through googleapis/sdk-platform-java#1841. For now, we get the following error without these configurations:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see
com.google.protobuf.Value
as an entry in the Trace library's reflect-config.json. It does show up for some, though: https://github.com/search?q=repo%3Agoogleapis%2Fgoogle-cloud-java+com.google.protobuf.Value+path%3A**%2Freflect-config.json&type=code&p=1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Analyzing the stacktrace of the test shows that the use of
com.google.protobuf.Value
is coming fromspring-cloud-gcp/spring-cloud-gcp-samples/spring-cloud-gcp-trace-sample/src/test/java/com/example/TraceSampleApplicationIntegrationTests.java
Line 238 in 154cbe5
This line of code eventually leads to
GeneratedMessageV3#getMethodOrDie
being called:I've moved the configuration to the
test/
directory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Update] Tests are passing without these configurations after rebasing with
origin/main
.