Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Commit 1373dcd

Browse files
author
Alexander
committed
Applied futurize script from futures
1 parent 771bcb0 commit 1373dcd

23 files changed

+83
-49
lines changed

crossdock/server/endtoend.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from builtins import range
2+
from builtins import object
13
import tornado.web
24
import json
35

@@ -99,7 +101,7 @@ def generate_traces(self, request, response_writer):
99101
tracer = self.tracers[sampler_type]
100102
for _ in range(req.get('count', 0)):
101103
span = tracer.start_span(req['operation'])
102-
for k, v in req.get('tags', {}).iteritems():
104+
for k, v in req.get('tags', {}).items():
103105
span.set_tag(k, v)
104106
span.finish()
105107
response_writer.finish()

crossdock/server/serializer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str
12
import json
23
import logging
34

@@ -93,7 +94,7 @@ def traced_service_object_to_json(obj):
9394

9495

9596
def set_traced_service_object_values(obj, values, downstream_func):
96-
for k in values.iterkeys():
97+
for k in values.keys():
9798
if hasattr(obj, k):
9899
if k == 'downstream':
99100
if values[k] is not None:

crossdock/server/server.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import object
12
import logging
23

34
import tornado.web

jaeger_client/codecs.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from future import standard_library
23+
standard_library.install_aliases()
24+
from past.builtins import basestring
25+
from builtins import object
2226

23-
import urllib
27+
import urllib.request, urllib.parse, urllib.error
2428

