Skip to content

Commit

Permalink
First cut at contract workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thpierce committed Feb 8, 2024
1 parent 840e3c7 commit 4839653
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 31 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/main_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# This workflow build the aws-opentelemetry-distro wheel file, upload to staging S3 bucket, and build project docker image then push to staging ECR
name: Python Instrumentation Main Build
on:
push:
branches:
- main
- contract-tests-workflow
- "release/v*"
env:
AWS_DEFAULT_REGION: us-east-1
STAGING_ECR_REGISTRY: 637423224110.dkr.ecr.us-east-1.amazonaws.com
STAGING_ECR_REPOSITORY: aws-observability/adot-autoinstrumentation-python-staging
S3_INTEGRATION_BUCKET: ${{ secrets.S3_INTEGRATION_BUCKET }}

concurrency:
group: python-instrumentation-main-build
cancel-in-progress: false

permissions:
id-token: write
contents: read

jobs:
build:
env:
py38: "3.8"
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
python-version: [ py38 ]
package: [ "aws-opentelemetry-distro" ]
os: [ ubuntu-latest ]
outputs:
python_distro_tag: ${{ steps.python_distro_versioning.outputs.STAGING_TAG}}
staging-image-name: ${{ steps.imageNameOutput.outputs.imageName }}
staging_wheel_file: ${{ steps.staging_wheel_build.outputs.STAGING_WHEEL}}
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env[matrix.python-version] }}

- name: Install tox
run: pip install tox==3.27.1 tox-factor

- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v1
with:
path: |
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}

- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json

- name: Install Dependencies and Build Wheel
id: staging_wheel_build
run: |
pip install --upgrade pip setuptools wheel packaging build
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python -m build --outdir ../dist
cd ../dist
pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
echo "ADOT_PYTHON_VERSION=$pkg_version" >> $GITHUB_OUTPUT
shortsha="$(git rev-parse --short HEAD)"
echo "STAGING_WHEEL=aws_opentelemetry_distro-$pkg_version-$shortsha.whl" >> $GITHUB_OUTPUT
- name: Run contract test setup script
run: bash contract-tests/set-up-contract-tests.sh

- name: Run contract tests with pytest
run: |
pip install pytest
pytest contract-tests/tests
- name: Upload to GitHub Actions
uses: actions/upload-artifact@v3
with:
name: aws_opentelemetry_distro.whl
path: dist/${{ steps.staging_wheel_build.outputs.STAGING_WHEEL}}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE_ARN }}
aws-region: ${{ env.AWS_DEFAULT_REGION }}

- name: Upload wheel to S3
run: aws s3 cp dist/${{ steps.staging_wheel_build.outputs.STAGING_WHEEL}} ${{ env.S3_INTEGRATION_BUCKET }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to AWS ECR
uses: docker/login-action@v3
with:
registry: ${{ env.STAGING_ECR_REGISTRY }}
env:
AWS_REGION: ${{ env.AWS_DEFAULT_REGION }}

- name: Get Python Distro Image Tag
id: python_distro_versioning
run: |
shortsha="$(git rev-parse --short HEAD)"
python_distro_tag=${{ steps.staging_wheel_build.outputs.ADOT_PYTHON_VERSION }}-$shortsha
echo "STAGING_TAG=$python_distro_tag" >> $GITHUB_OUTPUT
- name: Build and push staging image
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./Dockerfile
platforms: linux/amd64
tags: |
${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.python_distro_versioning.outputs.STAGING_TAG }}
- name: Set image name to output
id: imageNameOutput
run: echo "imageName=${{ env.STAGING_ECR_REGISTRY }}/${{ env.STAGING_ECR_REPOSITORY }}:${{ steps.python_distro_versioning.outputs.STAGING_TAG }}" >> "$GITHUB_OUTPUT"

# TODO: Add Contract test and E2E test
130 changes: 130 additions & 0 deletions .github/workflows/pr_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Python Instrumentation PR Build
on:
push:
branches:
- contract-tests-workflow

env:
AWS_DEFAULT_REGION: us-east-1
TEST_TAG: 637423224110.dkr.ecr.us-east-1.amazonaws.com/eks/observability/adot-autoinstrumentation-python:test

jobs:
build:
env:
py38: "3.8"
py39: "3.9"
py310: "3.10"
py311: "3.11"
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
matrix:
python-version: [ py38, py39, py310, py311 ]
package: [ "aws-opentelemetry-distro" ]
os: [ ubuntu-latest ]
outputs:
staging-image-name: ${{ steps.imageNameOutput.outputs.imageName }}
staging_wheel_file: ${{ steps.pr_wheel_build.outputs.STAGING_WHEEL}}
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env[matrix.python-version] }}

- name: Install tox
run: pip install tox==3.27.1 tox-factor

- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v1
with:
path: |
.tox
~/.cache/pip
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}

- name: run tox
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json

