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

Run system tests in parallel #1909

Merged
merged 46 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ecfe60c
Prepare RunSuite to trigger tests in parallel
mrodm Jun 12, 2024
bc822c7
Reduce log from container status - temporal
mrodm Jun 12, 2024
ef1383c
Add debug message
mrodm Jun 13, 2024
85eb196
Rename field - default parallel false
mrodm Jun 13, 2024
4e928a0
Avod checking agent logs if test is skipped
mrodm Jun 13, 2024
7719ea8
Show agent data instead of JSON
mrodm Jun 13, 2024
cfb1905
Move pkgManifest and dataStreamManifest to constructor tester
mrodm Jun 13, 2024
a68f6fd
Remove extra parameter in Debugf
mrodm Jun 13, 2024
ac95e8b
Update package-spec dep
mrodm Jun 13, 2024
fa31ae5
Ensure routines finished if context cancelled or signal received
mrodm Jun 13, 2024
4c926bf
Reorder where handlers are defined
mrodm Jun 13, 2024
ae89c2e
Return service to be able to set the shutdown service handler
mrodm Jun 13, 2024
c36f4bd
Add license header
mrodm Jun 13, 2024
3213751
Revert reorder of checkEnrolledAgents and handlers
mrodm Jun 13, 2024
06d5b77
Restore debug message
mrodm Jun 13, 2024
74bdd72
Update comments
mrodm Jun 17, 2024
b50f5cd
Rename function and set private struct
mrodm Jun 17, 2024
37f8d44
Enable parallel tests in apache and nginx
mrodm Jun 17, 2024
f608d06
Remove duplicated debug log (shown in system runner)
mrodm Jun 17, 2024
e642460
Fix format global config
mrodm Jun 17, 2024
6107bca
Test duplicating configuration files in nginx - to be removed
mrodm Jun 17, 2024
d6113ba
Use channel to loop for results
mrodm Jun 17, 2024
2cdeacf
Reverted changes in service deployer
mrodm Jun 17, 2024
5c8f500
Move reading global config to cmd
mrodm Jun 17, 2024
b84c8dc
Read global config in commands for all runners
mrodm Jun 17, 2024
a8e1ee1
Add support to skip tests with global config in all runners
mrodm Jun 17, 2024
80c231c
Add comment about runners wihtout parallel system test support
mrodm Jun 17, 2024
37ee89a
Merge remote-tracking branch 'upstream/main' into system-tests-parallel
mrodm Jun 17, 2024
c933c0d
Update debug messages
mrodm Jun 17, 2024
9758666
Update package-spec to elastic/main 572e54732
mrodm Jun 17, 2024
1c4b9cf
Update log message
mrodm Jun 17, 2024
419f8ea
Update docs
mrodm Jun 17, 2024
d579fb7
Update docs
mrodm Jun 18, 2024
d8a16e9
Return just the error from tests
mrodm Jun 18, 2024
94b533f
Run system tests in parallel for sql_input
mrodm Jun 18, 2024
7b52032
Update variable name
mrodm Jun 18, 2024
a3c7288
Set maximum routines dynamically
mrodm Jun 18, 2024
3cc537d
Sort test results
mrodm Jun 18, 2024
e891842
Remove duplicated test config files
mrodm Jun 18, 2024
5f04b26
Add function to check if there is any skip configuration
mrodm Jun 18, 2024
59f7ef9
Check if test config is nil
mrodm Jun 18, 2024
ec7cb78
Remove TODO comments
mrodm Jun 19, 2024
8d8fb5d
Rename variable
mrodm Jun 19, 2024
9a228b9
Add notes about running system tests in parallel
mrodm Jun 19, 2024
a47379e
Remove package-spec replace in go.mod
mrodm Jun 19, 2024
f9ffd44
Merge remote-tracking branch 'upstream/main' into system-tests-parallel
mrodm Jun 19, 2024
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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/elastic/package-spec/v3 => github.com/mrodm/package-spec/v3 v3.0.0-20240613145150-8d065e83d217
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requires a new version of package-spec

