Skip to content
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

Add serverless beats tests #3658

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
c55bbde
cleaning up
fearful-symmetry Aug 15, 2023
12ac235
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Aug 15, 2023
e939383
final bit of cleanup
fearful-symmetry Aug 16, 2023
2afe998
fix magefile, cleanup docs
fearful-symmetry Aug 16, 2023
413c0d7
clean up errors, make linter happy
fearful-symmetry Aug 16, 2023
a16767d
fix headers
fearful-symmetry Aug 16, 2023
7e8970a
fix fields in runner config
fearful-symmetry Aug 16, 2023
9e26b7c
add dashboard checks
fearful-symmetry Aug 17, 2023
3aab6e6
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Aug 17, 2023
369f62e
clean up, refactor
fearful-symmetry Aug 25, 2023
0b7afae
clean up
fearful-symmetry Aug 25, 2023
ef23b3a
tinker with env vars
fearful-symmetry Aug 28, 2023
a20930d
fix defaults in fixture
fearful-symmetry Aug 29, 2023
7d5da83
check binary name in test setup
fearful-symmetry Aug 29, 2023
e75b495
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Sep 5, 2023
85b4ba5
allow ilm override in tests
fearful-symmetry Sep 6, 2023
0051120
fix filebeat tests, add cleanup
fearful-symmetry Sep 6, 2023
fd88bf2
tinker with dashboards
fearful-symmetry Sep 11, 2023
ec9c8c5
fix ilm tests
fearful-symmetry Sep 13, 2023
e312d0b
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Sep 13, 2023
27f8814
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Sep 21, 2023
5611ff9
Merge remote-tracking branch 'origin/serverless-tests' into serverles…
fearful-symmetry Sep 21, 2023
8267e47
use API keys for auth
fearful-symmetry Sep 26, 2023
a733070
Merge remote-tracking branch 'origin/serverless-tests' into serverles…
fearful-symmetry Sep 26, 2023
acff625
add additional integration tests
fearful-symmetry Sep 27, 2023
3196a39
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Sep 28, 2023
a79b814
Merge remote-tracking branch 'upstream/main' into serverless-tests
fearful-symmetry Sep 28, 2023
de89941
remove beats-specific code
fearful-symmetry Sep 28, 2023
6a5277b
hack in serverless tests
fearful-symmetry Sep 29, 2023
a5039e6
tinker with tests
fearful-symmetry Sep 29, 2023
5a49c56
change env var naming
fearful-symmetry Sep 29, 2023
918fec6
actually use correct provisioner name
fearful-symmetry Sep 29, 2023
459206a
tinker with buildkite again
fearful-symmetry Oct 2, 2023
a7c0c0a
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 2, 2023
d158d76
fix things after refactor
fearful-symmetry Oct 3, 2023
b2e4e87
fix buildkite
fearful-symmetry Oct 3, 2023
f359ef0
fix my bash scripts
fearful-symmetry Oct 3, 2023
bf3e5f4
my bash is a tad rusty
fearful-symmetry Oct 3, 2023
1e00bd0
tinker with script hooks
fearful-symmetry Oct 3, 2023
203491c
not sure what ci role I broke
fearful-symmetry Oct 3, 2023
0903608
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 4, 2023
875bbd1
clean up es handlers
fearful-symmetry Oct 5, 2023
c1cadb1
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 5, 2023
2b0d84d
deal with recent refactor
fearful-symmetry Oct 5, 2023
8c07f05
fix my broken refactor
fearful-symmetry Oct 5, 2023
9edc32c
change url, see what happens
fearful-symmetry Oct 5, 2023
0c7d0cb
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 6, 2023
ea4d684
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 9, 2023
4fe9a58
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 10, 2023
c3c8255
tinker with tests more
fearful-symmetry Oct 10, 2023
0a0ea06
swap pipelines, see what happens
fearful-symmetry Oct 10, 2023
d9b62c0
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 10, 2023
4165bdb
break apart beat runners
fearful-symmetry Oct 11, 2023
1194e06
create test
fearful-symmetry Oct 12, 2023
c09e3f6
add more tests
fearful-symmetry Oct 12, 2023
bf89a85
override tests in progress
fearful-symmetry Oct 13, 2023
6dc7c94
finish overwrite tests
fearful-symmetry Oct 13, 2023
421e35f
still adding tests
fearful-symmetry Oct 16, 2023
ee2a073
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Oct 25, 2023
99ac425
cleanup
fearful-symmetry Oct 25, 2023
a7f4383
fix env var names
fearful-symmetry Oct 25, 2023
d62781c
fix filebeat setup, test names
fearful-symmetry Oct 25, 2023
27f1701
fixing up filebeat
fearful-symmetry Oct 26, 2023
a590d3b
use templates, fix ES query
fearful-symmetry Oct 26, 2023
38775b1
tinker with buildkite
fearful-symmetry Oct 27, 2023
ac2d445
still tinkering
fearful-symmetry Oct 27, 2023
587def0
still trying to get it to work
fearful-symmetry Oct 27, 2023
3e0eb23
still trying to get it to work
fearful-symmetry Oct 27, 2023
94b3961
add script, see what happens
fearful-symmetry Oct 27, 2023
d8f17aa
tinkering with script
fearful-symmetry Oct 27, 2023
5cf68f5
tinkering with script
fearful-symmetry Oct 27, 2023
e9d8404
trying to diagnose buildkite
fearful-symmetry Oct 27, 2023
03d3705
still fighting with buildkite
fearful-symmetry Oct 27, 2023
18523dc
still trying to get it to work
fearful-symmetry Oct 27, 2023
8da7a0b
set workspace
fearful-symmetry Oct 27, 2023
40bea83
change workspace
fearful-symmetry Oct 27, 2023
4ad1f14
change workspace, again
fearful-symmetry Oct 27, 2023
77186df
change workspace, again
fearful-symmetry Oct 27, 2023
c6ce641
trying to debug buildkite
fearful-symmetry Oct 27, 2023
537c81f
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Oct 30, 2023
03aabf9
add debug statements
fearful-symmetry Oct 30, 2023
48d6c5a
run mage twice
fearful-symmetry Oct 30, 2023
04d501d
I swear I'll figure this out
fearful-symmetry Oct 30, 2023
a81c543
potential script install issue?
fearful-symmetry Oct 30, 2023
75437d9
use different condition for if block
fearful-symmetry Oct 30, 2023
6bd9190
fix potential wrong flag in setup scripts
fearful-symmetry Oct 30, 2023
cdf67cf
change -p flag
fearful-symmetry Oct 30, 2023
a9ed68c
fix workspace path, add tests,remove debug code
fearful-symmetry Oct 30, 2023
478e357
use proper env vars
fearful-symmetry Oct 30, 2023
2bf8b9d
fix mage call, directories
fearful-symmetry Oct 30, 2023
860829c
set working directories
fearful-symmetry Oct 30, 2023
1c522ff
now trying to get auth working
fearful-symmetry Oct 30, 2023
c55b000
change name to make setup happy
fearful-symmetry Oct 30, 2023
f4f69ea
disable cleanup
fearful-symmetry Oct 31, 2023
1ad5919
re-enable cleanup
fearful-symmetry Oct 31, 2023
4823f2b
run one test at a time
fearful-symmetry Oct 31, 2023
ff33974
refactor, run filebeat
fearful-symmetry Oct 31, 2023
9664cb3
move function def
fearful-symmetry Oct 31, 2023
882bc6e
fix if blocks
fearful-symmetry Oct 31, 2023
af010c5
fix test run, add support for auditbeat and packetbeat
fearful-symmetry Oct 31, 2023
e5e7b69
add packetbeat support, run auditbeat tests
fearful-symmetry Oct 31, 2023
2b8f099
add serverless buildkite logic
fearful-symmetry Nov 1, 2023
97a60d4
add more documentation
fearful-symmetry Nov 1, 2023
b86305e
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 2, 2023
8454892
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 7, 2023
72567f4
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 8, 2023
48d7ea2
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 10, 2023
374cc74
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 13, 2023
fac8582
Merge remote-tracking branch 'upstream/main' into add-beats-tests-to-…
fearful-symmetry Nov 14, 2023
5cef809
fix up tests
fearful-symmetry Nov 16, 2023
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
12 changes: 12 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ steps:
provider: "gcp"
machineType: "n1-standard-8"

