Skip to content

Commit a7db760

Browse files
committed
post-beautifier
1 parent b7d3e01 commit a7db760

File tree

10 files changed

+122
-64
lines changed

10 files changed

+122
-64
lines changed

instana/agent.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@
55
import instana.fsm as f
66
import instana.agent_const as a
77

8+
89
class From(object):
910
pid = ""
1011
hostId = ""
12+
1113
def __init__(self, **kwds):
1214
self.__dict__.update(kwds)
1315

16+
1417
class Head(urllib2.Request):
18+
1519
def get_method(self):
1620
return "HEAD"
1721

22+
1823
class Put(urllib2.Request):
24+
1925
def get_method(self):
2026
return "PUT"
2127

28+
2229
class Agent(object):
2330
sensor = None
2431
host = a.AGENT_DEFAULT_HOST
@@ -71,7 +78,8 @@ def full_request_response(self, url, method, o, body, header):
7178
self.reset()
7279
else:
7380
if response.getcode() < 200 or response.getcode() >= 300:
74-
l.error("Request returned erroneous code", response.getcode())
81+
l.error("Request returned erroneous code",
82+
response.getcode())
7583
if self.can_send():
7684
self.reset()
7785
else:
@@ -93,10 +101,10 @@ def make_url(self, prefix):
93101

94102
def make_host_url(self, host, prefix):
95103
port = self.sensor.options.agent_port
96-
if port == 0:
97-
port = a.AGENT_DEFAULT_PORT
104+
if port == 0:
105+
port = a.AGENT_DEFAULT_PORT
98106

99-
return self.make_full_url(host, port, prefix)
107+
return self.make_full_url(host, port, prefix)
100108

101109
def make_full_url(self, host, port, prefix):
102110
s = "http://%s:%s%s" % (host, str(port), prefix)

instana/agent_const.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AGENT_DISCOVERY_URL = "/com.instana.plugin.python.discovery"
2-
AGENT_TRACES_URL = "/com.instana.plugin.python/traces."
3-
AGENT_DATA_URL = "/com.instana.plugin.python."
4-
AGENT_DEFAULT_HOST = "localhost"
5-
AGENT_DEFAULT_PORT = 42699
6-
AGENT_HEADER = "Instana Agent"
2+
AGENT_TRACES_URL = "/com.instana.plugin.python/traces."
3+
AGENT_DATA_URL = "/com.instana.plugin.python."
4+
AGENT_DEFAULT_HOST = "localhost"
5+
AGENT_DEFAULT_PORT = 42699
6+
AGENT_HEADER = "Instana Agent"

instana/fsm.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
import instana.log as l
77
import instana.agent_const as a
88

9+
910
class Discovery(object):
1011
pid = 0
1112
name = None
1213
args = None
14+
1315
def __init__(self, **kwds):
1416
self.__dict__.update(kwds)
1517

18+
1619
class Fsm(object):
17-
E_START = "start"
18-
E_LOOKUP = "lookup"
20+
E_START = "start"
21+
E_LOOKUP = "lookup"
1922
E_ANNOUNCE = "announce"
20-
E_TEST = "test"
23+
E_TEST = "test"
2124

2225
RETRY_PERIOD = 30
2326

@@ -29,16 +32,17 @@ def __init__(self, agent):
2932

3033
self.agent = agent
3134
self.fsm = f.Fysom({
32-
"initial": "none",
33-
"events": [
34-
{"name": self.E_START, "src": ["none", "unannounced", "announced", "ready"], "dst": "init"},
35-
{"name": self.E_LOOKUP, "src": "init", "dst": "unannounced"},
36-
{"name": self.E_ANNOUNCE, "src": "unannounced", "dst": "announced"},
37-
{"name": self.E_TEST, "src": "announced", "dst": "ready"}],
38-
"callbacks": {
39-
"onstart": self.lookup_agent_host,
40-
"onenterunannounced": self.announce_sensor,
41-
"onenterannounced": self.test_agent}})
35+
"initial": "none",
36+
"events": [
37+
{"name": self.E_START, "src": [
38+
"none", "unannounced", "announced", "ready"], "dst": "init"},
39+
{"name": self.E_LOOKUP, "src": "init", "dst": "unannounced"},
40+
{"name": self.E_ANNOUNCE, "src": "unannounced", "dst": "announced"},
41+
{"name": self.E_TEST, "src": "announced", "dst": "ready"}],
42+
"callbacks": {
43+
"onstart": self.lookup_agent_host,
44+
"onenterunannounced": self.announce_sensor,
45+
"onenterannounced": self.test_agent}})
4246

