Skip to content

Commit 3ec5668

Browse files
committed
Implement appender of slow queries to system_views.slow_queries table
patch by Stefan Miklosovic; reviewed by Dmitry Konstantinov, Bernardo Botella for CASSANDRA-13001
1 parent 2e602ec commit 3ec5668

25 files changed

+1534
-352
lines changed

conf/cassandra.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,10 @@ request_timeout: 10000ms
13961396
# How long before a node logs slow queries. Select queries that take longer than
13971397
# this timeout to execute, will generate an aggregated log message, so that slow queries
13981398
# can be identified. Set this value to zero to disable slow query logging.
1399+
#
1400+
# It is possible to log slow queries into system_views.slow_queries virtual table.
1401+
# Consult logback.xml to uncomment specific appender and logger to enable this functionality.
1402+
#
13991403
# Min unit: ms
14001404
slow_query_log_timeout: 500ms
14011405

conf/logback.xml

+13
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ appender reference in the root level section below.
119119
</filter>
120120
</appender> -->
121121

122+
<!-- Uncomment below configuration and corresponding appender-ref in slow_queries logger to activate
123+
logging into system_views.slow_queries virtual table. -->
124+
<!-- <appender name="SLOW_QUERIES_TO_VTABLE" class="org.apache.cassandra.utils.logging.SlowQueriesAppender"/> -->
125+
126+
<!-- Log slow queries to system_views.slow_queries virtual table -->
127+
<logger name="slow_queries" additivity="false" level="DEBUG">
128+
<appender-ref ref="DEBUGLOG"/>
129+
<!-- uncomment this appender reference together with appender definition above
130+
to start to put slow queries into system_views.slow_queries virtual table
131+
<appender-ref ref="SLOW_QUERIES_TO_VTABLE"/>
132+
-->
133+
</logger>
134+
122135
<root level="INFO">
123136
<appender-ref ref="SYSTEMLOG" />
124137
<appender-ref ref="STDOUT" />

src/java/org/apache/cassandra/config/CassandraRelevantProperties.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import accord.utils.Invariants;
2929
import org.apache.cassandra.db.virtual.LogMessagesTable;
30+
import org.apache.cassandra.db.virtual.SlowQueriesTable;
3031
import org.apache.cassandra.exceptions.ConfigurationException;
3132
import org.apache.cassandra.utils.FBUtilities;
3233
import org.apache.cassandra.utils.StorageCompatibilityMode;
@@ -363,6 +364,8 @@ public enum CassandraRelevantProperties
363364
LOG4J2_DISABLE_JMX_LEGACY("log4j2.disable.jmx"),
364365
LOG4J_SHUTDOWN_HOOK_ENABLED("log4j.shutdownHookEnabled"),
365366
LOGBACK_CONFIGURATION_FILE("logback.configurationFile"),
367+
/** Maximum number of rows in system_views.slow_queries */
368+
LOGS_SLOW_QUERIES_VIRTUAL_TABLE_MAX_ROWS("cassandra.virtual.slow_queries.max.rows", convertToString(SlowQueriesTable.LOGS_VIRTUAL_TABLE_DEFAULT_ROWS)),
366369
/** Maximum number of rows in system_views.logs table */
367370
LOGS_VIRTUAL_TABLE_MAX_ROWS("cassandra.virtual.logs.max.rows", convertToString(LogMessagesTable.LOGS_VIRTUAL_TABLE_DEFAULT_ROWS)),
368371
/**

src/java/org/apache/cassandra/db/AbstractReadQuery.java

+12
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,16 @@ public String toCQLString()
118118
}
119119

120120
protected abstract void appendCQLWhereClause(StringBuilder sb);
121+
122+
@Override
123+
public String monitoredOnKeyspace()
124+
{
125+
return metadata().keyspace;
126+
}
127+
128+
@Override
129+
public String monitoredOnTable()
130+
{
131+
return metadata().name;
132+
}
121133
}

src/java/org/apache/cassandra/db/monitoring/Monitorable.java

+74
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
public interface Monitorable
2222
{
23+
Monitorable NO_OP = new NoOp();
24+
2325
String name();
2426
long creationTimeNanos();
2527
long timeoutNanos();
@@ -33,4 +35,76 @@ public interface Monitorable
3335

3436
boolean abort();
3537
boolean complete();
38+
39+
default String monitoredOnKeyspace() { return null; };
40+
default String monitoredOnTable() { return null; };
41+
42+
class NoOp implements Monitorable
43+
{
44+
@Override
45+
public String name()
46+
{
47+
return null;
48+
}
49+
50+
@Override
51+
public long creationTimeNanos()
52+
{
53+
return 0;
54+
}
55+
56+
@Override
57+
public long timeoutNanos()
58+
{
59+
return 0;
60+
}
61+
62+
@Override
63+
public long slowTimeoutNanos()
64+
{
65+
return 0;
66+
}
67+
68+
@Override
69+
public boolean isInProgress()
70+
{
71+
return false;
72+
}
73+
74+
@Override
75+
public boolean isAborted()
76+
{
77+
return false;
78+
}
79+
80+
@Override
81+
public boolean isCompleted()
82+
{
83+
return false;
84+
}
85+
86+
@Override
87+
public boolean isSlow()
88+
{
89+
return false;
90+
}
91+
92+
@Override
93+
public boolean isCrossNode()
94+
{
95+
return false;
96+
}
97+
98+
@Override
99+
public boolean abort()
100+
{
101+
return false;
102+
}
103+
104+
@Override
105+
public boolean complete()
106+
{
107+
return false;
108+
}
109+
}
36110
}

0 commit comments

Comments
 (0)