Generating the Binary

(Prerna Manaktala) #1


I am new to golang and elasticsearch.
I installed golang on mac and cloned the packetbeat repo.Trying to run the commang to execute step 1. Generating the Binary, but am unsuccesful.
Can you please guide me as to how to generate the binary so that I can do a code coverage of my tests written in python.

(Andrew Kroh) #2

Hi @Prerna_Manaktala, please follow the instructions listed in the Developer Guide for compiling. It links to a guide to setting up Go and shows the commands for building.

After you can compile, you can generate a code coverage report that includes the python tests by running make full-coverage.

If you encounter a problem please include information about your environment and the error. And we'll try to help you out!


(Prerna Manaktala) #3

Thanks Andrew.
I did above steps and am getting this error:
$ make

first make sure we have godep

go get
/Users/prernamanaktala/work/bin/godep go build

Godeps/_workspace/src/ undefined: tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
Godeps/_workspace/src/ undefined: tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
godep: go exit status 2
make: *** [packetbeat] Error 1

I did godep restore also which worked fine as I installed bazaar.
But how to resolve the make error?
My os is max osx Yosemite, version 10.10.5

(Steffen Siering) #4


have you installed go 1.4.* ? For building you will need go 1.5.1 which adds these missing symbols.

(Prerna Manaktala) #5