4347
def reset(self):
4448
self.fsm.start()
@@ -68,7 +72,8 @@ def get_default_gateway(self):
6872
l.debug("checking default gateway")
6973

7074
try:
71-
proc = subprocess.Popen("/sbin/ip route | awk '/default/ { print $3 }'", stdout=subprocess.PIPE)
75+
proc = subprocess.Popen(
76+
"/sbin/ip route | awk '/default/ { print $3 }'", stdout=subprocess.PIPE)
7277

7378
return proc.stdout.read()
7479
except Exception as e:
@@ -79,7 +84,8 @@ def get_default_gateway(self):
7984
def check_host(self, host):
8085
l.debug("checking host", host)
8186

82-
(b, h) = self.agent.request_header(self.agent.make_host_url(host, "/"), "GET", "Server")
87+
(b, h) = self.agent.request_header(
88+
self.agent.make_host_url(host, "/"), "GET", "Server")
8389

8490
return h
8591

@@ -90,7 +96,8 @@ def announce_sensor(self, e):
9096
name=sys.executable,
9197
args=sys.argv[0:])
9298

93-
(b, h) = self.agent.request_response(self.agent.make_url(a.AGENT_DISCOVERY_URL), "PUT", d)
99+
(b, h) = self.agent.request_response(
100+
self.agent.make_url(a.AGENT_DISCOVERY_URL), "PUT", d)
94101
if not b:
95102
l.error("Cannot announce sensor. Scheduling retry.")
96103
self.schedule_retry(self.announce_sensor, e)

instana/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
HTTP_CLIENT = "g.hc"
22
HTTP_SERVER = "g.http"
33

4+
45
class HttpData(object):
56
host = None
67
url = None

instana/log.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
logger = l.getLogger('instana')
44

5+
56
def init(level):
67
ch = l.StreamHandler()
78
f = l.Formatter('%(asctime)s: %(levelname)s: %(name)s: %(message)s')
89
ch.setFormatter(f)
910
logger.addHandler(ch)
1011
logger.setLevel(level)
1112

13+
1214
def debug(s, *args):
1315
logger.debug("%s %s" % (s, ' '.join(args)))
1416

17+
1518
def info(s, *args):
1619
logger.info("%s %s" % (s, ' '.join(args)))
1720

21+
1822
def warn(s, *args):
1923
logger.warn("%s %s" % (s, ' '.join(args)))
2024

25+
2126
def error(s, *args):
2227
logger.error("%s %s" % (s, ' '.join(args)))

instana/meter.py

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,26 @@
77
import sys
88
import instana.agent_const as a
99

10+
1011
class Snapshot(object):
1112
name = None
1213
version = None
13-
rlimit_core=(0, 0)
14-
rlimit_cpu=(0, 0)
15-
rlimit_fsize=(0, 0)
16-
rlimit_data=(0, 0)
17-
rlimit_stack=(0, 0)
18-
rlimit_rss=(0, 0)
19-
rlimit_nproc=(0, 0)
20-
rlimit_nofile=(0, 0)
21-
rlimit_memlock=(0, 0)
22-
rlimit_as=(0, 0)
14+
rlimit_core = (0, 0)
15+
rlimit_cpu = (0, 0)
16+
rlimit_fsize = (0, 0)
17+
rlimit_data = (0, 0)
18+
rlimit_stack = (0, 0)
19+
rlimit_rss = (0, 0)
20+
rlimit_nproc = (0, 0)
21+
rlimit_nofile = (0, 0)
22+
rlimit_memlock = (0, 0)
23+
rlimit_as = (0, 0)
2324
versions = None
2425

2526
def __init__(self, **kwds):
2627
self.__dict__.update(kwds)
2728

