whatap-python 2.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. whatap/LICENSE +0 -0
  2. whatap/README.rst +49 -0
  3. whatap/__init__.py +923 -0
  4. whatap/__main__.py +4 -0
  5. whatap/agent/darwin/amd64/whatap_python +0 -0
  6. whatap/agent/darwin/arm64/whatap_python +0 -0
  7. whatap/agent/linux/amd64/whatap_python +0 -0
  8. whatap/agent/linux/arm64/whatap_python +0 -0
  9. whatap/agent/windows/whatap_python.exe +0 -0
  10. whatap/bootstrap/__init__.py +0 -0
  11. whatap/bootstrap/sitecustomize.py +19 -0
  12. whatap/build.py +4 -0
  13. whatap/conf/__init__.py +0 -0
  14. whatap/conf/configuration.py +280 -0
  15. whatap/conf/configure.py +105 -0
  16. whatap/conf/license.py +49 -0
  17. whatap/control/__init__.py +0 -0
  18. whatap/counter/__init__.py +14 -0
  19. whatap/counter/counter_manager.py +45 -0
  20. whatap/counter/tasks/__init__.py +3 -0
  21. whatap/counter/tasks/base_task.py +26 -0
  22. whatap/counter/tasks/llm_evaluator_task.py +501 -0
  23. whatap/counter/tasks/llm_log_sink_task.py +309 -0
  24. whatap/counter/tasks/llm_stat_task.py +78 -0
  25. whatap/counter/tasks/openfiledescriptor.py +67 -0
  26. whatap/io/__init__.py +1 -0
  27. whatap/io/data_inputx.py +161 -0
  28. whatap/io/data_outputx.py +262 -0
  29. whatap/llm/__init__.py +17 -0
  30. whatap/llm/definitions.py +43 -0
  31. whatap/llm/evaluators/__init__.py +136 -0
  32. whatap/llm/evaluators/base.py +114 -0
  33. whatap/llm/evaluators/builtins/__init__.py +91 -0
  34. whatap/llm/evaluators/builtins/answer_relevance.py +46 -0
  35. whatap/llm/evaluators/builtins/combined_judge.py +271 -0
  36. whatap/llm/evaluators/builtins/factuality.py +71 -0
  37. whatap/llm/evaluators/builtins/hallucination.py +97 -0
  38. whatap/llm/evaluators/builtins/llm_judge.py +516 -0
  39. whatap/llm/evaluators/builtins/pii_leak.py +214 -0
  40. whatap/llm/evaluators/builtins/prompt_injection.py +71 -0
  41. whatap/llm/evaluators/builtins/toxicity.py +53 -0
  42. whatap/llm/evaluators/builtins/url_scan.py +194 -0
  43. whatap/llm/evaluators/registry.py +192 -0
  44. whatap/llm/evaluators/sampler.py +83 -0
  45. whatap/llm/evaluators/scope.py +334 -0
  46. whatap/llm/features.py +66 -0
  47. whatap/llm/log_sink_packs/__init__.py +9 -0
  48. whatap/llm/log_sink_packs/llm_input_message.py +16 -0
  49. whatap/llm/log_sink_packs/llm_log_sink_pack.py +72 -0
  50. whatap/llm/log_sink_packs/llm_output_message.py +19 -0
  51. whatap/llm/log_sink_packs/llm_step_eval_status.py +94 -0
  52. whatap/llm/log_sink_packs/llm_step_status.py +118 -0
  53. whatap/llm/log_sink_packs/llm_system_message.py +16 -0
  54. whatap/llm/log_sink_packs/llm_tool_calls.py +44 -0
  55. whatap/llm/log_sink_packs/llm_tool_results.py +16 -0
  56. whatap/llm/log_sink_packs/llm_tx_status.py +108 -0
  57. whatap/llm/pricing.py +236 -0
  58. whatap/llm/prompt_meta.py +288 -0
  59. whatap/llm/providers/__init__.py +0 -0
  60. whatap/llm/providers/anthropic/__init__.py +37 -0
  61. whatap/llm/providers/anthropic/messages/__init__.py +0 -0
  62. whatap/llm/providers/anthropic/messages/messages.py +70 -0
  63. whatap/llm/providers/anthropic/messages/messages_context.py +76 -0
  64. whatap/llm/providers/anthropic/messages/messages_extractor.py +126 -0
  65. whatap/llm/providers/interceptor.py +182 -0
  66. whatap/llm/providers/openai/__init__.py +133 -0
  67. whatap/llm/providers/openai/chat/__init__.py +0 -0
  68. whatap/llm/providers/openai/chat/chat.py +82 -0
  69. whatap/llm/providers/openai/chat/chat_context.py +78 -0
  70. whatap/llm/providers/openai/chat/chat_extractor.py +127 -0
  71. whatap/llm/providers/openai/completions/__init__.py +0 -0
  72. whatap/llm/providers/openai/completions/completions.py +70 -0
  73. whatap/llm/providers/openai/completions/completions_context.py +31 -0
  74. whatap/llm/providers/openai/completions/completions_extractor.py +61 -0
  75. whatap/llm/providers/openai/content_parser.py +41 -0
  76. whatap/llm/providers/openai/embeddings/__init__.py +0 -0
  77. whatap/llm/providers/openai/embeddings/embeddings.py +59 -0
  78. whatap/llm/providers/openai/embeddings/embeddings_context.py +25 -0
  79. whatap/llm/providers/openai/embeddings/embeddings_extractor.py +26 -0
  80. whatap/llm/providers/openai/responses/__init__.py +0 -0
  81. whatap/llm/providers/openai/responses/responses.py +70 -0
  82. whatap/llm/providers/openai/responses/responses_context.py +88 -0
  83. whatap/llm/providers/openai/responses/responses_extractor.py +126 -0
  84. whatap/llm/providers/stream_accumulator.py +73 -0
  85. whatap/llm/stats/__init__.py +35 -0
  86. whatap/llm/stats/active_stat.py +86 -0
  87. whatap/llm/stats/answer_relevance_eval_stat.py +10 -0
  88. whatap/llm/stats/api_status_stat.py +35 -0
  89. whatap/llm/stats/base_stat.py +107 -0
  90. whatap/llm/stats/combined_judge_eval_stat.py +11 -0
  91. whatap/llm/stats/error_stat.py +59 -0
  92. whatap/llm/stats/eval_stat.py +225 -0
  93. whatap/llm/stats/factuality_eval_stat.py +10 -0
  94. whatap/llm/stats/feature_stat.py +104 -0
  95. whatap/llm/stats/finish_stat.py +105 -0
  96. whatap/llm/stats/hallucination_eval_stat.py +10 -0
  97. whatap/llm/stats/meter.py +18 -0
  98. whatap/llm/stats/perf_stat.py +117 -0
  99. whatap/llm/stats/pii_leak_eval_stat.py +12 -0
  100. whatap/llm/stats/prompt_injection_eval_stat.py +10 -0
  101. whatap/llm/stats/token_usage_stat.py +133 -0
  102. whatap/llm/stats/toxicity_eval_stat.py +10 -0
  103. whatap/llm/stats/url_scan_eval_stat.py +12 -0
  104. whatap/net/__init__.py +0 -0
  105. whatap/net/async_sender.py +107 -0
  106. whatap/net/packet_enum.py +44 -0
  107. whatap/net/packet_type_enum.py +31 -0
  108. whatap/net/param_def.py +69 -0
  109. whatap/net/stackhelper.py +87 -0
  110. whatap/net/udp_session.py +394 -0
  111. whatap/net/udp_thread.py +54 -0
  112. whatap/pack/__init__.py +0 -0
  113. whatap/pack/logSinkPack.py +77 -0
  114. whatap/pack/pack.py +34 -0
  115. whatap/pack/pack_enum.py +41 -0
  116. whatap/pack/tagCountPack.py +61 -0
  117. whatap/scripts/__init__.py +208 -0
  118. whatap/trace/__init__.py +12 -0
  119. whatap/trace/mod/__init__.py +0 -0
  120. whatap/trace/mod/amqp/__init__.py +0 -0
  121. whatap/trace/mod/amqp/kombu.py +122 -0
  122. whatap/trace/mod/amqp/pika.py +62 -0
  123. whatap/trace/mod/application/__init__.py +0 -0
  124. whatap/trace/mod/application/bottle.py +34 -0
  125. whatap/trace/mod/application/celery.py +81 -0
  126. whatap/trace/mod/application/cherrypy.py +30 -0
  127. whatap/trace/mod/application/django.py +287 -0
  128. whatap/trace/mod/application/django_asgi.py +266 -0
  129. whatap/trace/mod/application/django_py3.py +251 -0
  130. whatap/trace/mod/application/fastapi/__init__.py +31 -0
  131. whatap/trace/mod/application/fastapi/endpoint.py +73 -0
  132. whatap/trace/mod/application/fastapi/exception_log.py +63 -0
  133. whatap/trace/mod/application/fastapi/instrumentation.py +204 -0
  134. whatap/trace/mod/application/fastapi/scope.py +115 -0
  135. whatap/trace/mod/application/fastapi/transaction.py +67 -0
  136. whatap/trace/mod/application/flask.py +52 -0
  137. whatap/trace/mod/application/frappe.py +224 -0
  138. whatap/trace/mod/application/graphql.py +170 -0
  139. whatap/trace/mod/application/nameko.py +39 -0
  140. whatap/trace/mod/application/odoo.py +63 -0
  141. whatap/trace/mod/application/starlette.py +126 -0
  142. whatap/trace/mod/application/tornado.py +163 -0
  143. whatap/trace/mod/application/wsgi.py +195 -0
  144. whatap/trace/mod/database/__init__.py +0 -0
  145. whatap/trace/mod/database/cxoracle.py +49 -0
  146. whatap/trace/mod/database/mongo.py +169 -0
  147. whatap/trace/mod/database/mysql.py +80 -0
  148. whatap/trace/mod/database/neo4j.py +90 -0
  149. whatap/trace/mod/database/psycopg2.py +45 -0
  150. whatap/trace/mod/database/psycopg3.py +359 -0
  151. whatap/trace/mod/database/redis.py +122 -0
  152. whatap/trace/mod/database/sqlalchemy.py +213 -0
  153. whatap/trace/mod/database/sqlite3.py +130 -0
  154. whatap/trace/mod/database/util.py +630 -0
  155. whatap/trace/mod/email/__init__.py +0 -0
  156. whatap/trace/mod/email/smtp.py +78 -0
  157. whatap/trace/mod/httpc/__init__.py +0 -0
  158. whatap/trace/mod/httpc/django.py +31 -0
  159. whatap/trace/mod/httpc/httplib.py +70 -0
  160. whatap/trace/mod/httpc/httpx.py +62 -0
  161. whatap/trace/mod/httpc/requests.py +20 -0
  162. whatap/trace/mod/httpc/urllib3.py +27 -0
  163. whatap/trace/mod/httpc/util.py +388 -0
  164. whatap/trace/mod/logging.py +161 -0
  165. whatap/trace/mod/plugin.py +84 -0
  166. whatap/trace/mod/standalone/__init__.py +0 -0
  167. whatap/trace/mod/standalone/multiple.py +293 -0
  168. whatap/trace/mod/standalone/single.py +135 -0
  169. whatap/trace/simple_trace_context.py +18 -0
  170. whatap/trace/trace_context.py +212 -0
  171. whatap/trace/trace_context_manager.py +244 -0
  172. whatap/trace/trace_error.py +84 -0
  173. whatap/trace/trace_handler.py +89 -0
  174. whatap/trace/trace_import.py +91 -0
  175. whatap/trace/trace_module_definition.py +156 -0
  176. whatap/util/__init__.py +0 -0
  177. whatap/util/bit_util.py +49 -0
  178. whatap/util/cardinality/__init__.py +0 -0
  179. whatap/util/cardinality/hyperloglog.py +84 -0
  180. whatap/util/cardinality/murmurhash.py +20 -0
  181. whatap/util/cardinality/registerset.py +60 -0
  182. whatap/util/compare_util.py +19 -0
  183. whatap/util/date_util.py +55 -0
  184. whatap/util/debug_util.py +73 -0
  185. whatap/util/escape_literal_sql.py +233 -0
  186. whatap/util/frame_util.py +20 -0
  187. whatap/util/hash_util.py +103 -0
  188. whatap/util/hexa32.py +66 -0
  189. whatap/util/int_set.py +199 -0
  190. whatap/util/ip_util.py +63 -0
  191. whatap/util/keygen.py +11 -0
  192. whatap/util/linked_list.py +113 -0
  193. whatap/util/linked_map.py +359 -0
  194. whatap/util/metering_util.py +103 -0
  195. whatap/util/request_double_queue.py +68 -0
  196. whatap/util/request_queue.py +60 -0
  197. whatap/util/string_util.py +20 -0
  198. whatap/util/throttle_util.py +99 -0
  199. whatap/util/userid_util.py +134 -0
  200. whatap/value/__init__.py +1 -0
  201. whatap/value/blob_value.py +38 -0
  202. whatap/value/boolean_value.py +33 -0
  203. whatap/value/decimal_value.py +36 -0
  204. whatap/value/double_summary.py +86 -0
  205. whatap/value/double_value.py +33 -0
  206. whatap/value/float_array.py +42 -0
  207. whatap/value/float_value.py +34 -0
  208. whatap/value/int_array.py +42 -0
  209. whatap/value/ip4_value.py +50 -0
  210. whatap/value/list_value.py +105 -0
  211. whatap/value/long_array.py +44 -0
  212. whatap/value/long_summary.py +83 -0
  213. whatap/value/map_value.py +154 -0
  214. whatap/value/null_value.py +21 -0
  215. whatap/value/number_value.py +33 -0
  216. whatap/value/summary_value.py +39 -0
  217. whatap/value/text_array.py +58 -0
  218. whatap/value/text_hash_value.py +37 -0
  219. whatap/value/text_value.py +43 -0
  220. whatap/value/value.py +26 -0
  221. whatap/value/value_enum.py +80 -0
  222. whatap/whatap.conf +14 -0
  223. whatap_python-2.1.0.dist-info/METADATA +87 -0
  224. whatap_python-2.1.0.dist-info/RECORD +227 -0
  225. whatap_python-2.1.0.dist-info/WHEEL +5 -0
  226. whatap_python-2.1.0.dist-info/entry_points.txt +6 -0
  227. whatap_python-2.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,20 @@