Thanks Stephen, I was able to compile packetbeat after removing the older version of go on my system.
But make fulltests gives this error:
/Users/prernamanaktala/work/bin/godep go tool cover -html=./coverage/unit.cov -o coverage/unit.html
make -C ./tests coverage
make -C .. packetbeat.test
make[2]: `packetbeat.test' is up to date.
make -C .. env
test -d env || virtualenv env > /dev/null
/bin/sh: virtualenv: command not found
make[2]: *** [env/bin/activate] Error 127
make[1]: *** [test] Error 2
make: *** [full-coverage] Error 2

Is gotestcover generated in bin the binary file to be used in next steps?

(Andrew Kroh) #6

It looks like you are missing the virtualenv command. See regarding how to install it.

(Prerna Manaktala) #7

Thanks again. I am able to do make full-coverage now.
But I still did not understand how I can run packetbeat with my python tests: which I have in a local repo.
Do I still need to run:go test -c -covermode=count -coverpkg ./...
If yes then which folder do I run this command in?

I understand that I generated packetbeat.test which is used in further steps.

(Steffen Siering) #8

packetbeat.test is a special packetbeat binary compiled with golang test framework included. Just try './packetbeat.test -h'. This binary basicaly includes all flags from 'go test' and packetbeat with 'go test' flags prefixed with '-test.'.

The system tests are based on python too. See tests/pbtests/ how packetbeat.test is run to create coverage information. At minimum you would require to run 'packetbeat.test -systemTest -test.coverprofile coverage.cov ' to run packetbeat with code coverage written to coverage.cov.

(Prerna Manaktala) #9

./packetbeat.test -systemTest -c config.yml -test.coverprofile coverage.cov
Failed to read config.yml: open config.yml: no such file or directory. Exiting.

config.yml is to be created by us?

output of ./packetbeat.test -h' is
-I string
-N Disable actual publishing for testing
-O Read packets one at a time (press Enter)
-c string
Configuration file (default "/etc/beat/beat.yml")
-cpuprofile string
Write cpu profile to file
-d string
Enable certain debug selectors
Print the list of devices and exit
-dump string
Write all captured packets to this libpcap file
-e Output to stdout and disable syslog/file output
-l int
Loop file. 0 - loop forever (default 1)
-memprofile string
Write memory profile to this file
Set to true when running system tests
-t Read packets as fast as possible, without sleeping
Test configuration and exit.
-test.bench string
regular expression to select benchmarks to run
print memory allocations for benchmarks
-test.benchtime duration
approximate run time for each benchmark (default 1s)
-test.blockprofile string
write a goroutine blocking profile to the named file after execution
-test.blockprofilerate int
if >= 0, calls runtime.SetBlockProfileRate() (default 1)
-test.count n
run tests and benchmarks n times (default 1)
-test.coverprofile string
write a coverage profile to the named file after execution
-test.cpu string
comma-separated list of number of CPUs to use for each test
-test.cpuprofile string
write a cpu profile to the named file during execution
-test.memprofile string
write a memory profile to the named file after execution
-test.memprofilerate int
if >=0, sets runtime.MemProfileRate
-test.outputdir string
directory in which to write profiles
-test.parallel int
maximum test parallelism (default 8) string
regular expression to select tests and examples to run
run smaller test suite to save time
-test.timeout duration
if positive, sets an aggregate time limit for all tests
-test.trace string
write an execution trace to the named file after execution
verbose: print additional output
-v Log at INFO level
Print version and exit
-waitstop int
Additional seconds to wait befor shutting down

Can I run ./packetbeat.test with some options/flags and give path to my python tests in a local folder?

(ruflin) #10

@Prerna_Manaktala Here you can see the exact commands that are used to run the system tests:

make -C .. packetbeat.test
make -C .. env
. ../env/bin/activate && nosetests --processes=${PROCESSES} --process-timeout=$(TIMEOUT)

First the test binary is created, the the environment is setup and then nosetests is used to run the tests.

If you run full-coverage, your tests should be automatically picked up, run an added to the coverage report. If you only want to run a single test or test file, for simplicity you can temporarly edit the nosetests command in the Makefile and add a filter for the specific tests.

(Steffen Siering) #11

@Prerna_Manaktala yes you have to configure packetbeat. What kind of tests do you want to run? You actively want to sniff packets or you want to drive your tests using a pcap?

For configuring and running packetbeat check out our docs:

Our system tests do test packetbeat using pcap files. Check out to figure out how we start packetbeat. Our tests create run directories per test into which a sample configuration is build used to execute packetbeat.

Use '-c' on packetbeat.test to set the location of your configuration file.

(Prerna Manaktala) #13

Thanks , I want to run python tests in /usr/local/testrunner( git clone of ) and my packetbeat.test is located in /Users/prernamanaktala/work/src/ which got generated after doing make full-coverage .My question is how can I know the code coverage in my python tests using packetbeat?

(Prerna Manaktala) #14

Also is there an existing config.yml I can look at?

(ruflin) #15

@Prerna_Manaktala Here you can find the default config with all options inside:

About generating the code coverage this blog post could also help:

(Prerna Manaktala) #16

Yes I used the default config file and the blog post above for code-coverage.
But I am not able to make a connection between packetbeat , golang code:
and python tests written to test the golang code:

(Andrew Kroh) #17

There is no relationship between them unless you are using Packetbeat within couchbase/query. Are you? Otherwise, to get test coverage from your own application you do not need Packetbeat, instead you need to instrument your own application to generate code coverage metrics.

You can use the commands from Packetbeat as an example. This process is what is documented in the blog post where Packetbeat is used as an example.

(Prerna Manaktala) #18

Yes I want to use packetbeat within couchbase/query. Thats right.
But when I try to follow instructions in the blog. and run go test -c -covermode=count -coverpkg ./...
inside couchbase/query and have main_test.go in it as explained in blog,It gives me this error:
./main_test.go:19: undefined: main
how should i start with packetbeat in couchbase/query?

(Andrew Kroh) #19

Sorry @Prerna_Manaktala, I am having a difficult time understanding how you are trying to use Packetbeat. Could you explain a bit about how you are trying to use Packetbeat and what your goals are with this testing? This will help us answer your question. Thanks!

(Prerna Manaktala) #20

Yes sure.
I want to use packetbeat to get how much test coverage I have in my python tests in: /usr/local/couchbase/testrunner which is clone of These tests are written for golang query code in /Users/prernamanaktala/work/src/ which is clone of My packetbeat code is in /Users/prernamanaktala/work/src/ where I am able to do make full-coverage without changing the makefile and see unit.html and coverage.html.

I am able to change the makefile in packetbeat to point to my git ,but when I do make full-coverage then, i get errors and packetbeat.test does not get generated.But unit.cov gets generated in coverage folder.
prernamanaktala@couchbases-MacBook-Pro packetbeat (master) $ make full-coverage
make coverage

gotestcover is needed to fetch coverage for multiple packages

go get
mkdir -p coverage
GOPATH=/Users/prernamanaktala/work/src/ /Users/prernamanaktala/work/bin/gotestcover -coverprofile=./coverage/unit.cov -covermode=count
test failed
make[1]: *** [coverage] Error 1
make: *** [full-coverage] Error 2

(ruflin) #21

@Prerna_Manaktala As @andrewkroh mentioned, there seems to be some confusion between the coverage report and packetbeat. Packetbeat is only the example project that is mentioned in the blog post to see how we implemented the coverage report. The coverage report and scripts itself are completely independent of packetbeat. So in case you want to implement a system coverage report for your project, you don't need packetbeat. You need to create the files mentioned in the blog post in your own project.

So if I understand you right now, what you are trying to do is getting a coverage report for couchbase/query binary by running your python tests stored in couchbase/testrunner? I assume so far these tests were run with the "default" binary generated from couchbase/query?