29+
2830
class GC(object):
2931
collect0 = 0
3032
collect1 = 0
@@ -36,6 +38,7 @@ class GC(object):
3638
def __init__(self, **kwds):
3739
self.__dict__.update(kwds)
3840

41+
3942
class Metrics(object):
4043
ru_utime = .0
4144
ru_stime = .0
@@ -50,7 +53,7 @@ class Metrics(object):
5053
ru_oublock = 0
5154
ru_msgsnd = 0
5255
ru_msgrcv = 0
53-
ru_nsignals = 0
56+
ru_nsignals = 0
5457
ru_nvcs = 0
5558
ru_nivcsw = 0
5659
dead_threads = 0
@@ -61,6 +64,7 @@ class Metrics(object):
6164
def __init__(self, **kwds):
6265
self.__dict__.update(kwds)
6366

67+
6468
class EntityData(object):
6569
pid = 0
6670
snapshot = None
@@ -69,6 +73,7 @@ class EntityData(object):
6973
def __init__(self, **kwds):
7074
self.__dict__.update(kwds)
7175

76+
7277
class Meter(object):
7378
SNAPSHOT_PERIOD = 600
7479
snapshot_countdown = 1
@@ -105,13 +110,18 @@ def collect_snapshot(self):
105110
version=sys.version,
106111
rlimit_core=resource.getrlimit(resource.RLIMIT_CORE),
107112
rlimit_cpu=resource.getrlimit(resource.RLIMIT_CPU),
108-
rlimit_fsize=resource.getrlimit(resource.RLIMIT_FSIZE),
113+
rlimit_fsize=resource.getrlimit(
114+
resource.RLIMIT_FSIZE),
109115
rlimit_data=resource.getrlimit(resource.RLIMIT_DATA),
110-
rlimit_stack=resource.getrlimit(resource.RLIMIT_STACK),
116+
rlimit_stack=resource.getrlimit(
117+
resource.RLIMIT_STACK),
111118
rlimit_rss=resource.getrlimit(resource.RLIMIT_RSS),
112-
rlimit_nproc=resource.getrlimit(resource.RLIMIT_NPROC),
113-
rlimit_nofile=resource.getrlimit(resource.RLIMIT_NOFILE),
114-
rlimit_memlock=resource.getrlimit(resource.RLIMIT_MEMLOCK),
119+
rlimit_nproc=resource.getrlimit(
120+
resource.RLIMIT_NPROC),
121+
rlimit_nofile=resource.getrlimit(
122+
resource.RLIMIT_NOFILE),
123+
rlimit_memlock=resource.getrlimit(
124+
resource.RLIMIT_MEMLOCK),
115125
rlimit_as=resource.getrlimit(resource.RLIMIT_AS),
116126
versions=self.collect_modules())
117127

@@ -147,33 +157,47 @@ def collect_metrics(self):
147157
c = list(gc.get_count())
148158
th = list(gc.get_threshold())
149159
g = GC(collect0=c[0] if not self.last_collect else c[0] - self.last_collect[0],
150-
collect1=c[1] if not self.last_collect else c[1] - self.last_collect[1],
151-
collect2=c[2] if not self.last_collect else c[2] - self.last_collect[2],
160+
collect1=c[1] if not self.last_collect else c[
161+
1] - self.last_collect[1],
162+
collect2=c[2] if not self.last_collect else c[
163+
2] - self.last_collect[2],
152164
threshold0=th[0],
153165
threshold1=th[1],
154166
threshold2=th[2])
155167

156168
thr = t.enumerate()
157169
daemon_threads = len(map(lambda tr: tr.daemon and tr.is_alive(), thr))
158-
alive_threads = len(map(lambda tr: not tr.daemon and tr.is_alive(), thr))
170+
alive_threads = len(
171+
map(lambda tr: not tr.daemon and tr.is_alive(), thr))
159172
dead_threads = len(map(lambda tr: not tr.is_alive(), thr))
160173

