Skip to content

Commit

Permalink
Rename AgentReflectionUtil (apache#23062)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 23, 2022
1 parent 5ccb3b9 commit f1bedeb
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.lang.reflect.Method;

/**
* Reflection utility.
* Agent reflection utility.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ReflectionUtil {
public final class AgentReflectionUtil {

/**
* Get field value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public final class ReflectionUtilTest {
public final class AgentReflectionUtilTest {

@Test
public void assertGetFieldValue() {
ReflectionFixture reflectionFixture = new ReflectionFixture("foo");
assertThat(ReflectionUtil.getFieldValue(reflectionFixture, "value"), is(reflectionFixture.getValue()));
assertThat(AgentReflectionUtil.getFieldValue(reflectionFixture, "value"), is(reflectionFixture.getValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;

import io.prometheus.client.Counter;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -32,7 +32,7 @@ public void assertCreate() {
CounterWrapper counterWrapper = new CounterWrapper(counter);
counterWrapper.inc();
counterWrapper.inc(1);
counter = (Counter) ReflectionUtil.getFieldValue(counterWrapper, "counter");
counter = (Counter) AgentReflectionUtil.getFieldValue(counterWrapper, "counter");
assertThat(counter.get(), is(2.0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;

import io.prometheus.client.Gauge;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -32,7 +32,7 @@ public void assertCreate() {
GaugeWrapper gaugeWrapper = new GaugeWrapper(gauge);
gaugeWrapper.inc();
gaugeWrapper.inc(1);
gauge = (Gauge) ReflectionUtil.getFieldValue(gaugeWrapper, "gauge");
gauge = (Gauge) AgentReflectionUtil.getFieldValue(gaugeWrapper, "gauge");
assertThat(gauge.get(), is(2.0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;

import io.prometheus.client.Histogram;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -31,7 +31,7 @@ public void assertCreate() {
Histogram histogram = Histogram.build().name("a").help("help").create();
HistogramWrapper histogramWrapper = new HistogramWrapper(histogram);
histogramWrapper.observe(1);
histogram = (Histogram) ReflectionUtil.getFieldValue(histogramWrapper, "histogram");
histogram = (Histogram) AgentReflectionUtil.getFieldValue(histogramWrapper, "histogram");
assertThat(histogram.collect().size(), is(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.wrapper.type;

import io.prometheus.client.Summary;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -30,7 +30,7 @@ public final class SummaryWrapperTest {
public void assertCreate() {
SummaryWrapper summaryWrapper = new SummaryWrapper(Summary.build().name("a").help("help").create());
summaryWrapper.observe(1);
Summary summary = (Summary) ReflectionUtil.getFieldValue(summaryWrapper, "summary");
Summary summary = (Summary) AgentReflectionUtil.getFieldValue(summaryWrapper, "summary");
assertThat(summary.collect().size(), is(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.shardingsphere.agent.advice.MethodInvocationResult;
import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.apache.shardingsphere.agent.plugin.tracing.jaeger.constant.JaegerConstants;
import org.apache.shardingsphere.agent.plugin.tracing.jaeger.span.JaegerErrorSpan;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
Expand All @@ -50,7 +50,7 @@ public void beforeMethod(final TargetAdviceObject target, final Method method, f
@Override
public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final MethodInvocationResult invocationResult) {
ExecutorDataMap.getValue().remove(JaegerConstants.ROOT_SPAN);
BackendConnection connection = ((ConnectionSession) ReflectionUtil.getFieldValue(target, "connectionSession")).getBackendConnection();
BackendConnection connection = ((ConnectionSession) AgentReflectionUtil.getFieldValue(target, "connectionSession")).getBackendConnection();
Scope scope = GlobalTracer.get().scopeManager().active();
scope.span().setTag(JaegerConstants.ShardingSphereTags.CONNECTION_COUNT.getKey(), connection.getConnectionSize());
scope.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;

import java.lang.reflect.Method;
import java.sql.DatabaseMetaData;
Expand All @@ -56,8 +56,8 @@ public void beforeMethod(final TargetAdviceObject target, final Method method, f
builder = builder.asChildOf(root);
}
JDBCExecutionUnit executionUnit = (JDBCExecutionUnit) args[0];
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) ReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) ReflectionUtil.invokeMethod(
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) AgentReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) AgentReflectionUtil.invokeMethod(
JDBCExecutorCallback.class.getDeclaredMethod("getDataSourceMetaData", DatabaseMetaData.class, DatabaseType.class),
target, executionUnit.getStorageResource().getConnection().getMetaData(), storageTypes.get(executionUnit.getExecutionUnit().getDataSourceName()));
builder.withTag(Tags.COMPONENT.getKey(), JaegerConstants.COMPONENT_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;

import java.lang.reflect.Method;
import java.sql.DatabaseMetaData;
Expand All @@ -58,8 +58,8 @@ public void beforeMethod(final TargetAdviceObject target, final Method method, f
spanBuilder.setAttribute(OpenTelemetryConstants.COMPONENT, OpenTelemetryConstants.COMPONENT_NAME);
spanBuilder.setAttribute(OpenTelemetryConstants.DB_TYPE, OpenTelemetryConstants.DB_TYPE_VALUE);
JDBCExecutionUnit executionUnit = (JDBCExecutionUnit) args[0];
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) ReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) ReflectionUtil.invokeMethod(
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) AgentReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) AgentReflectionUtil.invokeMethod(
JDBCExecutorCallback.class.getDeclaredMethod("getDataSourceMetaData", DatabaseMetaData.class, DatabaseType.class),
target, executionUnit.getStorageResource().getConnection().getMetaData(), storageTypes.get(executionUnit.getExecutionUnit().getDataSourceName()));
spanBuilder.setAttribute(OpenTelemetryConstants.DB_INSTANCE, executionUnit.getExecutionUnit().getDataSourceName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.shardingsphere.agent.advice.MethodInvocationResult;
import org.apache.shardingsphere.agent.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;
import org.apache.shardingsphere.agent.plugin.tracing.zipkin.constant.ZipkinConstants;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
import org.apache.shardingsphere.proxy.backend.communication.BackendConnection;
Expand All @@ -46,7 +46,7 @@ public void beforeMethod(final TargetAdviceObject target, final Method method, f

@Override
public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final MethodInvocationResult invocationResult) {
BackendConnection connection = ((ConnectionSession) ReflectionUtil.getFieldValue(target, "connectionSession")).getBackendConnection();
BackendConnection connection = ((ConnectionSession) AgentReflectionUtil.getFieldValue(target, "connectionSession")).getBackendConnection();
Span span = (Span) ExecutorDataMap.getValue().remove(ZipkinConstants.ROOT_SPAN);
span.tag(ZipkinConstants.Tags.CONNECTION_COUNT, String.valueOf(connection.getConnectionSize()));
span.finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback;
import org.apache.shardingsphere.agent.core.util.ReflectionUtil;
import org.apache.shardingsphere.agent.core.util.AgentReflectionUtil;

import java.lang.reflect.Method;
import java.sql.DatabaseMetaData;
Expand All @@ -51,8 +51,8 @@ public void beforeMethod(final TargetAdviceObject target, final Method method, f
span.tag(ZipkinConstants.Tags.COMPONENT, ZipkinConstants.COMPONENT_NAME);
span.tag(ZipkinConstants.Tags.DB_TYPE, ZipkinConstants.DB_TYPE_VALUE);
JDBCExecutionUnit executionUnit = (JDBCExecutionUnit) args[0];
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) ReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) ReflectionUtil.invokeMethod(
Map<String, DatabaseType> storageTypes = (Map<String, DatabaseType>) AgentReflectionUtil.getFieldValue(target, "storageTypes");
DataSourceMetaData metaData = (DataSourceMetaData) AgentReflectionUtil.invokeMethod(
JDBCExecutorCallback.class.getDeclaredMethod("getDataSourceMetaData", DatabaseMetaData.class, DatabaseType.class),
target, executionUnit.getStorageResource().getConnection().getMetaData(), storageTypes.get(executionUnit.getExecutionUnit().getDataSourceName()));
span.tag(ZipkinConstants.Tags.DB_INSTANCE, executionUnit.getExecutionUnit().getDataSourceName());
Expand Down

0 comments on commit f1bedeb

Please sign in to comment.