2529
from opentracing import (
2630
InvalidCarrierException,
@@ -64,9 +68,9 @@ def inject(self, span_context, carrier):
6468
parent_id=span_context.parent_id, flags=span_context.flags)
6569
baggage = span_context.baggage
6670
if baggage:
67-
for key, value in baggage.iteritems():
71+
for key, value in baggage.items():
6872
if self.url_encoding:
69-
encoded_value = urllib.quote(value)
73+
encoded_value = urllib.parse.quote(value)
7074
else:
7175
encoded_value = value
7276
carrier['%s%s' % (self.baggage_prefix, key)] = encoded_value
@@ -77,24 +81,24 @@ def extract(self, carrier):
7781
trace_id, span_id, parent_id, flags = None, None, None, None
7882
baggage = None
7983
debug_id = None
80-
for key, value in carrier.iteritems():
84+
for key, value in carrier.items():
8185
uc_key = key.lower()
8286
if uc_key == self.trace_id_header:
8387
if self.url_encoding:
84-
value = urllib.unquote(value)
88+
value = urllib.parse.unquote(value)
8589
trace_id, span_id, parent_id, flags = \
8690
span_context_from_string(value)
8791
elif uc_key.startswith(self.baggage_prefix):
8892
if self.url_encoding:
89-
value = urllib.unquote(value)
93+
value = urllib.parse.unquote(value)
9094
attr_key = key[self.prefix_length:]
9195
if baggage is None:
9296
baggage = {attr_key.lower(): value}
9397
else:
9498
baggage[attr_key.lower()] = value
9599
elif uc_key == self.debug_id_header:
96100
if self.url_encoding:
97-
value = urllib.unquote(value)
101+
value = urllib.parse.unquote(value)
98102
debug_id = value
99103
if not trace_id and baggage:
100104
raise SpanContextCorruptedException('baggage without trace ctx')
@@ -137,7 +141,7 @@ def span_context_to_string(trace_id, span_id, parent_id, flags):
137141
:param parent_id:
138142
:param flags:
139143
"""
140-
parent_id = parent_id or 0L
144+
parent_id = parent_id or 0
141145
return '{:x}:{:x}:{:x}:{:x}'.format(trace_id, span_id, parent_id, flags)
142146

143147

@@ -162,9 +166,9 @@ def span_context_from_string(value):
162166
raise SpanContextCorruptedException(
163167
'malformed trace context "%s"' % value)
164168
try:
165-
trace_id = long(parts[0], 16)
166-
span_id = long(parts[1], 16)
167-
parent_id = long(parts[2], 16)
169+
trace_id = int(parts[0], 16)
170+
span_id = int(parts[1], 16)
171+
parent_id = int(parts[2], 16)
168172
flags = int(parts[3], 16)
169173
if trace_id < 1 or span_id < 1 or parent_id < 0 or flags < 0:
170174
raise SpanContextCorruptedException(

jaeger_client/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import object
2223

2324
import logging
2425
import threading

jaeger_client/local_agent_net.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import object
2223
from threadloop import ThreadLoop
2324
import tornado
2425
import tornado.httpclient

jaeger_client/metrics.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import object
2223

2324

2425
class Metrics(object):

jaeger_client/rate_limiter.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import object
12
# Copyright (c) 2017 Uber Technologies, Inc.
23
#
34
# Permission is hereby granted, free of charge, to any person obtaining a copy

jaeger_client/reporter.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import object
2223
import logging
2324
import threading
2425

jaeger_client/sampler.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from __future__ import division
23+
from builtins import object
24+
from past.utils import old_div
2225
import logging
2326
import random
2427
import json
@@ -45,7 +48,7 @@
4548
SAMPLER_TYPE_TAG_KEY = 'sampler.type'
4649
SAMPLER_PARAM_TAG_KEY = 'sampler.param'
4750
DEFAULT_SAMPLING_PROBABILITY = 0.001
48-
DEFAULT_LOWER_BOUND = 1.0 / (10.0 * 60.0) # sample once every 10 minutes
51+
DEFAULT_LOWER_BOUND = old_div(1.0, (10.0 * 60.0)) # sample once every 10 minutes
4952
DEFAULT_MAX_OPERATIONS = 2000
5053

5154
STRATEGIES_STR = 'perOperationStrategies'
@@ -306,7 +309,7 @@ def update(self, strategies):
306309
ProbabilisticSampler(self.default_sampling_probability)
307310

308311
def close(self):
309-
for _, sampler in self.samplers.iteritems():
312+
for _, sampler in self.samplers.items():
310313
sampler.close()
311314

312315
def __str__(self):

jaeger_client/span.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import str
2223

2324
import json
2425
import threading
@@ -54,7 +55,7 @@ def __init__(self, context, tracer, operation_name,
5455
self.tags = []
5556
self.logs = []
5657
if tags:
57-
for k, v in tags.iteritems():
58+
for k, v in tags.items():
5859
self.set_tag(k, v)
5960

6061
def set_operation_name(self, operation_name):

jaeger_client/thrift.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from past.builtins import basestring
12
# Copyright (c) 2016 Uber Technologies, Inc.
23
#
34
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -30,8 +31,8 @@
3031

3132
_max_signed_port = (1 << 15) - 1
3233
_max_unsigned_port = (1 << 16)
33-
_max_signed_id = (1L << 63) - 1
34-
_max_unsigned_id = (1L << 64)
34+
_max_signed_id = (1 << 63) - 1
35+
_max_unsigned_id = (1 << 64)
3536

3637

3738
def ipv4_to_int(ipv4):
@@ -117,7 +118,7 @@ def timestamp_micros(ts):
117118
:param ts:
118119
:return:
119120
"""
120-
return long(ts * 1000000)
121+
return int(ts * 1000000)
121122

122123

123124
def make_zipkin_spans(spans):