161174
m = Metrics(ru_utime=u[0] if not self.last_usage else u[0] - self.last_usage[0],
162-
ru_stime=u[1] if not self.last_usage else u[1] - self.last_usage[1],
175+
ru_stime=u[1] if not self.last_usage else u[
176+
1] - self.last_usage[1],
163177
ru_maxrss=u[2],
164178
ru_ixrss=u[3],
165179
ru_idrss=u[4],
166180
ru_isrss=u[5],
167-
ru_minflt=u[6] if not self.last_usage else u[6] - self.last_usage[6],
168-
ru_majflt=u[7] if not self.last_usage else u[7] - self.last_usage[7],
169-
ru_nswap=u[8] if not self.last_usage else u[8] - self.last_usage[8],
170-
ru_inblock=u[9] if not self.last_usage else u[9] - self.last_usage[9],
171-
ru_oublock=u[10] if not self.last_usage else u[10] - self.last_usage[10],
172-
ru_msgsnd=u[11] if not self.last_usage else u[11] - self.last_usage[11],
173-
ru_msgrcv=u[12] if not self.last_usage else u[12] - self.last_usage[12],
174-
ru_nsignals=u[13] if not self.last_usage else u[13] - self.last_usage[13],
175-
ru_nvcs=u[14] if not self.last_usage else u[14] - self.last_usage[14],
176-
ru_nivcsw=u[15] if not self.last_usage else u[15] - self.last_usage[15],
181+
ru_minflt=u[6] if not self.last_usage else u[
182+
6] - self.last_usage[6],
183+
ru_majflt=u[7] if not self.last_usage else u[
184+
7] - self.last_usage[7],
185+
ru_nswap=u[8] if not self.last_usage else u[
186+
8] - self.last_usage[8],
187+
ru_inblock=u[9] if not self.last_usage else u[
188+
9] - self.last_usage[9],
189+
ru_oublock=u[10] if not self.last_usage else u[
190+
10] - self.last_usage[10],
191+
ru_msgsnd=u[11] if not self.last_usage else u[
192+
11] - self.last_usage[11],
193+
ru_msgrcv=u[12] if not self.last_usage else u[
194+
12] - self.last_usage[12],
195+
ru_nsignals=u[13] if not self.last_usage else u[
196+
13] - self.last_usage[13],
197+
ru_nvcs=u[14] if not self.last_usage else u[
198+
14] - self.last_usage[14],
199+
ru_nivcsw=u[15] if not self.last_usage else u[
200+
15] - self.last_usage[15],
177201
alive_threads=alive_threads,
178202
dead_threads=dead_threads,
179203
daemon_threads=daemon_threads,

instana/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import instana.log as l
22
import logging
33

4+
45
class Options(object):
56
service = ''
67
agent_host = ''

instana/recorder.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import thread
55
import time
66

7+
78
class InstanaSpan(object):
89
t = 0
910
p = None
@@ -17,6 +18,7 @@ class InstanaSpan(object):
1718
def __init__(self, **kwds):
1819
self.__dict__.update(kwds)
1920

21+
2022
class InstanaRecorder(SpanRecorder):
2123
sensor = None
2224

@@ -29,17 +31,20 @@ def record_span(self, span):
2931
data = self.get_span_log_field(span, "data")
3032
if not data.service:
3133
data.service = self.sensor.service_name
32-
34+
3335
thread.start_new_thread(self.sensor.agent.request,
3436
(self.sensor.agent.make_url(a.AGENT_TRACES_URL), "POST",
3537
[InstanaSpan(t=span.context.trace_id,
36-
p=span.parent_id,
37-
s=span.context.span_id,
38-
ts=int(round(span.start_time * 1000)),
39-
d=int(round(span.duration * 1000)),
40-
n=self.get_string_span_log_field(span, "type"),
41-
f=self.sensor.agent.from_,
42-
data=data)]))
38+
p=span.parent_id,
39+
s=span.context.span_id,
40+
ts=int(
41+
round(span.start_time * 1000)),
42+
d=int(
43+
round(span.duration * 1000)),
44+
n=self.get_string_span_log_field(
45+
span, "type"),
46+
f=self.sensor.agent.from_,
47+
data=data)]))
4348

4449
def get_string_span_log_field(self, span, field):
4550
ret = self.get_span_log_field(span, field)
@@ -55,6 +60,8 @@ def get_span_log_field(self, span, field):
5560

5661
return None
5762

63+
5864
class InstanaSampler(Sampler):
65+
5966
def sampled(self, trace_id):
6067
return False

0 commit comments

Comments
 (0)