Skip to content

Enable integration tests again #23

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

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions .buildkite/generatesteps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os

import yaml


def benchmark_to_steps(python, connection_class):
return [
{
"group": f":elasticsearch: :python: ES Serverless ({python}/{connection_class})",
Copy link
Member Author

Choose a reason for hiding this comment

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

A group isn't strictly necessary, but it allows for a nicer summary.

"steps": [
{
"label": "Run tests",
"agents": {"provider": "gcp"},
"env": {
"PYTHON_VERSION": f"{python}",
"PYTHON_CONNECTION_CLASS": f"{connection_class}",
# TEMPORARY for 3.11
# https://github.com/aio-libs/aiohttp/issues/6600
"AIOHTTP_NO_EXTENSIONS": 1,
# https://github.com/aio-libs/frozenlist/issues/285
"FROZENLIST_NO_EXTENSIONS": 1,
# https://github.com/aio-libs/yarl/issues/680
"YARL_NO_EXTENSIONS": 1,
"EC_REGISTER_BACKEND": "appex-qa-team-cluster",
"EC_ENV": "qa",
"EC_REGION": "aws-eu-west-1",
"EC_PROJECT_PREFIX": f"esv-client-python-test-{python}-{connection_class}",
},
"command": "./.buildkite/run-tests",
"artifact_paths": "junit/*-junit.xml",
"retry": {"manual": False},
"key": f"run_{python.replace('.', '_')}_{connection_class}",
},
{
"label": "Teardown",
"agents": {"provider": "gcp"},
"env": {
"PYTHON_VERSION": f"{python}",
"PYTHON_CONNECTION_CLASS": f"{connection_class}",
"EC_REGISTER_BACKEND": "appex-qa-team-cluster",
"EC_ENV": "qa",
"EC_REGION": "aws-eu-west-1",
"EC_PROJECT_PREFIX": f"esv-client-python-test-{python}-{connection_class}",
},
"command": ".buildkite/teardown-tests",
"depends_on": f"run_{python.replace('.', '_')}_{connection_class}",
"allow_dependency_failure": True,
},
],
}
]


if __name__ == "__main__":
steps = []
for python in ["3.7", "3.8", "3.9", "3.10", "3.11"]:
for connection_class in ["urllib3", "requests"]:
Comment on lines +56 to +57
Copy link
Member Author

Choose a reason for hiding this comment

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

This could be in rest-tests.yaml!

steps.extend(benchmark_to_steps(python, connection_class))
print(yaml.dump({"steps": steps}, Dumper=yaml.Dumper, sort_keys=False))
36 changes: 6 additions & 30 deletions .buildkite/rest-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
steps:
- label: ":elasticsearch: :python: ES Serverless ({{ matrix.python }}/{{ matrix.connection_class }}) Python Test Suite: {{ matrix.suite }}"
agents:
provider: gcp
env:
PYTHON_VERSION: "{{ matrix.python }}"
PYTHON_CONNECTION_CLASS: "{{ matrix.connection_class }}"
# TEMPORARY for 3.11
# https://github.com/aio-libs/aiohttp/issues/6600
AIOHTTP_NO_EXTENSIONS: 1
# https://github.com/aio-libs/frozenlist/issues/285
FROZENLIST_NO_EXTENSIONS: 1
# https://github.com/aio-libs/yarl/issues/680
YARL_NO_EXTENSIONS: 1
EC_REGISTER_BACKEND: "appex-qa-team-cluster"
EC_ENV: "qa"
EC_REGION: "aws-eu-west-1"
EC_PROJECT_PREFIX: "esv-client-python-test-{{ matrix.python }}-{{ matrix.connection_class }}"
matrix:
setup:
python:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
connection_class:
- urllib3
- requests
command: echo "Skipping ./.buildkite/run-tests for now"
artifact_paths: "junit/*-junit.xml"
- label: ":pipeline: Generate steps"
command: |
set -eo pipefail

