8000 Feature/add tcpdump support (#9396) · arangodb/arangodb@61f3397 · GitHub
[go: up one dir, main page]

Skip to content

Commit 61f3397

Browse files
dothebartjsteemann
authored andcommitted
Feature/add tcpdump support (#9396)
1 parent 3f9b859 commit 61f3397

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

README_maintainers.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,35 @@ syntax --option value --sub:option value. Using Valgrind could look like this:
374374
- we force the logging not to happen asynchronous
375375
- eventually you may still add temporary `console.log()` statements to tests you debug.
376376
377+
Running tcpdump / windump for the SUT
378+
-------------------------------------
379+
Don't want to miss a beat of your test? If you want to invoke tcpdump with sudo, make sure
380+
that your current shell has sudo enabled. Try like this:
381+
382+
sudo /bin/true; ./scripts/unittest http_server \
383+
--sniff sudo --cleanup false
384+
385+
The pcap file will end up in your tests temporary directory.
386+
You may need to press an additional `ctrl+c` to force stop the sudo'ed tcpdump.
387+
388+
On windows you can use TShark, you need a npcap enabled installation. List your devices
389+
to sniff on using the -D option:
390+
391+
c:/Program\ Files/wireshark/tshark.exe -D
392+
1. \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} (Npcap Loopback Adapter)
393+
2. \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} (Ethernet)
394+
3. \\.\USBPcap1 (USBPcap1)
395+
396+
choose the `Npcap Loopback Adapter` number - 1:
397+
398+
./scripts/unittest http_server \
399+
--sniff true \
400+
--cleanup false \
401+
--sniffDevice 1\
402+
--sniffProgramm c:/Programm Files/wireshark/tshark.exe
403+
404+
you can later on use wireshark to inpsect the capture files.
405+
377406
Debugging AQL execution blocks
378407
------------------------------
379408
To debug AQL execution blocks, two steps are required:

js/client/modules/@arangodb/process-utils.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ const platform = internal.platform;
5959
const abortSignal = 6;
6060
const termSignal = 15;
6161

62+
let tcpdump;
63+
6264
class ConfigBuilder {
6365
constructor(type) {
6466
this.config = {
@@ -1310,7 +1312,11 @@ function shutdownInstance (instanceInfo, options, forceTerminate) {
13101312
}
13111313
});
13121314
}
1313-
1315+
if (tcpdump !== undefined) {
1316+
print(CYAN + "Stopping tcpdump" + RESET);
1317+
killExternal(tcpdump.pid);
1318+
statusExternal(tcpdump.pid, true);
1319+
}
13141320
cleanupDirectories.unshift(instanceInfo.rootDir);
13151321
return shutdownSuccess;
13161322
}
@@ -1562,6 +1568,38 @@ function launchFinalize(options, instanceInfo, startTime) {
15621568
});
15631569

15641570
print(Date() + ' sniffing template:\n tcpdump -ni lo -s0 -w /tmp/out.pcap ' + ports.join(' or ') + '\n');
1571+
if (options.sniff !== undefined && options.sniff !== false) {
1572+
options.cleanup = false;
1573+
let device = 'lo';
1574+
if (platform.substr(0, 3) === 'win') {
1575+
device = '1';
1576+
}
1577+
if (options.sniffDevice !== undefined) {
1578+
device = options.sniffDevice;
1579+
}
1580+
1581+
let pcapFile = fs.join(instanceInfo.rootDir, 'out.pcap');
1582+
let args = ['-ni', device, '-s0', '-w', pcapFile];
1583+
for (let port = 0; port < ports.length; port ++) {
1584+
if (port > 0) {
1585+
args.push('or');
1586+
}
1587+
args.push(ports[port]);
1588+
}
1589+
let prog = 'tcpdump';
1590+
if (platform.substr(0, 3) === 'win') {
1591+
prog = 'c:/Program Files/Wireshark/tshark.exe';
1592+
}
1593+
if (options.sniffProgramm !== undefined) {
1594+
prog = options.sniffProgramm;
1595+
}
1596+
if (options.sniff === 'sudo') {
1597+
args.unshift(prog);
1598+
prog = 'sudo';
1599+
}
1600+
print(CYAN + 'launching ' + prog + ' ' + JSON.stringify(args) + RESET);
1601+
tcpdump = executeExternal(prog, args);
1602+
}
15651603
print(processInfo.join('\n') + '\n');
15661604
internal.sleep(options.sleepBeforeStart);
15671605
}

js/client/modules/@arangodb/testing.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ let optionsDocumentation = [
8181
' and logs are removed after termination of the test.',
8282
'',
8383
' - `protocol`: the protocol to talk to the server - [tcp (default), ssl, unix]',
84+
' - `sniff`: if we should try to launch tcpdump / windump for a testrun',
85+
' false / true / sudo',
86+
' - `sniffDevice`: the device tcpdump / tshark should use',
87+
' - `sniffProgramm`: specify your own programm',
8488
' - `build`: the directory containing the binaries',
8589
' - `buildType`: Windows build type (Debug, Release), leave empty on linux',
8690
' - `configDir`: the directory containing the config files, defaults to',
@@ -162,6 +166,9 @@ const optionsDefaults = {
162166
'sanitizer': false,
163167
'activefailover': false,
164168
'singles': 2,
169+
'sniff': false,
170+
'sniffDevice': undefined,
171+
'sniffProgramm': undefined,
165172
'skipLogAnalysis': true,
166173
'skipMemoryIntense': false,
167174
'skipNightly': true,

0 commit comments

Comments
 (0)
0