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

Update serverless support in integration tests, expand test tooling, add support for beats testing #3486

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
61 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
17cf6d4
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 12, 2023
0bda272
fix a few serverless bugs, timeout
fearful-symmetry Oct 13, 2023
23ec4aa
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 16, 2023
9794006
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 19, 2023
3848c41
remove os restriction
fearful-symmetry Oct 19, 2023
92aacb4
increase timeouts
fearful-symmetry Oct 19, 2023
b380976
Merge remote-tracking branch 'upstream/main' into support-serverless-…
fearful-symmetry Oct 23, 2023
0bc94bb
revert timeout change
fearful-symmetry Oct 23, 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
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ steps:

- label: "Serverless integration test"
cmacknz marked this conversation as resolved.
Show resolved Hide resolved
key: "serverless-integration-tests"
command: ".buildkite/scripts/steps/integration_tests.sh serverless integration:single TestMonitoringLogsShipped"
command: ".buildkite/scripts/steps/integration_tests.sh serverless integration:single TestMonitoringLogsShipped" #right now, run a single test in serverless mode as a sort of smoke test, instead of re-running the entire suite
artifact_paths:
- "build/TEST-**"
- "build/diagnostics/*"
Expand Down
6 changes: 4 additions & 2 deletions pkg/testing/ess/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ func (p *provisioner) Provision(ctx context.Context, requests []runner.StackRequ
results[r] = resp
}

// wait 15 minutes for all stacks to be ready
readyCtx, readyCancel := context.WithTimeout(ctx, 15*time.Minute)
// set a long timeout
// this context travels up to the magefile, clients that want a shorter timeout can set
// it via mage's -t flag
readyCtx, readyCancel := context.WithTimeout(ctx, 25*time.Minute)
Copy link
Member

Choose a reason for hiding this comment

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

Why the additional 10 minutes, is serverless that much slower?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually for stateful, I ran into a couple timeouts while testing.

Copy link
Member

Choose a reason for hiding this comment

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

Did it fix the problem, or does it just wait longer before failing? Sometimes the stack can fail to come up and waiting doesn't fix it, it just makes you wait longer until finding out.

defer readyCancel()

g, gCtx := errgroup.WithContext(readyCtx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/ess/serverless_provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (prov *ServerlessProvision) Provision(ctx context.Context, requests []runne
Kibana: client.proj.Endpoints.Kibana,
Username: client.proj.Credentials.Username,
Password: client.proj.Credentials.Password,
Internal: map[string]interface{}{"ID": proj.ID},
Internal: map[string]interface{}{"deployment_id": proj.ID},
}
stacks = append(stacks, newStack)
prov.stacksMut.Lock()
Expand Down
108 changes: 88 additions & 20 deletions pkg/testing/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,94 @@ func ExtractArtifact(l Logger, artifactFile, outputDir string) error {
return nil
}

// RunBeat runs the given given beat
// the beat will run until an error, or the given timeout is reached
func (f *Fixture) RunBeat(ctx context.Context) error {
if f.binaryName == "elastic-agent" {
return errors.New("RunBeat() can't be run against elastic-agent")
}

var err error
err = f.EnsurePrepared(ctx)
if err != nil {
return fmt.Errorf("error preparing beat: %w", err)
}

var logProxy Logger
if f.logOutput {
logProxy = f.t
}
stdOut := newLogWatcher(logProxy)
stdErr := newLogWatcher(logProxy)
args := []string{"run", "-e", "-c", filepath.Join(f.workDir, fmt.Sprintf("%s.yml", f.binaryName))}

args = append(args, f.additionalArgs...)

proc, err := process.Start(
f.binaryPath(),
process.WithContext(ctx),
process.WithArgs(args),
process.WithCmdOptions(attachOutErr(stdOut, stdErr)))

if err != nil {
return fmt.Errorf("failed to spawn %s: %w", f.binaryName, err)
}

killProc := func() {
_ = proc.Kill()
<-proc.Wait()
}

var doneChan <-chan time.Time
if f.runLength != 0 {
doneChan = time.After(f.runLength)
}

stopping := false
for {
select {
case <-ctx.Done():
killProc()
return ctx.Err()
case ps := <-proc.Wait():
if stopping {
return nil
}
return fmt.Errorf("elastic-agent exited unexpectedly with exit code: %d", ps.ExitCode())
case err := <-stdOut.Watch():
if !f.allowErrs {
// no errors allowed
killProc()
return fmt.Errorf("elastic-agent logged an unexpected error: %w", err)
}
case err := <-stdErr.Watch():
if !f.allowErrs {
// no errors allowed
killProc()
return fmt.Errorf("elastic-agent logged an unexpected error: %w", err)
}
case <-doneChan:
if !stopping {
// trigger the stop
stopping = true
_ = proc.Stop()
}
}
}
}

// Run runs the provided binary.
//
// If `states` are provided and the binary is Elastic Agent, agent runs until each state has been reached. Once reached the
// If `states` are provided, agent runs until each state has been reached. Once reached the
// Elastic Agent is stopped. If at any time the Elastic Agent logs an error log and the Fixture is not started
// with `WithAllowErrors()` then `Run` will exit early and return the logged error.
//
// If no `states` are provided then the Elastic Agent runs until the context is or the timeout specified with WithRunLength is reached.
func (f *Fixture) Run(ctx context.Context, states ...State) error {
isBeat := false
if f.binaryName != "elastic-agent" {
isBeat = true
return errors.New("Run() can only be used with elastic-agent, use RunBeat()")
}

if !isBeat && f.installed {
if f.installed {
return errors.New("fixture is installed; cannot be run")
}

Expand All @@ -302,9 +376,6 @@ func (f *Fixture) Run(ctx context.Context, states ...State) error {
defer cancel()

var smInstance *stateMachine
if states != nil && isBeat {
return errors.New("states not supported when running against beats")
}
if states != nil {
smInstance, err = newStateMachine(states)
if err != nil {
Expand All @@ -316,16 +387,15 @@ func (f *Fixture) Run(ctx context.Context, states ...State) error {
var agentClient client.Client
var stateCh chan *client.AgentState
var stateErrCh chan error
if !isBeat {
cAddr, err := control.AddressFromPath(f.operatingSystem, f.workDir)
if err != nil {
return fmt.Errorf("failed to get control protcol address: %w", err)
}
agentClient = client.New(client.WithAddress(cAddr))
f.setClient(agentClient)
defer f.setClient(nil)
stateCh, stateErrCh = watchState(ctx, agentClient, f.connectTimout)

cAddr, err := control.AddressFromPath(f.operatingSystem, f.workDir)
if err != nil {
return fmt.Errorf("failed to get control protcol address: %w", err)
}
agentClient = client.New(client.WithAddress(cAddr))
f.setClient(agentClient)
defer f.setClient(nil)
stateCh, stateErrCh = watchState(ctx, agentClient, f.connectTimout)

var logProxy Logger
if f.logOutput {
Expand All @@ -335,9 +405,7 @@ func (f *Fixture) Run(ctx context.Context, states ...State) error {
stdErr := newLogWatcher(logProxy)

args := []string{"run", "-e", "--disable-encrypted-store", "--testing-mode"}
if isBeat {
args = []string{"run", "-e", "-c", filepath.Join(f.workDir, fmt.Sprintf("%s.yml", f.binaryName))}
}

args = append(args, f.additionalArgs...)

proc, err := process.Start(
Expand Down
5 changes: 2 additions & 3 deletions testing/integration/monitoring_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

func TestMonitoringLogsShipped(t *testing.T) {
info := define.Require(t, define.Requirements{
OS: []define.OS{{Type: define.Linux}},
Stack: &define.Stack{},
Local: false,
Sudo: true,
Expand Down Expand Up @@ -86,8 +85,8 @@ func TestMonitoringLogsShipped(t *testing.T) {
docs := findESDocs(t, func() (estools.Documents, error) {
return estools.GetLogsForDatastream(info.ESClient, "elastic_agent.metricbeat")
})
require.NotZero(t, len(docs.Hits.Hits))
t.Logf("metricbeat: Got %d documents", len(docs.Hits.Hits))
require.NotZero(t, len(docs.Hits.Hits))

// Stage 4: make sure all components are healthy
t.Log("Making sure all components are healthy")
Expand Down Expand Up @@ -181,7 +180,7 @@ func findESDocs(t *testing.T, findFn func() (estools.Documents, error)) estools.
docs, err = findFn()
return err == nil
},
3*time.Minute,
10*time.Minute,
cmacknz marked this conversation as resolved.
Show resolved Hide resolved
15*time.Second,
)

Expand Down
Loading