Skip to content

Instantly share code, notes, and snippets.

@zmoog
Last active February 6, 2023 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmoog/cf50d14416f5c732656fb2f41a1e7acf to your computer and use it in GitHub Desktop.
Save zmoog/cf50d14416f5c732656fb2f41a1e7acf to your computer and use it in GitHub Desktop.
Document how to run ingest pipelines tests in Beats

I couldn't find how to run ingest pipeline tests in Beats, so I'm writing this Gist to capture what I know so far.

Assumption

Steps

Checking the Linux version:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.4 LTS
Release:	20.04
Codename:	focal
# install mage
mkdir -p ~/bin
cd ~/bin
wget https://github.com/magefile/mage/releases/download/v1.14.0/mage_1.14.0_Linux-64bit.tar.gz
tar zxvf mage_1.14.0_Linux-64bit.tar.gz
export PATH=$PATH:~/bin

# install go
sudo apt install golang
go version


# docker
# https://docs.docker.com/engine/install/ubuntu/
sudo apt-get update
sudo apt-get install \
	ca-certificates \
	curl \
	gnupg \
	lsb-release

sudo mkdir -p /etc/apt/keyrings
	curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
	  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
	  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
	  
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose


# https://docs.docker.com/engine/install/linux-postinstall/
sudo groupadd docker || echo
sudo usermod -aG docker $USER
# Log out and log back in so that your group membership is re-evaluated.

	
# clone 
mkdir -p ~/code/projects/elastic
cd ~/code/projects/elastic

git clone https://github.com/elastic/beats.git
cd beats/x-pack/filebeat/

# python
sudo apt install python3-pip

# 
mage pythonVirtualEnv

# run tests for activitylogs
TESTING_FILEBEAT_MODULES=azure TESTING_FILEBEAT_FILESETS=activitylogs MODULES_PATH=module PYTEST_ADDOPTS="-k test_xpack_modules.py"  mage -v pythonIntegTest

I am using Filebeat as an example.

First, walk into the Filebeat root directory:

cd x-pack/filebeat/

In general you can use the following command:

TESTING_FILEBEAT_MODULES=<module> \
TESTING_FILEBEAT_FILESETS=<fileset> \
MODULES_PATH=module \
mage -v pythonIntegTest

For example, here's the command line to test the activitylogs fileset in the azure module:

TESTING_FILEBEAT_MODULES=azure \
TESTING_FILEBEAT_FILESETS=activitylogs \
MODULES_PATH=module \
mage -v pythonIntegTest

Additional environment variables:

# To rebuild the expected logs.
GENERATE=1

# To skip everything but the modules test.
PYTEST_ADDOPTS="-k test_modules"
PYTEST_ADDOPTS="-k test_modules -vv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment