Skip to content

Commit

Permalink
Merge pull request #1286 from tuohai666/dev
Browse files Browse the repository at this point in the history
#1172, add connection.count
  • Loading branch information
terrymanu authored Sep 20, 2018
2 parents 78431e1 + 37463ef commit 89a1fd0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
@Getter
public final class GetConnectionFinishEvent extends GetConnectionEvent {

private final int connectionCount;

private final DataSourceMetaData dataSourceMetaData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private List<Connection> createConnections(final DataSource dataSource, final in
}

private void postGetConnectionEvent(final List<Connection> connections) throws SQLException {
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(DataSourceMetaDataFactory.newInstance(databaseType, connections.get(0).getMetaData().getURL()));
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(connections.size(), DataSourceMetaDataFactory.newInstance(databaseType, connections.get(0).getMetaData().getURL()));
finishEvent.setExecuteSuccess();
ShardingEventBusInstance.getInstance().post(finishEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public final class ShardingTags {
* Records the bind variables of SQL.
*/
public static final StringTag DB_BIND_VARIABLES = new StringTag("db.bind_vars");

/**
* Records the connection count.
*/
public static final StringTag CONNECTION_COUNT = new StringTag("connection.count");
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ protected void tracingFinish(final GetConnectionEvent event) {
GetConnectionFinishEvent finishEvent = (GetConnectionFinishEvent) event;
Span span = getSpan().get();
if (null != finishEvent.getDataSourceMetaData()) {
span = span.setTag(Tags.PEER_HOSTNAME.getKey(), finishEvent.getDataSourceMetaData().getHostName()).setTag(Tags.PEER_PORT.getKey(), finishEvent.getDataSourceMetaData().getPort());
span = span.setTag(Tags.PEER_HOSTNAME.getKey(), finishEvent.getDataSourceMetaData().getHostName())
.setTag(ShardingTags.CONNECTION_COUNT.getKey(), ((GetConnectionFinishEvent) event).getConnectionCount())
.setTag(Tags.PEER_PORT.getKey(), finishEvent.getDataSourceMetaData().getPort());
}
span.finish();
getSpan().remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ public List<Connection> getConnections(final String dataSourceName, final int co
ShardingEventBusInstance.getInstance().post(new GetConnectionStartEvent(dataSourceName));
List<Connection> result = ruleRegistry.getBackendDataSource().getConnections(dataSourceName, connectionSize);
cachedConnections.addAll(result);
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, result.get(0).getMetaData().getURL()));
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(result.size(), DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, result.get(0).getMetaData().getURL()));
finishEvent.setExecuteSuccess();
ShardingEventBusInstance.getInstance().post(finishEvent);
return result;
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(null);
GetConnectionEvent finishEvent = new GetConnectionFinishEvent(0, null);
finishEvent.setExecuteFailure(ex);
ShardingEventBusInstance.getInstance().post(finishEvent);
throw ex;
Expand Down

0 comments on commit 89a1fd0

Please sign in to comment.