jaeger_client/tracer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def start_span(self,
132132
if sampled:
133133
flags = SAMPLED_FLAG
134134
tags = tags or {}
135-
for k, v in sampler_tags.iteritems():
135+
for k, v in sampler_tags.items():
136136
tags[k] = v
137137
else: # have debug id
138138
flags = SAMPLED_FLAG | DEBUG_FLAG
@@ -159,7 +159,7 @@ def start_span(self,
159159

160160
if (rpc_server or not parent_id) and (flags & SAMPLED_FLAG):
161161
# this is a first-in-process span, and is sampled
162-
for k, v in self.tags.iteritems():
162+
for k, v in self.tags.items():
163163
span.set_tag(k, v)
164164

165165
self._emit_span_metrics(span=span, join=rpc_server)

jaeger_client/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from builtins import str
2+
from builtins import range
3+
from builtins import object
14
# Copyright (c) 2016 Uber Technologies, Inc.
25
#
36
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -74,7 +77,7 @@ def local_ip():
7477
if ip.startswith('127.'):
7578
# Check eth0, eth1, eth2, en0, ...
7679
interfaces = [
77-
i + str(n) for i in ('eth', 'en', 'wlan') for n in xrange(3)
80+
i + str(n) for i in ('eth', 'en', 'wlan') for n in range(3)
7881
] # :(
7982
for interface in interfaces:
8083
try:

tests/test_codecs.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_trace_context_from_to_string(self):
8484
from_string = span_context_from_string
8585

8686
tests = [
87-
[(256L, 127L, None, 1), '100:7f:0:1'],
88-
[(256L, 127L, 256L, 0), '100:7f:100:0'],
87+
[(256, 127, None, 1), '100:7f:0:1'],
88+
[(256, 127, 256, 0), '100:7f:100:0'],
8989
]
9090
for test in tests:
9191
ctx = test[0]
@@ -95,13 +95,13 @@ def test_trace_context_from_to_string(self):
9595
self.assertEqual(ctx_rev, ctx)
9696

9797
ctx_rev = from_string(['100:7f:100:0'])
98-
assert ctx_rev == (256L, 127L, 256L, 0), 'Array is acceptable'
98+
assert ctx_rev == (256, 127, 256, 0), 'Array is acceptable'
9999

100100
with self.assertRaises(SpanContextCorruptedException):
101101
from_string(['100:7f:100:0', 'garbage'])
102102

103103
ctx_rev = from_string(u'100:7f:100:0')
104-
assert ctx_rev == (256L, 127L, 256L, 0), 'Unicode is acceptable'
104+
assert ctx_rev == (256, 127, 256, 0), 'Unicode is acceptable'
105105

106106
def test_context_to_readable_headers(self):
107107
for url_encoding in [False, True]:
@@ -215,14 +215,14 @@ def test_context_from_large_ids(self):
215215
'Trace-ID': 'FFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFF:1',
216216
}
217217
context = codec.extract(headers)
218-
assert context.trace_id == 0xFFFFFFFFFFFFFFFFL
219-
assert context.trace_id == (1L << 64) - 1
218+
assert context.trace_id == 0xFFFFFFFFFFFFFFFF
219+
assert context.trace_id == (1 << 64) - 1
220220
assert context.trace_id > 0
221-
assert context.span_id == 0xFFFFFFFFFFFFFFFFL
222-
assert context.span_id == (1L << 64) - 1
221+
assert context.span_id == 0xFFFFFFFFFFFFFFFF
222+
assert context.span_id == (1 << 64) - 1
223223
assert context.span_id > 0
224-
assert context.parent_id == 0xFFFFFFFFFFFFFFFFL
225-
assert context.parent_id == (1L << 64) - 1
224+
assert context.parent_id == 0xFFFFFFFFFFFFFFFF
225+
assert context.parent_id == (1 << 64) - 1
226226
assert context.parent_id > 0
227227

228228
def test_zipkin_codec_extract(self):
@@ -322,6 +322,6 @@ def test_debug_id():
322322
span = tracer.start_span('test', child_of=context)
323323
assert span.is_debug()
324324
assert span.is_sampled()
325-
tags = filter(lambda t: t.key == debug_header, span.tags)
325+
tags = [t for t in span.tags if t.key == debug_header]
326326
assert len(tags) == 1
327327
assert tags[0].value == 'Coraline'

tests/test_crossdock.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# THE SOFTWARE.
2020

2121
from __future__ import absolute_import
22+
from builtins import str
2223

2324
import mock
2425
import json

tests/test_local_agent_net.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from future import standard_library
2+
standard_library.install_aliases()
13
import pytest
24
import tornado.web
3-
from urlparse import urlparse
5+
from urllib.parse import urlparse
46
from jaeger_client.local_agent_net import LocalAgentSender
57
from jaeger_client.config import DEFAULT_REPORTING_PORT
68

tests/test_rate_limiter.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import range
12
# Copyright (c) 2017 Uber Technologies, Inc.
23
#
34
# Permission is hereby granted, free of charge, to any person obtaining a copy

tests/test_reporter.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import print_function
2+
from builtins import range
3+
from builtins import object
14
# Copyright (c) 2016 Uber Technologies, Inc.
25
#
36
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -163,7 +166,7 @@ def _wait_for(self, fn):
163166
if fn():
164167
return
165168
yield tornado.gen.sleep(0.001)
166-
print 'waited for condition %f' % (time.time() - start)
169+
print('waited for condition %f' % (time.time() - start))
167170

168171
@gen_test
169172
def test_submit_batch_size_1(self):

tests/test_sampler.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import division
2+
from builtins import range
3+
from past.utils import old_div
14
# Copyright (c) 2016 Uber Technologies, Inc.
25
#
36
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -36,7 +39,7 @@
3639
get_rate_limit,
3740
)
3841

