8000 Feature/add tcpdump support by dothebart · Pull Request #9396 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Feature/add tcpdump support #9396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8000 Merged
merged 2 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README_maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,35 @@ syntax --option value --sub:option value. Using Valgrind could look like this:
- we force the logging not to happen asynchronous
- eventually you may still add temporary `console.log()` statements to tests you debug.

Running tcpdump / windump for the SUT
-------------------------------------
Don't want to miss a beat of your test? If you want to invoke tcpdump with sudo, make sure
that your current shell has sudo enabled. Try like this:

sudo /bin/true; ./scripts/unittest http_server \
--sniff sudo --cleanup false

The pcap file will end up in your tests temporary directory.
You may need to press an additional `ctrl+c` to force stop the sudo'ed tcpdump.

On windows you can use TShark, you need a npcap enabled installation. List your devices
to sniff on using the -D option:

c:/Program\ Files/wireshark/tshark.exe -D
1. \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} (Npcap Loopback Adapter)
2. \Device\NPF_{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} (Ethernet)
3. \\.\USBPcap1 (USBPcap1)

choose the `Npcap Loopback Adapter` number - 1:

./scripts/unittest http_server \
--sniff true \
--cleanup false \
--sniffDevice 1\
--sniffProgramm c:/Programm Files/wireshark/tshark.exe

you can later on use wireshark to inpsect the capture files.

Debugging AQL execution blocks
------------------------------
To debug AQL execution blocks, two steps are required:
Expand Down
40 changes: 39 additions & 1 deletion js/client/modules/@arangodb/process-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const platform = internal.platform;
const abortSignal = 6;
const termSignal = 15;

let tcpdump;

class ConfigBuilder {
constructor(type) {
this.config = {
Expand Down Expand Up @@ -1310,7 +1312,11 @@ function shutdownInstance (instanceInfo, options, forceTerminate) {
}
});
}

if (tcpdump !== undefined) {
print(CYAN + "Stopping tcpdump" + RESET);
killExternal(tcpdump.pid);
statusExternal(tcpdump.pid, true);
}
cleanupDirectories.unshift(instanceInfo.rootDir);
return shutdownSuccess;
}
Expand Down Expand Up @@ -1562,6 +1568,38 @@ function launchFinalize(options, instanceInfo, startTime) {
});

print(Date() + ' sniffing template:\n tcpdump -ni lo -s0 -w /tmp/out.pcap ' + ports.join(' or ') + '\n');
if (options.sniff !== undefined && options.sniff !== false) {
options.cleanup = false;
let device = 'lo';
if (platform.substr(0, 3) === 'win') {
device = '1';
}
if (options.sniffDevice !== undefined) {
device = options.sniffDevice;
}

let pcapFile = fs.join(instanceInfo.rootDir, 'out.pcap');
let args = ['-ni', device, '-s0', '-w', pcapFile];
for (let port = 0; port < ports.length; port ++) {
if (port > 0) {
args.push('or');
}
args.push(ports[port]);
}
let prog = 'tcpdump';
if (platform.substr(0, 3) === 'win') {
prog = 'c:/Program Files/Wireshark/tshark.exe';
}
if (options.sniffProgramm !== undefined) {
prog = options.sniffProgramm;
}
if (options.sniff === 'sudo') {
args.unshift(prog);
prog = 'sudo';
}
print(CYAN + 'launching ' + prog + ' ' + JSON.stringify(args) + RESET);
tcpdump = executeExternal(prog, args);
}
print(processInfo.join('\n') + '\n');
internal.sleep(options.sleepBeforeStart);
}
Expand Down
7 changes: 7 additions & 0 deletions js/client/modules/@arangodb/testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ let optionsDocumentation = [
' and logs are removed after termination of the test.',
'',
' - `protocol`: the protocol to talk to the server - [tcp (default), ssl, unix]',
' - `sniff`: if we should try to launch tcpdump / windump for a testrun',
' false / true / sudo',
' - `sniffDevice`: the device tcpdump / tshark should use',
' - `sniffProgramm`: specify your own programm',
' - `build`: the directory containing the binaries',
' - `buildType`: Windows build type (Debug, Release), leave empty on linux',
' - `configDir`: the directory containing the config files, defaults to',
Expand Down Expand Up @@ -162,6 +166,9 @@ const optionsDefaults = {
'sanitizer': false,
'activefailover': false,
'singles': 2,
'sniff': false,
'sniffDevice': undefined,
'sniffProgramm': undefined,
'skipLogAnalysis': true,
'skipMemoryIntense': false,
'skipNightly': true,
Expand Down
0