Skip to content

Commit

Permalink
Merge branch 'master' into 438-fleet-server-scenarios
Browse files Browse the repository at this point in the history
* master:
  chore: add debug info for the payload (elastic#1044)
  chore: add debug traces for the webhook payload (elastic#1043)
  fix: wrong interpolation (elastic#1042)
  Update Elastic Agent to not use Kibana (elastic#1036)
  fix: apply X version for non-master branches (elastic#1037)
  fix: add NodeJS to PATH (elastic#1035)
  fix: use an agent when building kibana (elastic#1030)
  fix(jjb): use a branch that exists (elastic#1029)
  remove uninstall step (elastic#1017)
  fix: delay checking stale agent version until it's used (elastic#1016)
  fix: use same JJB than in custom kibana (elastic#1010)
  chore: simplify PR template (elastic#1011)
  feat: support passing KIBANA_VERSION (elastic#905)
  [mergify] assign the original author (elastic#1009)
  Remove the agent config file parameters for stand alone (elastic#983)
  Uniquify the stand-alone step for checking agent status (elastic#993)
  • Loading branch information
mdelapenya committed Apr 15, 2021
2 parents 6d60a6d + 2ac7071 commit 04c7fc8
Show file tree
Hide file tree
Showing 20 changed files with 304 additions and 77 deletions.
4 changes: 3 additions & 1 deletion .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ pipeline {
booleanParam(name: "BEATS_USE_CI_SNAPSHOTS", defaultValue: false, description: "If it's needed to use the binary snapshots produced by Beats CI instead of the official releases")
choice(name: 'LOG_LEVEL', choices: ['DEBUG', 'TRACE', 'INFO'], description: 'Log level to be used')
choice(name: 'TIMEOUT_FACTOR', choices: ['5', '3', '7', '11'], description: 'Max number of minutes for timeout backoff strategies')
string(name: 'KIBANA_VERSION', defaultValue: '', description: 'Docker tag of the kibana to be used for the tests. It will refer to an image related to a Kibana PR, under the Observability-CI namespace')
string(name: 'STACK_VERSION', defaultValue: '8.0.0-SNAPSHOT', description: 'SemVer version of the stack to be used for the tests.')
string(name: 'HELM_CHART_VERSION', defaultValue: '7.11.2', description: 'SemVer version of Helm chart to be used.')
string(name: 'HELM_VERSION', defaultValue: '3.5.2', description: 'SemVer version of Helm to be used.')
string(name: 'HELM_KIND_VERSION', defaultValue: '0.10.0', description: 'SemVer version of Kind to be used.')
string(name: 'HELM_KUBERNETES_VERSION', defaultValue: '1.18.2', description: 'SemVer version of Kubernetes to be used.')
string(name: 'GITHUB_CHECK_NAME', defaultValue: '', description: 'Name of the GitHub check to be updated. Only if this build is triggered from another parent stream.')
string(name: 'GITHUB_CHECK_REPO', defaultValue: '', description: 'Name of the GitHub repo to be updated. Only if this build is triggered from another parent stream.')
string(name: 'GITHUB_CHECK_SHA1', defaultValue: '', description: 'Name of the GitHub repo to be updated. Only if this build is triggered from another parent stream.')
string(name: 'GITHUB_CHECK_SHA1', defaultValue: '', description: 'Git SHA for the Beats upstream project (branch or PR)')
}
stages {
stage('Initializing'){
Expand All @@ -69,6 +70,7 @@ pipeline {
ELASTIC_AGENT_DOWNLOAD_URL = "${params.ELASTIC_AGENT_DOWNLOAD_URL.trim()}"
BEAT_VERSION = "${params.BEAT_VERSION.trim()}"
BEATS_USE_CI_SNAPSHOTS = "${params.BEATS_USE_CI_SNAPSHOTS}"
KIBANA_VERSION = "${params.KIBANA_VERSION.trim()}"
STACK_VERSION = "${params.STACK_VERSION.trim()}"
FORCE_SKIP_GIT_CHECKS = "${params.forceSkipGitChecks}"
FORCE_SKIP_PRESUBMIT = "${params.forceSkipPresubmit}"
Expand Down
139 changes: 139 additions & 0 deletions .ci/e2eKibana.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/usr/bin/env groovy

@Library('apm@current') _

pipeline {
agent none
environment {
REPO = 'kibana'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
GITHUB_APP_SECRET = 'secret/observability-team/ci/github-app'
GITHUB_CHECK_E2E_TESTS_NAME = 'E2E Tests'
PIPELINE_LOG_LEVEL = "INFO"
}
options {
timeout(time: 3, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
disableConcurrentBuilds()
}
// http://JENKINS_URL/generic-webhook-trigger/invoke
// Pull requests events: https://docs.github.com/en/developers/webhooks-and-events/github-event-types#pullrequestevent
triggers {
GenericTrigger(
genericVariables: [
[key: 'GT_REPO', value: '$.repository.full_name'],
[key: 'GT_PR', value: '$.issue.number'],
[key: 'GT_BODY', value: '$.comment.body'],
[key: 'GT_COMMENT_ID', value: '$.comment.id']
[key: 'GT_PAYLOAD', value: '$']
],
genericHeaderVariables: [
[key: 'x-github-event', regexpFilter: 'comment']
],
causeString: 'Triggered on #$GT_PR via comment: $GT_BODY',
printContributedVariables: false,
printPostContent: false,
silentResponse: true,
regexpFilterText: '$GT_REPO$GT_BODY',
regexpFilterExpression: '^elastic/kibana/run-fleet-e2e-tests$'
)
}
parameters {
string(name: 'kibana_pr', defaultValue: "master", description: "PR ID to use to build the Docker image. (e.g 10000)")
}
stages {
stage('Process GitHub Event') {
agent { label 'ubuntu-20' }
environment {
HOME = "${env.WORKSPACE}/${BASE_DIR}"
PATH = "${env.HOME}/bin:${env.HOME}/node_modules:${env.HOME}/node_modules/.bin:${env.PATH}"
}
steps {
echo(message: "$env.GT_PAYLOAD")
checkPermissions()
buildKibanaDockerImage(refspec: getBranch())
catchError(buildResult: 'UNSTABLE', message: 'Unable to run e2e tests', stageResult: 'FAILURE') {
runE2ETests('fleet')
}
}
}
}
}

def checkPermissions(){
if(env.GT_PR){
if(!githubPrCheckApproved(changeId: "${env.GT_PR}", org: 'elastic', repo: 'kibana')){
error("Only PRs from Elasticians can be tested with Fleet E2E tests")
}

if(!hasCommentAuthorWritePermissions(repoName: 'elastic/kibana', commentId: env.GT_COMMENT_ID)){
error("Only Elasticians can trigger Fleet E2E tests")
}
}
}

def getBranch(){
return "PR/" + getID()
}

def getID(){
if(env.GT_PR){
return "${env.GT_PR}"
}

return "${params.kibana_pr}"
}

def runE2ETests(String suite) {
// we need a second API request, as the issue_comment API does not retrieve data about the pull request
// See https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#issue_comment
def prID = getID()
def token = githubAppToken(secret: "${env.GITHUB_APP_SECRET}")

def pullRequest = githubApiCall(token: token, url: "https://api.github.com/repos/${env.$GT_REPO}/pulls/${prID}")
def baseRef = pullRequest?.base?.ref
def headSha = pullRequest?.head?.sha

// we are going to use the 'pr12345' tag as default
def dockerTag = "pr${params.kibana_pr}"
if(env.GT_PR){
// it's a PR: we are going to use its head SHA as tag
dockerTag = headSha
}

log(level: 'DEBUG', text: "Triggering '${suite}' E2E tests for PR-${prID} using '${dockerTag}' as Docker tag")

// Kibana's maintenance branches follow the 7.11, 7.12 schema.
def branchName = "${baseRef}"
if (branchName != "master") {
branchName += ".x"
}
def e2eTestsPipeline = "e2e-tests/e2e-testing-mbp/${branchName}"

def parameters = [
booleanParam(name: 'forceSkipGitChecks', value: true),
booleanParam(name: 'forceSkipPresubmit', value: true),
booleanParam(name: 'notifyOnGreenBuilds', value: false),
booleanParam(name: 'BEATS_USE_CI_SNAPSHOTS', value: true),
string(name: 'runTestsSuites', value: suite),
string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_E2E_TESTS_NAME),
string(name: 'GITHUB_CHECK_REPO', value: env.REPO),
string(name: 'KIBANA_VERSION', value: dockerTag),
]

build(job: "${e2eTestsPipeline}",
parameters: parameters,
propagate: false,
wait: false
)

/*
// commented out to avoid sending Github statuses to Kibana PRs
def notifyContext = "${env.pr_head_sha}"
githubNotify(context: "${notifyContext}", description: "${notifyContext} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${e2eTestsPipeline.replaceAll('/','+')}")
*/
}
18 changes: 18 additions & 0 deletions .ci/jobs/kibana-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- job:
name: e2e-tests/e2e-testing-kibana-fleet
display-name: Fleet UI e2e tests Pipeline
description: Jenkins pipeline to run the end2end tests for the Fleet UI
project-type: pipeline
pipeline-scm:
script-path: .ci/e2eKibana.groovy
scm:
- git:
url: git@github.com:elastic/e2e-testing.git
wipe-workspace: 'True'
name: origin
shallow-clone: true
credentials-id: f6c7695a-671e-4f4f-a331-acdce44ff9ba
branches:
- "master"
triggers: []
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ Link related issues below. Insert the issue link or reference after the word "Cl
-->
-

<!-- Recommended
## Use cases
<!-- Recommended
Explain here the different behaviors that this PR introduces or modifies in this project, user roles, environment configuration, etc.
If you are familiar with Gherkin test scenarios, we recommend its usage: https://cucumber.io/docs/gherkin/reference/
-->

<!-- Optional
## Screenshots
<!-- Optional
Add here screenshots about how the project will be changed after the PR is applied. They could be related to web pages, terminal, etc, or any other image you consider important to be shared with the team.
-->

<!-- Recommended
## Logs
<!-- Recommended
Paste here output logs discovered while creating this PR, such as stack traces or integration logs, or any other output you consider important to be shared with the team.
-->

<!-- Optional
## Follow-ups
<!-- Optional
Add here any thought that you consider could be identified as an actionable step once this PR is merged.
-->
9 changes: 9 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,34 @@ pull_request_rules:
```
- name: backport patches to 7.x branch
conditions:
- merged
- base=master
- label=v7.13.0
actions:
backport:
assignees:
- "{{ author }}"
branches:
- "7.x"
- name: backport patches to 7.12 branch
conditions:
- merged
- base=master
- label=v7.12.0
actions:
backport:
assignees:
- "{{ author }}"
branches:
- "7.12.x"
- name: backport patches to 7.11 branch
conditions:
- merged
- base=master
- label=v7.11.0
actions:
backport:
assignees:
- "{{ author }}"
branches:
- "7.11.x"
2 changes: 1 addition & 1 deletion cli/config/compose/profiles/fleet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
test: "curl -f http://localhost:5601/login | grep kbn-injected-metadata 2>&1 >/dev/null"
retries: 600
interval: 1s
image: "docker.elastic.co/kibana/kibana:${stackVersion:-8.0.0-SNAPSHOT}"
image: "docker.elastic.co/${kibanaDockerNamespace:-beats}/kibana:${kibanaVersion:-8.0.0-SNAPSHOT}"
ports:
- "5601:5601"
volumes:
Expand Down
9 changes: 3 additions & 6 deletions cli/config/compose/services/elastic-agent/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ services:
kibana:
condition: service_healthy
environment:
- "KIBANA_HOST=http://${kibanaHost:-kibana}:${kibanaPort:-5601}"
- "FLEET_SERVER_ELASTICSEARCH_HOST=http://${elasticsearchHost:-elasticsearch}:${elasticsearchPort:-9200}"
- "FLEET_SERVER_ENABLE=${fleetServerMode:-0}"
- "FLEET_SERVER_INSECURE_HTTP=${fleetServerMode:-0}"
- "KIBANA_FLEET_SETUP=${fleetServerMode:-0}"
- "FLEET_SERVER_HOST=0.0.0.0"
- "KIBANA_USERNAME=elastic"
- "KIBANA_PASSWORD=changeme"
- "FLEET_SERVER_ELASTICSEARCH_USERNAME=elastic"
- "FLEET_SERVER_ELASTICSEARCH_PASSWORD=changeme"
platform: ${elasticAgentPlatform:-linux/amd64}
ports:
- "127.0.0.1:8220:8220"
volumes:
- "${elasticAgentConfigFile}:/usr/share/elastic-agent/elastic-agent.yml"
3 changes: 2 additions & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ The following environment variables affect how the tests are run in both the CI
- `BEATS_USE_CI_SNAPSHOTS`: Set this environment variable to `true` if it's needed to use the binary snapshots produced by Beats CI instead of the official releases. The snapshots will be downloaded from a bucket in Google Cloud Storage. This variable is used by the Beats repository, when testing the artifacts generated by the packaging job. Default: `false`.
- `LOG_LEVEL`: Set this environment variable to `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR` or `FATAL` to set the log level in the project. Default: `INFO`.
- `DEVELOPER_MODE`: Set this environment variable to `true` to activate developer mode, which means not destroying the services provisioned by the test framework. Default: `false`.
- `STACK_VERSION`. Set this environment variable to the proper version of the Elastic Stack (Elasticsearch and Kibana) to be used in the current execution. The default value depens on the branch you are targeting your work.
- `KIBANA_VERSION`. Set this environment variable to the proper version of the Kibana instance to be used in the current execution, which should be used for the Docker tag of the kibana instance. It will refer to an image related to a Kibana PR, under the Observability-CI namespace. Default is empty
- `STACK_VERSION`. Set this environment variable to the proper version of the Elasticsearch to be used in the current execution. The default value depens on the branch you are targeting your work.
- **master (Fleet):** https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/e2e/_suites/fleet/ingest-manager_test.go#L39
- **master (Integrations):** https://github.com/elastic/e2e-testing/blob/0446248bae1ff604219735998841a21a7576bfdd/e2e/_suites/metricbeat/metricbeat_test.go#L30
- `TIMEOUT_FACTOR`: Set this environment variable to an integer number, which represents the factor to be used while waiting for resources within the tests. I.e. waiting for Kibana needs around 30 seconds. Instead of hardcoding 30 seconds, or 3 minutes, in the code, we use a backoff strategy to wait until an amount of time, specific per situation, multiplying it by the timeout factor. With that in mind, we are able to set a higher factor on CI without changing the code, and the developer is able to locally set specific conditions when running the tests on slower machines. Default: `3`.
Expand Down
4 changes: 3 additions & 1 deletion e2e/_suites/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ To change it, please use Docker UI, go to `Preferences > Resources > File Sharin
This is an example of the optional configuration:

```shell
# There should be a Docker image for the runtime dependencies (elasticsearch, kibana, package registry)
# There should be a Docker image for the runtime dependencies (elasticsearch, package registry)
export STACK_VERSION=8.0.0-SNAPSHOT
# There should be a Docker image for the runtime dependencies (kibana)
export KIBANA_VERSION=pr12345
# (Fleet mode) This environment variable will use a fixed version of the Elastic agent binary, obtained from
# https://artifacts-api.elastic.co/v1/search/8.0.0-SNAPSHOT/elastic-agent
export ELASTIC_AGENT_DOWNLOAD_URL="https://snapshots.elastic.co/8.0.0-59098054/downloads/beats/elastic-agent/elastic-agent-8.0.0-SNAPSHOT-linux-x86_64.tar.gz"
Expand Down
1 change: 0 additions & 1 deletion e2e/_suites/fleet/features/fleet_mode_agent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ Scenario Outline: Un-installing the installed <os> agent
Given a "<os>" agent is deployed to Fleet with "tar" installer
When the "elastic-agent" process is "uninstalled" on the host
Then the file system Agent folder is empty
And the agent is listed in Fleet as "offline"

@centos
Examples: Centos
Expand Down
7 changes: 6 additions & 1 deletion e2e/_suites/fleet/features/stand_alone_agent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ Examples: Ubi8
@run_fleet_server
Scenario Outline: Deploying a <image> stand-alone agent with fleet server mode
When a "<image>" stand-alone agent is deployed with fleet server mode
Then the agent is listed in Fleet as "online"
Then the stand-alone agent is listed in Fleet as "online"

@default
Examples: default
| image |
| default |

@ubi8
Examples: Ubi8
| image |
| ubi8 |
18 changes: 18 additions & 0 deletions e2e/_suites/fleet/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cucumber/godog"
"github.com/elastic/e2e-testing/cli/services"
curl "github.com/elastic/e2e-testing/cli/shell"
shell "github.com/elastic/e2e-testing/cli/shell"
"github.com/elastic/e2e-testing/e2e"
"github.com/elastic/e2e-testing/e2e/steps"
"github.com/google/uuid"
Expand Down Expand Up @@ -169,6 +170,23 @@ func (fts *FleetTestSuite) anStaleAgentIsDeployedToFleetWithInstaller(image, ver
agentVersionBackup := fts.Version
defer func() { fts.Version = agentVersionBackup }()

agentStaleVersion = shell.GetEnv("ELASTIC_AGENT_STALE_VERSION", agentStaleVersion)
// check if stale version is an alias
v, err := e2e.GetElasticArtifactVersion(agentStaleVersion)
if err != nil {
log.WithFields(log.Fields{
"error": err,
"version": agentStaleVersion,
}).Error("Failed to get stale version")
return err
}
agentStaleVersion = v

useCISnapshots := shell.GetEnvBool("BEATS_USE_CI_SNAPSHOTS")
if useCISnapshots && !strings.HasSuffix(agentStaleVersion, "-SNAPSHOT") {
agentStaleVersion += "-SNAPSHOT"
}

switch version {
case "stale":
version = agentStaleVersion
Expand Down
Loading

0 comments on commit 04c7fc8

Please sign in to comment.