From f86bdb97a39867c6288803493e6bd0374c27b4a4 Mon Sep 17 00:00:00 2001 From: kimmking Date: Tue, 25 Aug 2020 17:02:43 +0800 Subject: [PATCH] Rename MetricsUtils methods (#7059) --- .../jdbc/connection/BackendTransactionManager.java | 6 +++--- .../wrapper/PreparedStatementExecutorWrapper.java | 12 ++++++------ .../jdbc/wrapper/StatementExecutorWrapper.java | 4 ++-- .../proxy/backend/metrics/MetricsUtils.java | 12 ++++++------ .../proxy/backend/metrics/MetricsUtilsTest.java | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java index 311ceb1f45..82c5bcb3b2 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java @@ -58,7 +58,7 @@ public final class BackendTransactionManager implements TransactionManager { } else { shardingTransactionManager.begin(); } - MetricsUtils.buriedTransactionMetric("begin"); + MetricsUtils.collectTransactionMetric("begin"); } @Override @@ -70,7 +70,7 @@ public final class BackendTransactionManager implements TransactionManager { } else { shardingTransactionManager.commit(); } - MetricsUtils.buriedTransactionMetric("commit"); + MetricsUtils.collectTransactionMetric("commit"); } finally { connection.getStateHandler().setStatus(ConnectionStatus.TERMINATED); } @@ -86,7 +86,7 @@ public final class BackendTransactionManager implements TransactionManager { } else { shardingTransactionManager.rollback(); } - MetricsUtils.buriedTransactionMetric("rollback"); + MetricsUtils.collectTransactionMetric("rollback"); } finally { connection.getStateHandler().setStatus(ConnectionStatus.TERMINATED); } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java index ddb416b4d6..2a2bbef1ff 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java @@ -68,7 +68,7 @@ public final class PreparedStatementExecutorWrapper implements JDBCExecutorWrapp new CommonSQLStatementContext(sqlStatement), new ExecutionUnit(schema.getSchema().getDataSources().keySet().iterator().next(), new SQLUnit(sql, parameters))); } RouteContext routeContext = new DataNodeRouter(schema.getSchema().getMetaData(), PROXY_SCHEMA_CONTEXTS.getSchemaContexts().getProps(), rules).route(sqlStatement, sql, parameters); - routeMetricsCollect(routeContext, rules); + collectRouteMetrics(routeContext, rules); SQLRewriteEntry sqlRewriteEntry = new SQLRewriteEntry(schema.getSchema().getMetaData().getSchema().getConfiguredSchemaMetaData(), PROXY_SCHEMA_CONTEXTS.getSchemaContexts().getProps(), rules); SQLRewriteResult sqlRewriteResult = sqlRewriteEntry.rewrite(sql, new ArrayList<>(parameters), routeContext); return new ExecutionContext(routeContext.getSqlStatementContext(), ExecutionContextBuilder.build(schema.getSchema().getMetaData(), sqlRewriteResult)); @@ -79,14 +79,14 @@ public final class PreparedStatementExecutorWrapper implements JDBCExecutorWrapp return ((PreparedStatement) statement).execute(); } - private void routeMetricsCollect(final RouteContext routeContext, final Collection rules) { - MetricsUtils.buriedShardingMetrics(routeContext.getRouteResult().getRouteUnits()); - MetricsUtils.buriedShardingRuleMetrics(routeContext, rules); - } - @Override public ExecuteGroupEngine getExecuteGroupEngine(final BackendConnection backendConnection, final StatementOption option) { int maxConnectionsSizePerQuery = PROXY_SCHEMA_CONTEXTS.getSchemaContexts().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); return new PreparedStatementExecuteGroupEngine(maxConnectionsSizePerQuery, backendConnection, option, schema.getSchema().getRules()); } + + private void collectRouteMetrics(final RouteContext routeContext, final Collection rules) { + MetricsUtils.collectRouteUnitMetrics(routeContext.getRouteResult().getRouteUnits()); + MetricsUtils.collectShardingRuleMetrics(routeContext, rules); + } } diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java index a0dccf35ae..8b76bb2084 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java @@ -81,8 +81,8 @@ public final class StatementExecutorWrapper implements JDBCExecutorWrapper { } private void routeMetricsCollect(final RouteContext routeContext, final Collection rules) { - MetricsUtils.buriedShardingMetrics(routeContext.getRouteResult().getRouteUnits()); - MetricsUtils.buriedShardingRuleMetrics(routeContext, rules); + MetricsUtils.collectRouteUnitMetrics(routeContext.getRouteResult().getRouteUnits()); + MetricsUtils.collectShardingRuleMetrics(routeContext, rules); } @Override diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java index a0ba3c4566..81a549fafa 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java @@ -36,11 +36,11 @@ import java.util.Collection; public final class MetricsUtils { /** - * Buried sharding metrics. + * Collect sharding metrics. * * @param routeUnits route units */ - public static void buriedShardingMetrics(final Collection routeUnits) { + public static void collectRouteUnitMetrics(final Collection routeUnits) { if (!routeUnits.isEmpty()) { for (RouteUnit each : routeUnits) { Collection tableMappers = each.getTableMappers(); @@ -55,21 +55,21 @@ public final class MetricsUtils { } /** - * Buried transaction metric. + * Collect transaction metric. * * @param labelValue label value */ - public static void buriedTransactionMetric(final String labelValue) { + public static void collectTransactionMetric(final String labelValue) { SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterIncrement(MetricsLabelEnum.TRANSACTION.getName(), labelValue)); } /** - * Buried sharding rule metrics. + * Collect sharding rule metrics. * * @param routeContext route context * @param rules rules */ - public static void buriedShardingRuleMetrics(final RouteContext routeContext, final Collection rules) { + public static void collectShardingRuleMetrics(final RouteContext routeContext, final Collection rules) { routeContext.getRouteResult().getActualDataSourceNames().forEach(dataSourceName -> rules.forEach(each -> { if (each instanceof ShadowRule && ((ShadowRule) each).getShadowMappings().containsValue(dataSourceName)) { SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterIncrement(MetricsLabelEnum.SHADOW_HIT_TOTAL.getName())); diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtilsTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtilsTest.java index 066ed9bc70..32842dfed1 100644 --- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtilsTest.java +++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtilsTest.java @@ -33,14 +33,14 @@ public final class MetricsUtilsTest { RouteMapper dataSourceMapper = new RouteMapper("ds", "ds_0"); RouteMapper tableMapper = new RouteMapper("t_order", "t_order_0"); RouteUnit unit = new RouteUnit(dataSourceMapper, Collections.singletonList(tableMapper)); - MetricsUtils.buriedShardingMetrics(Collections.singleton(unit)); + MetricsUtils.collectRouteUnitMetrics(Collections.singleton(unit)); } @Test public void testBuriedTransactionMetric() { - MetricsUtils.buriedTransactionMetric("begin"); - MetricsUtils.buriedTransactionMetric("commit"); - MetricsUtils.buriedTransactionMetric("rollback"); + MetricsUtils.collectTransactionMetric("begin"); + MetricsUtils.collectTransactionMetric("commit"); + MetricsUtils.collectTransactionMetric("rollback"); } } -- GitLab