Add runtime hints for Cassandra observability.
See #1321 Original pull request: #1322
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.cassandra.aot;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
@@ -28,6 +29,15 @@ import org.springframework.data.cassandra.repository.support.SimpleCassandraRepo
|
||||
import org.springframework.data.cassandra.repository.support.SimpleReactiveCassandraRepository;
|
||||
import org.springframework.data.repository.util.ReactiveWrappers;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
import com.datastax.oss.driver.api.core.cql.BatchStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.BoundStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
import com.datastax.oss.driver.api.core.session.Request;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} for repository types and entity callbacks.
|
||||
@@ -40,6 +50,9 @@ class CassandraRuntimeHints implements RuntimeHintsRegistrar {
|
||||
private static final boolean PROJECT_REACTOR_PRESENT = ReactiveWrappers
|
||||
.isAvailable(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
|
||||
|
||||
private static final boolean OBSERVABILITY_PRESENT = ClassUtils
|
||||
.isPresent("io.micrometer.observation.ObservationRegistry", CassandraRuntimeHints.class.getClassLoader());
|
||||
|
||||
@Override
|
||||
public void registerHints(org.springframework.aot.hint.RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
|
||||
@@ -57,5 +70,27 @@ class CassandraRuntimeHints implements RuntimeHintsRegistrar {
|
||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
}
|
||||
|
||||
if (OBSERVABILITY_PRESENT) {
|
||||
|
||||
List<Class<?>> statementInterfaces = Arrays.asList(BatchStatement.class, PreparedStatement.class,
|
||||
BoundStatement.class, SimpleStatement.class, Statement.class);
|
||||
|
||||
hints.reflection().registerTypes(statementInterfaces.stream().map(TypeReference::of).toList(), builder -> builder
|
||||
.withMembers(MemberCategory.INTROSPECT_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
|
||||
TypeReference obsSupplier = TypeReference
|
||||
.of("org.springframework.data.cassandra.observability.CassandraObservationSupplier");
|
||||
hints.reflection().registerTypes(List.of(obsSupplier), builder -> builder
|
||||
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
|
||||
for (Class<?> statementInterface : statementInterfaces) {
|
||||
hints.proxies().registerJdkProxy(TypeReference.of(statementInterface), TypeReference.of(Request.class),
|
||||
obsSupplier);
|
||||
}
|
||||
|
||||
hints.proxies().registerJdkProxy(CqlSession.class);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user