Skip to content

Commit 4344a11

Browse files
authored
Integration Test: upgrade Integrations Server in ECH (#8417)
* WIP: Implementing UpgradeDeployment method * Adding AvailableVersions method to StatefulProvisioner * WIP: adding test for upgrading integration server in ECH * Ensure test runs against FRH ECH region * WIP * WIP * Add test for generating upgrade deployment request * Flesh out test some more * Fixing filename in reference * Make DeploymentStatus contain status and health * Cleanup deployment after test * Add error handling * Make linter happy * Fix typo * Fix check * Adding logging * Filter by min/max versions * Fix call * Running non-sudo upgrade group tests * Running upgrade FIPS tests * Remove non-sudo upgrade group from regular integration tests * Fix env var for ECH region and default it to gcp-us-west2 * Use env var for ECH API key * Run ECH deployment upgrade test if PR label is present * Fix missing key check * Add label on PR that bumps integration test versions * Export EC_API_KEY * WIP: debugging * Append query string to URL after joining paths * Fix up logic in doGet to construct URL without escaping ? * WIP: Remove some debug logging * Add bounds check * Fix start index math * Removing debug logs * WIP: don't clean up deployment so we can investigate * Add doPut method on client * Remove debugging statements * Fix build tag * Change group for testing in PR * Cleanup * Add comment * Cleanup * Update deployment version after upgrade * Test group in PR * Fix unit test * Undo unintentional changes
1 parent 24512d3 commit 4344a11

18 files changed

+645
-95
lines changed

.buildkite/bk.integration-fips.pipeline.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@ steps:
107107
groups:
108108
- fleet
109109

110+
- label: "fips:upgrade-ech-deployment"
111+
if: build.env("BUILDKITE_PULL_REQUEST") != "false" && build.env("GITHUB_PR_LABELS") =~ /.*(Testing:run:TestUpgradeIntegrationsServer).*/
112+
env:
113+
FIPS: "true"
114+
TEST_PACKAGE: "github.com/elastic/elastic-agent/testing/integration/ess"
115+
command: |
116+
export EC_API_KEY=$(retry -t 5 -- vault kv get -field=apiKey kv/ci-shared/platform-ingest/platform-ingest-ec-prod)
117+
.buildkite/scripts/buildkite-integration-tests.sh ech-deployment false
118+
artifact_paths:
119+
- build/**
120+
- build/diagnostics/**
121+
retry:
122+
automatic:
123+
limit: 1
124+
agents:
125+
provider: "aws"
126+
image: "${IMAGE_UBUNTU_X86_64_FIPS}"
127+
instanceType: "m5.2xlarge"
128+
110129
- label: ESS FIPS stack cleanup
111130
depends_on:
112131
- integration-tests-ubuntu-fips

.ci/updatecli/updatecli-bump-stack-version.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ sources:
2626
key: .build
2727
targets:
2828
updateStackImages:
29-
name: "Update create_deployment_csp_configuration.yaml"
29+
name: "Update deployment_csp_configuration.yaml"
3030
sourceid: lastStableStackSnapshot
3131
scmid: githubConfig
3232
kind: file
3333
spec:
34-
file: "pkg/testing/ess/create_deployment_csp_configuration.yaml"
34+
file: "pkg/testing/ess/deployment_csp_configuration.yaml"
3535
matchpattern: '(\S*_image: ".*docker.*):(.+)"'
3636
replacepattern: '$1:{{ source "lastStableStackSnapshot" }}-SNAPSHOT"'
3737
actions:
@@ -48,4 +48,4 @@ actions:
4848
- "Team:Elastic-Agent-Control-Plane"
4949
title: '[{{ requiredEnv "BRANCH_NAME" }}][Automation] Bump stack images versions to {{ source "lastStableStackSnapshot" }}'
5050
description: |
51-
Updates `create_deployment_csp_configuration.yml`. It is used to pin stable images versions for integration tests.
51+
Updates `deployment_csp_configuration.yml`. It is used to pin stable images versions for integration tests.

.github/workflows/bump-agent-versions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ else
3838
--label 'update-versions' \
3939
--label 'skip-changelog' \
4040
--label 'backport-skip' \
41+
--label 'Testing:run:TestUpgradeIntegrationsServer' \
4142
--repo $GITHUB_REPOSITORY)
4243
echo "pr=$pr" >> "$GITHUB_OUTPUT" # set the step output for Slack notifications
4344
echo "Created a PR with the an update: $pr"

.mergify.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ defaults:
1919
labels:
2020
- "backport"
2121
pull_request_rules:
22-
- name: automatic approval for updatecli pull requests with changes in .buildkite or create_deployment_csp_configuration.yaml
22+
- name: automatic approval for updatecli pull requests with changes in .buildkite or deployment_csp_configuration.yaml
2323
conditions:
2424
- author=github-actions[bot]
2525
- check-success=buildkite/elastic-agent
26-
- or:
27-
- files~=^pkg/testing/ess/create_deployment_csp_configuration.yaml$
26+
- or:
27+
- files~=^pkg/testing/ess/deployment_csp_configuration.yaml$
2828
- files~=^.buildkite/(pipeline.yml|bk.integration.pipeline.yml)$
2929
- head~=^updatecli_.*
3030
actions:
3131
review:
3232
type: APPROVE
3333
message: Automatically approving mergify
34-
- name: automatic squash and merge with success checks and the files matching the regex .buildkite or create_deployment_csp_configuration.yaml is modified.
34+
- name: automatic squash and merge with success checks and the files matching the regex .buildkite or deployment_csp_configuration.yaml is modified.
3535
conditions:
3636
- author=github-actions[bot]
3737
- check-success=buildkite/elastic-agent
38-
- or:
39-
- files~=^pkg/testing/ess/create_deployment_csp_configuration.yaml$
38+
- or:
39+
- files~=^pkg/testing/ess/deployment_csp_configuration.yaml$
4040
- files~=^.buildkite/(pipeline.yml|bk.integration.pipeline.yml)$
4141
- head~=^updatecli_.*
4242
- "#approved-reviews-by>=1"
@@ -46,8 +46,8 @@ pull_request_rules:
4646
- name: rebase pull requests for the VM autobump and ESS version pinning
4747
conditions:
4848
- author=github-actions[bot]
49-
- or:
50-
- files~=^pkg/testing/ess/create_deployment_csp_configuration.yaml$
49+
- or:
50+
- files~=^pkg/testing/ess/deployment_csp_configuration.yaml$
5151
- files~=^.buildkite/(pipeline.yml|bk.integration.pipeline.yml)$
5252
- head~=^updatecli_.*
5353
- "#check-failure>0"

pkg/testing/common/stack.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
package common
66

7-
import "context"
7+
import (
8+
"context"
9+
)
810

911
// Stack is a created stack.
1012
type Stack struct {
@@ -72,9 +74,12 @@ type StackProvisioner interface {
7274
// Create creates a stack.
7375
Create(ctx context.Context, request StackRequest) (Stack, error)
7476

75-
// WaitForReady should block until the stack is ready or the context is cancelled.
77+
// WaitForReady should block until the stack is ready and healthy or the context is cancelled.
7678
WaitForReady(ctx context.Context, stack Stack) (Stack, error)
7779

7880
// Delete deletes the stack.
7981
Delete(ctx context.Context, stack Stack) error
82+
83+
// Upgrade upgrades the stack to a new version.
84+
Upgrade(ctx context.Context, stack Stack, newVersion string) error
8085
}

pkg/testing/ess/client.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import (
1010
"io"
1111
"net/http"
1212
"net/url"
13+
14+
"github.com/elastic/elastic-agent/pkg/testing/common"
1315
)
1416

1517
type Client struct {
1618
config *Config
1719
client *http.Client
20+
logger common.Logger
1821
}
1922

2023
func NewClient(config Config) *Client {
@@ -28,11 +31,14 @@ func NewClient(config Config) *Client {
2831
return c
2932
}
3033

34+
func (c *Client) SetLogger(logger common.Logger) {
35+
c.logger = logger
36+
}
37+
3138
func (c *Client) doGet(ctx context.Context, relativeUrl string) (*http.Response, error) {
32-
u, err := url.JoinPath(c.config.BaseUrl, relativeUrl)
33-
if err != nil {
34-
return nil, fmt.Errorf("unable to create API URL: %w", err)
35-
}
39+
// We don't use url.JoinPath because it escapes the "?" in
40+
// relativeUrl if it contains a query string
41+
u := c.config.BaseUrl + "/" + relativeUrl
3642

3743
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
3844
if err != nil {
@@ -45,12 +51,20 @@ func (c *Client) doGet(ctx context.Context, relativeUrl string) (*http.Response,
4551
}
4652

4753
func (c *Client) doPost(ctx context.Context, relativeUrl, contentType string, body io.Reader) (*http.Response, error) {
54+
return c.doWrite(ctx, http.MethodPost, relativeUrl, contentType, body)
55+
}
56+
57+
func (c *Client) doPut(ctx context.Context, relativeUrl, contentType string, body io.Reader) (*http.Response, error) {
58+
return c.doWrite(ctx, http.MethodPut, relativeUrl, contentType, body)
59+
}
60+
61+
func (c *Client) doWrite(ctx context.Context, method, relativeUrl, contentType string, body io.Reader) (*http.Response, error) {
4862
u, err := url.JoinPath(c.config.BaseUrl, relativeUrl)
4963
if err != nil {
5064
return nil, fmt.Errorf("unable to create API URL: %w", err)
5165
}
5266

53-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, u, body)
67+
req, err := http.NewRequestWithContext(ctx, method, u, body)
5468
if err != nil {
5569
return nil, fmt.Errorf("unable to create POST request: %w", err)
5670
}

0 commit comments

Comments
 (0)