39-
MAX_INT = 1L << 63
42+
MAX_INT = 1 << 63
4043

4144
def get_tags(type, param):
4245
return {
@@ -61,7 +64,7 @@ def test_probabilistic_sampler_errors():
6164

6265
def test_probabilistic_sampler():
6366
sampler = ProbabilisticSampler(0.5)
64-
assert MAX_INT == 0x8000000000000000L
67+
assert MAX_INT == 0x8000000000000000
6568
sampled, tags = sampler.is_sampled(MAX_INT-10)
6669
assert sampled
6770
assert tags == get_tags('probabilistic', 0.5)
@@ -167,7 +170,7 @@ def test_guaranteed_throughput_probabilistic_sampler():
167170
sampled, tags = sampler.is_sampled(MAX_INT-10)
168171
assert sampled
169172
assert tags == get_tags('probabilistic', 0.51)
170-
sampled, tags = sampler.is_sampled(MAX_INT+(MAX_INT/4))
173+
sampled, tags = sampler.is_sampled(MAX_INT+(old_div(MAX_INT,4)))
171174
assert sampled
172175
assert tags == get_tags('lowerbound', 0.51)
173176

@@ -198,7 +201,7 @@ def test_adaptive_sampler():
198201
sampled, tags = sampler.is_sampled(MAX_INT-10, "new_op")
199202
assert sampled
200203
assert tags == get_tags('probabilistic', 0.51)
201-
sampled, tags = sampler.is_sampled(MAX_INT+(MAX_INT/4), "new_op")
204+
sampled, tags = sampler.is_sampled(MAX_INT+(old_div(MAX_INT,4)), "new_op")
202205
assert sampled
203206
assert tags == get_tags('lowerbound', 0.51)
204207

@@ -207,7 +210,7 @@ def test_adaptive_sampler():
207210
sampled, tags = sampler.is_sampled(MAX_INT-10, "new_op_2")
208211
assert sampled
209212
assert tags == get_tags('probabilistic', 0.51)
210-
sampled, _ = sampler.is_sampled(MAX_INT+(MAX_INT/4), "new_op_2")
213+
sampled, _ = sampler.is_sampled(MAX_INT+(old_div(MAX_INT,4)), "new_op_2")
211214
assert not sampled
212215
assert '%s' % sampler == 'AdaptiveSampler(0.51, 3, 2)'
213216

0 commit comments

Comments
 (0)