Skip to content

Commit a93e303

Browse files
Kyle-Verhoogbrettlangdon
authored andcommitted
Revert "[cassandra] Support unicode batched queries" (#739)
1 parent 205ea18 commit a93e303

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

ddtrace/contrib/cassandra/session.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# project
1111
from ddtrace import Pin
12-
from ddtrace.compat import stringify, to_unicode
12+
from ddtrace.compat import stringify
1313

1414
from ...utils.formats import deep_getattr
1515
from ...utils.deprecation import deprecated
@@ -169,7 +169,7 @@ def traced_execute_async(func, instance, args, kwargs):
169169
def _start_span_and_set_tags(pin, query, session, cluster):
170170
service = pin.service
171171
tracer = pin.tracer
172-
span = tracer.trace(cassx.QUERY, service=service, span_type=cassx.TYPE)
172+
span = tracer.trace("cassandra.query", service=service, span_type=cassx.TYPE)
173173
_sanitize_query(span, query)
174174
span.set_tags(_extract_session_metas(session)) # FIXME[matt] do once?
175175
span.set_tags(_extract_cluster_metas(cluster))
@@ -241,8 +241,8 @@ def _sanitize_query(span, query):
241241
elif t == 'BatchStatement':
242242
resource = 'BatchStatement'
243243
q = "; ".join(q[1] for q in query._statements_and_parameters[:2])
244-
span.set_tag(cassx.QUERY, to_unicode(q))
245-
span.set_metric(cassx.BATCH_SIZE, len(query._statements_and_parameters))
244+
span.set_tag("cassandra.query", q)
245+
span.set_metric("cassandra.batch_size", len(query._statements_and_parameters))
246246
elif t == 'BoundStatement':
247247
ps = getattr(query, 'prepared_statement', None)
248248
if ps:

ddtrace/ext/cassandra.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@
99
PAGINATED = "cassandra.paginated"
1010
ROW_COUNT = "cassandra.row_count"
1111
PAGE_NUMBER = "cassandra.page_number"
12-
QUERY = "cassandra.query"
13-
BATCH_SIZE = "cassandra.batch_size"

tests/contrib/cassandra/test.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
# -*- coding: utf-8 -*-
21
# stdlib
32
import logging
43
import unittest
54
from threading import Event
65

76
# 3p
7+
from nose.tools import eq_, ok_
8+
from nose.plugins.attrib import attr
89
from cassandra.cluster import Cluster, ResultSet
910
from cassandra.query import BatchStatement, SimpleStatement
1011

1112
# project
12-
from ddtrace.compat import to_unicode
1313
from ddtrace.contrib.cassandra.patch import patch, unpatch
1414
from ddtrace.contrib.cassandra.session import get_traced_cassandra, SERVICE
1515
from ddtrace.ext import net, cassandra as cassx, errors
1616
from ddtrace import Pin
1717

1818
# testing
19-
from nose.tools import eq_, ok_
20-
from nose.plugins.attrib import attr
2119
from tests.contrib.config import CASSANDRA_CONFIG
2220
from tests.opentracer.utils import init_tracer
2321
from tests.test_tracer import get_dummy_tracer
@@ -32,7 +30,6 @@
3230

3331
logging.getLogger('cassandra').setLevel(logging.INFO)
3432

35-
3633
def setUpModule():
3734
# skip all the modules if the Cluster is not available
3835
if not Cluster:
@@ -49,7 +46,6 @@ def setUpModule():
4946
session.execute("INSERT INTO test.person (name, age, description) VALUES ('Athena', 100, 'Whose shield is thunder')")
5047
session.execute("INSERT INTO test.person (name, age, description) VALUES ('Calypso', 100, 'Softly-braided nymph')")
5148

52-
5349
def tearDownModule():
5450
# destroy the KEYSPACE
5551
cluster = Cluster(port=CASSANDRA_CONFIG['port'], connect_timeout=CONNECTION_TIMEOUT_SECS)
@@ -156,7 +152,6 @@ def execute_fn(session, query):
156152
event = Event()
157153
result = []
158154
future = session.execute_async(query)
159-
160155
def callback(results):
161156
result.append(ResultSet(future, results))
162157
event.set()
@@ -184,7 +179,7 @@ def test_paginated_query(self):
184179
writer = tracer.writer
185180
statement = SimpleStatement(self.TEST_QUERY_PAGINATED, fetch_size=1)
186181
result = session.execute(statement)
187-
# iterate over all pages
182+
#iterate over all pages
188183
results = list(result)
189184
eq_(len(results), 3)
190185

@@ -209,7 +204,7 @@ def test_paginated_query(self):
209204
eq_(query.get_tag(cassx.ROW_COUNT), '1')
210205
eq_(query.get_tag(net.TARGET_HOST), '127.0.0.1')
211206
eq_(query.get_tag(cassx.PAGINATED), 'True')
212-
eq_(query.get_tag(cassx.PAGE_NUMBER), str(i + 1))
207+
eq_(query.get_tag(cassx.PAGE_NUMBER), str(i+1))
213208

214209
def test_trace_with_service(self):
215210
session, tracer = self._traced_session()
@@ -221,22 +216,6 @@ def test_trace_with_service(self):
221216
query = spans[0]
222217
eq_(query.service, self.TEST_SERVICE)
223218

224-
def test_unicode_batch_statement(self):
225-
# ensure that unicode included in queries is properly handled
226-
session, tracer = self._traced_session()
227-
228-
batch = BatchStatement()
229-
query = 'INSERT INTO test.person_write (name, age, description) VALUES (%s, %s, %s)'
230-
batch.add(SimpleStatement(query), ('Joe', 1, '好'))
231-
session.execute(batch)
232-
233-
spans = tracer.writer.pop()
234-
eq_(len(spans), 1)
235-
s = spans[0]
236-
eq_(s.resource, 'BatchStatement')
237-
eq_(s.get_metric('cassandra.batch_size'), 1)
238-
eq_(s.get_tag(cassx.QUERY), to_unicode('INSERT INTO test.person_write (name, age, description) VALUES (\'Joe\', 1, \'\')'))
239-
240219
def test_trace_error(self):
241220
session, tracer = self._traced_session()
242221
writer = tracer.writer

tests/test_compat.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from nose.tools import eq_, ok_, assert_raises
77

88
# Project
9-
from ddtrace.compat import to_unicode, PY2, reraise, get_connection_response, stringify
9+
from ddtrace.compat import to_unicode, PY2, reraise, get_connection_response
1010

1111

1212
# Use different test suites for each Python version, this allows us to test the expected
@@ -71,12 +71,6 @@ def getresponse(self, *args, **kwargs):
7171
mock = MockConn()
7272
get_connection_response(mock)
7373

74-
def test_stringify_unicode(self):
75-
# ensure stringify can handle decoding strings that have been to_unicode()'d
76-
stringify(to_unicode('€'))
77-
stringify(to_unicode('\xc3\xbf'))
78-
stringify(to_unicode('好'))
79-
8074
else:
8175
class TestCompatPY3(object):
8276
def test_to_unicode_string(self):
@@ -130,7 +124,7 @@ def test_reraise(self):
130124
with assert_raises(Exception) as ex:
131125
try:
132126
raise Exception('Ouch!')
133-
except Exception:
127+
except Exception as e:
134128
# original exception we want to re-raise
135129
(typ, val, tb) = sys.exc_info()
136130
try:

0 commit comments

Comments
 (0)