whatap 1.0.1 → 1.0.2

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 (198) hide show
  1. package/README.md +32 -78
  2. package/lib/conf/conf-sys-mon.js +101 -0
  3. package/lib/conf/config-default.js +10 -3
  4. package/lib/conf/configure.js +369 -349
  5. package/lib/conf/license.js +1 -1
  6. package/lib/control/cmd-config.js +24 -0
  7. package/lib/control/control-handler.js +367 -0
  8. package/lib/control/packagectr-helper.js +34 -3
  9. package/lib/core/agent.js +176 -882
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/request-agent.js +27 -0
  12. package/lib/core/shimmer.js +82 -36
  13. package/lib/counter/counter-manager.js +79 -8
  14. package/lib/counter/meter/meter-activex.js +67 -0
  15. package/lib/counter/meter/meter-httpc.js +57 -0
  16. package/lib/counter/meter/meter-resource.js +9 -0
  17. package/lib/counter/meter/meter-service.js +168 -0
  18. package/lib/counter/meter/meter-socket.io.js +51 -0
  19. package/lib/counter/meter/meter-sql.js +71 -0
  20. package/lib/counter/meter/meter-users.js +58 -0
  21. package/lib/counter/meter.js +183 -0
  22. package/lib/counter/task/activetransaction.js +68 -17
  23. package/lib/counter/task/agentinfo.js +107 -0
  24. package/lib/{system → counter/task}/gc-action.js +27 -74
  25. package/lib/counter/task/gcstat.js +34 -0
  26. package/lib/counter/task/heapmem.js +25 -0
  27. package/lib/counter/task/httpc.js +76 -0
  28. package/lib/counter/task/metering-info.js +125 -0
  29. package/lib/counter/task/proc-cpu.js +29 -0
  30. package/lib/counter/task/realtimeuser.js +31 -0
  31. package/lib/counter/task/res/systemECSTask.js +39 -0
  32. package/lib/counter/task/res/systemKubeTask.js +53 -0
  33. package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
  34. package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
  35. package/lib/counter/task/res-sys-cpu.js +62 -0
  36. package/lib/counter/task/service.js +202 -0
  37. package/lib/counter/task/socketio.js +30 -0
  38. package/lib/counter/task/sql.js +105 -0
  39. package/lib/counter/task/systemperf.js +43 -0
  40. package/lib/data/datapack-sender.js +289 -0
  41. package/lib/data/dataprofile-agent.js +162 -0
  42. package/lib/data/datatext-agent.js +135 -0
  43. package/lib/data/event-level.js +15 -0
  44. package/lib/data/test.js +49 -0
  45. package/lib/data/zipprofile.js +197 -0
  46. package/lib/env/constants.js +21 -0
  47. package/lib/error/error-handler.js +437 -0
  48. package/lib/io/data-inputx.js +13 -3
  49. package/lib/io/data-outputx.js +268 -206
  50. package/lib/kube/kube-client.js +144 -0
  51. package/lib/lang/text-types.js +58 -0
  52. package/lib/logger.js +6 -6
  53. package/lib/logsink/line-log-util.js +87 -0
  54. package/lib/logsink/line-log.js +12 -0
  55. package/lib/logsink/log-sender.js +78 -0
  56. package/lib/logsink/log-tracer.js +40 -0
  57. package/lib/logsink/sender-util.js +56 -0
  58. package/lib/logsink/zip/zip-send.js +177 -0
  59. package/lib/net/netflag.js +55 -0
  60. package/lib/net/receiver.js +66 -0
  61. package/lib/net/security-master.js +139 -20
  62. package/lib/net/sender.js +141 -0
  63. package/lib/net/tcp-return.js +18 -0
  64. package/lib/net/tcp-session.js +286 -0
  65. package/lib/net/tcpreq-client-proxy.js +70 -0
  66. package/lib/net/tcprequest-mgr.js +58 -0
  67. package/lib/observers/apollo-server-observer.js +33 -27
  68. package/lib/observers/cluster-observer.js +22 -0
  69. package/lib/observers/express-observer.js +215 -0
  70. package/lib/observers/file-observer.js +184 -0
  71. package/lib/observers/global-observer.js +155 -80
  72. package/lib/observers/grpc-observer.js +336 -0
  73. package/lib/observers/http-observer.js +666 -236
  74. package/lib/observers/maria-observer.js +204 -362
  75. package/lib/observers/memcached-observer.js +56 -0
  76. package/lib/observers/mongo-observer.js +317 -0
  77. package/lib/observers/mongodb-observer.js +169 -226
  78. package/lib/observers/mongoose-observer.js +518 -323
  79. package/lib/observers/mssql-observer.js +177 -418
  80. package/lib/observers/mysql-observer.js +342 -449
  81. package/lib/observers/mysql2-observer.js +396 -358
  82. package/lib/observers/net-observer.js +77 -0
  83. package/lib/observers/oracle-observer.js +559 -384
  84. package/lib/observers/pgsql-observer.js +231 -489
  85. package/lib/observers/prisma-observer.js +303 -92
  86. package/lib/observers/process-observer.js +79 -35
  87. package/lib/observers/promise-observer.js +31 -0
  88. package/lib/observers/redis-observer.js +166 -331
  89. package/lib/observers/schedule-observer.js +67 -0
  90. package/lib/observers/socket.io-observer.js +226 -187
  91. package/lib/observers/stream-observer.js +19 -0
  92. package/lib/observers/thrift-observer.js +197 -0
  93. package/lib/observers/websocket-observer.js +175 -301
  94. package/lib/pack/activestack-pack.js +55 -0
  95. package/lib/pack/apenum.js +8 -0
  96. package/lib/pack/counter-pack.js +3 -0
  97. package/lib/pack/errorsnap-pack.js +69 -0
  98. package/lib/pack/event-pack.js +54 -0
  99. package/lib/pack/hitmap-pack.js +63 -0
  100. package/lib/pack/hitmap-pack1.js +152 -0
  101. package/lib/pack/log-sink-pack.js +14 -52
  102. package/lib/pack/netstat.js +15 -0
  103. package/lib/pack/otype.js +7 -0
  104. package/lib/pack/profile-pack.js +49 -0
  105. package/lib/pack/realtimeuser-pack.js +41 -0
  106. package/lib/pack/stat-general-pack.js +96 -0
  107. package/lib/pack/staterror-pack.js +120 -0
  108. package/lib/pack/stathttpc-pack.js +66 -0
  109. package/lib/pack/stathttpc-rec.js +78 -0
  110. package/lib/pack/statremote-pack.js +46 -0
  111. package/lib/pack/statservice-pack.js +63 -0
  112. package/lib/pack/statservice-pack1.js +88 -0
  113. package/lib/pack/statservice-rec.js +292 -0
  114. package/lib/pack/statservice-rec_dep.js +151 -0
  115. package/lib/pack/statsql-pack.js +69 -0
  116. package/lib/pack/statsql-rec.js +100 -0
  117. package/lib/pack/statuseragent-pack.js +44 -0
  118. package/lib/pack/tagcount-pack.js +4 -4
  119. package/lib/pack/tagctr.js +15 -0
  120. package/lib/pack/text-pack.js +50 -0
  121. package/lib/pack/time-count.js +25 -0
  122. package/lib/pack/websocket.js +15 -0
  123. package/lib/pack/zip-pack.js +70 -0
  124. package/lib/pii/pii-item.js +31 -0
  125. package/lib/pii/pii-mask.js +174 -0
  126. package/lib/plugin/plugin-loadermanager.js +57 -0
  127. package/lib/plugin/plugin.js +75 -0
  128. package/lib/service/tx-record.js +332 -0
  129. package/lib/stat/stat-error.js +116 -0
  130. package/lib/stat/stat-httpc.js +98 -0
  131. package/lib/stat/stat-remote-ip.js +46 -0
  132. package/lib/stat/stat-remote-ipurl.js +88 -0
  133. package/lib/stat/stat-sql.js +113 -0
  134. package/lib/stat/stat-tranx.js +58 -0
  135. package/lib/stat/stat-tx-caller.js +160 -0
  136. package/lib/stat/stat-tx-domain.js +111 -0
  137. package/lib/stat/stat-tx-referer.js +112 -0
  138. package/lib/stat/stat-useragent.js +48 -0
  139. package/lib/stat/timingsender.js +76 -0
  140. package/lib/step/activestack-step.js +38 -0
  141. package/lib/step/dbc-step.js +36 -0
  142. package/lib/step/http-stepx.js +67 -0
  143. package/lib/step/message-step.js +40 -0
  144. package/lib/step/method-stepx.js +45 -0
  145. package/lib/step/resultset-step.js +40 -0
  146. package/lib/step/securemsg-step.js +44 -0
  147. package/lib/step/socket-step.js +46 -0
  148. package/lib/step/sql-stepx.js +68 -0
  149. package/lib/step/sqlxtype.js +16 -0
  150. package/lib/step/step.js +66 -0
  151. package/lib/step/stepenum.js +54 -0
  152. package/lib/topology/link.js +63 -0
  153. package/lib/topology/nodeinfo.js +123 -0
  154. package/lib/topology/status-detector.js +111 -0
  155. package/lib/trace/trace-context-manager.js +113 -25
  156. package/lib/trace/trace-context.js +21 -7
  157. package/lib/trace/trace-httpc.js +17 -11
  158. package/lib/trace/trace-sql.js +29 -21
  159. package/lib/util/anylist.js +103 -0
  160. package/lib/util/cardinality/hyperloglog.js +106 -0
  161. package/lib/util/cardinality/murmurhash.js +31 -0
  162. package/lib/util/cardinality/registerset.js +75 -0
  163. package/lib/util/errordata.js +21 -0
  164. package/lib/util/escape-literal-sql.js +5 -5
  165. package/lib/util/hashutil.js +18 -18
  166. package/lib/util/iputil_x.js +527 -0
  167. package/lib/util/keygen.js +0 -3
  168. package/lib/util/kube-util.js +73 -0
  169. package/lib/util/linkedset.js +1 -2
  170. package/lib/util/nodeutil.js +2 -1
  171. package/lib/util/paramsecurity.js +80 -0
  172. package/lib/util/pre-process.js +13 -0
  173. package/lib/util/process-seq.js +166 -0
  174. package/lib/util/property-util.js +36 -0
  175. package/lib/util/request-queue.js +70 -0
  176. package/lib/util/requestdouble-queue.js +72 -0
  177. package/lib/util/resourceprofile.js +157 -0
  178. package/lib/util/stop-watch.js +30 -0
  179. package/lib/util/system-util.js +10 -0
  180. package/lib/util/userid-util.js +57 -0
  181. package/lib/value/map-value.js +3 -2
  182. package/package.json +9 -4
  183. package/whatap.conf +1 -4
  184. package/agent/darwin/arm64/whatap_nodejs +0 -0
  185. package/agent/linux/amd64/whatap_nodejs +0 -0
  186. package/agent/linux/arm64/whatap_nodejs +0 -0
  187. package/build.txt +0 -4
  188. package/lib/observers/ioredis-observer.js +0 -294
  189. package/lib/udp/async_sender.js +0 -119
  190. package/lib/udp/index.js +0 -17
  191. package/lib/udp/packet_enum.js +0 -52
  192. package/lib/udp/packet_queue.js +0 -69
  193. package/lib/udp/packet_type_enum.js +0 -33
  194. package/lib/udp/param_def.js +0 -72
  195. package/lib/udp/udp_session.js +0 -336
  196. package/lib/util/sql-util.js +0 -178
  197. package/lib/util/trace-helper.js +0 -91
  198. package/lib/util/transfer.js +0 -58
@@ -132,7 +132,7 @@ MapValue.prototype.getValueType = function() {
132
132
  };
133
133
  MapValue.prototype.write = function(dout) {
134
134
  dout.writeDecimal(this.table.size());
135
- var en = this.table.keys();
135
+ var en = this.table.keys();
136
136
  while(en.hasMoreElements()) {
137
137
  var key = en.nextElement();
138
138
  dout.writeText(key);
@@ -160,7 +160,7 @@ MapValue.prototype.toObject = function() {
160
160
  return this.table;
161
161
  };
162
162
  MapValue.prototype.putAllMap = function(m) {
163
- var en = m.keys();
163
+ var en = m.keys();
164
164
  while(en.hasMoreElements()) {
165
165
  var key = en.nextElement();
166
166
  var value =m.get(key);
@@ -172,6 +172,7 @@ MapValue.prototype.putAllMap = function(m) {
172
172
  MapValue.prototype.putAllMapValue = function(m) {
173
173
  this.putAllMap(m);
174
174
  };
175
+
175
176
  MapValue.prototype.internList = function (key) {
176
177
  let lv = this.table.get(key);
177
178
  if(!lv){
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "releaseDate": "20250924",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
@@ -11,13 +11,18 @@
11
11
  },
12
12
  "license": "UNLICENSED",
13
13
  "engines": {
14
- "node": ">=17"
14
+ "node": ">=v16.4.0"
15
15
  },
16
16
  "dependencies": {
17
+ "crypto": "^1.0.1",
18
+ "df": "^1.1.1",
17
19
  "long": "^3.2.0",
18
- "proper-lockfile": "^4.1.2"
20
+ "pidusage": "^1.1.0"
19
21
  },
20
22
  "devDependencies": {
21
- "long": "^3.2.0"
23
+ "crypto": "^1.0.1",
24
+ "df": "^1.1.1",
25
+ "long": "^3.2.0",
26
+ "pidusage": "^1.1.0"
22
27
  }
23
28
  }
package/whatap.conf CHANGED
@@ -1,5 +1,2 @@
1
1
  license=XXXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXX
2
- whatap.server.host=XXX.XXX.XXX.XXX
3
-
4
- app_name=XXX
5
- app_process_name=node
2
+ whatap.server.host=XXX.XXX.XXX.XXX
Binary file
Binary file
Binary file
package/build.txt DELETED
@@ -1,4 +0,0 @@
1
- app = 'NodeJS'
2
- name = 'whatap_nodejs'
3
- version = 'dev1.0.5'
4
- build_date = '20250923'
@@ -1,294 +0,0 @@
1
- var TraceContextManager = require('../trace/trace-context-manager'),
2
- HashUtil = require('../util/hashutil'),
3
- Logger = require('../logger'),
4
- conf = require('../conf/configure'),
5
- AsyncSender = require('../udp/async_sender'),
6
- PacketTypeEnum = require('../udp/packet_type_enum');
7
-
8
- const { AsyncResource } = require('async_hooks');
9
-
10
- var IORedisObserver = function (agent) {
11
- this.agent = agent;
12
- this.aop = agent.aop;
13
- this.packages = ['ioredis'];
14
- };
15
-
16
- IORedisObserver.prototype.inject = function (mod, modName) {
17
- if (mod.__whatap_observe__) {
18
- return;
19
- }
20
- mod.__whatap_observe__ = true;
21
- Logger.initPrint("IORedisObserver");
22
-
23
- if (conf.sql_enabled === false) {
24
- return;
25
- }
26
-
27
- var self = this;
28
- var dbc_hash = 0;
29
- var dbc = 'redis://';
30
-
31
- // Redis 명령어 매핑 (Redis observer와 동일)
32
- var REDIS_COMMANDS = {
33
- // 기본 명령어들
34
- 'ping': 'PING', 'get': 'GET', 'set': 'SET', 'del': 'DEL', 'exists': 'EXISTS', 'keys': 'KEYS',
35
- 'setex': 'SETEX', 'setEx': 'SETEX', 'expire': 'EXPIRE', 'expireAt': 'EXPIREAT', 'expireat': 'EXPIREAT',
36
- 'ttl': 'TTL', 'incr': 'INCR', 'decr': 'DECR', 'incrBy': 'INCRBY', 'incrby': 'INCRBY',
37
- 'decrBy': 'DECRBY', 'decrby': 'DECRBY', 'mGet': 'MGET', 'mget': 'MGET', 'mSet': 'MSET', 'mset': 'MSET',
38
-
39
- // Hash 명령어들
40
- 'hSet': 'HSET', 'hset': 'HSET', 'hGet': 'HGET', 'hget': 'HGET', 'hGetAll': 'HGETALL', 'hgetall': 'HGETALL',
41
- 'hMGet': 'HMGET', 'hmget': 'HMGET', 'hMSet': 'HMSET', 'hmset': 'HMSET', 'hDel': 'HDEL', 'hdel': 'HDEL',
42
-
43
- // List 명령어들
44
- 'lPush': 'LPUSH', 'lpush': 'LPUSH', 'rPush': 'RPUSH', 'rpush': 'RPUSH', 'lPop': 'LPOP', 'lpop': 'LPOP',
45
- 'rPop': 'RPOP', 'rpop': 'RPOP', 'lRange': 'LRANGE', 'lrange': 'LRANGE', 'lLen': 'LLEN', 'llen': 'LLEN',
46
- 'lSet': 'LSET', 'lset': 'LSET', 'lRem': 'LREM', 'lrem': 'LREM',
47
-
48
- // Set 명령어들
49
- 'sAdd': 'SADD', 'sadd': 'SADD', 'sMembers': 'SMEMBERS', 'smembers': 'SMEMBERS', 'sRem': 'SREM', 'srem': 'SREM',
50
- 'sCard': 'SCARD', 'scard': 'SCARD',
51
-
52
- // Sorted Set 명령어들
53
- 'zAdd': 'ZADD', 'zadd': 'ZADD', 'zRange': 'ZRANGE', 'zrange': 'ZRANGE', 'zRem': 'ZREM', 'zrem': 'ZREM'
54
- };
55
-
56
- // DBC 정보 설정
57
- function setupDbcInfo(connectionOptions) {
58
- if (dbc_hash === 0 && connectionOptions) {
59
- dbc = 'redis://';
60
- dbc += connectionOptions.host || 'localhost';
61
- dbc += ':';
62
- dbc += connectionOptions.port || 6379;
63
- dbc += '/';
64
- dbc += connectionOptions.db || 0;
65
- dbc_hash = HashUtil.hashFromString(dbc);
66
- }
67
- }
68
-
69
- function handleRedisError(ctx, err) {
70
- if (!err) return;
71
-
72
- try {
73
- var errorClass = err.code || err.name || 'IORedisError';
74
- var errorMessage = err.message || 'ioredis error';
75
-
76
- if (!ctx.error) ctx.error = 1;
77
- ctx.status = 500;
78
- var errors = [errorClass, errorMessage];
79
-
80
- AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
81
- } catch (e) {
82
- Logger.printError('WHATAP-234', 'Error handling IORedis error', e, false);
83
- }
84
- }
85
-
86
- // IORedis 클래스의 prototype.sendCommand 메서드를 직접 후킹하는 방식
87
- if (mod && mod.prototype && !mod.__whatap_wrapped__) {
88
- // IORedis의 핵심 메서드인 sendCommand를 후킹
89
- if (mod.prototype.sendCommand && !mod.prototype.sendCommand.__whatap_wrapped__) {
90
- var originalSendCommand = mod.prototype.sendCommand;
91
-
92
- mod.prototype.sendCommand = function(command, stream) {
93
- var ctx = TraceContextManager.getCurrentContext();
94
- if (!ctx || !command || !command.name) {
95
- return originalSendCommand.apply(this, arguments);
96
- }
97
-
98
- var commandName = command.name.toLowerCase();
99
- var normalizedCommand = REDIS_COMMANDS[commandName] || command.name.toUpperCase();
100
-
101
- // 연결 정보 설정 (한 번만)
102
- if (dbc_hash === 0 && this.options) {
103
- setupDbcInfo(this.options);
104
- }
105
-
106
- var self = this;
107
- var commandArgs = command.args || [];
108
-
109
- const asyncResource = new AsyncResource('ioredis-command');
110
-
111
- return asyncResource.runInAsyncScope(() => {
112
- // DB 연결 패킷 전송
113
- ctx.start_time = Date.now();
114
- ctx.elapsed = 0;
115
- ctx.active_sqlhash = true;
116
- AsyncSender.send_packet(PacketTypeEnum.TX_DB_CONN, ctx, [dbc]);
117
-
118
- // IORedis 명령 시작
119
- var command_start_time = Date.now();
120
- ctx.footprint(`IORedis ${normalizedCommand} Start`);
121
-
122
- // IORedis에서는 command.args에서 쿼리 조합 (Python APM 방식 참고)
123
- var queryParts = [normalizedCommand];
124
- if (commandArgs && commandArgs.length > 0) {
125
- // 각 인자를 문자열로 변환하고 20자로 제한
126
- var argStrings = commandArgs.map(function(arg) {
127
- var argStr = String(arg);
128
- return argStr.length > 20 ? argStr.substring(0, 20) + '...' : argStr;
129
- });
130
- queryParts = queryParts.concat(argStrings);
131
- }
132
- var commandText = `Redis ` + queryParts.join(' ');
133
-
134
- try {
135
- var result = originalSendCommand.apply(self, arguments);
136
-
137
- // IORedis는 항상 Promise를 반환
138
- if (result && typeof result.then === 'function') {
139
- return result.then(
140
- function(res) {
141
- var command_elapsed = Date.now() - command_start_time;
142
- var resultCount = 0;
143
-
144
- if (res !== undefined && res !== null) {
145
- if (Array.isArray(res)) {
146
- resultCount = res.length;
147
- } else if (typeof res === 'string' || typeof res === 'number') {
148
- resultCount = 1;
149
- }
150
- }
151
-
152
- ctx.elapsed = command_elapsed;
153
- ctx.active_sqlhash = false;
154
- AsyncSender.send_packet(PacketTypeEnum.TX_SQL, ctx, [dbc, commandText, String(resultCount)]);
155
- ctx.footprint(`IORedis ${normalizedCommand} Done`);
156
- return res;
157
- },
158
- function(err) {
159
- handleRedisError(ctx, err);
160
- var command_elapsed = Date.now() - command_start_time;
161
- ctx.elapsed = command_elapsed;
162
- ctx.active_sqlhash = false;
163
- AsyncSender.send_packet(PacketTypeEnum.TX_SQL, ctx, [dbc, commandText, '0']);
164
- ctx.footprint(`IORedis ${normalizedCommand} Done`);
165
- throw err;
166
- }
167
- );
168
- } else {
169
- // 예외적으로 Promise가 아닌 경우 처리
170
- var command_elapsed = Date.now() - command_start_time;
171
- var resultCount = 0;
172
-
173
- if (result !== undefined && result !== null) {
174
- if (Array.isArray(result)) {
175
- resultCount = result.length;
176
- } else if (typeof result === 'string' || typeof result === 'number') {
177
- resultCount = 1;
178
- }
179
- }
180
-
181
- ctx.elapsed = command_elapsed;
182
- ctx.active_sqlhash = false;
183
- AsyncSender.send_packet(PacketTypeEnum.TX_SQL, ctx, [dbc, commandText, String(resultCount)]);
184
- ctx.footprint(`IORedis ${normalizedCommand} Done`);
185
- return result;
186
- }
187
- } catch (commandError) {
188
- handleRedisError(ctx, commandError);
189
- var command_elapsed = Date.now() - command_start_time;
190
- ctx.elapsed = command_elapsed;
191
- ctx.active_sqlhash = false;
192
- AsyncSender.send_packet(PacketTypeEnum.TX_SQL, ctx, [dbc, commandText, '0']);
193
- ctx.footprint(`IORedis ${normalizedCommand} Done`);
194
- throw commandError;
195
- }
196
- });
197
- };
198
-
199
- mod.prototype.sendCommand.__whatap_wrapped__ = true;
200
- }
201
-
202
- // IORedis 생성자도 후킹하여 연결 정보 수집
203
- var originalConstructor = mod;
204
- function WrappedIORedis() {
205
- var args = Array.prototype.slice.call(arguments);
206
- var ctx = TraceContextManager.getCurrentContext();
207
-
208
- if (ctx) {
209
- ctx.start_time = Date.now();
210
- ctx.footprint('IORedis Client Creating');
211
- ctx.db_opening = true;
212
- }
213
-
214
- // 원본 생성자 호출
215
- var client = Object.create(originalConstructor.prototype);
216
- originalConstructor.apply(client, args);
217
-
218
- // 연결 옵션 파싱 및 DBC 정보 설정
219
- var options = {};
220
- if (args.length > 0) {
221
- if (typeof args[0] === 'string') {
222
- try {
223
- var url = new URL(args[0]);
224
- options = {
225
- host: url.hostname,
226
- port: parseInt(url.port) || 6379,
227
- db: parseInt(url.pathname.slice(1)) || 0
228
- };
229
- } catch (e) {
230
- options = { host: 'localhost', port: 6379, db: 0 };
231
- }
232
- } else if (typeof args[0] === 'number') {
233
- options = {
234
- host: args[1] || 'localhost',
235
- port: args[0],
236
- db: 0
237
- };
238
- } else if (typeof args[0] === 'object') {
239
- options = args[0] || {};
240
- if (!options.host) options.host = 'localhost';
241
- if (!options.port) options.port = 6379;
242
- if (options.db === undefined) options.db = 0;
243
- }
244
- } else {
245
- options = { host: 'localhost', port: 6379, db: 0 };
246
- }
247
-
248
- setupDbcInfo(options);
249
-
250
- if (ctx) {
251
- ctx.elapsed = Date.now() - (ctx.start_time || Date.now());
252
- ctx.footprint('IORedis Client Created');
253
- if (ctx.db_opening !== undefined) {
254
- ctx.db_opening = false;
255
- }
256
- }
257
-
258
- return client;
259
- }
260
-
261
- // 프로토타입과 정적 속성 복사
262
- WrappedIORedis.prototype = originalConstructor.prototype;
263
- Object.setPrototypeOf(WrappedIORedis, originalConstructor);
264
-
265
- Object.getOwnPropertyNames(originalConstructor).forEach(function(prop) {
266
- if (prop !== 'prototype' && prop !== 'name' && prop !== 'length') {
267
- try {
268
- var descriptor = Object.getOwnPropertyDescriptor(originalConstructor, prop);
269
- if (descriptor && descriptor.configurable !== false) {
270
- Object.defineProperty(WrappedIORedis, prop, descriptor);
271
- }
272
- } catch (e) {
273
- // 복사할 수 없는 속성은 건너뛰기
274
- }
275
- }
276
- });
277
-
278
- // 모듈 교체
279
- Object.getOwnPropertyNames(WrappedIORedis).forEach(function(prop) {
280
- if (prop !== 'prototype') {
281
- try {
282
- mod[prop] = WrappedIORedis[prop];
283
- } catch (e) {
284
- // 설정할 수 없는 속성은 건너뛰기
285
- }
286
- }
287
- });
288
-
289
- mod.__whatap_wrapped__ = true;
290
- Logger.initPrint("IORedis sendCommand method successfully wrapped");
291
- }
292
- };
293
-
294
- exports.IORedisObserver = IORedisObserver;
@@ -1,119 +0,0 @@
1
- const udpSession = require('./udp_session');
2
- const PacketTypeEnum = require('./packet_type_enum');
3
- const PacketQueue = require('./packet_queue');
4
-
5
- const SendType = {
6
- DATAS: 1,
7
- RELAY: 2
8
- };
9
-
10
- const packetQueue = PacketQueue.getInstance();
11
- let initialized = false;
12
- let sendThread = null;
13
-
14
- /**
15
- * Send a packet asynchronously
16
- * @param {number} packet_type - Type of packet from PacketTypeEnum
17
- * @param {object} ctx - Trace context
18
- * @param {array} datas - Array of data strings to send
19
- */
20
- function send_packet(packet_type, ctx, datas = []) {
21
- _initThread();
22
-
23
- // Deep copy the context to prevent modification
24
- let copiedCtx = structuredClone(ctx);
25
- if (packetQueue.full()) {
26
- return;
27
- }
28
-
29
- packetQueue.put([SendType.DATAS, [packet_type, copiedCtx, datas]]);
30
- }
31
-
32
- /**
33
- * Send relay pack data asynchronously
34
- * @param {Buffer} packbytes - Bytes to send
35
- */
36
- function send_relaypack(packbytes) {
37
- _initThread();
38
-
39
- if (packetQueue.full()) {
40
- return;
41
- }
42
-
43
- packetQueue.put([SendType.RELAY, packbytes]);
44
- }
45
-
46
- /**
47
- * Start the async processing thread
48
- */
49
- function startWhatapThread() {
50
- // If thread is already running, don't start another
51
- if (sendThread) {
52
- return;
53
- }
54
-
55
- // Start processing loop
56
- const processQueue = () => {
57
- const packet = packetQueue.get();
58
-
59
- if (!packet) {
60
- // No packet, wait and try again
61
- setTimeout(processQueue, 100);
62
- return;
63
- }
64
-
65
- try {
66
- const [sendType, params] = packet;
67
- if (sendType === SendType.DATAS) {
68
- const [packet_type, ctx, datas] = params;
69
- udpSession.send_packet(packet_type, ctx, datas);
70
- } else if (sendType === SendType.RELAY) {
71
- const packbytes = params;
72
- udpSession.send_relaypack(packbytes);
73
- }
74
- } catch (e) {
75
- console.error("Error processing queue item:", e);
76
- }
77
-
78
- // Continue processing
79
- setTimeout(processQueue, 0);
80
- };
81
-
82
- // Start the processing loop
83
- sendThread = setTimeout(processQueue, 0);
84
- console.log("WhaTap async sender thread started");
85
- }
86
-
87
- /**
88
- * Initialize the thread if not already initialized
89
- */
90
- function _initThread() {
91
- if (initialized) {
92
- return;
93
- }
94
-
95
- // Lock used to avoid multiple initializations
96
- const initLock = function() {
97
- if (initialized) {
98
- return;
99
- }
100
-
101
- try {
102
- initialized = true;
103
- startWhatapThread();
104
- } catch (e) {
105
- console.error("Error initializing thread:", e);
106
- initialized = false;
107
- }
108
- };
109
-
110
- initLock();
111
- }
112
-
113
- // Export functions
114
- module.exports = {
115
- send_packet,
116
- send_relaypack,
117
- startWhatapThread,
118
- _initThread
119
- };
package/lib/udp/index.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Main entry point for UDP module
3
- */
4
-
5
- const PacketEnum = require('./packet_enum');
6
- const PacketTypeEnum = require('./packet_type_enum');
7
- const ParamDef = require('./param_def');
8
- const UdpSession = require('./udp_session');
9
- const AsyncSender = require('./async_sender');
10
-
11
- module.exports = {
12
- PacketEnum,
13
- PacketTypeEnum,
14
- ParamDef,
15
- UdpSession,
16
- AsyncSender
17
- };
@@ -1,52 +0,0 @@
1
- class PacketEnum {
2
- static get PACKET_BUFFER_SIZE() { return 48 * 1024; }
3
- static get PACKET_SEND_BUFFER_SIZE() { return 64 * 1024; }
4
- static get DATA_SIZE_LIMIT() { return 30 * 1024 + 1; }
5
-
6
- static get SERVER() { return "127.0.0.1"; }
7
- static get PORT() { return 6600; }
8
- static get PACKET_VERSION() { return 60101; }
9
-
10
- // PACKET_HEADER
11
- static get PACKET_HEADER_TYPE_POS() { return 0; }
12
- static get PACKET_HEADER_TYPE_SIZE() { return 1; }
13
-
14
- static get PACKET_HEADER_VERSION_POS() { return 1; }
15
- static get PACKET_HEADER_VERSION_SIZE() { return 4; }
16
-
17
- static get PACKET_HEADER_LEN_POS() { return 5; }
18
- static get PACKET_HEADER_LEN_SIZE() { return 4; }
19
-
20
- // PACKET_BODY
21
- static get PACKET_BODY_ID_POS() { return 9; }
22
- static get PACKET_BODY_ID_SIZE() { return 8; }
23
-
24
- static get PACKET_BODY_START_TIME_POS() { return 17; }
25
- static get PACKET_BODY_START_TIME_SIZE() { return 8; }
26
-
27
- static get PACKET_BODY_ELAPSED_POS() { return 25; }
28
- static get PACKET_BODY_ELAPSED_SIZE() { return 4; }
29
-
30
- static get PACKET_BODY_CPU_POS() { return 29; }
31
- static get PACKET_BODY_CPU_SIZE() { return 8; }
32
-
33
- static get PACKET_BODY_MEMORY_POS() { return 37; }
34
- static get PACKET_BODY_MEMORY_SIZE() { return 8; }
35
-
36
- static get PACKET_BODY_THREAD_ID_POS() { return 45; }
37
- static get PACKET_BODY_THREAD_ID_SIZE() { return 8; }
38
-
39
- static get PACKET_BODY_TRACE_DATA_POS() { return 53; }
40
-
41
- // PACKET_SIZE
42
- static get PACKET_HEADER_SIZE() {
43
- return this.PACKET_HEADER_TYPE_SIZE + this.PACKET_HEADER_VERSION_SIZE + this.PACKET_HEADER_LEN_SIZE;
44
- }
45
-
46
- static get PACKET_BODY_REQUIRED_SIZE() {
47
- return this.PACKET_BODY_ID_SIZE + this.PACKET_BODY_START_TIME_SIZE + this.PACKET_BODY_ELAPSED_SIZE +
48
- this.PACKET_BODY_CPU_SIZE + this.PACKET_BODY_MEMORY_SIZE;
49
- }
50
- }
51
-
52
- module.exports = PacketEnum;
@@ -1,69 +0,0 @@
1
- /**
2
- * PacketQueue - Queue implementation for async sending packets
3
- * Implemented as a singleton to ensure only one queue exists.
4
- */
5
-
6
- class PacketQueue {
7
- constructor(maxSize = 1000) {
8
- // Singleton pattern: If instance exists, return it
9
- if (PacketQueue.instance) {
10
- return PacketQueue.instance;
11
- }
12
-
13
- // Initialize queue
14
- this.queue = [];
15
- this.maxSize = maxSize;
16
-
17
- // Store the instance
18
- PacketQueue.instance = this;
19
- }
20
-
21
- put(item) {
22
- if (this.queue.length < this.maxSize) {
23
- this.queue.push(item);
24
- return true;
25
- }
26
- return false;
27
- }
28
-
29
- get() {
30
- if (this.queue.length > 0) {
31
- return this.queue.shift();
32
- }
33
- return null;
34
- }
35
-
36
- full() {
37
- return this.queue.length >= this.maxSize;
38
- }
39
-
40
- empty() {
41
- return this.queue.length === 0;
42
- }
43
-
44
- size() {
45
- return this.queue.length;
46
- }
47
-
48
- clear() {
49
- this.queue = [];
50
- }
51
-
52
- /**
53
- * Get the singleton instance
54
- * @param {number} maxSize - Maximum size of the queue (only used if instance doesn't exist)
55
- * @returns {PacketQueue} - The singleton instance
56
- */
57
- static getInstance(maxSize = 1000) {
58
- if (!PacketQueue.instance) {
59
- PacketQueue.instance = new PacketQueue(maxSize);
60
- }
61
- return PacketQueue.instance;
62
- }
63
- }
64
-
65
- // Initialize the static instance property
66
- PacketQueue.instance = null;
67
-
68
- // Export the class
69
- module.exports = PacketQueue;
@@ -1,33 +0,0 @@
1
- class PacketTypeEnum {
2
- static get TX_BLANK() { return 0; }
3
- static get TX_START() { return 1; }
4
- static get TX_DB_CONN() { return 2; }
5
- static get TX_DB_FETCH() { return 3; }
6
- static get TX_SQL() { return 4; }
7
- static get TX_SQL_START() { return 5; }
8
- static get TX_SQL_END() { return 6; }
9
-
10
- static get TX_HTTPC() { return 7; }
11
- static get TX_HTTPC_START() { return 8; }
12
- static get TX_HTTPC_END() { return 9; }
13
-
14
- static get TX_ERROR() { return 10; }
15
- static get TX_MSG() { return 11; }
16
- static get TX_METHOD() { return 12; }
17
-
18
- static get TX_SECURE_MSG() { return 13; }
19
- static get TX_WEB_SOCKET() { return 16; }
20
-
21
- static get TX_END() { return 255; }
22
-
23
- static get TX_PARAM() { return 30; }
24
- static get ACTIVE_STACK() { return 40; }
25
- static get ACTIVE_STATS() { return 41; }
26
- static get DBCONN_POOL() { return 42; }
27
-
28
- static get EVENT() { return 50; }
29
-
30
- static get RELAY_PACK() { return 244; }
31
- }
32
-
33
- module.exports = PacketTypeEnum;