Skip to content

Commit

Permalink
[7.17](backport #35780) Upgrade to Go 1.19.10 and handle changes in g…
Browse files Browse the repository at this point in the history
…olang Debian base image (#35840)

* ci: use ubuntu:22 workers (#34315)

(cherry picked from commit a5f15b6)

# Conflicts:
#	.ci/beats-tester.groovy
#	.ci/build-docker-images.groovy
#	.ci/heartbeat-synthetics.groovy
#	x-pack/filebeat/Jenkinsfile.yml
#	x-pack/metricbeat/Jenkinsfile.yml

* remove unexisting files in 7.17 when backporting another PR

* fix merge conflicts

* Upgrade to Go 1.19.10 and handle changes in golang Debian base image (#35780)

* Explicitly install netcat-openbsd everywhere.

The plain netcat package appears to have been removed in the latest
golang:1.19.10 base image.

* Setup a virtualenv in Docker containers.

This fixes the PEP668 error about "externally managed environments"
which prevents modifying the system python installation.

* Revert "Revert "[Automation] Bump Golang version to 1.19.10 (#35751)" (#35784)"

This reverts commit 27b1799.

* Reword CHANGELOG.next.asciidoc

Co-authored-by: subham sarkar <sarkar.subhams2@gmail.com>

* Improve PEP668 comments.

* Install latest PyYAML in test containers.

* Add check to see if already in a venv.

* Upgrade pytest and py.

Remove dependency on pytest-otel as it prevented upgrading pytest.

* Check for pre-set virtualenv earlier.

* Always create a fresh virtualenv in Docker.

Remove duplicate dependencies from the docker files.

* Fix metricbeat integration tests.

* Force install Python dependencies for Metricbeat.

---------

Co-authored-by: subham sarkar <sarkar.subhams2@gmail.com>
(cherry picked from commit 62374dd)

# Conflicts:
#	dev-tools/mage/pytest.go
#	libbeat/docs/version.asciidoc
#	libbeat/tests/system/requirements.txt
#	libbeat/tests/system/requirements_aix.txt
#	metricbeat/Dockerfile

* Remove extra entry in CHANGELOG.next.asciidoc

* Fix conflict in version.asciidoc

* Fix conflict in requirements.txt

* Fix conflict in requirements_aix.txt

* Fix conflict in metricbeat Dockerfile

* Fix conflict in pytest.go

* Add missing force create virtual env option.

* python tests: compatibility and stability improvements (#31588)

This commit improves the compatibility and stability of Python tests
for Filebeat. It addresses two main probmes:
1. Some deprecated TLS functions are now raising deprecation
exceptions (since Python 3.10.0)
2. Some tests, on failure, leave Filebeat running and bound to port
8080, this creates a cascading failure of the subsequent tests that
require the same port to be available.

The main changes are:
 - Ensuring Filebeat process is always terminated, even if the test
 fails
 - Using the replacement methods/objects for the deprecated TLS
 functions.

(cherry picked from commit 682045a)

# Conflicts:
#	libbeat/tests/system/beat/beat.py

* Remove duplicate entries in CHANGELOG-developer.next.asciidoc

* Resolve conflicts in beat.py

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
Co-authored-by: Craig MacKenzie <craig.mackenzie@elastic.co>
Co-authored-by: Tiago Queiroz <tiago.queiroz@elastic.co>
  • Loading branch information
4 people committed Jun 21, 2023
1 parent 2235c96 commit 205b27e
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .ci/apm-beats-update.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipeline {
}
stages {
stage('Filter build') {
agent { label 'ubuntu-18 && immutable' }
agent { label 'ubuntu-22 && immutable' }
when {
beforeAgent true
anyOf {
Expand Down
2 changes: 1 addition & 1 deletion .ci/beats-tester.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pipeline {
}
stages {
stage('Filter build') {
agent { label 'ubuntu && immutable' }
agent { label 'ubuntu-22' }
when {
beforeAgent true
anyOf {
Expand Down
2 changes: 1 addition & 1 deletion .ci/ironbank-validation.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@Library('apm@current') _

pipeline {
agent { label 'ubuntu-20 && immutable' }
agent { label 'ubuntu-22 && immutable' }
environment {
REPO = 'beats'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
Expand Down
4 changes: 2 additions & 2 deletions .ci/packaging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pipeline {
stages {
stage('Filter build') {
options { skipDefaultCheckout() }
agent { label 'ubuntu-20 && immutable' }
agent { label 'ubuntu-22 && immutable' }
when {
beforeAgent true
anyOf {
Expand Down Expand Up @@ -290,7 +290,7 @@ def generateArmStep(beat) {

def generateLinuxStep(beat) {
return {
withNode(labels: 'ubuntu-20.04 && immutable') {
withNode(labels: 'ubuntu-22.04 && immutable') {
withEnv(["HOME=${env.WORKSPACE}", "PLATFORMS=${linuxPlatforms()}", "BEATS_FOLDER=${beat}"]) {
withGithubNotify(context: "Packaging Linux ${beat}") {
deleteDir()
Expand Down
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.9
1.19.10
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ linters-settings:

gosimple:
# Select the Go version to target. The default is '1.13'.
go: "1.19.9"
go: "1.19.10"

nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
Expand All @@ -120,19 +120,19 @@ linters-settings:

staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.19.9"
go: "1.19.10"
checks: ["all"]

stylecheck:
# Select the Go version to target. The default is '1.13'.
go: "1.19.9"
go: "1.19.10"
# Disabled:
# ST1005: error strings should not be capitalized
checks: ["all", "-ST1005"]

unused:
# Select the Go version to target. The default is '1.13'.
go: "1.19.9"
go: "1.19.10"

gosec:
excludes:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Update Go version to 1.17.1. {pull}27543[27543]
- Whitelist `GCP_*` environment variables in dev tools {pull}28364[28364]
- Improve tests files with shorter statements. {pull}35667[35667]
- Improve compatibility and reduce flakyness of Python tests {pull}31588[31588]

==== Deprecated

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
==== Breaking changes

*Affecting all Beats*
- Update Go version to 1.19.10 {pull}35751[35751]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@Library('apm@current') _

pipeline {
agent { label 'ubuntu-18 && immutable' }
agent { label 'ubuntu-22 && immutable' }
environment {
AWS_ACCOUNT_SECRET = 'secret/observability-team/ci/elastic-observability-aws-account-auth'
AWS_REGION = "${params.awsRegion}"
Expand Down
10 changes: 7 additions & 3 deletions auditbeat/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19.9
FROM golang:1.19.10

RUN \
apt-get update \
Expand All @@ -10,6 +10,10 @@ RUN \
iproute2 \
&& rm -rf /var/lib/apt/lists/*

# Use a virtualenv to avoid the PEP668 "externally managed environment" error caused by conflicts
# with the system Python installation. golang:1.19.10 uses Debian 12 which now enforces PEP668.
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN pip3 install --upgrade pip==20.1.1
RUN pip3 install --upgrade setuptools==47.3.2
RUN pip3 install --upgrade docker-compose==1.23.2
2 changes: 1 addition & 1 deletion auditbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ when:
parameters: ## when parameter was selected in the UI.
- "auditbeat"
tags: true ## for all the tags
platform: "immutable && ubuntu-18" ## default label for all the stages
platform: "immutable && ubuntu-22" ## default label for all the stages
stages:
arm:
mage: "mage build unitTest"
Expand Down
2 changes: 1 addition & 1 deletion auditbeat/scripts/mage/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ModuleDocs() error {
}

// Run the docs_collector.py script.
ve, err := devtools.PythonVirtualenv()
ve, err := devtools.PythonVirtualenv(false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ when:
parameters: ## when parameter was selected in the UI.
- "kubernetes"
tags: true ## for all the tags
platform: "immutable && ubuntu-18" ## default label for all the stages
platform: "immutable && ubuntu-22" ## default label for all the stages
stages:
lint:
make: |
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var Docs = docsBuilder{}
// FieldDocs generates docs/fields.asciidoc from the specified fields.yml file.
func (docsBuilder) FieldDocs(fieldsYML string) error {
// Run the docs_collector.py script.
ve, err := PythonVirtualenv()
ve, err := PythonVirtualenv(false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func PythonAutopep8() error {
}

fmt.Println(">> fmt - autopep8: Formatting Python code")
ve, err := PythonVirtualenv()
ve, err := PythonVirtualenv(false)
if err != nil {
return err
}
Expand Down
15 changes: 12 additions & 3 deletions dev-tools/mage/pytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type PythonTestArgs struct {
Files []string // Globs used to find tests.
XUnitReportFile string // File to write the XUnit XML test report to.
CoverageProfileFile string // Test coverage profile file.
ForceCreateVenv bool // Set to true to always install required dependencies in the test virtual environment.
}

func makePythonTestArgs(name string) PythonTestArgs {
Expand Down Expand Up @@ -114,7 +115,8 @@ func DefaultPythonTestIntegrationArgs() PythonTestArgs { return makePythonTestAr
func PythonTest(params PythonTestArgs) error {
fmt.Println(">> python test:", params.TestName, "Testing")

ve, err := PythonVirtualenv()
// Only activate the virtualenv if necessary.
ve, err := PythonVirtualenv(params.ForceCreateVenv)
if err != nil {
return err
}
Expand Down Expand Up @@ -196,7 +198,7 @@ func PythonTestForModule(params PythonTestArgs) error {
// PythonVirtualenv constructs a virtualenv that contains the given modules as
// defined in the requirements file pointed to by requirementsTxt. It returns
// the path to the virtualenv.
func PythonVirtualenv() (string, error) {
func PythonVirtualenv(forceCreate bool) (string, error) {
pythonVirtualenvLock.Lock()
defer pythonVirtualenvLock.Unlock()

Expand All @@ -217,7 +219,7 @@ func PythonVirtualenv() (string, error) {
// Only execute if requirements.txt is newer than the virtualenv activate
// script.
activate := virtualenvPath(ve, "activate")
if IsUpToDate(activate, reqs...) {
if !forceCreate && IsUpToDate(activate, reqs...) {
return pythonVirtualenvDir, nil
}

Expand Down Expand Up @@ -277,6 +279,12 @@ func pythonVirtualenvPath() (string, error) {
return pythonVirtualenvDir, nil
}

// If VIRTUAL_ENV is set we are already in a virtual environment.
pythonVirtualenvDir = os.Getenv("VIRTUAL_ENV")
if pythonVirtualenvDir != "" {
return pythonVirtualenvDir, nil
}

// PYTHON_ENV can override the default location. This is used by CI to
// shorten the overall shebang interpreter path below the path length limits.
pythonVirtualenvDir = os.Getenv("PYTHON_ENV")
Expand All @@ -288,6 +296,7 @@ func pythonVirtualenvPath() (string, error) {

pythonVirtualenvDir = info.RootDir
}

pythonVirtualenvDir = filepath.Join(pythonVirtualenvDir, "build/ve")

// Use OS and docker specific virtualenv's because the interpreter in
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/target/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c Compose) composeForEachVariant(action, message string) error {
return errors.Wrap(err, "finding supported versions files")
}

virtualenv, err := devtools.PythonVirtualenv()
virtualenv, err := devtools.PythonVirtualenv(false)
if err != nil {
return errors.Wrap(err, "configuring Python virtual environment")
}
Expand Down
6 changes: 5 additions & 1 deletion dev-tools/mage/target/integtest/integtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func PythonIntegTest(ctx context.Context) error {
}
return runner.Test("pythonIntegTest", func() error {
mg.Deps(devtools.BuildSystemTestBinary)
return devtools.PythonTest(devtools.DefaultPythonTestIntegrationArgs())
args := devtools.DefaultPythonTestIntegrationArgs()
// Always create a fresh virtual environment when running tests in a container, until we get
// get the requirements installed as part of the container build.
args.ForceCreateVenv = true
return devtools.PythonTest(args)
})
}
2 changes: 1 addition & 1 deletion filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ when:
parameters: ## when parameter was selected in the UI.
- "filebeat"
tags: true ## for all the tags
platform: "immutable && ubuntu-18" ## default label for all the stages
platform: "immutable && ubuntu-22" ## default label for all the stages
stages:
arm:
mage: "mage build unitTest"
Expand Down
2 changes: 1 addition & 1 deletion filebeat/scripts/mage/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// CollectDocs executes the Filebeat docs_collector script to collect/generate
// documentation from each module.
func CollectDocs() error {
ve, err := devtools.PythonVirtualenv()
ve, err := devtools.PythonVirtualenv(false)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions filebeat/tests/system/test_syslog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_syslog_with_tcp(self):
)

filebeat = self.start_beat()
self.addCleanup(filebeat.kill_and_wait)

self.wait_until(lambda: self.log_contains("Started listening for TCP connection"))

Expand Down Expand Up @@ -72,6 +73,7 @@ def test_syslog_with_tcp_invalid_message(self):
)

filebeat = self.start_beat()
self.addCleanup(filebeat.kill_and_wait)

self.wait_until(lambda: self.log_contains("Started listening for TCP connection"))

Expand Down Expand Up @@ -112,6 +114,7 @@ def test_syslog_with_udp(self):
)

filebeat = self.start_beat()
self.addCleanup(filebeat.kill_and_wait)

self.wait_until(lambda: self.log_contains("Started listening for UDP connection"))

Expand Down Expand Up @@ -172,6 +175,7 @@ def run_filebeat_and_send_using_socket(self, socket_type, send_over_socket):
)

filebeat = self.start_beat()
self.addCleanup(filebeat.kill_and_wait)

self.wait_until(lambda: self.log_contains("Started listening for UNIX connection"))

Expand Down Expand Up @@ -232,6 +236,7 @@ def run_filebeat_and_send_invalid_message_using_socket(self, socket_type, send_o
)

filebeat = self.start_beat()
self.addCleanup(filebeat.kill_and_wait)

self.wait_until(lambda: self.log_contains("Started listening for UNIX connection"))

Expand Down
Loading

0 comments on commit 205b27e

Please sign in to comment.