whatap 1.0.1-canary.2 → 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.
- package/README.md +33 -77
- package/lib/conf/conf-sys-mon.js +101 -0
- package/lib/conf/config-default.js +10 -3
- package/lib/conf/configure.js +369 -349
- package/lib/conf/license.js +1 -1
- package/lib/control/cmd-config.js +24 -0
- package/lib/control/control-handler.js +367 -0
- package/lib/control/packagectr-helper.js +34 -3
- package/lib/core/agent.js +176 -888
- package/lib/core/interceptor.js +6 -6
- package/lib/core/request-agent.js +27 -0
- package/lib/core/shimmer.js +82 -36
- package/lib/counter/counter-manager.js +79 -8
- package/lib/counter/meter/meter-activex.js +67 -0
- package/lib/counter/meter/meter-httpc.js +57 -0
- package/lib/counter/meter/meter-resource.js +9 -0
- package/lib/counter/meter/meter-service.js +168 -0
- package/lib/counter/meter/meter-socket.io.js +51 -0
- package/lib/counter/meter/meter-sql.js +71 -0
- package/lib/counter/meter/meter-users.js +58 -0
- package/lib/counter/meter.js +183 -0
- package/lib/counter/task/activetransaction.js +68 -17
- package/lib/counter/task/agentinfo.js +107 -0
- package/lib/{system → counter/task}/gc-action.js +27 -74
- package/lib/counter/task/gcstat.js +34 -0
- package/lib/counter/task/heapmem.js +25 -0
- package/lib/counter/task/httpc.js +76 -0
- package/lib/counter/task/metering-info.js +125 -0
- package/lib/counter/task/proc-cpu.js +29 -0
- package/lib/counter/task/realtimeuser.js +31 -0
- package/lib/counter/task/res/systemECSTask.js +39 -0
- package/lib/counter/task/res/systemKubeTask.js +53 -0
- package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
- package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
- package/lib/counter/task/res-sys-cpu.js +62 -0
- package/lib/counter/task/service.js +202 -0
- package/lib/counter/task/socketio.js +30 -0
- package/lib/counter/task/sql.js +105 -0
- package/lib/counter/task/systemperf.js +43 -0
- package/lib/data/datapack-sender.js +289 -0
- package/lib/data/dataprofile-agent.js +162 -0
- package/lib/data/datatext-agent.js +135 -0
- package/lib/data/event-level.js +15 -0
- package/lib/data/test.js +49 -0
- package/lib/data/zipprofile.js +197 -0
- package/lib/env/constants.js +21 -0
- package/lib/error/error-handler.js +437 -0
- package/lib/io/data-inputx.js +13 -3
- package/lib/io/data-outputx.js +268 -206
- package/lib/kube/kube-client.js +144 -0
- package/lib/lang/text-types.js +58 -0
- package/lib/logger.js +6 -6
- package/lib/logsink/line-log-util.js +87 -0
- package/lib/logsink/line-log.js +12 -0
- package/lib/logsink/log-sender.js +78 -0
- package/lib/logsink/log-tracer.js +40 -0
- package/lib/logsink/sender-util.js +56 -0
- package/lib/logsink/zip/zip-send.js +177 -0
- package/lib/net/netflag.js +55 -0
- package/lib/net/receiver.js +66 -0
- package/lib/net/security-master.js +139 -20
- package/lib/net/sender.js +141 -0
- package/lib/net/tcp-return.js +18 -0
- package/lib/net/tcp-session.js +286 -0
- package/lib/net/tcpreq-client-proxy.js +70 -0
- package/lib/net/tcprequest-mgr.js +58 -0
- package/lib/observers/apollo-server-observer.js +33 -27
- package/lib/observers/cluster-observer.js +22 -0
- package/lib/observers/express-observer.js +215 -0
- package/lib/observers/file-observer.js +184 -0
- package/lib/observers/global-observer.js +155 -80
- package/lib/observers/grpc-observer.js +336 -0
- package/lib/observers/http-observer.js +666 -236
- package/lib/observers/maria-observer.js +204 -362
- package/lib/observers/memcached-observer.js +56 -0
- package/lib/observers/mongo-observer.js +317 -0
- package/lib/observers/mongodb-observer.js +169 -226
- package/lib/observers/mongoose-observer.js +518 -323
- package/lib/observers/mssql-observer.js +177 -418
- package/lib/observers/mysql-observer.js +342 -449
- package/lib/observers/mysql2-observer.js +396 -358
- package/lib/observers/net-observer.js +77 -0
- package/lib/observers/oracle-observer.js +559 -384
- package/lib/observers/pgsql-observer.js +231 -489
- package/lib/observers/prisma-observer.js +303 -92
- package/lib/observers/process-observer.js +79 -35
- package/lib/observers/promise-observer.js +31 -0
- package/lib/observers/redis-observer.js +166 -331
- package/lib/observers/schedule-observer.js +67 -0
- package/lib/observers/socket.io-observer.js +226 -187
- package/lib/observers/stream-observer.js +19 -0
- package/lib/observers/thrift-observer.js +197 -0
- package/lib/observers/websocket-observer.js +175 -301
- package/lib/pack/activestack-pack.js +55 -0
- package/lib/pack/apenum.js +8 -0
- package/lib/pack/counter-pack.js +3 -0
- package/lib/pack/errorsnap-pack.js +69 -0
- package/lib/pack/event-pack.js +54 -0
- package/lib/pack/hitmap-pack.js +63 -0
- package/lib/pack/hitmap-pack1.js +152 -0
- package/lib/pack/log-sink-pack.js +14 -52
- package/lib/pack/netstat.js +15 -0
- package/lib/pack/otype.js +7 -0
- package/lib/pack/profile-pack.js +49 -0
- package/lib/pack/realtimeuser-pack.js +41 -0
- package/lib/pack/stat-general-pack.js +96 -0
- package/lib/pack/staterror-pack.js +120 -0
- package/lib/pack/stathttpc-pack.js +66 -0
- package/lib/pack/stathttpc-rec.js +78 -0
- package/lib/pack/statremote-pack.js +46 -0
- package/lib/pack/statservice-pack.js +63 -0
- package/lib/pack/statservice-pack1.js +88 -0
- package/lib/pack/statservice-rec.js +292 -0
- package/lib/pack/statservice-rec_dep.js +151 -0
- package/lib/pack/statsql-pack.js +69 -0
- package/lib/pack/statsql-rec.js +100 -0
- package/lib/pack/statuseragent-pack.js +44 -0
- package/lib/pack/tagcount-pack.js +4 -4
- package/lib/pack/tagctr.js +15 -0
- package/lib/pack/text-pack.js +50 -0
- package/lib/pack/time-count.js +25 -0
- package/lib/pack/websocket.js +15 -0
- package/lib/pack/zip-pack.js +70 -0
- package/lib/pii/pii-item.js +31 -0
- package/lib/pii/pii-mask.js +174 -0
- package/lib/plugin/plugin-loadermanager.js +57 -0
- package/lib/plugin/plugin.js +75 -0
- package/lib/service/tx-record.js +332 -0
- package/lib/stat/stat-error.js +116 -0
- package/lib/stat/stat-httpc.js +98 -0
- package/lib/stat/stat-remote-ip.js +46 -0
- package/lib/stat/stat-remote-ipurl.js +88 -0
- package/lib/stat/stat-sql.js +113 -0
- package/lib/stat/stat-tranx.js +58 -0
- package/lib/stat/stat-tx-caller.js +160 -0
- package/lib/stat/stat-tx-domain.js +111 -0
- package/lib/stat/stat-tx-referer.js +112 -0
- package/lib/stat/stat-useragent.js +48 -0
- package/lib/stat/timingsender.js +76 -0
- package/lib/step/activestack-step.js +38 -0
- package/lib/step/dbc-step.js +36 -0
- package/lib/step/http-stepx.js +67 -0
- package/lib/step/message-step.js +40 -0
- package/lib/step/method-stepx.js +45 -0
- package/lib/step/resultset-step.js +40 -0
- package/lib/step/securemsg-step.js +44 -0
- package/lib/step/socket-step.js +46 -0
- package/lib/step/sql-stepx.js +68 -0
- package/lib/step/sqlxtype.js +16 -0
- package/lib/step/step.js +66 -0
- package/lib/step/stepenum.js +54 -0
- package/lib/topology/link.js +63 -0
- package/lib/topology/nodeinfo.js +123 -0
- package/lib/topology/status-detector.js +111 -0
- package/lib/trace/trace-context-manager.js +113 -25
- package/lib/trace/trace-context.js +21 -7
- package/lib/trace/trace-httpc.js +17 -11
- package/lib/trace/trace-sql.js +29 -21
- package/lib/util/anylist.js +103 -0
- package/lib/util/cardinality/hyperloglog.js +106 -0
- package/lib/util/cardinality/murmurhash.js +31 -0
- package/lib/util/cardinality/registerset.js +75 -0
- package/lib/util/errordata.js +21 -0
- package/lib/util/escape-literal-sql.js +5 -5
- package/lib/util/hashutil.js +18 -18
- package/lib/util/iputil_x.js +527 -0
- package/lib/util/keygen.js +0 -3
- package/lib/util/kube-util.js +73 -0
- package/lib/util/linkedset.js +1 -2
- package/lib/util/nodeutil.js +2 -1
- package/lib/util/paramsecurity.js +80 -0
- package/lib/util/pre-process.js +13 -0
- package/lib/util/process-seq.js +166 -0
- package/lib/util/property-util.js +36 -0
- package/lib/util/request-queue.js +70 -0
- package/lib/util/requestdouble-queue.js +72 -0
- package/lib/util/resourceprofile.js +157 -0
- package/lib/util/stop-watch.js +30 -0
- package/lib/util/system-util.js +10 -0
- package/lib/util/userid-util.js +57 -0
- package/lib/value/map-value.js +3 -2
- package/package.json +9 -5
- package/whatap.conf +1 -4
- package/agent/darwin/arm64/whatap_nodejs +0 -0
- package/agent/linux/amd64/whatap_nodejs +0 -0
- package/agent/linux/arm64/whatap_nodejs +0 -0
- package/build.txt +0 -4
- package/lib/observers/ioredis-observer.js +0 -294
- package/lib/udp/async_sender.js +0 -119
- package/lib/udp/index.js +0 -17
- package/lib/udp/packet_enum.js +0 -52
- package/lib/udp/packet_queue.js +0 -69
- package/lib/udp/packet_type_enum.js +0 -33
- package/lib/udp/param_def.js +0 -72
- package/lib/udp/udp_session.js +0 -336
- package/lib/util/sql-util.js +0 -178
- package/lib/util/trace-helper.js +0 -91
- package/lib/util/transfer.js +0 -58
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var net = require('net'),
|
|
8
|
+
netflag = require('./netflag').NetFlag,
|
|
9
|
+
netsrc = require('./netflag').NetSrc,
|
|
10
|
+
secu = require('./security-master'),
|
|
11
|
+
conf = require('./../conf/configure'),
|
|
12
|
+
DataOutputX = require('./../io/data-outputx'),
|
|
13
|
+
DataInputX = require('./../io/data-inputx'),
|
|
14
|
+
IPUtil = require('./../util/iputil'),
|
|
15
|
+
TcpReturn = require('./tcp-return'),
|
|
16
|
+
Receiver = require('./receiver'),
|
|
17
|
+
OidUtil = require('../util/oidutil'),
|
|
18
|
+
Logger = require('../logger'),
|
|
19
|
+
Long = require('long');
|
|
20
|
+
|
|
21
|
+
function TcpSession() {
|
|
22
|
+
if(typeof TcpSession.instance === 'object') {
|
|
23
|
+
return TcpSession.instance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.in = null;
|
|
27
|
+
this.out = null;
|
|
28
|
+
this.receiver = new Receiver();
|
|
29
|
+
this._cb = null;
|
|
30
|
+
this.reconnectCnt = 0;
|
|
31
|
+
TcpSession.instance = this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
TcpSession.prototype.open = function(cb){
|
|
35
|
+
var self = this;
|
|
36
|
+
|
|
37
|
+
if(cb) this._cb = cb;
|
|
38
|
+
|
|
39
|
+
self.auto_oname_reset = conf.auto_oname_reset;
|
|
40
|
+
if(secu.PCODE == null || secu.PCODE === 0) {
|
|
41
|
+
if(cb) return cb(new Error('PCODE is not defined..'));
|
|
42
|
+
}
|
|
43
|
+
if(this.isOpen()) {
|
|
44
|
+
++self.reconnectCnt;
|
|
45
|
+
if(self.reconnectCnt >= 3) {
|
|
46
|
+
self.close();
|
|
47
|
+
}
|
|
48
|
+
return cb(new Error('Already connected..'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var host = conf.getWhatapServerHost();
|
|
52
|
+
var port = conf.whatap_server_port || 6600;
|
|
53
|
+
var connection_timeout = conf.tcp_connection_timeout;
|
|
54
|
+
|
|
55
|
+
var options = {
|
|
56
|
+
host: host,
|
|
57
|
+
port: port
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Logger.print('WHATAP-180', "Try to connect to " + JSON.stringify(options), false);
|
|
61
|
+
this.out = net.connect(options, function() {
|
|
62
|
+
var localAddr = (this.localAddress || IPUtil.getIp());
|
|
63
|
+
|
|
64
|
+
if(conf.auto_oname_enabled === true) {
|
|
65
|
+
var oname = conf["whatap.oname"];
|
|
66
|
+
if((oname == null || oname.length === 0)
|
|
67
|
+
&& self.auto_oname_reset === conf.auto_oname_reset) {
|
|
68
|
+
self.prepareAutoOnameByServer(localAddr);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
secu.decideAgentOnameOid(localAddr);
|
|
74
|
+
if(conf.cipher_net_enabled){
|
|
75
|
+
try {
|
|
76
|
+
self.out.write( self.keyReset() );
|
|
77
|
+
} catch(e) {
|
|
78
|
+
Logger.printError("WHATAP-125", "KeyReset " + host + ":" + port, e, true);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
this.out.setKeepAlive(true , 60000);
|
|
84
|
+
this.out.setTimeout(connection_timeout);
|
|
85
|
+
|
|
86
|
+
this.out.on('error', function (err) {
|
|
87
|
+
Logger.printError("WHATAP-127", 'Failed to connect to ' + JSON.stringify(options), err);
|
|
88
|
+
self.close();
|
|
89
|
+
cb(err);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
this.out.on('timeout' , function () {
|
|
93
|
+
Logger.print("WHATAP-184", "Socket timeout. WhaTap will retry connect after " + (connection_timeout/1000) + " sec.", false);
|
|
94
|
+
self.close();
|
|
95
|
+
setTimeout(function() {
|
|
96
|
+
self.open(cb);
|
|
97
|
+
} , 500);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
var firstReceived = false;
|
|
101
|
+
this.out.on('data', function(data) {
|
|
102
|
+
if(self.PREPARE_AGENT) {
|
|
103
|
+
var din = new DataInputX(data);
|
|
104
|
+
var source = din.readByte();
|
|
105
|
+
var code = din.readByte();
|
|
106
|
+
var pcode = din.readLong();
|
|
107
|
+
var oid = din.readInt();
|
|
108
|
+
var transfer_key = din.readInt();
|
|
109
|
+
var _data = din.readIntBytes(8 * 1024 * 1024);
|
|
110
|
+
if (conf.cypher_level > 0) {
|
|
111
|
+
_data = secu.cypher.decrypt(_data);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var oname = new DataInputX(_data).readText();
|
|
115
|
+
|
|
116
|
+
var localAddr = (this.localAddress || IPUtil.getIp());
|
|
117
|
+
secu.setAgentOnameOid(oname, localAddr);
|
|
118
|
+
self.PREPARE_AGENT = false;
|
|
119
|
+
if(conf.cipher_net_enabled) {
|
|
120
|
+
try {
|
|
121
|
+
self.out.write( self.keyReset() );
|
|
122
|
+
} catch(e) {
|
|
123
|
+
Logger.printError("WHATAP-125", "KeyReset " + host + ":" + port, e, true);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if(firstReceived) {
|
|
130
|
+
self.read(data);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
var d = self.readKeyReset(data);
|
|
134
|
+
if( d && d.length != 0 ) {
|
|
135
|
+
conf.updateNetCypherKey(d);
|
|
136
|
+
firstReceived = true;
|
|
137
|
+
if(cb) cb();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
this.out.on('end', function(){
|
|
142
|
+
Logger.print("WHATAP-183", "Disconnected from server, please check your network or Whatap Server!!!!!", false);
|
|
143
|
+
self.close();
|
|
144
|
+
setTimeout(function() {
|
|
145
|
+
cb(new Error('Socket end Event!!!!!'));
|
|
146
|
+
return;
|
|
147
|
+
},500);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
TcpSession.prototype.close = function(){
|
|
152
|
+
if(this.out){
|
|
153
|
+
this.out.destroy();
|
|
154
|
+
this.out = null;
|
|
155
|
+
this.reconnectCnt = 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
TcpSession.prototype.send = function(code , b ){
|
|
160
|
+
try{
|
|
161
|
+
if(this.out == null ){
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
var out = new DataOutputX();
|
|
165
|
+
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
166
|
+
out.writeByte(code);
|
|
167
|
+
out.writeLong(secu.PCODE);
|
|
168
|
+
out.writeInt(secu.OID);
|
|
169
|
+
out.writeInt(conf.TRANSFER_KEY);
|
|
170
|
+
out.writeIntBytes(b);
|
|
171
|
+
/*if(this.out === null ){
|
|
172
|
+
if(this._cb) {
|
|
173
|
+
setTimeout(function() {
|
|
174
|
+
this._cb(new Error('[Send Error] Socket is null !! TCP Session Reconnection......'));
|
|
175
|
+
return;
|
|
176
|
+
},100);
|
|
177
|
+
}
|
|
178
|
+
} */
|
|
179
|
+
this.out.write(out.toByteArray());
|
|
180
|
+
return true;
|
|
181
|
+
} catch(e) {
|
|
182
|
+
Logger.printError('WHATAP-126', 'TcpSession Error', e);
|
|
183
|
+
}
|
|
184
|
+
this.close();
|
|
185
|
+
return false;
|
|
186
|
+
};
|
|
187
|
+
TcpSession.prototype.readKeyReset = function( inPS /* DataInputX */){
|
|
188
|
+
try {
|
|
189
|
+
if( inPS.constructor === Buffer){
|
|
190
|
+
inPS = new DataInputX(inPS);
|
|
191
|
+
}
|
|
192
|
+
var source = inPS.readByte();
|
|
193
|
+
var code = inPS.readByte();
|
|
194
|
+
var pcode = inPS.readLong();
|
|
195
|
+
var oid = inPS.readInt();
|
|
196
|
+
var transfer_key = inPS.readInt();
|
|
197
|
+
var data = inPS.readIntBytes(1024);
|
|
198
|
+
|
|
199
|
+
if( pcode != secu.PCODE || oid != secu.OID){
|
|
200
|
+
return null;
|
|
201
|
+
} else {
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
} catch(e) {
|
|
205
|
+
Logger.printError("WHATAP-189", 'License key or invalid agent version error(fail key)', e, true);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
TcpSession.prototype.keyReset = function(){
|
|
210
|
+
var msg = new DataOutputX().writeText("hello").writeText(secu.ONAME).writeInt8(secu.IP).toByteArray();
|
|
211
|
+
if( conf.cypher_level > 0 ){
|
|
212
|
+
msg = secu.cypher.encrypt(msg);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
var out = new DataOutputX();
|
|
216
|
+
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
217
|
+
out.writeByte(netflag.KEY_RESET);
|
|
218
|
+
out.writeLong(Long.fromValue(secu.PCODE));
|
|
219
|
+
out.writeInt(secu.OID);
|
|
220
|
+
out.writeInt(0);
|
|
221
|
+
out.writeIntBytes(msg);
|
|
222
|
+
return out.toByteArray();
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
TcpSession.prototype.isOpen = function(){
|
|
226
|
+
return this.out != null;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
TcpSession.prototype.read = function (data) {
|
|
230
|
+
var din = new DataInputX(data);
|
|
231
|
+
var out = new TcpReturn();
|
|
232
|
+
var source = din.readByte();
|
|
233
|
+
|
|
234
|
+
out.code = din.readByte();
|
|
235
|
+
var pcode = din.readLong();
|
|
236
|
+
var oid = din.readInt();
|
|
237
|
+
out.transfer_key = din.readInt();
|
|
238
|
+
out.data = din.readIntBytes();
|
|
239
|
+
|
|
240
|
+
if(pcode != secu.PCODE || oid != secu.OID) {
|
|
241
|
+
Logger.printError('WHATAP-190', 'Received data is not mine..', new Error('Receive data error'));
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
this.receiver.read(out);
|
|
245
|
+
};
|
|
246
|
+
TcpSession.prototype.prepareAutoOnameByServer = function (localAddr) {
|
|
247
|
+
var self = this;
|
|
248
|
+
try {
|
|
249
|
+
var auto_oname_prefix = conf.auto_oname_prefix;
|
|
250
|
+
|
|
251
|
+
if(auto_oname_prefix.indexOf('{') >= 0) {
|
|
252
|
+
OidUtil.setIp(localAddr);
|
|
253
|
+
OidUtil.setPort(port);
|
|
254
|
+
OidUtil.setPid(process.pid);
|
|
255
|
+
OidUtil.setHostName(require('os').hostname());
|
|
256
|
+
auto_oname_prefix = OidUtil.mkOname(conf.auto_oname_prefix);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
var pout = new DataOutputX();
|
|
260
|
+
pout.writeText(auto_oname_prefix);
|
|
261
|
+
pout.writeInt(IPUtil.stringToInt(localAddr));
|
|
262
|
+
var msg = pout.toByteArray();
|
|
263
|
+
|
|
264
|
+
var trkey = 0;
|
|
265
|
+
if(conf.cypher_level > 0) {
|
|
266
|
+
msg = secu.cypher.encrypt(msg);
|
|
267
|
+
var b0 = 1;
|
|
268
|
+
var b1 = (conf.cypher_level / 8);
|
|
269
|
+
trkey = DataInputX.toInt([b0, b1, 0, 0], 0);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
var out = new DataOutputX();
|
|
273
|
+
out.writeByte(netsrc.AGENT_JAVA_EMBED);
|
|
274
|
+
out.writeByte(netflag.PREPARE_AGENT);
|
|
275
|
+
out.writeLong(secu.PCODE);
|
|
276
|
+
out.writeInt(0);
|
|
277
|
+
out.writeInt(trkey);
|
|
278
|
+
out.writeIntBytes(msg);
|
|
279
|
+
self.PREPARE_AGENT = true;
|
|
280
|
+
self.out.write(out.toByteArray());
|
|
281
|
+
} catch(e) {
|
|
282
|
+
Logger.printError("WHATAP-003", "Prepare oname error", e, false);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
module.exports = new TcpSession();
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var net = require('net'),
|
|
2
|
+
DataOutputX = require('../io/data-outputx'),
|
|
3
|
+
DataInputX = require('../io/data-inputx'),
|
|
4
|
+
Logger = require('../logger')
|
|
5
|
+
;
|
|
6
|
+
var READ_MAX = 8 * 1024 * 1024;
|
|
7
|
+
|
|
8
|
+
var TcpRequestClientProxy = function(msg){
|
|
9
|
+
this.msg = msg;
|
|
10
|
+
this.failConLog = true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
TcpRequestClientProxy.prototype.close = function(){
|
|
14
|
+
if(!this.client) return;
|
|
15
|
+
|
|
16
|
+
this.client.destroy();
|
|
17
|
+
this.client = undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
TcpRequestClientProxy.prototype.isOpen = function(){
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
TcpRequestClientProxy.prototype.send = function(din){
|
|
25
|
+
if(!this.client) return;
|
|
26
|
+
|
|
27
|
+
var out = new DataOutputX();
|
|
28
|
+
out.write(ss(0XCAFE));
|
|
29
|
+
out.writeIntBytes(din.toByteArray())
|
|
30
|
+
|
|
31
|
+
this.client.write( out.toByteArray()
|
|
32
|
+
, function(error, data){
|
|
33
|
+
if(error){
|
|
34
|
+
return Logger.printError('WHATAP-996', 'TcpRequestClientProxy (send)', e, true);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
TcpRequestClientProxy.prototype.open = function(host, port, connectCb, dataCb){
|
|
41
|
+
var self = this;
|
|
42
|
+
|
|
43
|
+
this.client = net.connect({host: host, port: port}, connectCb);
|
|
44
|
+
this.client.on('data', function(data) {
|
|
45
|
+
var din = new DataInputX(data);
|
|
46
|
+
var cafe = din.readUInt16BE();
|
|
47
|
+
var bytes = din.readIntBytes(READ_MAX);
|
|
48
|
+
|
|
49
|
+
if(dataCb) dataCb(undefined, bytes);
|
|
50
|
+
self.close();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.client.on('error', function (err) {
|
|
54
|
+
Logger.printError("WHATAP-128", 'Failed to connect to ' + self.msg , err, true);
|
|
55
|
+
if(dataCb) dataCb(err);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this.client.on('close', function() {
|
|
59
|
+
self.close();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ss(v) {
|
|
64
|
+
var buf = new Array(2);
|
|
65
|
+
buf[0] = ((v >>> 8) & 0xFF);
|
|
66
|
+
buf[1] = ((v >>> 0) & 0xFF);
|
|
67
|
+
return buf;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = TcpRequestClientProxy;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var Sender = require('./sender'),
|
|
8
|
+
Receiver = require('./receiver'),
|
|
9
|
+
conf = require('./../conf/configure'),
|
|
10
|
+
Logger = require('../logger'),
|
|
11
|
+
RequestDoubleQueue = require('./../util/requestdouble-queue');
|
|
12
|
+
|
|
13
|
+
var TcpRequestManager = function(agent){
|
|
14
|
+
if(TcpRequestManager.instance === 'object') {
|
|
15
|
+
return TcpRequestManager.instance;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.agent = agent;
|
|
19
|
+
this.sender1 = new Sender(agent, this);
|
|
20
|
+
this.sender2 = new Sender(agent, this);
|
|
21
|
+
this.receiver = new Receiver(agent, this);
|
|
22
|
+
this.pool = new RequestDoubleQueue(conf.net_send_queue1_size, conf.net_send_queue2_size);
|
|
23
|
+
this.sendDropped = 0;
|
|
24
|
+
this.isExistData = false;
|
|
25
|
+
|
|
26
|
+
TcpRequestManager.instance = this;
|
|
27
|
+
};
|
|
28
|
+
TcpRequestManager.prototype.add = function(flag, p){
|
|
29
|
+
var _this = this;
|
|
30
|
+
var ok = this.pool.put1({flag: flag, pack: p});
|
|
31
|
+
if(ok === false){
|
|
32
|
+
this.sendDropped++;
|
|
33
|
+
Logger.print("WHATAP-201", 'Data[1] drop count : ' + this.sendDropped)
|
|
34
|
+
} else {
|
|
35
|
+
process.nextTick(function () {
|
|
36
|
+
_this.notify();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
TcpRequestManager.prototype.addProfile = function(flag, p) {
|
|
41
|
+
var self = this;
|
|
42
|
+
var ok = this.pool.put2({flag: flag, pack: p});
|
|
43
|
+
|
|
44
|
+
if(ok === false){
|
|
45
|
+
this.sendDropped++;
|
|
46
|
+
Logger.print("WHATAP-201", 'Data[2] drop count : ' + this.sendDropped)
|
|
47
|
+
}else{
|
|
48
|
+
process.nextTick(function () {
|
|
49
|
+
self.notify();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
TcpRequestManager.prototype.notify = function(){
|
|
54
|
+
this.sender1.startCheckQueue();
|
|
55
|
+
this.sender2.startCheckQueue();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = new TcpRequestManager();
|
|
@@ -8,9 +8,11 @@ var TraceContextManager = require('../trace/trace-context-manager'),
|
|
|
8
8
|
conf = require('../conf/configure'),
|
|
9
9
|
Logger = require('../logger');
|
|
10
10
|
const HashUtil = require('../util/hashutil');
|
|
11
|
+
const DataTextAgent = require('../data/datatext-agent');
|
|
12
|
+
const MessageStep = require('../step/message-step');
|
|
11
13
|
const shimmer = require('../core/shimmer');
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
+
const StatError = require("whatap/lib/stat/stat-error");
|
|
15
|
+
const TextTypes = require("whatap/lib/lang/text-types");
|
|
14
16
|
|
|
15
17
|
var profile_graphql_enabled = conf.getProperty('profile_graphql_enabled', true);
|
|
16
18
|
var profile_graphql_variable_enabled = conf.getProperty('profile_graphql_variable_enabled', false);
|
|
@@ -43,7 +45,7 @@ function checkIgnoreOperation(ignore_operation, operation_name) {
|
|
|
43
45
|
return true;
|
|
44
46
|
}
|
|
45
47
|
} catch (e) {
|
|
46
|
-
Logger.printError('WHATAP-
|
|
48
|
+
Logger.printError('WHATAP-803', 'GraphQL checkIgnoreOperation error: ' + e, false);
|
|
47
49
|
}
|
|
48
50
|
return false;
|
|
49
51
|
}
|
|
@@ -78,25 +80,32 @@ function wrapExecuteHTTPGraphQLRequest(original) {
|
|
|
78
80
|
|
|
79
81
|
// Operation Type Step (query)
|
|
80
82
|
if(body.query && body.query.trim()){
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
var step_type = new MessageStep();
|
|
84
|
+
step_type.hash = HashUtil.hashFromString('Type');
|
|
85
|
+
step_type.start_time = ctx.getElapsedTime();
|
|
86
|
+
step_type.desc = body.query.trim().startsWith('mutation') ? 'mutation' : 'query';
|
|
87
|
+
DataTextAgent.MESSAGE.add(step_type.hash, "Type");
|
|
88
|
+
ctx.profile.push(step_type);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
// Operation Name Step
|
|
88
92
|
if(operationName){
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
var step_operation = new MessageStep();
|
|
94
|
+
step_operation.hash = HashUtil.hashFromString('Operation');
|
|
95
|
+
step_operation.start_time = ctx.getElapsedTime();
|
|
96
|
+
step_operation.desc = operationName || 'anonymous';
|
|
97
|
+
DataTextAgent.MESSAGE.add(step_operation.hash, "Operation");
|
|
98
|
+
ctx.profile.push(step_operation);
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
// Variables Step
|
|
95
102
|
if (profile_graphql_variable_enabled && body.variables && Object.keys(body.variables).length > 0) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
var step_variables = new MessageStep();
|
|
104
|
+
step_variables.hash = HashUtil.hashFromString('Variables');
|
|
105
|
+
step_variables.start_time = ctx.getElapsedTime();
|
|
106
|
+
step_variables.desc = JSON.stringify(Object.keys(body.variables));
|
|
107
|
+
DataTextAgent.MESSAGE.add(step_variables.hash, "Variables");
|
|
108
|
+
ctx.profile.push(step_variables);
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
const response = await original.apply(this, arguments);
|
|
@@ -107,30 +116,27 @@ function wrapExecuteHTTPGraphQLRequest(original) {
|
|
|
107
116
|
const result = JSON.parse(response.body.string);
|
|
108
117
|
if (result.errors && result.errors.length > 0) {
|
|
109
118
|
const errorMessages = result.errors.map(error => error.message).join('\n');
|
|
110
|
-
ctx.
|
|
119
|
+
ctx.statusCode = response.status;
|
|
120
|
+
ctx.error_message = errorMessages;
|
|
121
|
+
ctx.error_class = 'GraphQLError';
|
|
111
122
|
|
|
112
|
-
if
|
|
113
|
-
ctx.error =
|
|
114
|
-
let errors = ['GraphQLError', errorMessages];
|
|
115
|
-
AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
|
|
123
|
+
if(ctx.error.isZero()){
|
|
124
|
+
ctx.error = StatError.addError(response.status, errorMessages, ctx.service_hash, TextTypes.SQL, HashUtil.hashFromString(ctx.service_name));
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
} catch (e) {
|
|
119
|
-
Logger.printError('WHATAP-
|
|
128
|
+
Logger.printError('WHATAP-802', 'GraphQL error parsing failed', e, false);
|
|
120
129
|
}
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
return response;
|
|
124
133
|
|
|
125
134
|
} catch (err) {
|
|
126
|
-
Logger.printError('WHATAP-
|
|
135
|
+
Logger.printError('WHATAP-801', 'GraphQL executeHTTPGraphQLRequest error: ' + err, false);
|
|
127
136
|
if (ctx) {
|
|
128
|
-
ctx.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
let errors = [err.name || err.constructor?.name || 'UnknownError', err.message];
|
|
132
|
-
AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
|
|
133
|
-
}
|
|
137
|
+
ctx.statusCode = 500;
|
|
138
|
+
ctx.error_message = err.message;
|
|
139
|
+
ctx.error_class = err.name || err.constructor?.name || 'UnknownError'
|
|
134
140
|
}
|
|
135
141
|
return original.apply(this, arguments);
|
|
136
142
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
var ClusterObserver = function(agent){
|
|
8
|
+
this.agent = agent;
|
|
9
|
+
this.packages = ['cluster'];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
ClusterObserver.prototype.inject = function( mod ){
|
|
13
|
+
var aop = this.agent.aop;
|
|
14
|
+
|
|
15
|
+
aop.before(mod, 'fork', function(obj, args, result){
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
aop.after(mod, 'fork', function(obj, args, result){
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.ClusterObserver = ClusterObserver;
|