4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ github.com/elastic/gojsonschema v1.2.1 h1:cUMbgsz0wyEB4x7xf3zUEvUVDl6WCz2RKcQPul
github.com/elastic/gojsonschema v1.2.1/go.mod h1:biw5eBS2Z4T02wjATMRSfecfjCmwaDPvuaqf844gLrg=
github.com/elastic/kbncontent v0.1.4 h1:GoUkJkqkn2H6iJTnOHcxEqYVVYyjvcebLQVaSR1aSvU=
github.com/elastic/kbncontent v0.1.4/go.mod h1:kOPREITK9gSJsiw/WKe7QWSO+PRiZMyEFQCw+CMLAHI=
github.com/elastic/package-spec/v3 v3.1.5 h1:BoUvKZI3WhbxsWAvsOqIasgpCo8fmjmj7lZgO1JyB2s=
github.com/elastic/package-spec/v3 v3.1.5/go.mod h1:kHltfTMhDn9Whp3LZluVwI0WFW5uHwqtlByx6+c8ZHE=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
Expand Down Expand Up @@ -316,6 +314,8 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mrodm/package-spec/v3 v3.0.0-20240613145150-8d065e83d217 h1:Ywx/eMe8dX0yx3xf7nWwlHMp6Bp+NyBqXtl95KvNpXU=
github.com/mrodm/package-spec/v3 v3.0.0-20240613145150-8d065e83d217/go.mod h1:Qdq/tqETSbbTpCfUAlVTtIvO2RiAdXp6aXTbqeGdHfE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
Expand Down
6 changes: 5 additions & 1 deletion internal/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,29 +370,33 @@ func (p *Project) WaitForHealthy(ctx context.Context, opts CommandOptions) error
}

for _, containerDescription := range descriptions {
logger.Debugf("Container status: %s", containerDescription.String())

// No healthcheck defined for service
if containerDescription.State.Status == "running" && containerDescription.State.Health == nil {
logger.Debugf("Container %s status: %s (no health status)", containerDescription.ID, containerDescription.State.Status)
continue
}

// Service is up and running and it's healthy
if containerDescription.State.Status == "running" && containerDescription.State.Health.Status == "healthy" {
logger.Debugf("Container %s status: %s (health: %s)", containerDescription.ID, containerDescription.State.Status, containerDescription.State.Health.Status)
continue
}

// Container started and finished with exit code 0
if containerDescription.State.Status == "exited" && containerDescription.State.ExitCode == 0 {
logger.Debugf("Container %s status: %s (exit code: %d)", containerDescription.ID, containerDescription.State.Status, containerDescription.State.ExitCode)
continue
}

// Container exited with code > 0
if containerDescription.State.Status == "exited" && containerDescription.State.ExitCode > 0 {
logger.Debugf("Container %s status: %s (exit code: %d)", containerDescription.ID, containerDescription.State.Status, containerDescription.State.ExitCode)
return fmt.Errorf("container (ID: %s) exited with code %d", containerDescription.ID, containerDescription.State.ExitCode)
}

// Any different status is considered unhealthy
logger.Debugf("Container %s status: unhealthy", containerDescription.ID)
Comment on lines +376 to +399
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Examples of logs withthese changes:

2024/06/13 19:32:35 DEBUG Wait for healthy containers: 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c
2024/06/13 19:32:35 DEBUG output command: /usr/bin/docker inspect 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c
2024/06/13 19:32:35 DEBUG Container 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c status: unhealthy
2024/06/13 19:32:36 DEBUG Wait for healthy containers: 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c
2024/06/13 19:32:36 DEBUG output command: /usr/bin/docker inspect 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c
2024/06/13 19:32:36 DEBUG Container 8f38b80e7a6b5638fd3e53bc250f49f5c2e27fa10810de506e4495d7169d4a5c status: running (health: healthy)

Previously:

2024/06/13 15:43:06 DEBUG Wait for healthy containers: 2306f9dd160408ce2e26b72565d1d3037153de14167052733f2cfd553f212de4
2024/06/13 15:43:06 DEBUG output command: /usr/bin/docker inspect 2306f9dd160408ce2e26b72565d1d3037153de14167052733f2cfd553f212de4
2024/06/13 15:43:06 DEBUG Container status: {"Config":{"Image":"elastic-package-service-87356-nginx","Labels":{"com.docker.compose.config-hash":"07b2d6403034e11414161c6489c787924e32ab36e7d12c69b977e184cf40e3c3","com.docker.compose.container-number":"1","com.docker.compose.depends_on":"","com.docker.compose.image":"sha256:106ba62762b92ccdde0edf49e09063ee28a3be98e9342dfcd3980314b0e4c192","com.docker.compose.oneoff":"False","com.docker.compose.project":"elastic-package-service-87356","com.docker.compose.project.config_files":"/opt/buildkite-agent/builds/bk-agent-prod-gcp-1718292959927056914/elastic/elastic-package/test/packages/parallel/nginx/_dev/deploy/docker/docker-compose.yml","com.docker.compose.project.working_dir":"/opt/buildkite-agent/builds/bk-agent-prod-gcp-1718292959927056914/elastic/elastic-package/test/packages/parallel/nginx/_dev/deploy/docker","com.docker.compose.service":"nginx","com.docker.compose.version":"2.24.1","maintainer":"NGINX Docker Maintainers \[email protected]\u003e"}},"ID":"2306f9dd160408ce2e26b72565d1d3037153de14167052733f2cfd553f212de4","State":{"Status":"running","ExitCode":0,"Health":{"Status":"healthy","Log":[{"Start":"2024-06-13T15:43:05.983549466Z","ExitCode":0,"Output":"  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current\n                                 Dload  Upload   Total   Spent    Left  Speed\n\r  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0\r100    97  100    97    0     0  97000      0 --:--:-- --:--:-- --:--:-- 97000\nActive connections: 1 \nserver accepts handled requests\n 1 1 1 \nReading: 0 Writing: 1 Waiting: 0 \n"}]}}}

Copy link
Member

Choose a reason for hiding this comment

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

Maybe these logs are too verbose? But we can leave them and update later when/if we add the trace debug level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to keep the previous log messages ?

Copy link
Member

Choose a reason for hiding this comment

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

I mean to leave it as is now in the PR, and reduce later when we have more log levels.

healthy = false
}

