private List<ServerAddress> extractServerAddresses(MongoClient client) { Cluster cluster = (Cluster) ReflectionTestUtils.getField(client, "cluster"); ClusterSettings clusterSettings = (ClusterSettings) ReflectionTestUtils .getField(cluster, "settings"); List<ServerAddress> allAddresses = clusterSettings.getHosts(); return allAddresses; }
@Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { Cluster cluster = (Cluster)allArguments[0]; StringBuilder peers = new StringBuilder(); for (ServerDescription description : cluster.getDescription().getServerDescriptions()) { ServerAddress address = description.getAddress(); peers.append(address.getHost() + ":" + address.getPort() + ";"); } objInst.setSkyWalkingDynamicField(peers.subSequence(0, peers.length() - 1).toString()); }
private String extractUrl(MongoDbFactory mongoDbFactory) { Cluster cluster = invokeMethod(this.<MongoClient>getField(mongoDbFactory, "mongoClient"), "getCluster"); return cluster.getSettings().getHosts().stream() .map(serverAddress -> String.format("mongodb://%s:%d/%s", serverAddress.getHost(), serverAddress.getPort(), mongoDbFactory.getDb().getName())) .collect(Collectors.joining(",")); }