python3 -m pip install pyyaml
python3 .buildkite/generatesteps.py | buildkite-agent pipeline upload
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we need two builds per combination (run-tests and teardown), the matrix functionality does not work and we need to generate the steps.

- wait: ~
continue_on_failure: true
- label: ":junit: Test results"
Expand Down
14 changes: 9 additions & 5 deletions .buildkite/run-tests
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail

# Default environment variables
export PYTHON_VERSION="${PYTHON_VERSION:=3.9}"
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
export EC_PROJECT_NAME="$EC_PROJECT_PREFIX-$BUILDKITE_JOB_ID"

set -euo pipefail
buildkite-agent meta-data set $EC_PROJECT_PREFIX $EC_PROJECT_NAME

# fetch cloud creds used by qaf
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" secret/ci/elastic-elasticsearch-serverless-python/cloud-access)
Expand All @@ -27,9 +27,13 @@ run_qaf() {

# ensure serverless instance is deleted even if script errors
cleanup() {
echo -e "--- :elasticsearch: Tear down serverless instance $EC_PROJECT_NAME"
run_qaf 'qaf elastic-cloud projects delete'
rm -rf "$(pwd)/cloud.json"
if [ -z "$BUILDKITE" ]; then
echo -e "--- :elasticsearch: Tear down serverless instance $EC_PROJECT_NAME"
run_qaf 'qaf elastic-cloud projects delete'
rm -rf "$(pwd)/cloud.json"
Comment on lines +31 to +33
Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to use run-tests locally, we need to tear down properly, hence the condition.

else
echo -e "--- In Buildkite, another job will cleanup"
fi
}
trap cleanup EXIT

Expand Down
29 changes: 29 additions & 0 deletions .buildkite/teardown-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

# Default environment variables
export PYTHON_VERSION="${PYTHON_VERSION:=3.9}"
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
export EC_PROJECT_NAME=$(buildkite-agent meta-data get $EC_PROJECT_PREFIX)
Copy link
Member Author

Choose a reason for hiding this comment

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

We retrieve the full project name to be able to tear it down.


# fetch cloud creds used by qaf
CLOUD_ACCESS_KEY=$(vault read -field="$EC_ENV" secret/ci/elastic-elasticsearch-serverless-python/cloud-access)
echo "{\"api_key\":{\"$EC_ENV\":\"$CLOUD_ACCESS_KEY\"}}" > "$(pwd)/cloud.json"

run_qaf() {
cmd=$1
docker run --rm \
-e EC_REGISTER_BACKEND \
-e EC_ENV \
-e EC_REGION \
-e EC_PROJECT_NAME \
-e VAULT_TOKEN \
-e BUILDKITE \
-v "$(pwd)/cloud.json:/root/.elastic/cloud.json" \
docker.elastic.co/employees/dolaru/qaf:latest \
bash -c "$cmd"
}

echo -e "--- :elasticsearch: Tear down serverless instance $EC_PROJECT_NAME"
run_qaf 'qaf elastic-cloud projects delete'
rm -rf "$(pwd)/cloud.json"
3 changes: 1 addition & 2 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ spec:
provider_settings:
build_pull_requests: true
build_branches: true
cancel_intermediate_builds: true
cancel_intermediate_builds_branch_filter: '!main'
cancel_intermediate_builds: false
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't want to cancel intermediate builds to make sure we always tear down all serverless projects.

schedules:
main_semi_daily:
branch: 'main'
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ include = [
"/docs/sphinx",
]

[tool.hatch.build.targets.wheel]
packages = ["elasticsearch_serverless"]

Comment on lines +98 to +100
Copy link
Member Author

Choose a reason for hiding this comment

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

This is required by a recent Hatch change: pypa/hatch#1113

[tool.pytest]
junit_family = "legacy"
addopts = "-vvv -p no:logging --cov-report=term-missing --cov=elasticsearch_serverless --cov-config=.pyproject.toml"
Expand Down