Expand Down
3 changes: 2 additions & 1 deletion internal/kibana/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ func (c *Client) waitUntilPolicyAssigned(ctx context.Context, a Agent, p Policy)
if err != nil {
return fmt.Errorf("can't get the agent: %w", err)
}
logger.Debugf("Agent data: %s", agent.String())
logger.Debugf("Agent %s (Host: %s): Policy ID %s LogLevel: %s Status: %s",
Copy link
Contributor Author

@mrodm mrodm Jun 13, 2024

Choose a reason for hiding this comment

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

Probably it could be improved better these logs (removing some field?)

Example of new logs:

2024/06/13 19:33:21 DEBUG Wait until the policy (ID: 1355408f-6518-4bbd-8b39-cded15bba61d, revision: 2) is assigned to the agent (ID: ca20edcb-a929-434d-b226-9138be510e80)...
2024/06/13 19:33:23 DEBUG GET https://127.0.0.1:5601/api/fleet/agents/ca20edcb-a929-434d-b226-9138be510e80
2024/06/13 19:33:23 DEBUG Agent ca20edcb-a929-434d-b226-9138be510e80 (Host: elastic-agent-12113): Policy ID 1355408f-6518-4bbd-8b39-cded15bba61d LogLevel: debug Status: updating

Previously:

2024/06/13 15:43:12 DEBUG Wait until the policy (ID: c9f48c54-c30e-4bb7-a17a-a66f6c1776b0, revision: 2) is assigned to the agent (ID: 8bf156ea-30b2-4714-8e99-d09059f0fe54)...
2024/06/13 15:43:14 DEBUG GET https://127.0.0.1:5601/api/fleet/agents/8bf156ea-30b2-4714-8e99-d09059f0fe54
2024/06/13 15:43:14 DEBUG Agent data: {"id":"8bf156ea-30b2-4714-8e99-d09059f0fe54","policy_id":"c9f48c54-c30e-4bb7-a17a-a66f6c1776b0","local_metadata":{"host":{"name":"docker-fleet-agent"},"elastic":{"agent":{"log_level":"info"}}},"status":"updating"}

agent.ID, agent.LocalMetadata.Host.Name, agent.PolicyID, agent.LocalMetadata.Elastic.Agent.LogLevel, agent.Status)

if agent.PolicyID == p.ID && agent.PolicyRevision >= p.Revision {
logger.Debugf("Policy revision assigned to the agent (ID: %s)...", a.ID)
Expand Down
4 changes: 2 additions & 2 deletions internal/servicedeployer/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
} else {
err = p.Up(ctx, opts)
if err != nil {
return nil, fmt.Errorf("could not boot up service using Docker Compose: %w", err)
return &service, fmt.Errorf("could not boot up service using Docker Compose: %w", err)
}
}

Expand All @@ -133,7 +133,7 @@ func (d *DockerComposeServiceDeployer) SetUp(ctx context.Context, svcInfo Servic
processServiceContainerLogs(context.WithoutCancel(ctx), p, compose.CommandOptions{
Env: opts.Env,
}, svcInfo.Name)
return nil, fmt.Errorf("service is unhealthy: %w", err)
return &service, fmt.Errorf("service is unhealthy: %w", err)
}

// Added a specific alias when connecting the service to the network.
Expand Down
2 changes: 1 addition & 1 deletion internal/servicedeployer/custom_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (d *CustomAgentDeployer) SetUp(ctx context.Context, svcInfo ServiceInfo) (D
processServiceContainerLogs(ctx, p, compose.CommandOptions{
Env: opts.Env,
}, svcInfo.Name)
return nil, fmt.Errorf("service is unhealthy: %w", err)
return &service, fmt.Errorf("service is unhealthy: %w", err)
}

