Skip to content
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

Adds contract test for CREATE DATABASE for MySQL #215

Merged
merged 3 commits into from
Jun 21, 2024

Conversation

georgeboc
Copy link
Contributor

Issue #, if available:
N/A

Description of changes:
Adding MySQL contract tests for app signals to ensure that customer experience doesn't break with any change. The new contract test covers the CREATE DATABASE SQL command. It also takes the opportunity to refactor the code in common with the PostgreSQL contract tests to avoid code duplication.

Contract tests running successfully:

$ ./scripts/build_and_install_distro.sh
...
$ ./scripts/set-up-contract-tests.sh
...
$ pytest contract-tests/tests
============================= test session starts ==============================
platform linux -- Python 3.8.11, pytest-7.1.3, pluggy-1.5.0
rootdir: /local/home/gbochile/aws-otel-python-instrumentation/contract-tests/tests, configfile: pyproject.toml
plugins: cov-4.1.0, flaky-3.7.0
collected 39 items

contract-tests/tests/test/amazon/psycopg2/psycopg2_test.py::Psycopg2Test::test_create_database_succeeds
-------------------------------- live log setup --------------------------------
2024-06-20 14:55:44 [    INFO] Pulling image aws-application-signals-mock-collector-python (container.py:53)
2024-06-20 14:55:45 [    INFO] Container started: d9689f28b345 (container.py:64)
2024-06-20 14:55:46 [    INFO] Pulling image postgres:latest (container.py:53)
2024-06-20 14:55:46 [    INFO] Container started: 23e433c8ee6e (container.py:64)
2024-06-20 14:55:46 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:55:46 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:55:47 [    INFO] Waiting to be ready... (waiting_utils.py:46)
-------------------------------- live log call ---------------------------------
2024-06-20 14:55:47 [    INFO] Pulling image aws-application-signals-tests-psycopg2-app (container.py:53)
2024-06-20 14:55:48 [    INFO] Container started: 68f62688d322 (container.py:64)
2024-06-20 14:55:54 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:55:54 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:55:54 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:55:54 [    INFO] Ready
 (contract_test_base.py:119)
2024-06-20 14:55:54 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:55:54 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7f2938bc3730>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 71%]
contract-tests/tests/test/amazon/psycopg2/psycopg2_test.py::Psycopg2Test::test_drop_table_succeeds
-------------------------------- live log call ---------------------------------
2024-06-20 14:55:55 [    INFO] Pulling image aws-application-signals-tests-psycopg2-app (container.py:53)
2024-06-20 14:55:55 [    INFO] Container started: 38c2e2937827 (container.py:64)
2024-06-20 14:56:01 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:01 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:02 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:56:02 [    INFO] Ready
 (contract_test_base.py:119)
2024-06-20 14:56:02 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:56:02 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7fa54b22f790>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 74%]
contract-tests/tests/test/amazon/psycopg2/psycopg2_test.py::Psycopg2Test::test_fault
-------------------------------- live log call ---------------------------------
2024-06-20 14:56:02 [    INFO] Pulling image aws-application-signals-tests-psycopg2-app (container.py:53)
2024-06-20 14:56:03 [    INFO] Container started: 2df7a0957e52 (container.py:64)
2024-06-20 14:56:09 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:09 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:09 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:56:09 [    INFO] Ready
Expected Exception with Invalid SQL occurred: relation "invalid_table" does not exist
LINE 1: SELECT DISTINCT id, name FROM invalid_table
                                      ^

 (contract_test_base.py:119)
2024-06-20 14:56:09 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:56:09 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7f4a5f0e77f0>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 76%]

...

contract-tests/tests/test/amazon/pymysql/pymysql_test.py::PyMysqlTest::test_create_database_succeeds
-------------------------------- live log setup --------------------------------
2024-06-20 14:56:11 [    INFO] Pulling image aws-application-signals-mock-collector-python (container.py:53)
2024-06-20 14:56:12 [    INFO] Container started: 593e6565ee45 (container.py:64)
2024-06-20 14:56:13 [    INFO] Pulling image mysql:latest (container.py:53)
2024-06-20 14:56:13 [    INFO] Container started: 5e44c6384697 (container.py:64)
2024-06-20 14:56:13 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:13 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:14 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:15 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:17 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:18 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:19 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:20 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:21 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:22 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:23 [    INFO] Waiting to be ready... (waiting_utils.py:46)
-------------------------------- live log call ---------------------------------
2024-06-20 14:56:23 [    INFO] Pulling image aws-application-signals-tests-pymysql-app (container.py:53)
2024-06-20 14:56:24 [    INFO] Container started: 518b7ef0c507 (container.py:64)
2024-06-20 14:56:30 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:30 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:30 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:56:30 [    INFO] Ready
 (contract_test_base.py:119)
2024-06-20 14:56:30 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:56:30 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7fbfc92c7ac0>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 79%]
contract-tests/tests/test/amazon/pymysql/pymysql_test.py::PyMysqlTest::test_drop_table_succeeds
-------------------------------- live log call ---------------------------------
2024-06-20 14:56:31 [    INFO] Pulling image aws-application-signals-tests-pymysql-app (container.py:53)
2024-06-20 14:56:31 [    INFO] Container started: 079eaf40b262 (container.py:64)
2024-06-20 14:56:37 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:37 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:38 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:56:38 [    INFO] Ready
 (contract_test_base.py:119)
2024-06-20 14:56:38 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:56:38 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7fc21bf53a00>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 82%]
contract-tests/tests/test/amazon/pymysql/pymysql_test.py::PyMysqlTest::test_fault
-------------------------------- live log call ---------------------------------
2024-06-20 14:56:38 [    INFO] Pulling image aws-application-signals-tests-pymysql-app (container.py:53)
2024-06-20 14:56:39 [    INFO] Container started: 1e5f0eaf1238 (container.py:64)
2024-06-20 14:56:45 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:45 [    INFO] Waiting to be ready... (waiting_utils.py:46)
2024-06-20 14:56:45 [    INFO] Application stdout (contract_test_base.py:118)
2024-06-20 14:56:45 [    INFO] Ready
Expected Exception with Invalid SQL occurred: (1146, "Table 'testdb.invalid_table' doesn't exist")
 (contract_test_base.py:119)
2024-06-20 14:56:45 [    INFO] Application stderr (contract_test_base.py:120)
2024-06-20 14:56:45 [    INFO] Failed to get k8s token: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
AwsEcsResourceDetector failed: Missing ECS_CONTAINER_METADATA_URI therefore process is not on ECS.
AwsEksResourceDetector failed: [Errno 2] No such file or directory: '/var/run/secrets/kubernetes.io/serviceaccount/token'
Exception  in detector <opentelemetry.sdk.extension.aws.resource.ec2.AwsEc2ResourceDetector object at 0x7f4b2a841420>, ignoring
AwsEc2ResourceDetector failed: timed out
Configuration of configurator not loaded, aws_configurator already loaded
 (contract_test_base.py:121)
PASSED                                                                   [ 84%]

...
======================== 39 passed in 363.85s (0:06:03) ========================

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@georgeboc georgeboc requested a review from a team as a code owner June 20, 2024 15:25
Copy link

@jerry-shao jerry-shao left a comment

Choose a reason for hiding this comment

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

LGTM

@thpierce thpierce merged commit 912dd93 into aws-observability:main Jun 21, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants