Skip to content

Commit

Permalink
Add tenantId to driver logs (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi-Du authored Apr 16, 2024
1 parent f7fbb0d commit b56fec3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.RemovalListener;
Expand Down Expand Up @@ -98,6 +100,10 @@ public CQLSessionCache(OperationsConfig operationsConfig, MeterRegistry meterReg
* @throws RuntimeException if database type is not supported
*/
private CqlSession getNewSession(SessionCacheKey cacheKey) {
DriverConfigLoader loader =
DriverConfigLoader.programmaticBuilder()
.withString(DefaultDriverOption.SESSION_NAME, cacheKey.tenantId)
.build();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Creating new session for tenant : {}", cacheKey.tenantId);
}
Expand All @@ -118,6 +124,7 @@ private CqlSession getNewSession(SessionCacheKey cacheKey) {
.withLocalDatacenter(operationsConfig.databaseConfig().localDatacenter())
.addContactPoints(seeds)
.withClassLoader(Thread.currentThread().getContextClassLoader())
.withConfigLoader(loader)
.withApplicationName(APPLICATION_NAME);
// To use username and password, a Base64Encoded text of the credential is passed as token.
// The text needs to be in format Cassandra:Base64(username):Base64(password)
Expand All @@ -144,6 +151,7 @@ private CqlSession getNewSession(SessionCacheKey cacheKey) {
.withLocalDatacenter(operationsConfig.databaseConfig().localDatacenter())
.withClassLoader(Thread.currentThread().getContextClassLoader())
.withApplicationName(APPLICATION_NAME)
.withConfigLoader(loader)
.build();
}
throw new RuntimeException("Unsupported database type: " + databaseConfig.type());
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ stargate:
# change test port from 8081 (used by other SG services)
quarkus:
http:
test-port: 9080
test-port: 9080

0 comments on commit b56fec3

Please sign in to comment.