1
+
2
+
3
+
4
+ def tokenizer(target, delim):
5
+ if not target:
6
+ return None
7
+
8
+ tokens = []
9
+ for t in target.split(delim):
10
+ t = t.strip()
11
+ if t:
12
+ tokens.append(t)
13
+
14
+ return tokens
15
+
16
+ def trimEmpty(src):
17
+ if src:
18
+ return src.strip()
19
+ else:
20
+ return ''
@@ -0,0 +1,99 @@
1
+ from whatap.conf.configure import Configure as conf
2
+ from whatap.pack.pack_enum import EventLevel
3
+ import whatap.net.async_sender as async_sender
4
+ from whatap.util.hash_util import HashUtil
5
+ from whatap.util.int_set import IntSet
6
+ import whatap.util.string_util as string_util
7
+ from whatap.util.ip_util import IPUtil
8
+ from whatap.net.packet_type_enum import PacketTypeEnum
9
+
10
+ def getThrottleStringToHashSet(value, deli):
11
+ intset = IntSet()
12
+ if value is not None:
13
+ vv = string_util.tokenizer(value, deli)
14
+ if vv is None:
15
+ return intset
16
+ for x in vv:
17
+ intset.put(HashUtil.hash(x))
18
+
19
+ return intset
20
+
21
+ def getThrottleIP(value, deli):
22
+ intset = IntSet()
23
+ if value is not None:
24
+ vv = string_util.tokenizer(value, deli)
25
+ if not vv :
26
+ return intset
27
+ for x in vv:
28
+ ip = IPUtil.toInt(x)
29
+ if ip != 0:
30
+ intset.put(ip)
31
+
32
+ return intset
33
+
34
+ def getThrottleIgnorePrefixl(value, deli):
35
+ strset = set()
36
+ if value:
37
+ vv = StringUtil.tokenizer(value, deli)
38
+ if not vv:
39
+ return []
40
+ for x in vv:
41
+ if x:
42
+ strset.add(x)
43
+
44
+ return list(strset)
45
+
46
+
47
+ passingUrlSet = getThrottleStringToHashSet(conf.throttle_passing_url, ",")
48
+ passingPrefix = getThrottleIgnorePrefixl(conf.throttle_passing_url_prefix, ",")
49
+ blockingUrlSet = getThrottleStringToHashSet(conf.throttle_blocking_url, ",")
50
+ blockingIPSet = getThrottleIP(conf.throttle_blocking_ip, ",")
51
+
52
+ blocking_enabled = blockingUrlSet.size() > 0 or blockingIPSet.size() > 0
53
+
54
+ def getHash():
55
+ k1 = string_util.trimEmpty(conf.throttle_passing_url)
56
+ k2 = string_util.trimEmpty(conf.throttle_passing_url_prefix)
57
+ k3 = string_util.trimEmpty(conf.throttle_blocking_url)
58
+ k4 = string_util.trimEmpty(conf.throttle_blocking_ip)
59
+ return hash(k1) ^ hash(k2) ^ hash(k3) ^ hash(k4)
60
+
61
+
62
+ def isblocking(str_ip, path):
63
+ remote_ip = IPUtil.toInt(str_ip)
64
+ if not blocking_enabled:
65
+ return False
66
+ if blockingIPSet.contains(remote_ip):
67
+ return True
68
+ urlhash = HashUtil.hashFromString(path)
69
+ if blockingUrlSet.contains(urlhash):
70
+ return True
71
+ return False
72
+
73
+ def sendrejectevent(ctx, path, ip):
74
+ pathHash = HashUtil.hashFromString(path)
75
+ datas = ("REJECTED_URL", EventLevel.WARNING,
76
+ "Rejected " + path,
77
+ pathHash,
78
+ path,
79
+ ip,
80
+ )
81
+ async_sender.send_packet(PacketTypeEnum.EVENT, ctx, datas)
82
+
83
+ valueHash = 0
84
+ def updateConfig():
85
+ global passingUrlSet, passingPrefix, blockingUrlSet, blockingIPSet, blocking_enabled, ignoreContext, ignoreDomain, valueHash
86
+ newHash = getHash()
87
+ if valueHash != newHash:
88
+ passingUrlSet = getThrottleStringToHashSet(conf.throttle_passing_url, ",")
89
+ passingPrefix = getThrottleIgnorePrefixl(conf.throttle_passing_url_prefix, ",")
90
+ blockingUrlSet = getThrottleStringToHashSet(conf.throttle_blocking_url, ",")
91
+ blockingIPSet = getThrottleIP(conf.throttle_blocking_ip, ",")
92
+
93
+ blocking_enabled = len(blockingUrlSet) > 0 or len(blockingIPSet) > 0
94
+
95
+ ignoreContext = StringUtil.tokenizer(conf.throttle_blocking_ignore_context, ",")
96
+ ignoreDomain = getThrottleStringToHashSet(conf.throttle_blocking_ignore_domain, ",")
97
+
98
+ valueHash = getHash()
99
+ conf.addObserver(updateConfig)
@@ -0,0 +1,134 @@
1
+ from whatap.util.hash_util import HashUtil as hash_util
2
+ from whatap.util.hexa32 import Hexa32 as hexa32
3
+ from whatap.util.keygen import KeyGen
4
+ import whatap.util.bit_util as bit_util
5
+ from whatap.conf.configure import Configure as conf
6
+ import logging as logging_module
7
+ import sys, traceback
8
+
9
+ logger = logging_module.getLogger(__name__)
10
+
11
+ def toDjangoHeaderName(src):
12
+
13
+ return 'HTTP_' + src.upper().replace('-','_')
14
+
15
+ class UseridUtil(object):
16
+ WHATAP_R = "WHATAP"
17
+
18
+ @staticmethod
19
+ def getUserId(req, defValue):
20
+ try:
21
+
22
+ if conf.user_header_ticket:
23
+ ticket = UseridUtil.getHeader(req, conf.user_header_ticket)
24
+ if ticket:
25
+ return hash_util.hashFromString(ticket), ticket
26
+ return 0, ""
27
+ cookie = UseridUtil.getHeader(req, "Cookie")
28
+ if cookie:
29
+ if len(cookie) >= conf.trace_user_cookie_limit :
30
+ return hash_util.hashFromString(defValue) if defValue else 0, defValue or ""
31
+
32
+ x1 = cookie.find(UseridUtil.WHATAP_R)
33
+ if x1 >= 0:
34
+ x2 = cookie.find(';', x1)
35
+ if x2 > 0:
36
+ value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1: x2]
37
+ else:
38
+ value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1:]
39
+ return hexa32.toLong32(value), value
40
+ userid = KeyGen.next()
41
+ return userid, hexa32.toString32(userid)
42
+ except Exception:
43
+ exc_type, exc_value, exc_traceback = sys.exc_info()
44
+ logger.debug("A502", 10, str(exc_value))
45
+ return hash_util.hashFromString(defValue) if defValue else 0, defValue or ""
46
+
47
+ @staticmethod
48
+ def setUserId(req, res, cookieValue):
49
+ try:
50
+ if not conf.user_header_ticket:
51
+ cookie = UseridUtil.getHeaderEx(req, "Cookie")
52
+ if not cookie or cookie.find(UseridUtil.WHATAP_R) < 0 or cookie.find(cookieValue) < 0:
53
+ UseridUtil.setCookie(res, UseridUtil.WHATAP_R, cookieValue, bit_util.INT_MAX_VALUE, "/", conf.trace_user_cookie_domain )
54
+ except Exception:
55
+ exc_type, exc_value, exc_traceback = sys.exc_info()
56
+ logger.debug("A503", 10, str(exc_value))
57
+
58
+ @staticmethod
59
+ def DEPRECATED_getUserid(req, res, defValue):
60
+ try:
61
+ if conf.user_header_ticket_enabled:
62
+ ticket = UseridUtil.getHeader(req, conf.user_header_ticket)
63
+ if ticket:
64
+ return hash_util.hash(ticket)
65
+ return 0
66
+ cookie = UseridUtil.getHeader(req, "Cookie")
67
+ if cookie:
68
+ if len(cookie) >= conf.trace_user_cookie_limit :
69
+ return defValue
70
+
71
+ x1 = cookie.find(UseridUtil.WHATAP_R)
72
+ if x1 >= 0:
73
+ x2 = cookie.find(';', x1)
74
+ if x2 > 0:
75
+ value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1: x2]
76
+ else:
77
+ value = cookie[x1 + len(UseridUtil.WHATAP_R) + 1:]
78
+ return hexa32.toLong32(value)
79
+ UseridUtil.setCookie(res, UseridUtil.WHATAP_R, hexa32.toString32(KeyGen.next()), bit_util.INT_MAX_VALUE, "/", conf.trace_user_cookie_domain )
80
+
81
+ except Exception:
82
+ exc_type, exc_value, exc_traceback = sys.exc_info()
83
+ logger.debug("A502",10, str(exc_value))
84
+
85
+ return defValue
86
+
87
+ META_DICT = {'django': lambda x, name: x.get(toDjangoHeaderName(name))}
88
+
89
+ @staticmethod
90
+ def getHeader(args, name):
91
+ for arg in args:
92
+ if isinstance(arg, dict):
93
+ if name in arg:
94
+ return arg[name]
95
+ else:
96
+ for fn in UseridUtil.META_DICT.values():
97
+ v = fn(arg, name)
98
+ if v:
99
+ return v
100
+
101
+ return None
102
+
103
+ GET_HEADER={'META': lambda x : x.META.get}
104
+ @staticmethod
105
+ def getHeaderEx(req, name):
106
+ name = toDjangoHeaderName(name)
107
+
108
+ for k, fn in UseridUtil.GET_HEADER.items():
109
+ if hasattr(req, k):
110
+ return fn(req)(name)
111
+
112
+ return None
113
+
114
+ SETCOOKIE_METHODS={
115
+ "set_cookie": lambda res, key, value, max_age, path, domain : res.set_cookie(key, value, max_age = max_age, path=path, domain=domain )
116
+ }
117
+ @staticmethod
118
+ def setCookie(res, key, value, max_age, path, domain):
119
+ for mname, fn in UseridUtil.SETCOOKIE_METHODS.items():
120
+ if hasattr(res, mname):
121
+ fn(res, key, value, max_age, path, domain)
122
+ break
123
+
124
+ @staticmethod
125
+ def getRemoteAddr(args):
126
+ if conf.trace_http_client_ip_header_key:
127
+ header_val = UseridUtil.getHeader(args, conf.trace_http_client_ip_header_key)
128
+ if header_val:
129
+ return header_val.split(',')[0].strip()
130
+ x_forwarded_for = UseridUtil.getHeader(args, "x-forwarded-for")
131
+ if x_forwarded_for:
132
+ return x_forwarded_for.split(',')[0].strip()
133
+ return UseridUtil.getHeader(args, "REMOTE_ADDR")
134
+ #return UseridUtil.getHeader(args, "REMOTE_ADDR")
@@ -0,0 +1 @@
1
+ from whatap.value.list_value import ListValue
@@ -0,0 +1,38 @@
1
+ from whatap.value.value import Value
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+ from whatap.util.compare_util import CompareUtil
5
+ from whatap.util.hash_util import HashUtil
6
+
7
+
8
+ class BlobValue(Value):
9
+ def __init__(self, value=None):
10
+ super(BlobValue, self).__init__()
11
+ self.value = value
12
+
13
+ def compareTo(self, object):
14
+ if isinstance(object, BlobValue):
15
+ return CompareUtil.compareTo(self.value, object.value)
16
+ return 1
17
+
18
+ def equals(self, object):
19
+ if isinstance(object, BlobValue):
20
+ if not self.value:
21
+ return object.value is None
22
+ return self.value == object.value
23
+ return False
24
+
25
+ def hashCode(self):
26
+ if not self.value:
27
+ return 0
28
+ return HashUtil.hash(self.value)
29
+
30
+ def write(self, dout):
31
+ dout.writeBlob(self.value)
32
+
33
+ def read(self, din):
34
+ self.value = din.readBlob()
35
+ return self
36
+
37
+ def getValueType(self):
38
+ return ValueEnum.BLOB
@@ -0,0 +1,33 @@
1
+ from whatap.value.value import Value
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+
5
+ class BooleanValue(Value):
6
+ def __init__(self, value=None):
7
+ super(BooleanValue, self).__init__()
8
+ self.value = value if isinstance(value, bool) else False
9
+
10
+ def compareTo(self, object):
11
+ if isinstance(object, BooleanValue):
12
+ if self.value == object.value:
13
+ return 0
14
+ return 1 if self.value else -1
15
+ return 1
16
+
17
+ def equals(self, object):
18
+ if isinstance(object, BooleanValue):
19
+ return self.value == object.value
20
+ return False
21
+
22
+ def hashCode(self):
23
+ return 1 if self.value else 0
24
+
25
+ def write(self, dout):
26
+ dout.writeBoolean(self.value)
27
+
28
+ def read(self, din):
29
+ self.value = din.readBoolean()
30
+ return self
31
+
32
+ def getValueType(self):
33
+ return ValueEnum.BOOLEAN
@@ -0,0 +1,36 @@
1
+ from whatap.value.number_value import NumberValue
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+
5
+ class DecimalValue(NumberValue):
6
+ def __init__(self, value=None):
7
+ super(DecimalValue, self).__init__()
8
+ self.value = value
9
+
10
+ def compareTo(self, object):
11
+ if isinstance(object, DecimalValue):
12
+ if self.value < object.value:
13
+ return -1
14
+ elif self.value == object.value:
15
+ return 0
16
+ else:
17
+ return 1
18
+ return 1
19
+
20
+ def equals(self, object):
21
+ if isinstance(object, DecimalValue):
22
+ return self.value == object.value
23
+ return False
24
+
25
+ def hashCode(self):
26
+ return self.value ^ (self.value >> 32)
27
+
28
+ def write(self, dout):
29
+ dout.writeDecimal(self.value)
30
+
31
+ def read(self, din):
32
+ self.value = din.readDecimal()
33
+ return self
34
+
35
+ def getValueType(self):
36
+ return ValueEnum.DECIMAL
@@ -0,0 +1,86 @@
1
+ from whatap.value.summary_value import SummaryValue
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+
5
+ class DoubleSummary(SummaryValue):
6
+ def __init__(self):
7
+ super(DoubleSummary. self).__init__()
8
+ self.sum = 0
9
+ self.count = 0
10
+ self.min = 0
11
+ self.max = 0
12
+
13
+ def getValueType(self):
14
+ return ValueEnum.DOUBLE_SUMMARY
15
+
16
+ def write(self, dout):
17
+ dout.writeDouble(self.sum)
18
+ dout.writeInt(self.count)
19
+ dout.writeDouble(self.min)
20
+ dout.writeDouble(self.max)
21
+
22
+ def read(self, din):
23
+ self.sum = din.readDouble()
24
+ self.count = din.readInt()
25
+ self.min = din.readDouble()
26
+ self.max = din.readDouble()
27
+ return self
28
+
29
+ def toObject(self):
30
+ return self
31
+
32
+ def addCount(self):
33
+ self.count += 1
34
+
35
+ def add(self, value):
36
+ if not value:
37
+ return self
38
+
39
+ if isinstance(value, int):
40
+ if not self.count:
41
+ self.sum = value
42
+ self.count = 1
43
+ self.max = value
44
+ self.min = value
45
+ else:
46
+ self.sum += value
47
+ self.count += 1
48
+ self.max = max(self.max, value)
49
+ self.min = min(self.min, value)
50
+
51
+ elif isinstance(value, SummaryValue):
52
+ if not value.getCount():
53
+ return self
54
+
55
+ self.count += value.getCount()
56
+ self.sum += value.doubleSum()
57
+ self.min = min(self.min, value.doubleMin())
58
+ self.max = max(self.max, value.doubleMax())
59
+ return self
60
+
61
+ def longSum(self):
62
+ return self.sum
63
+
64
+ def longMin(self):
65
+ return self.min
66
+
67
+ def longMax(self):
68
+ return self.max
69
+
70
+ def longAvg(self):
71
+ return 0 if not self.count else self.sum / self.count
72
+
73
+ def doubleSum(self):
74
+ return self.sum
75
+
76
+ def doubleMin(self):
77
+ return self.min
78
+
79
+ def doubleMax(self):
80
+ return self.max
81
+
82
+ def doubleAvg(self):
83
+ return 0 if not self.count else self.sum / self.count
84
+
85
+ def getCount(self):
86
+ return self.count
@@ -0,0 +1,33 @@
1
+ from whatap.value.number_value import NumberValue
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+
5
+ class DoubleValue(NumberValue):
6
+ def __init__(self, value=None):
7
+ super(DoubleValue, self).__init__()
8
+ self.value = value
9
+
10
+ def compareTo(self, object):
11
+ if isinstance(object, DoubleValue):
12
+ if self.value != object.value:
13
+ return 1 if self.value > object.value else -1
14
+ return 0
15
+ return 1
16
+
17
+ def equals(self, object):
18
+ if isinstance(object, DoubleValue):
19
+ return self.value == object.value
20
+ return False
21
+
22
+ def hashCode(self):
23
+ return self.value ^ (self.value >> 32)
24
+
25
+ def write(self, dout):
26
+ dout.writeDouble(self.value)
27
+
28
+ def read(self, din):
29
+ self.value = din.readDouble()
30
+ return self
31
+
32
+ def getValueType(self):
33
+ return ValueEnum.DOUBLE
@@ -0,0 +1,42 @@
1
+ from whatap.value.value import Value
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+ from whatap.util.compare_util import CompareUtil
5
+
6
+
7
+ class FloatArray(Value):
8
+ def __init__(self, value=None):
9
+ super(FloatArray, self).__init__()
10
+ self.value = value if isinstance(value, list) else []
11
+ self._hash = 0
12
+
13
+ def compareTo(self, object):
14
+ if isinstance(object, FloatArray):
15
+ return CompareUtil.compareTo(self.value, object.value)
16
+ return 1
17
+
18
+ def equals(self, object):
19
+ if isinstance(object, FloatArray):
20
+ return self.value == object.value
21
+ return False
22
+
23
+ def hashCode(self):
24
+ if not self._hash:
25
+ if not self.value:
26
+ return 0
27
+
28
+ result = 1
29
+ for v in self.value:
30
+ result = 31 * result + round(v)
31
+ self._hash = result
32
+ return self._hash
33
+
34
+ def write(self, dout):
35
+ dout.writeFloatArray(self.value)
36
+
37
+ def read(self, din):
38
+ self.value = din.readFloatArray()
39
+ return self
40
+
41
+ def getValueType(self):
42
+ return ValueEnum.ARRAY_FLOAT
@@ -0,0 +1,34 @@
1
+ from whatap.value.number_value import NumberValue
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+ from whatap.util.compare_util import CompareUtil
5
+
6
+
7
+ class FloatValue(NumberValue):
8
+ def __init__(self, value=0.0):
9
+
10
+ super(FloatValue, self).__init__()
11
+ self.value = value
12
+
13
+ def compareTo(self, object):
14
+ if isinstance(object, FloatValue):
15
+ return CompareUtil.compareTo(self.value, object.value)
16
+ return 1
17
+
18
+ def equals(self, object):
19
+ if isinstance(object, FloatValue):
20
+ return self.value == object.value
21
+ return False
22
+
23
+ def hashCode(self):
24
+ return round(self.value)
25
+
26
+ def write(self, dout):
27
+ dout.writeFloat(self.value)
28
+
29
+ def read(self, din):
30
+ self.value = din.readFloat()
31
+ return self
32
+
33
+ def getValueType(self):
34
+ return ValueEnum.FLOAT
@@ -0,0 +1,42 @@
1
+ from whatap.value.value import Value
2
+ from whatap.value.value_enum import ValueEnum
3
+
4
+ from whatap.util.compare_util import CompareUtil
5
+
6
+
7
+ class IntArray(Value):
8
+ def __init__(self, value=None):
9
+ super(IntArray, self).__init__()
10
+ self.value = value if isinstance(value, list) else []
11
+ self._hash = 0
12
+
13
+ def compareTo(self, object):
14
+ if isinstance(object, IntArray):
15
+ return CompareUtil.compareTo(self.value, object.value)
16
+ return 1
17
+
18
+ def equals(self, object):
19
+ if isinstance(object, IntArray):
20
+ return self.value == object.value
21
+ return False
22
+
23
+ def hashCode(self):
24
+ if not self._hash:
25
+ if not self.value:
26
+ return 0
27
+
28
+ result = 1
29
+ for v in self.value:
30
+ result = 31 * result + v
31
+ self._hash = result
32
+ return self._hash
33
+
34
+ def write(self, dout):
35
+ dout.writeIntArray(self.value)
36
+
37
+ def read(self, din):
38
+ self.value = din.readIntArray()
39
+ return self
40
+
41
+ def getValueType(self):
42
+ return ValueEnum.ARRAY_INT
@@ -0,0 +1,50 @@
1
+ from whatap.io.data_inputx import DataInputX
2
+ from whatap.value.value import Value
3
+ from whatap.value.value_enum import ValueEnum
4
+
5
+ from whatap.util.compare_util import CompareUtil
6
+ from whatap.util.ip_util import IPUtil
7
+
8
+
9
+ class IP4Value(Value):
10
+ def __init__(self, value=None):
11
+ super(IP4Value, self).__init__()
12
+ if isinstance(object, str):
13
+ self.value = IPUtil.toBytes(value)
14
+ else:
15
+ self.value = None
16
+ self.empty = bytearray(4)
17
+
18
+ def compareTo(self, object):
19
+ if isinstance(object, IP4Value):
20
+ return CompareUtil.compareTo(self.value, object.value)
21
+ return 1
22
+
23
+ def equals(self, object):
24
+ if isinstance(object, IP4Value):
25
+ return self.value == object.value
26
+ return False
27
+
28
+ def hashCode(self):
29
+ if self.value == self.empty:
30
+ return 0
31
+ return DataInputX.toInt(self.value, 0)
32
+
33
+ def write(self, dout):
34
+ if not self.value:
35
+ self.value = self.empty
36
+ dout.write(self.value)
37
+
38
+ def read(self, din):
39
+ if not self.value:
40
+ self.value = self.empty
41
+ self.value = din.read(4)
42
+ return self
43
+
44
+ def toString(self):
45
+ if not self.value:
46
+ self.value = self.empty
47
+ return IPUtil.toString(self.value)
48
+
49
+ def getValueType(self):
50
+ return ValueEnum.IP4ADDR