- name: Install Dependencies and Build Wheel
id: pr_wheel_build
run: |
pip install --upgrade pip setuptools wheel packaging build
rm -rf ./dist/*
cd ./aws-opentelemetry-distro
python -m build --outdir ../dist
cd ../dist
pkg_version=$(grep '__version__' ../aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | awk -F '"' '{print $2}')
echo "ADOT_PYTHON_VERSION=$pkg_version" >> $GITHUB_OUTPUT
shortsha="$(git rev-parse --short HEAD)"
echo "STAGING_WHEEL=aws_opentelemetry_distro-$pkg_version-$shortsha.whl" >> $GITHUB_OUTPUT
cp aws_opentelemetry_distro-$pkg_version-py3-none-any.whl aws_opentelemetry_distro-$pkg_version-$shortsha.whl
- name: Run contract test setup script
run: bash contract-tests/set-up-contract-tests.sh

- name: Run contract tests with pytest
run: |
pip install pytest
pytest contract-tests/tests
- name: Upload to GitHub Actions
uses: actions/upload-artifact@v3
with:
name: aws_opentelemetry_distro.whl
path: dist/${{ steps.pr_wheel_build.outputs.STAGING_WHEEL}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image for testing
uses: docker/build-push-action@v5
with:
push: false
context: .
file: ./Dockerfile
platforms: linux/amd64
tags: ${{ env.TEST_TAG }}
load: true

- name: Set image name to output
id: imageNameOutput
run: echo "imageName=${{ env.TEST_TAG }}" >> "$GITHUB_OUTPUT"
# TODO: Add E2E test
misc:
strategy:
fail-fast: false
matrix:
tox-environment: ["spellcheck", "lint"]
name: ${{ matrix.tox-environment }}
runs-on: ubuntu-20.04
steps:
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install tox
run: pip install tox==3.27.1
- name: Install libsnappy-dev
if: ${{ matrix.tox-environment == 'lint' }}
run: sudo apt-get install -y libsnappy-dev
- name: Cache tox environment
# Preserves .tox directory between runs for faster installs
uses: actions/cache@v1
with:
path: |
.tox
~/.cache/pip
key: v7-misc-tox-cache-${{ matrix.tox-environment }}-${{ hashFiles('tox.ini',
'dev-requirements.txt') }}
- name: run tox
run: tox -e ${{ matrix.tox-environment }}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# To build one auto-instrumentation image for Python, please:
# - Ensure the packages are installed in the `/autoinstrumentation` directory. This is required as when instrumenting the pod,
# one init container will be created to copy all the content in `/autoinstrumentation` directory to your app's container. Then
# update the `PYTHONPATH` environment variable accordingly. To achieve this, you can mimic the one in `autoinstrumentation/python/Dockerfile`
# by using multi-stage builds. In the first stage, install all the required packages in one custom directory with `pip install --target`.
# Then in the second stage, copy the directory to `/autoinstrumentation`.
# - Ensure you have `opentelemetry-distro` and `opentelemetry-instrumentation` or your customized alternatives installed.
# Those two packages are essential to Python auto-instrumentation.
# - Grant the necessary access to `/autoinstrumentation` directory. `chmod -R go+r /autoinstrumentation`
# - For auto-instrumentation by container injection, the Linux command cp is
# used and must be available in the image.
FROM python:3.10 AS build

WORKDIR /operator-build

ADD aws-opentelemetry-distro/ ./aws-opentelemetry-distro/

RUN mkdir workspace && pip install --target workspace ./aws-opentelemetry-distro

FROM busybox

COPY --from=build /operator-build/workspace /autoinstrumentation

RUN chmod -R go+r /autoinstrumentation
57 changes: 53 additions & 4 deletions aws-opentelemetry-distro/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,61 @@ license = "Apache-2.0"
requires-python = ">=3.8"

dependencies = [
"grpcio ~= 1.60.0",
"opentelemetry-api ~= 1.12",
"opentelemetry-instrumentation == 0.43b0",
"opentelemetry-instrumentation ~= 0.43b0",
"opentelemetry-sdk ~= 1.13",
"opentelemetry-distro == 0.43b0",
"opentelemetry-distro ~= 0.43b0",
"opentelemetry-sdk-extension-aws ~= 2.0.1",
"opentelemetry-exporter-otlp-proto-grpc == 1.22.0"
"opentelemetry-exporter-otlp-proto-grpc ~= 1.22.0",
"opentelemetry-exporter-otlp-proto-http ~= 1.22.0",
"opentelemetry-propagator-b3 ~= 1.22.0",
"opentelemetry-propagator-jaeger ~= 1.22.0",
"opentelemetry-propagator-aws-xray ~= 1.0.1",
"opentelemetry-propagator-ot-trace ~= 0.43b0",
"opentelemetry-exporter-otlp-proto-common ~= 1.22.0",
"opentelemetry-instrumentation-aio-pika ~= 0.43b0",
"opentelemetry-instrumentation-aiohttp-client ~= 0.43b0",
"opentelemetry-instrumentation-aiopg ~= 0.43b0",
"opentelemetry-instrumentation-asgi ~= 0.43b0",
"opentelemetry-instrumentation-asyncpg ~= 0.43b0",
"opentelemetry-instrumentation-boto ~= 0.43b0",
"opentelemetry-instrumentation-boto3sqs ~= 0.43b0",
"opentelemetry-instrumentation-botocore ~= 0.43b0",
"opentelemetry-instrumentation-celery ~= 0.43b0",
"opentelemetry-instrumentation-confluent-kafka ~= 0.43b0",
"opentelemetry-instrumentation-dbapi ~= 0.43b0",
"opentelemetry-instrumentation-django ~= 0.43b0",
"opentelemetry-instrumentation-elasticsearch ~= 0.43b0",
"opentelemetry-instrumentation-falcon ~= 0.43b0",
"opentelemetry-instrumentation-fastapi ~= 0.43b0",
"opentelemetry-instrumentation-flask ~= 0.43b0",
"opentelemetry-instrumentation-grpc ~= 0.43b0",
"opentelemetry-instrumentation-httpx ~= 0.43b0",
"opentelemetry-instrumentation-jinja2 ~= 0.43b0",
"opentelemetry-instrumentation-kafka-python ~= 0.43b0",
"opentelemetry-instrumentation-logging ~= 0.43b0",
"opentelemetry-instrumentation-mysql ~= 0.43b0",
"opentelemetry-instrumentation-mysqlclient ~= 0.43b0",
" opentelemetry-instrumentation-pika ~= 0.43b0",
"opentelemetry-instrumentation-psycopg2 ~= 0.43b0",
"opentelemetry-instrumentation-pymemcache ~= 0.43b0",
"opentelemetry-instrumentation-pymongo ~= 0.43b0",
"opentelemetry-instrumentation-pymysql ~= 0.43b0",
"opentelemetry-instrumentation-pyramid ~= 0.43b0",
"opentelemetry-instrumentation-redis ~= 0.43b0",
"opentelemetry-instrumentation-remoulade ~= 0.43b0",
"opentelemetry-instrumentation-requests ~= 0.43b0",
"opentelemetry-instrumentation-sklearn ~= 0.43b0",
"opentelemetry-instrumentation-sqlalchemy ~= 0.43b0",
"opentelemetry-instrumentation-sqlite3 ~= 0.43b0",
"opentelemetry-instrumentation-starlette ~= 0.43b0",
"opentelemetry-instrumentation-system-metrics ~= 0.43b0",
"opentelemetry-instrumentation-tornado ~= 0.43b0",
"opentelemetry-instrumentation-tortoiseorm ~= 0.43b0",
"opentelemetry-instrumentation-urllib ~= 0.43b0",
"opentelemetry-instrumentation-urllib3 ~= 0.43b0",
"opentelemetry-instrumentation-wsgi ~= 0.43b0"
]

[project.optional-dependencies]
Expand All @@ -41,4 +90,4 @@ include = [
]

[tool.hatch.build.targets.wheel]
packages = ["src/amazon"]
packages = ["src/amazon"]
9 changes: 4 additions & 5 deletions contract-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ The steps to add a new test for a library or framework are:

Pre-requirements:
* Have `docker` installed and running - verify by running the `docker` command.
* Create `aws-otel-python-instrumentation/contract-tests/dist` folder
* Copy the `aws_opentelemetry_distro` wheel file to `aws-otel-python-instrumentation/contract-tests/dist` folder
* Ensure the `aws_opentelemetry_distro` wheel file exists in to `aws-otel-python-instrumentation/dist` folder

From `aws-otel-python-instrumentation/contract-tests` execute:
From `aws-otel-python-instrumentation` dir, execute:

```
./set-up-contract-tests.sh
pytest tests
./contract-tests/set-up-contract-tests.sh
pytest contract-tests/tests
```
6 changes: 3 additions & 3 deletions contract-tests/images/applications/requests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Meant to be run from aws-otel-python-instrumentation/contract-tests.
# Assumes existence of dist/aws_opentelemetry_distro-<pkg_version>-py3-none-any.whl.
# Assumes filename of aws_opentelemetry_distro-<pkg_version>-py3-none-any.whl is passed in as "DISTRO" arg.
FROM python:3.9-slim
FROM public.ecr.aws/docker/library/python:3.11-slim
WORKDIR /requests
COPY ./dist /requests
COPY ./images/applications/requests /requests
COPY ./dist/$DISTRO /requests
COPY ./contract-tests/images/applications/requests /requests

ARG DISTRO
RUN pip install -r requirements.txt && pip install ${DISTRO} --force-reinstall
Expand Down
Loading

0 comments on commit 4839653

Please sign in to comment.