- label: "Serverless Beats Tests"
key: "serverless-beats-integration-tests"
command: ".buildkite/scripts/steps/beats_tests.sh"
if: "build.env('CRON') == 'yes'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the cron schedule controlled? Can you link to it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I was going to add it once the PR was merged, but the control panel for it is here: https://buildkite.com/elastic/elastic-agent/settings/schedules

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a link to that as a comment right above this so future us can find it easily

agents:
provider: "gcp"
machineType: "n1-standard-8"
retry:
manual:
allowed: true


- wait: ~
continue_on_failure: true
- label: "Processing test results"
Expand Down
4 changes: 2 additions & 2 deletions .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ getOSOptions() {
# Wrapper function for executing mage
mage() {
go version
if ! [ -x "$(type -p mage | sed 's/mage is //g')" ];
if ! [ -x "$(type -P mage | sed 's/mage is //g')" ];
pchila marked this conversation as resolved.
Show resolved Hide resolved
then
echo "installing mage ${SETUP_MAGE_VERSION}"
make mage
Expand All @@ -68,7 +68,7 @@ mage() {
# Wrapper function for executing go
go(){
# Search for the go in the Path
if ! [ -x "$(type -p go | sed 's/go is //g')" ];
if ! [ -x "$(type -P go | sed 's/go is //g')" ];
then
getOSOptions
echo "installing golang "${GO_VERSION}" for "${AGENT_OS_NAME}/${AGENT_OS_ARCH}" "
Expand Down
70 changes: 70 additions & 0 deletions .buildkite/scripts/steps/beats_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
set -euo pipefail

#=========================
# NOTE: This entire script is a temporary hack until we have buildkite set up on the beats repo.
# until then, we need some kind of serverless integration tests, hence this script, which just clones the beats repo,
# and runs the serverless integration suite against different beats
# After buildkite is set up on beats, this file/PR should be reverted.
#==========================

source .buildkite/scripts/common.sh
STACK_PROVISIONER="${1:-"serverless"}"

run_test_for_beat(){
local beat_name=$1

#build
export WORKSPACE="build/beats/x-pack/${beat_name}"
SNAPSHOT=true PLATFORMS=linux/amd64 PACKAGES=tar.gz,zip mage package

#run
export AGENT_BUILD_DIR="build/beats/x-pack/${beat_name}/build/distributions"
export WORKSPACE=$(pwd)

set +e
TEST_INTEG_CLEAN_ON_EXIT=true TEST_PLATFORMS="linux/amd64" STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage integration:testBeatServerless $beat_name
TESTS_EXIT_STATUS=$?
set -e

return $TESTS_EXIT_STATUS
}
#run mage before setup, since this will install go and mage
#the setup scripts will do a few things that assume we're running out of elastic-agent and will break things for beats, so run before we do actual setup
mage -l

mkdir -p build
cd build

git clone --filter=tree:0 [email protected]:elastic/beats.git
cd ..

# export WORKSPACE=beats/x-pack/metricbeat

# SNAPSHOT=true PLATFORMS=linux/amd64,windows/amd64 PACKAGES=tar.gz,zip mage package


# cd ..

# export AGENT_BUILD_DIR=build/beats/x-pack/metricbeat/build/distributions
# export WORKSPACE=$(pwd)

# set +e
# TEST_INTEG_CLEAN_ON_EXIT=true TEST_PLATFORMS="linux/amd64" STACK_PROVISIONER="$STACK_PROVISIONER" SNAPSHOT=true mage integration:testBeatServerless metricbeat
# TESTS_EXIT_STATUS=$?
# set -e

# exit $TESTS_EXIT_STATUS

echo "testing metricbeat..."
run_test_for_beat metricbeat



echo "testing filebeat..."
run_test_for_beat filebeat



echo "testing auditbeat..."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can skip testing auditbeat since our team doesn't maintain it. None of the code we are testing is really Beat specific regardless.

run_test_for_beat auditbeat
27 changes: 27 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,33 @@ func (Integration) PrepareOnRemote() {
mg.Deps(mage.InstallGoTestTools)
}

// Run beat serverless tests
func (Integration) TestBeatServerless(ctx context.Context, beatname string) error {
beatBuildPath := filepath.Join("..", "beats", "x-pack", beatname, "build", "distributions")
if os.Getenv("AGENT_BUILD_DIR") == "" {
err := os.Setenv("AGENT_BUILD_DIR", beatBuildPath)
if err != nil {
return fmt.Errorf("error setting build dir: %s", err)
}
}

// a bit of bypass logic; run as serverless by default
if os.Getenv("STACK_PROVISIONER") == "" {
err := os.Setenv("STACK_PROVISIONER", "serverless")
if err != nil {
return fmt.Errorf("error setting serverless stack var: %w", err)
}
} else if os.Getenv("STACK_PROVISIONER") == "stateful" {
fmt.Printf(">>> Warning: running TestBeatServerless as stateful\n")
pchila marked this conversation as resolved.
Show resolved Hide resolved
}

err := os.Setenv("TEST_BINARY_NAME", beatname)
if err != nil {
return fmt.Errorf("error setting binary name: %w", err)
}
return integRunner(ctx, false, "TestBeatsServerless")
}

// TestOnRemote shouldn't be called locally (called on remote host to perform testing)
func (Integration) TestOnRemote(ctx context.Context) error {
mg.Deps(Build.TestBinaries)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/tools/estools/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func GetLatestDocumentMatchingQuery(ctx context.Context, client elastictransport
queryRaw := map[string]interface{}{
"query": query,
"sort": map[string]interface{}{
"timestamp": "desc",
"@timestamp": "desc",
},
"size": 1,
}
Expand Down
Loading
Loading