logger.Debugf("adding service container %s internal ports to context", p.ContainerName(serviceName))
Expand Down
4 changes: 2 additions & 2 deletions internal/servicedeployer/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (tsd TerraformServiceDeployer) SetUp(ctx context.Context, svcInfo ServiceIn
}
err = p.Up(ctx, opts)
if err != nil {
return nil, fmt.Errorf("could not boot up service using Docker Compose: %w", err)
return &service, fmt.Errorf("could not boot up service using Docker Compose: %w", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe these changes could be done in a different PR.

I was thinking that it would be interesting to return also the service here in case of error, to be able to run the shutdownServiceHandler.

The same if there is any error while waiting to be healthy the container.

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed for now these changes.

}

err = p.WaitForHealthy(ctx, opts)
Expand All @@ -158,7 +158,7 @@ func (tsd TerraformServiceDeployer) SetUp(ctx context.Context, svcInfo ServiceIn
Env: opts.Env,
}, svcInfo.Name)
//lint:ignore ST1005 error starting with product name can be capitalized
return nil, fmt.Errorf("Terraform deployer is unhealthy: %w", err)
return &service, fmt.Errorf("Terraform deployer is unhealthy: %w", err)
}

svcInfo.Agent.Host.NamePrefix = "docker-fleet-agent"
Expand Down
47 changes: 47 additions & 0 deletions internal/testrunner/globaltestconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package testrunner

import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/elastic/go-ucfg"
"github.com/elastic/go-ucfg/yaml"
)

type GlobalTestConfig struct {
Asset GlobalRunnerTestConfig `config:"asset"`
Pipeline GlobalRunnerTestConfig `config:"pipeline"`
Policy GlobalRunnerTestConfig `config:"policy"`
Static GlobalRunnerTestConfig `config:"static"`
System GlobalRunnerTestConfig `config:"system"`
}

type GlobalRunnerTestConfig struct {
Parallel bool `config:"parallel"`
SkippableConfig `config:",inline"`
}

func AGlobalTestConfig(packageRootPath string) (*GlobalTestConfig, error) {
mrodm marked this conversation as resolved.
Show resolved Hide resolved
configFilePath := filepath.Join(packageRootPath, "_dev", "test", "config.yml")

data, err := os.ReadFile(configFilePath)
if errors.Is(err, os.ErrNotExist) {
return &GlobalTestConfig{}, nil
}
if err != nil {
return nil, fmt.Errorf("failed to read %s: %w", configFilePath, err)
}

var c GlobalTestConfig
cfg, err := yaml.NewConfig(data, ucfg.PathSep("."))
if err != nil {
return nil, fmt.Errorf("unable to load global test configuration file: %s: %w", configFilePath, err)
}
if err := cfg.Unpack(&c); err != nil {
return nil, fmt.Errorf("unable to unpack global test configuration file: %s: %w", configFilePath, err)
}

return &c, nil
}
5 changes: 5 additions & 0 deletions internal/testrunner/runners/asset/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (r tester) String() string {
return "asset loading"
}

// Parallel indicates if this tester can run in parallel or not.
func (r tester) Parallel() bool {
return false
}

// Run runs the asset loading tests
func (r *tester) Run(ctx context.Context) ([]testrunner.TestResult, error) {
return r.run(ctx)
Expand Down
5 changes: 5 additions & 0 deletions internal/testrunner/runners/pipeline/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (r *tester) String() string {
return "pipeline"
}

// Parallel indicates if this tester can run in parallel or not.
func (r tester) Parallel() bool {
return false
}

// Run runs the pipeline tests defined under the given folder
func (r *tester) Run(ctx context.Context) ([]testrunner.TestResult, error) {
return r.run(ctx)
Expand Down
5 changes: 5 additions & 0 deletions internal/testrunner/runners/policy/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func (r *tester) String() string {
return string(TestType)
}

// Parallel indicates if this tester can run in parallel or not.
func (r tester) Parallel() bool {
return false
}

func (r *tester) Run(ctx context.Context) ([]testrunner.TestResult, error) {
var results []testrunner.TestResult

Expand Down
5 changes: 5 additions & 0 deletions internal/testrunner/runners/static/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func (r tester) String() string {
return "static files"
}

// Parallel indicates if this tester can run in parallel or not.
func (r tester) Parallel() bool {
return false
}

func (r tester) Run(ctx context.Context) ([]testrunner.TestResult, error) {
return r.run(ctx)
}
Expand Down
Loading