diff --git a/.github/actions/test-control-plane/action.yaml b/.github/actions/test-control-plane/action.yaml new file mode 100644 index 000000000..8382e5318 --- /dev/null +++ b/.github/actions/test-control-plane/action.yaml @@ -0,0 +1,58 @@ +name: 'Test Control Plane' +description: 'Runs tests on the Pinecone control plane' + +inputs: + test_suite: + description: 'The type of the index (serverless, pod)' + required: true + default: 'serverless' + python_version: + description: 'The version of Python to use' + required: false + default: '3.9' + metric: + description: 'The metric of the index' + required: true + dimension: + description: 'The dimension of the index' + required: true + spec: + description: 'The deploy spec of the index' + required: true + use_grpc: + description: 'Whether to use gRPC or REST' + required: true + freshness_timeout_seconds: + description: 'The number of seconds to wait for the index to become fresh' + required: false + default: '60' + PINECONE_API_KEY: + description: 'The Pinecone API key' + required: true + +runs: + using: 'composite' + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python_version }} + + - name: Setup Poetry + uses: ./.github/actions/setup-poetry + with: + include_grpc: ${{ inputs.use_grpc }} + include_dev: 'true' + + - name: Run tests + id: data-plane-tests + shell: bash + run: poetry run pytest tests/integration/control/${{ inputs.test_suite }} + env: + PINECONE_API_KEY: ${{ inputs.PINECONE_API_KEY }} + USE_GRPC: ${{ inputs.use_grpc }} + METRIC: ${{ inputs.metric }} + DIMENSION: ${{ inputs.dimension }} + SPEC: ${{ inputs.spec }} + FRESHNESS_TIMEOUT_SECONDS: ${{ inputs.freshness_timeout_seconds }} + GITHUB_BUILD_NUMBER: '${{ github.run_number }}-p-${{ matrix.testConfig.python-version}}' \ No newline at end of file diff --git a/.github/actions/test-data-plane/action.yaml b/.github/actions/test-data-plane/action.yaml index 9fafc0d50..847d234df 100644 --- a/.github/actions/test-data-plane/action.yaml +++ b/.github/actions/test-data-plane/action.yaml @@ -30,11 +30,6 @@ inputs: required: false default: '3.9' -outputs: - index_name: - description: 'The name of the index, including randomized suffix' - value: ${{ steps.create-index.outputs.index_name }} - runs: using: 'composite' steps: diff --git a/.github/workflows/optimistic-updates.yaml b/.github/workflows/optimistic-updates.yaml new file mode 100644 index 000000000..3e52142e9 --- /dev/null +++ b/.github/workflows/optimistic-updates.yaml @@ -0,0 +1,93 @@ +name: Update Spec + +on: + workflow_dispatch: {} +# schedule: +# - cron: '0 0 * * *' + +jobs: + update-and-build: + name: Build docs with pdoc + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up git + run: | + git config --global user.name "Pinecone CI" + git config --global user.email "clients@pinecone.io" + + - name: Update spec + run: | + ./scripts/build-oas.sh + git add codegen + git add pinecone/core + + - name: Commit changes + id: commit + run: + if git diff --cached --quiet; then + echo "No changes are staged." + echo "new_changes=true" >> "$GITHUB_OUTPUT" + else + echo "There are staged changes." + git commit -m'Regenerate core with latest specs' + echo "new_changes=false" >> "$GITHUB_OUTPUT" + fi + + - name: Abort if no recent changes + if: steps.commit.outputs.new_changes == 'false' + uses: andymckay/cancel-action@0.3 + + - name: Test data plane (rest) + uses: ./.github/actions/test-data-plane + with: + metric: 'cosine' + use_grpc: false + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 + + - name: Test control plane (serverless, rest) + uses: ./.github/actions/test-control-plane + with: + test_suite: 'serverless' + use_grpc: false + metric: 'cosine' + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 + + - name: Test control plane (serverless, grpc) + uses: ./.github/actions/test-control-plane + with: + test_suite: 'serverless' + use_grpc: true + metric: 'cosine' + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 + + - name: Test control plane (pod, rest) + uses: ./.github/actions/test-control-plane + with: + test_suite: 'pod' + use_grpc: false + metric: 'cosine' + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 + + - name: Test control plane (pod, grpc) + uses: ./.github/actions/test-control-plane + with: + test_suite: 'pod' + use_grpc: true + metric: 'cosine' + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 + + - name: Push changes + run: git push \ No newline at end of file diff --git a/.github/workflows/testing-integration.yaml b/.github/workflows/testing-integration.yaml index 6a4bbdb18..de63ab806 100644 --- a/.github/workflows/testing-integration.yaml +++ b/.github/workflows/testing-integration.yaml @@ -26,130 +26,66 @@ jobs: PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' data-plane-serverless: - name: Data plane serverless integration tests + name: data serverless runs-on: ubuntu-latest strategy: fail-fast: false matrix: python_version: [3.8, 3.12] use_grpc: [true, false] - metric: - - cosine - # - euclidean - # - dotproduct - spec: - - '{ "serverless": { "region": "us-west-2", "cloud": "aws" }}' steps: - uses: actions/checkout@v4 - uses: ./.github/actions/test-data-plane with: python_version: '${{ matrix.python_version }}' use_grpc: '${{ matrix.use_grpc }}' - metric: '${{ matrix.metric }}' - spec: '${{ matrix.spec }}' + metric: 'cosine' + spec: '{ "serverless": { "region": "us-west-2", "cloud": "aws" }}' PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' freshness_timeout_seconds: 600 -# data-plane-pod: -# name: Data plane pod integration tests -# runs-on: ubuntu-latest -# strategy: -# max-parallel: 1 -# matrix: -# use_grpc: [true, false] -# metric: [cosine, dotproduct] -# spec: -# - '{ "pod": { "environment": "us-east1-gcp", "pod_type": "p1" }}' -# steps: -# - uses: actions/checkout@v4 -# - uses: ./.github/actions/test-data-plane -# with: -# use_grpc: '${{ matrix.use_grpc }}' -# metric: '${{ matrix.metric }}' -# spec: '${{ matrix.spec }}' -# PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' - control-rest-pod: - name: control plane pod/collection tests + control-plane-pod: + name: control pod runs-on: ubuntu-latest strategy: matrix: - pineconeEnv: - - prod - testConfig: - - python-version: 3.8 - pod: { environment: 'us-east1-gcp'} - - python-version: 3.12 - pod: { environment: 'us-east4-gcp'} + # python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.10'] + use_grpc: [true, false] fail-fast: false steps: - uses: actions/checkout@v4 - - name: 'Set up Python ${{ matrix.testConfig.python-version }}' - uses: actions/setup-python@v5 + - name: Test control plane (pod, rest) + uses: ./.github/actions/test-control-plane with: - python-version: '${{ matrix.testConfig.python-version }}' - - name: Setup Poetry - uses: ./.github/actions/setup-poetry - - name: 'Run integration tests (REST, prod)' - if: matrix.pineconeEnv == 'prod' - run: poetry run pytest tests/integration/control/pod -s -v - env: - PINECONE_DEBUG_CURL: 'true' - PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' - PINECONE_ENVIRONMENT: '${{ matrix.testConfig.pod.environment }}' - GITHUB_BUILD_NUMBER: '${{ github.run_number }}-s-${{ matrix.testConfig.python-version}}' - DIMENSION: 2500 - METRIC: 'cosine' - - name: 'Run integration tests (REST, staging)' - if: matrix.pineconeEnv == 'staging' - run: poetry run pytest tests/integration/control/pod -s -v - env: - PINECONE_DEBUG_CURL: 'true' - PINECONE_CONTROLLER_HOST: 'https://api-staging.pinecone.io' - PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY_STAGING }}' - PINECONE_ENVIRONMENT: '${{ matrix.testConfig.pod.environment }}' - GITHUB_BUILD_NUMBER: '${{ github.run_number }}-p-${{ matrix.testConfig.python-version}}' - DIMENSION: 1536 - METRIC: 'cosine' + python_version: '${{ matrix.python-version }}' + test_suite: 'pod' + use_grpc: ${{ matrix.use_grpc }} + metric: 'cosine' + dimension: 10 + spec: '{ "pod": { "environment": "us-east4-gcp", "pod_type": "p1.x1" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 - control-rest-serverless: - name: control plane serverless + control-plane-serverless: + name: control serverless runs-on: ubuntu-latest strategy: matrix: - pineconeEnv: - - prod - testConfig: - - python-version: 3.8 # Do one test run with 3.8 for sanity check - pod: { environment: 'us-east1-gcp'} - serverless: { cloud: 'aws', region: 'us-west-2'} - - python-version: 3.12 - pod: { environment: 'us-east1-gcp'} - serverless: { cloud: 'aws', region: 'us-west-2'} + # python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.10'] + use_grpc: [true, false] fail-fast: false steps: - uses: actions/checkout@v4 - - name: 'Set up Python ${{ matrix.testConfig.python-version }}' - uses: actions/setup-python@v5 + - name: Test control plane (serverless, rest) + uses: ./.github/actions/test-control-plane with: - python-version: '${{ matrix.testConfig.python-version }}' - - name: Setup Poetry - uses: ./.github/actions/setup-poetry - - name: 'Run integration tests (REST, prod)' - if: matrix.pineconeEnv == 'prod' - run: poetry run pytest tests/integration/control/serverless -s -vv - env: - PINECONE_DEBUG_CURL: 'true' - PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY }}' - GITHUB_BUILD_NUMBER: '${{ github.run_number }}-p-${{ matrix.testConfig.python-version}}' - SERVERLESS_CLOUD: '${{ matrix.testConfig.serverless.cloud }}' - SERVERLESS_REGION: '${{ matrix.testConfig.serverless.region }}' - - name: 'Run integration tests (REST, staging)' - if: matrix.pineconeEnv == 'staging' - run: poetry run pytest tests/integration/control/serverless -s -vv - env: - PINECONE_DEBUG_CURL: 'true' - PINECONE_CONTROLLER_HOST: 'https://api-staging.pinecone.io' - PINECONE_API_KEY: '${{ secrets.PINECONE_API_KEY_STAGING }}' - GITHUB_BUILD_NUMBER: '${{ github.run_number }}-s-${{ matrix.testConfig.python-version}}' - SERVERLESS_CLOUD: '${{ matrix.testConfig.serverless.cloud }}' - SERVERLESS_REGION: '${{ matrix.testConfig.serverless.region }}' + python_version: '${{ matrix.python-version }}' + test_suite: 'serverless' + use_grpc: ${{ matrix.use_grpc }} + metric: 'cosine' + dimension: 10 + spec: '{ "serverless": { "cloud": "aws", "region": "us-west-2" }}' + PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }} + freshness_timeout_seconds: 600 \ No newline at end of file diff --git a/tests/dependency/grpc/test_sanity.py b/tests/dependency/grpc/test_sanity.py index a7d8fb259..1d7c7afc3 100644 --- a/tests/dependency/grpc/test_sanity.py +++ b/tests/dependency/grpc/test_sanity.py @@ -31,7 +31,7 @@ def test_sanity(self, index_name, client): idx.upsert(vectors=[("1", [1.0, 2.0]), ("2", [3.0, 4.0]), ("3", [5.0, 6.0])]) # Wait for index freshness - time.sleep(30) + time.sleep(60) # Check the vector count reflects some data has been upserted description = idx.describe_index_stats() diff --git a/tests/dependency/rest/test_sanity.py b/tests/dependency/rest/test_sanity.py index 05ba5ed28..fd1bd82b0 100644 --- a/tests/dependency/rest/test_sanity.py +++ b/tests/dependency/rest/test_sanity.py @@ -31,7 +31,7 @@ def test_sanity(self, index_name, client): idx.upsert(vectors=[("1", [1.0, 2.0]), ("2", [3.0, 4.0]), ("3", [5.0, 6.0])]) # Wait for index freshness - time.sleep(30) + time.sleep(60) # Check the vector count reflects some data has been upserted description = idx.describe_index_stats() diff --git a/tests/integration/control/pod/conftest.py b/tests/integration/control/pod/conftest.py index 35f6613fd..6835b6f02 100644 --- a/tests/integration/control/pod/conftest.py +++ b/tests/integration/control/pod/conftest.py @@ -2,19 +2,35 @@ import random import string import time +import json from pinecone import Pinecone, PodSpec from ...helpers import generate_index_name, get_environment_var @pytest.fixture() -def client(): +def use_grpc(): + return get_environment_var("USE_GRPC") == "true" + + +@pytest.fixture() +def environment(spec): + return spec["pod"]["environment"] + + +@pytest.fixture() +def client(use_grpc): api_key = get_environment_var("PINECONE_API_KEY") - return Pinecone(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) + if use_grpc: + from pinecone.grpc import PineconeGRPC + + return PineconeGRPC(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) + else: + return Pinecone(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) @pytest.fixture() -def environment(): - return get_environment_var("PINECONE_ENVIRONMENT") +def spec(): + return json.loads(get_environment_var("SPEC")) @pytest.fixture() @@ -23,8 +39,7 @@ def dimension(): @pytest.fixture() -def create_index_params(index_name, environment, dimension, metric): - spec = {"pod": {"environment": environment, "pod_type": "p1.x1"}} +def create_index_params(index_name, spec, dimension, metric): return dict(name=index_name, dimension=dimension, metric=metric, spec=spec, timeout=-1) @@ -83,9 +98,7 @@ def reusable_collection(): name=index_name, dimension=dimension, metric=get_environment_var("METRIC"), - spec=PodSpec( - environment=get_environment_var("PINECONE_ENVIRONMENT"), - ), + spec=json.loads(get_environment_var("SPEC")), ) print(f"Created index {index_name}. Waiting 10 seconds to make sure it's ready...") time.sleep(10) @@ -102,15 +115,15 @@ def reusable_collection(): time_waited = 0 desc = pc.describe_collection(collection_name) collection_ready = desc["status"] - while collection_ready.lower() != "ready" and time_waited < 120: + while collection_ready.lower() != "ready" and time_waited < 300: print(f"Waiting for collection {collection_name} to be ready. Waited {time_waited} seconds...") time.sleep(5) time_waited += 5 desc = pc.describe_collection(collection_name) collection_ready = desc["status"] - if time_waited >= 120: - raise Exception(f"Collection {collection_name} is not ready after 120 seconds") + if time_waited >= 300: + raise Exception(f"Collection {collection_name} is not ready after 300 seconds") print(f"Collection {collection_name} is ready. Deleting index {index_name}...") pc.delete_index(index_name) @@ -126,7 +139,7 @@ def cleanup(client, index_name): yield time_waited = 0 - while index_exists(index_name, client) and time_waited < 120: + while index_exists(index_name, client) and time_waited < 300: print(f"Waiting for index {index_name} to be ready to delete. Waited {time_waited} seconds..") time_waited += 5 time.sleep(5) @@ -139,5 +152,5 @@ def cleanup(client, index_name): print(f"Unable to delete index {index_name}: {e}") pass - if time_waited >= 120: - raise Exception(f"Index {index_name} could not be deleted after 120 seconds") + if time_waited >= 300: + raise Exception(f"Index {index_name} could not be deleted after 300 seconds") diff --git a/tests/integration/control/pod/test_collections.py b/tests/integration/control/pod/test_collections.py index 10eb0499e..6d53222c8 100644 --- a/tests/integration/control/pod/test_collections.py +++ b/tests/integration/control/pod/test_collections.py @@ -26,8 +26,9 @@ def test_index_to_collection_to_index_happy_path( assert desc["status"] == "Initializing" time_waited = 0 + max_wait = 5 * 60 collection_ready = desc["status"] - while collection_ready.lower() != "ready" and time_waited < 120: + while collection_ready.lower() != "ready" and time_waited < max_wait: print(f"Waiting for collection {collection_name} to be ready. Waited {time_waited} seconds...") time.sleep(5) time_waited += 5 @@ -36,8 +37,8 @@ def test_index_to_collection_to_index_happy_path( assert collection_name in client.list_collections().names() - if time_waited >= 120: - raise Exception(f"Collection {collection_name} is not ready after 120 seconds") + if time_waited >= max_wait: + raise Exception(f"Collection {collection_name} is not ready after 5 minutes") # After collection ready, these should all be defined assert desc["name"] == collection_name @@ -96,5 +97,5 @@ def test_create_index_with_different_metric_from_orig_index( metric=target_metric, spec=PodSpec(environment=environment, source_collection=reusable_collection), ) - time.sleep(10) + time.sleep(30) client.delete_index(index_name, -1) diff --git a/tests/integration/control/serverless/conftest.py b/tests/integration/control/serverless/conftest.py index 1a6ee0ba1..b6d3ed2a8 100644 --- a/tests/integration/control/serverless/conftest.py +++ b/tests/integration/control/serverless/conftest.py @@ -2,29 +2,34 @@ import pytest import random import time +import json from pinecone import Pinecone, NotFoundException, PineconeApiException from ...helpers import generate_index_name, get_environment_var @pytest.fixture() -def client(): - api_key = get_environment_var("PINECONE_API_KEY") - return Pinecone(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) +def use_grpc(): + return get_environment_var("USE_GRPC", "false") == "true" @pytest.fixture() -def serverless_cloud(): - return get_environment_var("SERVERLESS_CLOUD", "aws") +def client(use_grpc): + api_key = get_environment_var("PINECONE_API_KEY") + if use_grpc: + from pinecone.grpc import PineconeGRPC + + return PineconeGRPC(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) + else: + return Pinecone(api_key=api_key, additional_headers={"sdk-test-suite": "pinecone-python-client"}) @pytest.fixture() -def serverless_region(): - return get_environment_var("SERVERLESS_REGION", "us-west-2") +def spec(): + return json.loads(get_environment_var("SPEC")) @pytest.fixture() -def create_sl_index_params(index_name, serverless_cloud, serverless_region): - spec = {"serverless": {"cloud": serverless_cloud, "region": serverless_region}} +def create_sl_index_params(index_name, spec): return dict(name=index_name, dimension=10, metric="cosine", spec=spec) @@ -53,19 +58,6 @@ def notready_sl_index(client, index_name, create_sl_index_params): yield index_name -@pytest.fixture() -def ready_pod_index(client, index_name, create_pod_index_params): - del create_pod_index_params["timeout"] - client.create_index(**create_pod_index_params) - yield index_name - - -@pytest.fixture() -def notready_pod_index(client, index_name, create_pod_index_params): - client.create_index(**create_pod_index_params) - yield index_name - - def delete_with_retry(client, index_name, retries=0, sleep_interval=5): print("Deleting index " + index_name + ", retry " + str(retries) + ", next sleep interval " + str(sleep_interval)) try: