whatap 0.5.26 → 1.0.0-canary.0

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 +78 -32
  2. package/agent/darwin/arm64/whatap_nodejs +0 -0
  3. package/agent/linux/amd64/whatap_nodejs +0 -0
  4. package/agent/linux/arm64/whatap_nodejs +0 -0
  5. package/build.txt +4 -0
  6. package/lib/conf/config-default.js +3 -10
  7. package/lib/conf/configure.js +349 -369
  8. package/lib/conf/license.js +1 -1
  9. package/lib/control/packagectr-helper.js +3 -34
  10. package/lib/core/agent.js +882 -176
  11. package/lib/core/interceptor.js +6 -6
  12. package/lib/core/shimmer.js +36 -82
  13. package/lib/counter/counter-manager.js +8 -79
  14. package/lib/counter/task/activetransaction.js +17 -68
  15. package/lib/io/data-inputx.js +3 -13
  16. package/lib/io/data-outputx.js +206 -268
  17. package/lib/logger.js +6 -6
  18. package/lib/net/security-master.js +20 -139
  19. package/lib/observers/apollo-server-observer.js +27 -33
  20. package/lib/observers/global-observer.js +80 -155
  21. package/lib/observers/http-observer.js +236 -666
  22. package/lib/observers/ioredis-observer.js +294 -0
  23. package/lib/observers/maria-observer.js +362 -204
  24. package/lib/observers/mongodb-observer.js +226 -169
  25. package/lib/observers/mongoose-observer.js +323 -518
  26. package/lib/observers/mssql-observer.js +418 -177
  27. package/lib/observers/mysql-observer.js +449 -342
  28. package/lib/observers/mysql2-observer.js +358 -396
  29. package/lib/observers/oracle-observer.js +384 -559
  30. package/lib/observers/pgsql-observer.js +489 -231
  31. package/lib/observers/prisma-observer.js +92 -303
  32. package/lib/observers/process-observer.js +35 -79
  33. package/lib/observers/redis-observer.js +331 -166
  34. package/lib/observers/socket.io-observer.js +187 -226
  35. package/lib/observers/websocket-observer.js +301 -175
  36. package/lib/pack/counter-pack.js +0 -3
  37. package/lib/pack/log-sink-pack.js +52 -14
  38. package/lib/pack/tagcount-pack.js +4 -4
  39. package/lib/{counter/task → system}/gc-action.js +74 -27
  40. package/lib/trace/trace-context-manager.js +25 -113
  41. package/lib/trace/trace-context.js +7 -21
  42. package/lib/trace/trace-httpc.js +11 -17
  43. package/lib/trace/trace-sql.js +21 -29
  44. package/lib/udp/async_sender.js +119 -0
  45. package/lib/udp/index.js +17 -0
  46. package/lib/udp/packet_enum.js +52 -0
  47. package/lib/udp/packet_queue.js +69 -0
  48. package/lib/udp/packet_type_enum.js +33 -0
  49. package/lib/udp/param_def.js +72 -0
  50. package/lib/udp/udp_session.js +336 -0
  51. package/lib/util/escape-literal-sql.js +5 -5
  52. package/lib/util/hashutil.js +18 -18
  53. package/lib/util/keygen.js +3 -0
  54. package/lib/util/linkedset.js +2 -1
  55. package/lib/util/nodeutil.js +1 -2
  56. package/lib/util/sql-util.js +178 -0
  57. package/lib/util/trace-helper.js +91 -0
  58. package/lib/util/transfer.js +58 -0
  59. package/lib/value/map-value.js +2 -3
  60. package/package.json +5 -10
  61. package/whatap.conf +4 -1
  62. package/lib/conf/conf-sys-mon.js +0 -101
  63. package/lib/control/cmd-config.js +0 -24
  64. package/lib/control/control-handler.js +0 -367
  65. package/lib/core/request-agent.js +0 -27
  66. package/lib/counter/meter/meter-activex.js +0 -67
  67. package/lib/counter/meter/meter-httpc.js +0 -57
  68. package/lib/counter/meter/meter-resource.js +0 -9
  69. package/lib/counter/meter/meter-service.js +0 -168
  70. package/lib/counter/meter/meter-socket.io.js +0 -51
  71. package/lib/counter/meter/meter-sql.js +0 -71
  72. package/lib/counter/meter/meter-users.js +0 -58
  73. package/lib/counter/meter.js +0 -183
  74. package/lib/counter/task/agentinfo.js +0 -107
  75. package/lib/counter/task/gcstat.js +0 -34
  76. package/lib/counter/task/heapmem.js +0 -25
  77. package/lib/counter/task/httpc.js +0 -76
  78. package/lib/counter/task/metering-info.js +0 -125
  79. package/lib/counter/task/proc-cpu.js +0 -29
  80. package/lib/counter/task/realtimeuser.js +0 -31
  81. package/lib/counter/task/res/systemECSTask.js +0 -39
  82. package/lib/counter/task/res/systemKubeTask.js +0 -53
  83. package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
  84. package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
  85. package/lib/counter/task/res-sys-cpu.js +0 -62
  86. package/lib/counter/task/service.js +0 -202
  87. package/lib/counter/task/socketio.js +0 -30
  88. package/lib/counter/task/sql.js +0 -105
  89. package/lib/counter/task/systemperf.js +0 -43
  90. package/lib/data/datapack-sender.js +0 -289
  91. package/lib/data/dataprofile-agent.js +0 -162
  92. package/lib/data/datatext-agent.js +0 -135
  93. package/lib/data/event-level.js +0 -15
  94. package/lib/data/test.js +0 -49
  95. package/lib/data/zipprofile.js +0 -197
  96. package/lib/env/constants.js +0 -21
  97. package/lib/error/error-handler.js +0 -437
  98. package/lib/kube/kube-client.js +0 -144
  99. package/lib/lang/text-types.js +0 -58
  100. package/lib/logsink/line-log-util.js +0 -87
  101. package/lib/logsink/line-log.js +0 -12
  102. package/lib/logsink/log-sender.js +0 -78
  103. package/lib/logsink/log-tracer.js +0 -40
  104. package/lib/logsink/sender-util.js +0 -56
  105. package/lib/logsink/zip/zip-send.js +0 -177
  106. package/lib/net/netflag.js +0 -55
  107. package/lib/net/receiver.js +0 -66
  108. package/lib/net/sender.js +0 -141
  109. package/lib/net/tcp-return.js +0 -18
  110. package/lib/net/tcp-session.js +0 -286
  111. package/lib/net/tcpreq-client-proxy.js +0 -70
  112. package/lib/net/tcprequest-mgr.js +0 -58
  113. package/lib/observers/cluster-observer.js +0 -22
  114. package/lib/observers/express-observer.js +0 -215
  115. package/lib/observers/file-observer.js +0 -184
  116. package/lib/observers/grpc-observer.js +0 -336
  117. package/lib/observers/memcached-observer.js +0 -56
  118. package/lib/observers/mongo-observer.js +0 -317
  119. package/lib/observers/net-observer.js +0 -77
  120. package/lib/observers/promise-observer.js +0 -31
  121. package/lib/observers/schedule-observer.js +0 -67
  122. package/lib/observers/stream-observer.js +0 -19
  123. package/lib/observers/thrift-observer.js +0 -197
  124. package/lib/pack/activestack-pack.js +0 -55
  125. package/lib/pack/apenum.js +0 -8
  126. package/lib/pack/errorsnap-pack.js +0 -69
  127. package/lib/pack/event-pack.js +0 -54
  128. package/lib/pack/hitmap-pack.js +0 -63
  129. package/lib/pack/hitmap-pack1.js +0 -152
  130. package/lib/pack/netstat.js +0 -15
  131. package/lib/pack/otype.js +0 -7
  132. package/lib/pack/profile-pack.js +0 -49
  133. package/lib/pack/realtimeuser-pack.js +0 -41
  134. package/lib/pack/stat-general-pack.js +0 -96
  135. package/lib/pack/staterror-pack.js +0 -120
  136. package/lib/pack/stathttpc-pack.js +0 -66
  137. package/lib/pack/stathttpc-rec.js +0 -78
  138. package/lib/pack/statremote-pack.js +0 -46
  139. package/lib/pack/statservice-pack.js +0 -63
  140. package/lib/pack/statservice-pack1.js +0 -88
  141. package/lib/pack/statservice-rec.js +0 -292
  142. package/lib/pack/statservice-rec_dep.js +0 -151
  143. package/lib/pack/statsql-pack.js +0 -69
  144. package/lib/pack/statsql-rec.js +0 -100
  145. package/lib/pack/statuseragent-pack.js +0 -44
  146. package/lib/pack/tagctr.js +0 -15
  147. package/lib/pack/text-pack.js +0 -50
  148. package/lib/pack/time-count.js +0 -25
  149. package/lib/pack/websocket.js +0 -15
  150. package/lib/pack/zip-pack.js +0 -70
  151. package/lib/pii/pii-item.js +0 -31
  152. package/lib/pii/pii-mask.js +0 -174
  153. package/lib/plugin/plugin-loadermanager.js +0 -57
  154. package/lib/plugin/plugin.js +0 -75
  155. package/lib/service/tx-record.js +0 -332
  156. package/lib/stat/stat-error.js +0 -116
  157. package/lib/stat/stat-httpc.js +0 -98
  158. package/lib/stat/stat-remote-ip.js +0 -46
  159. package/lib/stat/stat-remote-ipurl.js +0 -88
  160. package/lib/stat/stat-sql.js +0 -113
  161. package/lib/stat/stat-tranx.js +0 -58
  162. package/lib/stat/stat-tx-caller.js +0 -160
  163. package/lib/stat/stat-tx-domain.js +0 -111
  164. package/lib/stat/stat-tx-referer.js +0 -112
  165. package/lib/stat/stat-useragent.js +0 -48
  166. package/lib/stat/timingsender.js +0 -76
  167. package/lib/step/activestack-step.js +0 -38
  168. package/lib/step/dbc-step.js +0 -36
  169. package/lib/step/http-stepx.js +0 -67
  170. package/lib/step/message-step.js +0 -40
  171. package/lib/step/method-stepx.js +0 -45
  172. package/lib/step/resultset-step.js +0 -40
  173. package/lib/step/securemsg-step.js +0 -44
  174. package/lib/step/socket-step.js +0 -46
  175. package/lib/step/sql-stepx.js +0 -68
  176. package/lib/step/sqlxtype.js +0 -16
  177. package/lib/step/step.js +0 -66
  178. package/lib/step/stepenum.js +0 -54
  179. package/lib/topology/link.js +0 -63
  180. package/lib/topology/nodeinfo.js +0 -123
  181. package/lib/topology/status-detector.js +0 -111
  182. package/lib/util/anylist.js +0 -103
  183. package/lib/util/cardinality/hyperloglog.js +0 -106
  184. package/lib/util/cardinality/murmurhash.js +0 -31
  185. package/lib/util/cardinality/registerset.js +0 -75
  186. package/lib/util/errordata.js +0 -21
  187. package/lib/util/iputil_x.js +0 -527
  188. package/lib/util/kube-util.js +0 -73
  189. package/lib/util/paramsecurity.js +0 -80
  190. package/lib/util/pre-process.js +0 -13
  191. package/lib/util/process-seq.js +0 -166
  192. package/lib/util/property-util.js +0 -36
  193. package/lib/util/request-queue.js +0 -70
  194. package/lib/util/requestdouble-queue.js +0 -72
  195. package/lib/util/resourceprofile.js +0 -157
  196. package/lib/util/stop-watch.js +0 -30
  197. package/lib/util/system-util.js +0 -10
  198. package/lib/util/userid-util.js +0 -57
@@ -4,18 +4,17 @@ const MapValue = require('../value/map-value');
4
4
  const DataOutputX = require('../io/data-outputx');
5
5
  const DataInputX = require('../io/data-inputx');
6
6
  const HashUtil = require('../util/hashutil');
7
- const Value = require('../value/value');
8
7
  const BooleanValue = require('../value/boolean-value');
9
8
 
10
9
  function LogSinkPack() {
11
10
  Pack.call(this);
12
- this.category = '';
11
+ this.Category = '';
12
+ this.time = null;
13
13
  this.tagHash = 0;
14
14
  this.tags = new MapValue();
15
15
  this.line = 0;
16
16
  this.content = '';
17
17
  this.fields = new MapValue();
18
- this.dropped = false;
19
18
  }
20
19
 
21
20
  LogSinkPack.prototype = Object.create(Pack.prototype);
@@ -26,7 +25,7 @@ LogSinkPack.prototype.getPackType = function () {
26
25
  };
27
26
 
28
27
  LogSinkPack.prototype.toString = function () {
29
- return `${Pack.prototype.toString.call(this)} [category=${this.category}, tagHash=${this.tagHash}, tags=${this.tags}, content=${this.content}, fields=${this.fields}]`;
28
+ return `${Pack.prototype.toString.call(this)} [category=${this.Category}, tagHash=${this.tagHash}, tags=${this.tags}, content=${this.content}, fields=${this.fields}]`;
30
29
  };
