Skip to content

Commit

Permalink
Define logging levels and log clean up (#705)
Browse files Browse the repository at this point in the history
Closes #666
  • Loading branch information
jwaeab authored Aug 30, 2024
1 parent c6fd1e9 commit baeac37
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 105 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changes
## Version 5.0.5

* Define logging levels formally - Issue #666
* Deprecate cassandra-all to use testContainers instead - Issue #701
* Updata Mockito and JUnit versions - Issue #687
* Update Mockito and JUnit versions - Issue #687
* Metric status logger for troubleshooting - Issue #397

## Version 5.0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public DefaultJmxConnectionProvider(final Config config,
int port = jmxConfig.getPort();
boolean authEnabled = jmxSecurity.get().getJmxCredentials().isEnabled();
boolean tlsEnabled = jmxSecurity.get().getJmxTlsConfig().isEnabled();
LOG.info("Connecting through JMX using {}:{}, authentication: {}, tls: {}", host, port, authEnabled,
LOG.info("Connecting through JMX using {}:{}, authentication: {}, tls: {}",
host,
port,
authEnabled,
tlsEnabled);

Supplier<String[]> credentials = () -> convertCredentials(jmxSecurity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public DefaultNativeConnectionProvider(final Config config,
Security.CqlSecurity cqlSecurity = cqlSecuritySupplier.get();
boolean authEnabled = cqlSecurity.getCqlCredentials().isEnabled();
boolean tlsEnabled = cqlSecurity.getCqlTlsConfig().isEnabled();
LOG.info("Connecting through CQL using {}:{}, authentication: {}, tls: {}", host, port, authEnabled,
LOG.info("Connecting through CQL using {}:{}, authentication: {}, tls: {}",
host,
port,
authEnabled,
tlsEnabled);
AuthProvider authProvider = null;
if (authEnabled)
Expand Down Expand Up @@ -151,11 +154,11 @@ private static void handleRetry(
{
Thread.sleep(delay);
}
catch (InterruptedException e1)
catch (InterruptedException ie)
{
LOG.error(
"InterruptedException caught during the delay time, while trying to reconnect to Cassandra. Reason: ",
e1);
ie);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public void repairState(final TableReference tableReference,
final int repairedRanges,
final int notRepairedRanges)
{
LOG.trace("Updated repair state of {}, {}/{} repaired ranges", tableReference, repairedRanges,
LOG.trace("Updated repair state of {}, {}/{} repaired ranges",
tableReference,
repairedRanges,
notRepairedRanges);
}

Expand All @@ -243,11 +245,10 @@ public void repairSession(final TableReference tableReference,
final TimeUnit timeUnit,
final boolean successful)
{
if (LOG.isTraceEnabled())
{
LOG.trace("Repair timing for table {} {}ms, it was {}", tableReference,
timeUnit.toMillis(timeTaken), successful ? "successful" : "not successful");
}
LOG.trace("Repair timing for table {} {}ms, it was {}successful",
tableReference,
timeUnit.toMillis(timeTaken),
successful ? "" : "not ");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ protected final Context getContext()
tlsConfig = myCqlTLSConfigSupplier.get();
}
}
catch (NoSuchAlgorithmException | IOException | UnrecoverableKeyException | CertificateException
| KeyStoreException | KeyManagementException e)
catch (NoSuchAlgorithmException
| IOException
| UnrecoverableKeyException
| CertificateException
| KeyStoreException
| KeyManagementException
e)
{
LOG.warn("Unable to create new SSL Context after configuration changed. Trying with the old one", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void main(final String[] args)
}
catch (IOException e)
{
LOG.error("Error converting Ecc YAML file to markdown file", e);
LOG.error("Error converting ecc YAML file to markdown file", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public final void validate(final String repairConfigType)
if (repairIntervalSeconds < initialDelaySeconds)
{
LOG.warn("{} repair interval ({}s) is shorter than initial delay ({}s). Will use {}s as initial delay.",
repairConfigType, repairIntervalSeconds, initialDelaySeconds, repairIntervalSeconds);
repairConfigType,
repairIntervalSeconds,
initialDelaySeconds,
repairIntervalSeconds);
myInitialDelay = new Interval(myRepairInterval.getTime(), myRepairInterval.getUnit());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private boolean isJmxConnectionUp(final Map<String, Object> details)
}
catch (Exception e)
{
LOG.debug("Unable to connect over JMX", e);
LOG.error("Unable to connect over JMX", e);
details.put("JMX connection error:", e.getMessage());
}
return false;
Expand All @@ -92,7 +92,7 @@ private boolean isCqlConnectionUp(final Map<String, Object> details)
}
catch (Exception e)
{
LOG.debug("Unable to connect over CQL", e);
LOG.error("Unable to connect over CQL", e);
details.put("CQL connection error:", e.getMessage());
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ private void reconnect() throws IOException
boolean authEnabled = credentials != null;
boolean tlsEnabled = !tls.isEmpty();

LOG.debug("Connecting JMX through {}, credentials: {}, tls: {}", jmxUrl, authEnabled, tlsEnabled);
JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl, env);
LOG.debug("Connected JMX for {}", jmxUrl);
LOG.debug("Connected JMX for {}, credentials: {}, tls: {}", jmxUrl, authEnabled, tlsEnabled);

switchJmxConnection(jmxConnector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ private static CqlSession createSession(final Builder builder)

InitialContact initialContact = resolveInitialContact(contactEndPoint, builder);

LOG.debug("Connecting to {}({}), local data center: {}", contactEndPoint, initialContact.getHostId(),
LOG.debug("Connecting to {} ({}), local data center: {}",
contactEndPoint,
initialContact.getHostId(),
initialContact.getDataCenter());

CqlSessionBuilder sessionBuilder = fromBuilder(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public final void activate(final Configuration configuration)
Optional<DriverNode> localNode = nodeResolver.fromUUID(node.getHostId());
if (!localNode.isPresent())
{
LOG.error("Local node ({}) not found in resolver", node.getHostId());
throw new IllegalStateException("Local node (" + node.getHostId() + ") not found in resolver");
String msg = String.format("Local node (%s) not found in resolver", node.getHostId());
LOG.error(msg);
throw new IllegalStateException(msg);
}

long lookbackTimeInMillis = configuration.lookbackTimeSeconds() * ONE_SECOND_MILLIS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void close()
else
{
LOG.debug("Locally highest priority ({}) is higher than current ({}), will not remove",
myLocallyHighestPriority, myPriority);
myLocallyHighestPriority,
myPriority);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,33 +311,33 @@ private int liveNodes(final Collection<Node> nodes)
private void verifySchemasExists()
{
Optional<KeyspaceMetadata> keyspaceMetadata = myCasLockProperties
.getSession().getMetadata()
.getSession().getMetadata()
.getKeyspace(myCasLockProperties.getKeyspaceName());

if (!keyspaceMetadata.isPresent())
{
LOG.error("Keyspace {} does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName());
throw new IllegalStateException(
String.format("Keyspace %s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName()));
String msg = String.format("Keyspace %s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName());
LOG.error(msg);
throw new IllegalStateException(msg);
}

if (!keyspaceMetadata.get().getTable(TABLE_LOCK).isPresent())
{
LOG.error("Table {}.{} does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(), TABLE_LOCK);
throw new IllegalStateException(
String.format("Table %s.%s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(), TABLE_LOCK));
String msg = String.format("Table %s.%s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(),
TABLE_LOCK);
LOG.error(msg);
throw new IllegalStateException(msg);
}

if (!keyspaceMetadata.get().getTable(TABLE_LOCK_PRIORITY).isPresent())
{
LOG.error("Table {}.{} does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(), TABLE_LOCK_PRIORITY);
throw new IllegalStateException(
String.format("Table %s.%s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(), TABLE_LOCK_PRIORITY));
String msg = String.format("Table %s.%s does not exist, it needs to be created",
myCasLockProperties.getKeyspaceName(),
TABLE_LOCK_PRIORITY);
LOG.error(msg);
throw new IllegalStateException(msg);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ private CassandraMetric getMetrics(final TableReference tableReference) throws I
}
catch (IOException e)
{
THROTTLED_LOGGER.warn("Unable to fetch metrics from Cassandra, future metrics might contain stale values",
THROTTLED_LOGGER.warn(
"Unable to fetch metrics from Cassandra, future metrics might contain stale values",
e);
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private synchronized boolean tryRefreshHostStates()

if (changeHostState(host, true))
{
LOG.debug("Host {} marked as up", host);
LOG.debug("Host {} marked as UP", host);
}
}

Expand All @@ -129,7 +129,7 @@ private synchronized boolean tryRefreshHostStates()

if (changeHostState(host, false))
{
LOG.debug("Host {} marked as down", host);
LOG.debug("Host {} marked as DOWN", host);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ public void forceTerminateAllRepairSessions()
FORCE_TERMINATE_ALL_REPAIR_SESSIONS_METHOD,
null, null);
}
catch (InstanceNotFoundException | MBeanException | ReflectionException | IOException e)
catch (InstanceNotFoundException
| MBeanException
| ReflectionException
| IOException e)
{
LOG.error("Unable to terminate repair sessions");
}
Expand All @@ -214,7 +217,9 @@ public void removeStorageServiceListener(final NotificationListener listener)
myJmxConnector.removeConnectionNotificationListener(listener);
myMbeanServerConnection.removeNotificationListener(myStorageServiceObject, listener);
}
catch (InstanceNotFoundException | ListenerNotFoundException | IOException e)
catch (InstanceNotFoundException
| ListenerNotFoundException
| IOException e)
{
LOG.error("Unable to remove StorageService listener", e);
}
Expand All @@ -232,8 +237,7 @@ public long liveDiskSpaceUsed(final TableReference tableReference)
{
try
{
ObjectName objectName
= new ObjectName(String
ObjectName objectName = new ObjectName(String
.format("org.apache.cassandra.metrics:type=Table,keyspace=%s,scope=%s,name=LiveDiskSpaceUsed",
tableReference.getKeyspace(), tableReference.getTable()));

Expand Down Expand Up @@ -277,7 +281,10 @@ public long getMaxRepairedAt(final TableReference tableReference)
return maxRepaired;
}
}
catch (InstanceNotFoundException | MBeanException | ReflectionException | IOException e)
catch (InstanceNotFoundException
| MBeanException
| ReflectionException
| IOException e)
{
LOG.error("Unable to get maxRepaired for {}", tableReference, e);
}
Expand All @@ -289,8 +296,7 @@ public double getPercentRepaired(final TableReference tableReference)
{
try
{
ObjectName objectName
= new ObjectName(String
ObjectName objectName = new ObjectName(String
.format("org.apache.cassandra.metrics:type=Table,keyspace=%s,scope=%s,name=PercentRepaired",
tableReference.getKeyspace(), tableReference.getTable()));

Expand All @@ -317,10 +323,10 @@ public String getNodeStatus()
return (String) myMbeanServerConnection.getAttribute(myStorageServiceObject, "OperationMode");
}
catch (InstanceNotFoundException
| AttributeNotFoundException
| MBeanException
| ReflectionException
| IOException e)
| AttributeNotFoundException
| MBeanException
| ReflectionException
| IOException e)
{
LOG.error("Unable to retrieve node status {}", e.getMessage());
return "Unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void close()
}
catch (Exception e)
{
LOG.warn("Unable to release lock {} ", lock, e);
LOG.warn("Unable to release lock {}", lock, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,18 @@ private void verifySchemasExists()
Optional<KeyspaceMetadata> keyspaceMetadata = mySession.getMetadata().getKeyspace(myKeyspaceName);
if (!keyspaceMetadata.isPresent())
{
LOG.error("Keyspace {} does not exist, it needs to be created", myKeyspaceName);
throw new IllegalStateException("Keyspace " + myKeyspaceName
+ " does not exist, it needs to be created");
String msg = String.format("Keyspace %s does not exist, it needs to be created", myKeyspaceName);
LOG.error(msg);
throw new IllegalStateException(msg);
}

if (!keyspaceMetadata.get().getTable(TABLE_REJECT_CONFIGURATION).isPresent())
{
LOG.error("Table {}.{} does not exist, it needs to be created",
myKeyspaceName, TABLE_REJECT_CONFIGURATION);
throw new IllegalStateException("Table " + myKeyspaceName + "."
+ TABLE_REJECT_CONFIGURATION + " does not exist, it needs to be created");
String msg = String.format("Table %s.%s does not exist, it needs to be created",
myKeyspaceName,
TABLE_REJECT_CONFIGURATION);
LOG.error(msg);
throw new IllegalStateException(msg);
}
}
}
Expand Down Expand Up @@ -338,7 +339,7 @@ private long getRejectionsForTable(final TableReference tableReference)
}
catch (Exception e)
{
LOG.error("Unable to parse/fetch rejection time for {}", tableReference, e);
LOG.warn("Unable to parse/fetch rejection time for {}", tableReference, e);
rejectTime = DEFAULT_REJECT_TIME;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public void finishJob()
if (myTasks.isEmpty())
{
getOngoingJob().finishJob();
LOG.info("Completed Incremental On Demand Repair: {}", id);
LOG.info("Completed incremental on demand repair: {}", id);
}
if (hasFailed())
{
getOngoingJob().failJob();
LOG.error("Failed Incremental On Demand Repair: {}", id);
LOG.error("Failed incremental on demand repair: {}", id);
}
super.finishJob();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private void getOngoingJobs()
}
catch (Exception e)
{
LOG.info("Failed to get ongoing ondemand jobs: {}, automatic retry in {}s", e.getMessage(),
LOG.warn("Failed to get ongoing on demand jobs: {}, automatic retry in {}s",
e.getMessage(),
ONGOING_JOBS_PERIOD_SECONDS);
}
}
Expand Down
Loading

0 comments on commit baeac37

Please sign in to comment.