Skip to content

Commit d77492b

Browse files
committed
Added abstract tracing to Cluster and Session.
While building a Cluster object, one can pass a TracingInfo class implementation and it will be used for tracing in all sessions with this cluster from now on.
1 parent b8d43da commit d77492b

File tree

7 files changed

+97
-1
lines changed

7 files changed

+97
-1
lines changed

clirr-ignores.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
Modified by ScyllaDB
1717
-->
1818
<differences>
19+
<difference>
20+
<differenceType>7012</differenceType> <!-- method added to interface -->
21+
<className>com/datastax/driver/core/Session</className>
22+
<method>com.datastax.driver.core.tracing.TracingInfoFactory getTracingInfoFactory()</method>
23+
<justification>New method to get the TracingInfo data factory associated with this Session</justification>
24+
</difference>
1925
<difference>
2026
<differenceType>7004</differenceType> <!-- the number of arguments has changed -->
2127
<className>com/datastax/driver/core/Metadata</className>

driver-core/src/main/java/com/datastax/driver/core/Cluster.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import com.datastax.driver.core.policies.ReconnectionPolicy;
4040
import com.datastax.driver.core.policies.RetryPolicy;
4141
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
42+
import com.datastax.driver.core.tracing.NoopTracingInfoFactory;
43+
import com.datastax.driver.core.tracing.TracingInfoFactory;
4244
import com.datastax.driver.core.utils.MoreFutures;
4345
import com.google.common.annotations.VisibleForTesting;
4446
import com.google.common.base.Functions;
@@ -146,6 +148,8 @@ public class Cluster implements Closeable {
146148

147149
final Manager manager;
148150

151+
private TracingInfoFactory tracingInfoFactory = new NoopTracingInfoFactory();
152+
149153
/**
150154
* Constructs a new Cluster instance.
151155
*
@@ -197,6 +201,25 @@ private Cluster(
197201
this.manager = new Manager(name, contactPoints, configuration, listeners);
198202
}
199203

204+
/**
205+
* The tracingInfo factory class used by this Cluster.
206+
*
207+
* @return the factory used currently by this Cluster.
208+
*/
209+
public TracingInfoFactory getTracingInfoFactory() {
210+
return tracingInfoFactory;
211+
}
212+
213+
/**
214+
* Sets desired factory for tracing information for this Cluster. By default it is {@link
215+
* com.datastax.driver.core.tracing.NoopTracingInfoFactory}
216+
*
217+
* @param tracingInfoFactory the factory to be set for this Cluster.
218+
*/
219+
public void setTracingInfoFactory(TracingInfoFactory tracingInfoFactory) {
220+
this.tracingInfoFactory = tracingInfoFactory;
221+
}
222+
200223
/**
201224
* Initialize this Cluster instance.
202225
*

driver-core/src/main/java/com/datastax/driver/core/Session.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
17+
/*
18+
* Copyright (C) 2021 ScyllaDB
19+
*
20+
* Modified by ScyllaDB
21+
*/
1622
package com.datastax.driver.core;
1723

1824
import com.datastax.driver.core.exceptions.AuthenticationException;
1925
import com.datastax.driver.core.exceptions.NoHostAvailableException;
2026
import com.datastax.driver.core.exceptions.QueryExecutionException;
2127
import com.datastax.driver.core.exceptions.QueryValidationException;
2228
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
29+
import com.datastax.driver.core.tracing.TracingInfoFactory;
2330
import com.google.common.util.concurrent.ListenableFuture;
2431
import java.io.Closeable;
2532
import java.util.Collection;
@@ -41,6 +48,13 @@
4148
*/
4249
public interface Session extends Closeable {
4350

51+
/**
52+
* The tracingInfo factory class used by this Session.
53+
*
54+
* @return the factory used currently by this Session.
55+
*/
56+
TracingInfoFactory getTracingInfoFactory();
57+
4458
/**
4559
* The keyspace to which this Session is currently logged in, if any.
4660
*

driver-core/src/main/java/com/datastax/driver/core/SessionManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.datastax.driver.core.policies.LoadBalancingPolicy;
3030
import com.datastax.driver.core.policies.ReconnectionPolicy;
3131
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
32+
import com.datastax.driver.core.tracing.TracingInfoFactory;
3233
import com.datastax.driver.core.utils.MoreFutures;
3334
import com.google.common.base.Functions;
3435
import com.google.common.collect.ImmutableList;
@@ -76,6 +77,11 @@ class SessionManager extends AbstractSession {
7677
this.poolsState = new HostConnectionPool.PoolState();
7778
}
7879

80+
@Override
81+
public TracingInfoFactory getTracingInfoFactory() {
82+
return cluster.getTracingInfoFactory();
83+
}
84+
7985
@Override
8086
public Session init() {
8187
try {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2021 ScyllaDB
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.datastax.driver.core.tracing;
18+
19+
public class NoopTracingInfoFactory implements TracingInfoFactory {
20+
21+
private static class NoopTracingInfo implements TracingInfo {
22+
@Override
23+
public void setNameAndStartTime(String name) {}
24+
25+
@Override
26+
public void tracingFinished() {}
27+
}
28+
29+
public static final NoopTracingInfo INSTANCE = new NoopTracingInfo();
30+
31+
@Override
32+
public TracingInfo buildTracingInfo() {
33+
return INSTANCE;
34+
}
35+
36+
@Override
37+
public TracingInfo buildTracingInfo(TracingInfo parent) {
38+
return new NoopTracingInfo();
39+
}
40+
}

driver-core/src/test/java/com/datastax/driver/core/AsyncQueryTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static org.testng.Assert.assertTrue;
2828

2929
import com.datastax.driver.core.exceptions.InvalidQueryException;
30+
import com.datastax.driver.core.tracing.TracingInfoFactory;
3031
import com.datastax.driver.core.utils.CassandraVersion;
3132
import com.google.common.base.Function;
3233
import com.google.common.base.Throwables;
@@ -286,6 +287,11 @@ public ResultSet execute(Statement statement) {
286287
return executeAsync(statement).getUninterruptibly();
287288
}
288289

290+
@Override
291+
public TracingInfoFactory getTracingInfoFactory() {
292+
return session.getTracingInfoFactory();
293+
}
294+
289295
@Override
290296
public String getLoggedKeyspace() {
291297
return session.getLoggedKeyspace();

driver-core/src/test/java/com/datastax/driver/core/DelegatingClusterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import org.testng.annotations.Test;
3030

3131
public class DelegatingClusterTest {
32-
private static final Set<String> NON_DELEGATED_METHODS = ImmutableSet.of("getClusterName");
32+
private static final Set<String> NON_DELEGATED_METHODS =
33+
ImmutableSet.of("getClusterName", "setTracingInfoFactory", "getTracingInfoFactory");
3334

3435
/**
3536
* Checks that all methods of {@link DelegatingCluster} invoke their counterpart in {@link

0 commit comments

Comments
 (0)