31
30
 
32
31
  LogSinkPack.prototype.getTagAsBytes = function () {
@@ -85,13 +84,24 @@ LogSinkPack.prototype.setContentBytes = function (d) {
85
84
 
86
85
  LogSinkPack.prototype.write = function (dout) {
87
86
  Pack.prototype.write.call(this, dout);
87
+
88
88
  dout.writeByte(0);
89
- dout.writeText(this.category);
90
- dout.writeDecimal(this.tagHash);
91
- dout.writeValue(this.tags);
89
+ dout.writeText(this.Category);
90
+
91
+ if (this.tagHash === 0 && this.tags.size() > 0) {
92
+ const result = this.resetTagHash();
93
+ this.tagHash = result.tagHash;
94
+ dout.writeDecimal(result.tagHash);
95
+ dout.write(result.tagBytes);
96
+ } else {
97
+ dout.writeDecimal(this.tagHash);
98
+ dout.writeValue(this.tags);
99
+ }
100
+
92
101
  dout.writeDecimal(this.line);
93
102
  dout.writeText(this.content);
94
- if (this.fields.size() > 0) {
103
+
104
+ if (this.fields && this.fields.size() > 0) {
95
105
  dout.writeBoolean(true);
96
106
  dout.writeValue(this.fields);
97
107
  } else {
@@ -102,7 +112,7 @@ LogSinkPack.prototype.write = function (dout) {
102
112
  LogSinkPack.prototype.read = function (din) {
103
113
  Pack.prototype.read.call(this, din);
104
114
  const ver = din.readByte();
105
- this.category = din.readText();
115
+ this.Category = din.readText();
106
116
  this.tagHash = din.readDecimal();
107
117
  this.tags = din.readValue();
108
118
  this.line = din.readDecimal();
@@ -114,11 +124,11 @@ LogSinkPack.prototype.read = function (din) {
114
124
  };
115
125
 
116
126
  LogSinkPack.prototype.resetTagHash = function () {
117
- const out = new DataOutputX();
118
- out.writeValue(this.tags);
119
- const tagBytes = out.toByteArray();
120
- this.tagHash = HashUtil.hash64(tagBytes);
121
- return tagBytes;
127
+ const dout = new DataOutputX();
128
+ dout.writeValue(this.tags);
129
+ const tagBytes = dout.toByteArray();
130
+ const tagHash = HashUtil.hash(tagBytes);
131
+ return { tagHash: tagHash, tagBytes: tagBytes };
122
132
  };
123
133
 
124
134
  LogSinkPack.prototype.transferOidToTag = function () {
@@ -136,4 +146,32 @@ LogSinkPack.prototype.transferOidToTag = function () {
136
146
  }
137
147
  };
138
148
 
149
+ LogSinkPack.getLogSinkPack = function(options) {
150
+ const {
151
+ t = 0,
152
+ category = null,
153
+ tags = {},
154
+ fields = {},
155
+ line = 0,
156
+ content = null
157
+ } = options || {};
158
+
159
+ const pack = new LogSinkPack();
160
+ pack.time = t;
161
+ pack.Category = category;
162
+
163
+ for (const [k, v] of Object.entries(tags)) {
164
+ pack.tags.putString(k, String(v));
165
+ }
166
+
167
+ for (const [k, v] of Object.entries(fields)) {
168
+ pack.fields.putString(k, String(v));
169
+ }
170
+
171
+ pack.line = line;
172
+ pack.content = content;
173
+
174
+ return pack;
175
+ };
176
+
139
177
  module.exports = LogSinkPack;
@@ -21,10 +21,10 @@ function TagCountPack() {
21
21
  this.originOid = null;
22
22
  this.tags = new MapValue()
23
23
  this.fields = new MapValue()
24
- this.read_size
25
- this.fieldPos
26
- this.tagPos
27
- this.madeByPlugIn
24
+ this.read_size;
25
+ this.fieldPos;
26
+ this.tagPos;
27
+ this.madeByPlugIn;
28
28
  }
29
29
 
30
30
  TagCountPack.prototype = new Pack();
@@ -4,18 +4,22 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
7
- var CounterTask = require('./counter-task'),
8
- DataPackSender = require('../../data/datapack-sender'),
9
- conf = require('../../conf/configure'),
10
- DateUtil = require('../../util/dateutil'),
11
- Logger = require('../../logger'),
12
- TagCountPack = require('../../pack/tagcount-pack'),
13
- HashUtil = require('../../util/hashutil'),
14
- SecurityMaster = require('../../../lib/net/security-master'),
15
- NodeUtil = require('../../util/nodeutil'),
16
- IPUtil = require('../../util/iputil');
7
+ var CounterTask = require('../../lib/counter/task/counter-task'),
8
+ conf = require('../../lib/conf/configure'),
9
+ DateUtil = require('../../lib/util/dateutil'),
10
+ Logger = require('../../lib/logger'),
11
+ TagCountPack = require('../../lib/pack/tagcount-pack'),
12
+ HashUtil = require('../../lib/util/hashutil'),
13
+ SecurityMaster = require('../../lib/net/security-master'),
14
+ NodeUtil = require('../../lib/util/nodeutil'),
15
+ IPUtil = require('../../lib/util/iputil'),
16
+ AsyncSender = require('../../lib/udp/async_sender'),
17
+ DataOutputX = require('../../lib/io/data-outputx'),
18
+ ParamPack = require('../pack/param-pack').ParamPack,
19
+ MapValue = require('../value/map-value');
17
20
 
18
21
  const { PerformanceObserver } = require('perf_hooks');
22
+ const DataOuputX = require('../../lib/io/data-outputx');
19
23
 
20
24
  function GCAction() {
21
25
  CounterTask.call(this);
@@ -36,19 +40,19 @@ GCAction.prototype.checkGCObserverSupport = function () {
36
40
  }
37
41
  };
38
42
 
39
- GCAction.prototype.process = function (p) {
43
+ GCAction.prototype.process = function () {
40
44
  try {
41
45
  if (!conf.getProperty('perfx_nodejs_gc_enabled', false) || !this.isObserverSupported) {
42
46
  return;
43
47
  }
44
48
 
45
- this.nodejs_memory_gc(p);
49
+ this.getNodeMemoryGC();
46
50
  } catch (e) {
47
51
  Logger.printError("WHATAP-GC-003", "NodeJS GC process error", e, false);
48
52
  }
49
53
  };
50
54
 
51
- GCAction.prototype.nodejs_memory_gc = function (p) {
55
+ GCAction.prototype.getNodeMemoryGC = function () {
52
56
  const gcStats = new Map();
53
57
  const self = this;
54
58
 
@@ -78,7 +82,7 @@ GCAction.prototype.nodejs_memory_gc = function (p) {
78
82
 
79
83
  // 수집된 데이터가 있으면 전송
80
84
  if (gcStats.size > 0) {
81
- self.sendGCData(p, gcStats);
85
+ self.sendGCData(gcStats);
82
86
  }
83
87
  });
84
88
 
@@ -88,20 +92,21 @@ GCAction.prototype.nodejs_memory_gc = function (p) {
88
92
  }
89
93
  };
90
94
 
91
- GCAction.prototype.sendGCData = function (p, gc_stats) {
92
- const pk = new TagCountPack();
93
- pk.time = Math.floor(Date.now() / 1000) * 1000;
94
- pk.category = "nodejsx_memory_gc";
95
+ GCAction.prototype.sendGCData = function (gc_stats) {
96
+ var p = new TagCountPack();
97
+ p.pcode = SecurityMaster.PCODE;
98
+ p.time = Math.floor(Date.now() / 1000) * 1000;
99
+ p.category = "nodejsx_memory_gc";
95
100
 
96
- pk.putTagString("oname", SecurityMaster.ONAME);
97
- pk.putTagString("host_ip", IPUtil.getIp());
98
- pk.putTagInt("pid", process.pid);
99
- pk.putTagInt("!rectype", 2);
101
+ p.putTagString("oname", SecurityMaster.ONAME);
102
+ p.putTagString("host_ip", IPUtil.getIp());
103
+ p.putTagInt("pid", process.pid);
104
+ p.putTagInt("!rectype", 2);
100
105
 
101
- const idLv = pk.fields.internList("@id");
102
- const nameLv = pk.fields.internList("name");
103
- const countLv = pk.fields.internList("CollectionCount");
104
- const timeLv = pk.fields.internList("CollectionTime");
106
+ const idLv = p.fields.internList("@id");
107
+ const nameLv = p.fields.internList("name");
108
+ const countLv = p.fields.internList("CollectionCount");
109
+ const timeLv = p.fields.internList("CollectionTime");
105
110
 
106
111
  // GC 통계 데이터 추가
107
112
  for (const [gc_name, stats] of gc_stats) {
@@ -111,9 +116,51 @@ GCAction.prototype.sendGCData = function (p, gc_stats) {
111
116
  timeLv.addLong(Math.round(stats.collectionTime));
112
117
  }
113
118
 
114
- DataPackSender.sendTagCounterPack(pk);
119
+ const bout = new DataOuputX();
120
+ bout.writePack(p, null);
121
+ const packbytes = bout.toByteArray();
122
+
123
+ AsyncSender.send_relaypack(packbytes)
115
124
  };
116
125
 
126
+ GCAction.prototype.execSystemGC = function () {
127
+ var p = new ParamPack();
128
+ p.pcode = SecurityMaster.PCODE;
129
+ p.oid = SecurityMaster.OID;
130
+ p.oname = SecurityMaster.ONAME;
131
+ p.okind = SecurityMaster.OKIND;
132
+ // p.oid
133
+ try {
134
+ var mem1 = process.memoryUsage();
135
+ var total1 = mem1.heapTotal;
136
+ var used1 = mem1.heapUsed;
137
+
138
+ if (global && global.gc && typeof global.gc === 'function') {
139
+ global.gc();
140
+ } else {
141
+ Logger.printError('WHATAP-601', 'Garbage collection unavailable. Pass --expose-gc '
142
+ + 'when launching node to enable forced garbage collection.', new Error());
143
+ }
144
+
145
+ var mem2 = process.memoryUsage();
146
+ var total2 = mem2.heapTotal;
147
+ var used2 = mem2.heapUsed;
148
+
149
+ var mv = new MapValue();
150
+ mv.putLong("before-t", total1);
151
+ mv.putLong("before-u", used1);
152
+ mv.putLong("after-t", total2);
153
+ mv.putLong("after-u", used2);
154
+ p.putValue("gc", mv);
155
+
156
+ return p;
157
+ } catch (e) {
158
+ // p.putValue("error", e.toString());
159
+ console.log(`e: ${e}`)
160
+ }
161
+ return null;
162
+ }
163
+
117
164
  GCAction.prototype.getGCTypeName = function (kind) {
118
165
  const major = NodeUtil.getNodeMajorVersion();
119
166
 
@@ -7,11 +7,12 @@
7
7
  var IntKeyMap = require('../util/intkey-map'),
8
8
  HashUtil = require('../util/hashutil'),
9
9
  TraceContext = require('./trace-context'),
10
- Logger = require('../logger'),
11
- EventLevel = require('../data/event-level');
12
- Long = require('long');
10
+ Logger = require('../logger');
11
+ var Long = require('long');
13
12
  var { AsyncLocalStorage } = require('async_hooks');
14
13
  var crypto = require('crypto');
14
+ var { v1: uuidv1 } = require('uuid');
15
+ const KeyGen = require('../util/keygen');
15
16
 
16
17
  function TraceContextManager() {
17
18
  this.initialized = false;
@@ -19,6 +20,8 @@ function TraceContextManager() {
19
20
  this.currentId = null;
20
21
  this._asyncLocalStorage = new AsyncLocalStorage();
21
22
  this.entry = new IntKeyMap(1021,1).setMax(5000);
23
+ this.node = null;
24
+ this.clock_seq = null;
22
25
  }
23
26
 
24
27
  TraceContextManager.prototype.keys = function () {
@@ -31,14 +34,10 @@ TraceContextManager.prototype.size = function () {
31
34
  return this.entry.size();
32
35
  };
33
36
  TraceContextManager.prototype.getContext = function (key) {
34
- // if(key == null ) {
35
- // return null;
36
- // }
37
- // return this.entry.get(key);
38
37
  return this._asyncLocalStorage.getStore();
39
38
  };
40
39
  TraceContextManager.prototype.getCurrentContext = function () {
41
- return this.getContext(this.currentId);
40
+ return this.getContext();
42
41
  };
43
42
  TraceContextManager.prototype.start = function () {
44
43
 
@@ -47,10 +46,10 @@ TraceContextManager.prototype.start = function () {
47
46
  // var conf = require('../conf/configure');
48
47
  // if(this.size() > conf.profile_max_count) { return null; }
49
48
 
50
- var ctx = new TraceContext(this.getNextId());
49
+ var ctx = new TraceContext(KeyGen.next());
51
50
  ctx.start_time = Date.now();
52
- this.entry.put(ctx._id, ctx);
53
- this.currentId = ctx._id;
51
+ this.entry.put(ctx.id, ctx);
52
+ this.currentId = ctx.id;
54
53
 
55
54
  return ctx;
56
55
  };
@@ -88,119 +87,32 @@ TraceContextManager.prototype.resume = function (id) {
88
87
  return null;
89
88
  }
90
89
  };
91
- TraceContextManager.prototype.getTxProfile = function(n) {
92
- var ctx = this.getCurrentContext();
93
- if(ctx == null)
94
- return null;
95
- return ctx.profile.getLastSteps(n);
96
- };
97
90
  TraceContextManager.prototype.isExist = function (id) {
98
91
  return this.entry.containsKey(id);
99
92
  };
100
- var DataTextAgent = require('../data/datatext-agent');
101
- var MessageStep = require('../step/message-step');
102
- TraceContextManager.prototype.addStep = function (title, desc, ctx) {
103
- // var ctx = this.getCurrentContext();
104
- if(ctx == null) {
105
- return null;
106
- }
107
- try {
108
- var step = new MessageStep();
109
- step.start_time = ctx.getElapsedTime();
110
- step.hash = HashUtil.hashFromString(title);
111
- DataTextAgent.MESSAGE.add(step.hash, title);
112
- step.desc = desc;
113
- step.ctx = ctx;
114
- ctx.profile.push(step);
115
- return step;
116
- } catch(e) {
117
- return null;
118
- }
119
- };
120
- TraceContextManager.prototype.endStep = function (step) {
121
- if(step == null || step.ctx == null) {
122
- return;
123
- }
124
- this.resume(step.ctx);
125
- step.time = step.ctx.getElapsedTime() - step.start_time;
126
- };
127
-
128
- TraceContextManager.prototype.startTrace = function (title) {
129
- try{
130
- var ctx = this.start();
131
- if(ctx == null) {
132
- return null;
133
- }
134
- ctx.service_name = title;
135
- ctx.service_hash = HashUtil.hashFromString(title);
136
- var DataTextAgent = require('../data/datatext-agent'),
137
- ResourceProfile = require('../util/resourceprofile');
138
- DataTextAgent.SERVICE.add(ctx.service_hash, title);
139
- ctx.start_cpu = ResourceProfile.getCPUTime();
140
- ctx.start_malloc = ResourceProfile.getUsedHeapSize();
141
93
 
142
- return ctx;
143
- }catch(e){
144
- Logger.printError('WHATAP-998', 'TraceContext (startTrace)', e, true);
94
+ TraceContextManager.prototype.getId = function () {
95
+ if (!this.node) {
96
+ this.node = Math.floor(Math.random() * 0xffffffffffff);
145
97
  }
146
- };
147
- TraceContextManager.prototype.endTrace = function (ctx) {
148
- if(ctx == null) {return;}
149
- var ProfilePack = require('../pack/profile-pack'),
150
- TxRecord = require('../service/tx-record'),
151
- DateUtil = require('../util/dateutil'),
152
- MeterService = require('../counter/meter/meter-service').MeterService,
153
- DataProfileAgent = require('../data/dataprofile-agent'),
154
- ResourceProfile = require('../util/resourceprofile'),
155
- SecurityMaster = require('../net/security-master');
156
-
157
- var profile = new ProfilePack();
158
- var service = new TxRecord();
159
- profile.time = Long.fromValue(ctx.start_time);
160
- service.endTime = DateUtil.currentTime();
161
- service.elapsed = ctx.getElapsedTime();
162
- service.service = ctx.service_hash;
163
- DataTextAgent.SERVICE.add(ctx.service_hash, ctx.service_name);
164
98
 
165
- service.cpuTime = ResourceProfile.getCPUTime() - ctx.start_cpu;
166
- service.malloc = ResourceProfile.getUsedHeapSize() - ctx.start_malloc;
167
- if(service.malloc < 0) { service.malloc = 0; }
168
- service.seq = ctx.txid;
169
- service.sqlCount = ctx.sql_count;
170
- service.sqlTime = ctx.sql_time;
171
- service.sqlFetchCount = ctx.rs_count;
172
- service.sqlFetchTime = parseInt(ctx.rs_time);
173
- service.ipaddr = ctx.remoteIp;
174
- service.userid = ctx.userid;
175
-
176
- service.mcaller_pcode = ctx.mcaller_pcode;
177
- service.mcaller_okind = ctx.mcaller_okind;
178
- service.mcaller_oid = ctx.mcaller_oid;
179
-
180
- if (ctx.error.isZero()==false/*long*/) {
181
- service.error = ctx.error;
182
- service.errorLevel = EventLevel.WARNING;
99
+ if (!this.clock_seq) {
100
+ this.clock_seq = Math.floor(Math.random() * (1 << 14));
183
101
  }
184
- service.userAgent = ctx.userAgent;
185
- service.referer = ctx.referer;
186
-
187
- service.httpcCount = ctx.httpc_count;
188
- service.httpcTime = ctx.httpc_time;
189
- service.status = ctx.status;
190
102
 
191
- service.http_method=TxRecord.HTTP_METHOD[ctx.http_method] || TxRecord.WEB_GET;
103
+ const uuid1 = uuidv1({
104
+ node: this.node,
105
+ clockseq: this.clock_seq
106
+ });
192
107
 
193
- MeterService.add(service.service, service.elapsed, service.errorLevel, service.mcaller_pcode, service.mcaller_okind, service.mcaller_oid , service.apdex);
108
+ const buffer = Buffer.from(uuid1.replace(/-/g, ''), 'hex');
109
+ const uuidInt = BigInt('0x' + buffer.toString('hex'));
194
110
 
195
- profile.oid = SecurityMaster.OID;
196
- profile.service = service;
111
+ const upperBits = (uuidInt >> 64n) & 0xffffffffffffffffn;
112
+ const lowerBits = (uuidInt << 64n) & 0xffffffffffffffffn;
113
+ const key = upperBits ^ lowerBits;
197
114
 
198
- var self = this;
199
- setTimeout(function () {
200
- DataProfileAgent.sendProfile(ctx, profile, false);
201
- self.end(ctx._id);
202
- ctx = null;
203
- }, 100);
115
+ return Long.fromString(key.toString()).toNumber();
204
116
  };
205
117
 
206
118
  module.exports = new TraceContextManager();
@@ -13,39 +13,29 @@ var ProfileCollector = require('./profile-collector'),
13
13
  Long = require('long');
14
14
 
15
15
  function TraceContext(id) {
16
- this._id = id;
16
+ this.id = id;
17
17
  this.isStaticContents = false;
18
18
  this.profile = new ProfileCollector(this);
19
19
 
20
+ this.pid = process.pid;
21
+
20
22
  this.txid = KeyGen.next();
21
23
  this.thread = null;
22
24
  this.thread_id = 0;
23
25
 
24
26
  this.start_cpu = 0;
25
- this.start_malloc = 0;
26
- this.start_time = 0;
27
-
28
27
  this.status = 0;
29
28
 
30
29
  this.service_hash = 0;
31
30
  this.service_name = '';
32
31
  this.remoteIp = 0;
33
- this.error = Long.ZERO;
34
- this.error_class = '';
35
- this.error_message = '';
32
+ this.error = 0;
36
33
 
37
34
  this.http_method = '';
38
35
  this.http_query = '';
39
36
  this.http_content_type = '';
40
-
41
- this.sql_count = 0;
42
- this.sql_time = 0;
43
37
 
44
- this.sql_insert = 0;
45
- this.sql_update = 0;
46
- this.sql_delete = 0;
47
- this.sql_select = 0;
48
- this.sql_others = 0;
38
+ this.host = '';
49
39
 
50
40
  this.executed_sqlhash = 0;
51
41
  this.active_sqlhash = 0;
@@ -69,10 +59,6 @@ function TraceContext(id) {
69
59
  this.lastSqlStep = null; /*SqlStepX*/
70
60
  this.profileActive = 0;
71
61
 
72
- this.jdbc_updated = false;
73
- this.jdbc_update_record = 0;
74
- this.jdbc_identity = 0;
75
- this.jdbc_commit = 0;
76
62
  this.resultSql = new IntKeyMap().setMax(11);
77
63
 
78
64
  this.rs_count = 0;
@@ -80,7 +66,7 @@ function TraceContext(id) {
80
66
  this.db_opening = false;
81
67
  this.socket_connecting = false;
82
68
 
83
- this.mtid=Long.ZERO;
69
+ this.mtid= Long.ZERO;
84
70
  this.mdepth = 0;
85
71
  this.mcaller_pcode = 0;
86
72
  this.mcaller_okind = 0;
@@ -133,7 +119,7 @@ TraceContext.prototype.setCallerPOID= function (poidStr) {
133
119
  this.mcaller_okind = poid.okind;
134
120
  this.mcaller_oid = poid.oid;
135
121
  } catch (e) {
136
- Logger.printError('WHATAP-999', 'TraceContext (setCallerPOID)', e, true);
122
+ Logger.printError('WHATAP-701', 'TraceContext (setCallerPOID)', e, true);
137
123
  }
138
124
  };
139
125
  module.exports = TraceContext;
@@ -1,25 +1,19 @@
1
- const HttpStepX = require('../step/http-stepx'),
2
- conf = require('../conf/configure'),
3
- StatError= require('../stat/stat-error'),
4
- TextTypes= require("../lang/text-types");
1
+ const conf = require('../conf/configure'),
2
+ AsyncSender = require('../udp/async_sender'),
3
+ PacketTypeEnum = require('../udp/packet_type_enum');
5
4
 
6
5
  var TraceHttpc = function () {}
7
-
8
- TraceHttpc.prototype.hasHttpStepX = function (buffer) {
9
- if (!Array.isArray(buffer)) {
10
- return [];
11
- }
12
-
13
- return buffer.filter(item => item instanceof HttpStepX);
14
- }
15
-
16
- TraceHttpc.prototype.isSlowHttpc = function (ctx, httpc_step) {
17
- if(!ctx.profile.buffer)
6
+ TraceHttpc.prototype.isSlowHttpc = function (ctx) {
7
+ if(!ctx)
18
8
  return;
19
9
  var profile_error_httpc_time_max = conf.getProperty('profile_error_httpc_time_max', 10000);
20
10
 
21
- if(httpc_step.elapsed && (httpc_step.elapsed > profile_error_httpc_time_max)){
22
- httpc_step.error = StatError.addError('SLOW_HTTPC', 'SLOW HTTPC', ctx.service_hash, TextTypes.HTTPC_URL, null);
11
+ if(ctx.elapsed && (ctx.elapsed > profile_error_httpc_time_max)){
12
+ if (!ctx.error) ctx.error = 1;
13
+ ctx.status = 500;
14
+
15
+ var errors = ['SlOW_HTTPC', 'SlOW HTTPC'];
16
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
23
17
  }
24
18
  }
25
19
 
@@ -1,44 +1,36 @@
1
- const SqlStepX = require('../step/sql-stepx'),
2
- conf = require('../conf/configure'),
3
- StatError = require('../stat/stat-error'),
4
- TextTypes = require("../lang/text-types");
1
+ const conf = require('../conf/configure'),
2
+ AsyncSender = require('../udp/async_sender'),
3
+ PacketTypeEnum = require('../udp/packet_type_enum');
5
4
 
6
5
  var TraceSql = function () {}
7
6
 
8
- TraceSql.prototype.hasSqlStepX = function (buffer) {
9
- if (!Array.isArray(buffer)) {
10
- return [];
11
- }
12
-
13
- return buffer.filter(item => item instanceof SqlStepX);
14
- }
15
-
16
7
  TraceSql.prototype.isSlowSQL = function (ctx) {
17
- if(!ctx.profile.buffer)
18
- return;
8
+ if (!ctx) return;
19
9
 
20
10
  var profile_error_sql_time_max = conf.getProperty('profile_error_sql_time_max', 30000);
21
- var sqlStepX = this.hasSqlStepX(ctx.profile.buffer);
22
- var slow_sql_step = sqlStepX.find(step => step.elapsed > profile_error_sql_time_max);
23
- if(slow_sql_step){
24
- slow_sql_step.error = StatError.addError('SLOW_SQL', 'SLOW SQL', ctx.service_hash, TextTypes.SQL, null);
25
- if(ctx.error.isZero()){
26
- ctx.error = slow_sql_step.error;
27
- }
11
+ var sql_elapsed = ctx.elapsed || 0;
12
+
13
+ if (sql_elapsed > profile_error_sql_time_max) {
14
+ if (!ctx.error) ctx.error = 1;
15
+ ctx.status = 500;
16
+
17
+ var errors = ['SLOW_SQL', 'SLOW SQL'];
18
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
28
19
  }
29
20
  return;
30
21
  }
31
22
 
32
- TraceSql.prototype.isTooManyRecords = function (sql_step, rs_count, ctx) {
33
- if(!ctx.profile.buffer)
34
- return;
23
+ TraceSql.prototype.isTooManyRecords = function (rs_count, ctx) {
24
+ if (!ctx) return;
35
25
 
36
26
  var profile_error_sql_fetch_max = conf.getProperty('profile_error_sql_fetch_max', 10000);
37
- if(rs_count && rs_count > profile_error_sql_fetch_max){
38
- sql_step.error = StatError.addError('TOO_MANY_RECORDS', 'Too many records', ctx.service_hash, TextTypes.SQL, null)
39
- if(ctx.error.isZero()){
40
- ctx.error = sql_step.error;
41
- }
27
+ if (rs_count && rs_count > profile_error_sql_fetch_max) {
28
+ // Too many records 에러 처리
29
+ if (!ctx.error) ctx.error = 1;
30
+ ctx.status = 500;
31
+
32
+ var errors = ['TOO_MANY_RECORDS', 'Too many records'];
33
+ AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
42
34
  }
43
35
  }
44
36