Merge pull request #556 from datastax/435
PYTHON-435 - client-settable CL for trace queries
This commit is contained in:
@@ -3240,32 +3240,34 @@ class ResponseFuture(object):
|
||||
"""
|
||||
return [trace.trace_id for trace in self._query_traces]
|
||||
|
||||
def get_query_trace(self, max_wait=None):
|
||||
def get_query_trace(self, max_wait=None, query_cl=ConsistencyLevel.LOCAL_ONE):
|
||||
"""
|
||||
Fetches and returns the query trace of the last response, or `None` if tracing was
|
||||
not enabled.
|
||||
|
||||
Note that this may raise an exception if there are problems retrieving the trace
|
||||
details from Cassandra. If the trace is not available after `max_wait_sec`,
|
||||
details from Cassandra. If the trace is not available after `max_wait`,
|
||||
:exc:`cassandra.query.TraceUnavailable` will be raised.
|
||||
|
||||
`query_cl` is the consistency level used to poll the trace tables.
|
||||
"""
|
||||
if self._query_traces:
|
||||
return self._get_query_trace(len(self._query_traces) - 1, max_wait)
|
||||
return self._get_query_trace(len(self._query_traces) - 1, max_wait, query_cl)
|
||||
|
||||
def get_all_query_traces(self, max_wait_per=None):
|
||||
def get_all_query_traces(self, max_wait_per=None, query_cl=ConsistencyLevel.LOCAL_ONE):
|
||||
"""
|
||||
Fetches and returns the query traces for all query pages, if tracing was enabled.
|
||||
|
||||
See note in :meth:`~.get_query_trace` regarding possible exceptions.
|
||||
"""
|
||||
if self._query_traces:
|
||||
return [self._get_query_trace(i, max_wait_per) for i in range(len(self._query_traces))]
|
||||
return [self._get_query_trace(i, max_wait_per, query_cl) for i in range(len(self._query_traces))]
|
||||
return []
|
||||
|
||||
def _get_query_trace(self, i, max_wait):
|
||||
def _get_query_trace(self, i, max_wait, query_cl):
|
||||
trace = self._query_traces[i]
|
||||
if not trace.events:
|
||||
trace.populate(max_wait=max_wait)
|
||||
trace.populate(max_wait=max_wait, query_cl=query_cl)
|
||||
return trace
|
||||
|
||||
def add_callback(self, fn, *args, **kwargs):
|
||||
|
||||
@@ -864,7 +864,7 @@ class QueryTrace(object):
|
||||
self.trace_id = trace_id
|
||||
self._session = session
|
||||
|
||||
def populate(self, max_wait=2.0, wait_for_complete=True):
|
||||
def populate(self, max_wait=2.0, wait_for_complete=True, query_cl=None):
|
||||
"""
|
||||
Retrieves the actual tracing details from Cassandra and populates the
|
||||
attributes of this instance. Because tracing details are stored
|
||||
@@ -875,6 +875,9 @@ class QueryTrace(object):
|
||||
|
||||
`wait_for_complete=False` bypasses the wait for duration to be populated.
|
||||
This can be used to query events from partial sessions.
|
||||
|
||||
`query_cl` specifies a consistency level to use for polling the trace tables,
|
||||
if it should be different than the session default.
|
||||
"""
|
||||
attempt = 0
|
||||
start = time.time()
|
||||
@@ -886,7 +889,7 @@ class QueryTrace(object):
|
||||
|
||||
log.debug("Attempting to fetch trace info for trace ID: %s", self.trace_id)
|
||||
session_results = self._execute(
|
||||
self._SELECT_SESSIONS_FORMAT, (self.trace_id,), time_spent, max_wait)
|
||||
SimpleStatement(self._SELECT_SESSIONS_FORMAT, consistency_level=query_cl), (self.trace_id,), time_spent, max_wait)
|
||||
|
||||
is_complete = session_results and session_results[0].duration is not None
|
||||
if not session_results or (wait_for_complete and not is_complete):
|
||||
@@ -910,7 +913,7 @@ class QueryTrace(object):
|
||||
log.debug("Attempting to fetch trace events for trace ID: %s", self.trace_id)
|
||||
time_spent = time.time() - start
|
||||
event_results = self._execute(
|
||||
self._SELECT_EVENTS_FORMAT, (self.trace_id,), time_spent, max_wait)
|
||||
SimpleStatement(self._SELECT_EVENTS_FORMAT, consistency_level=query_cl), (self.trace_id,), time_spent, max_wait)
|
||||
log.debug("Fetched trace events for trace ID: %s", self.trace_id)
|
||||
self.events = tuple(TraceEvent(r.activity, r.event_id, r.source, r.source_elapsed, r.thread)
|
||||
for r in event_results)
|
||||
|
||||
Reference in New Issue
Block a user