Skip to content

Commit 51e03f8

Browse files
authored
Add AAD to workload configs (#42389)
* update workloads to use aad * update workloads to use aad * improve setup scripts * revert bicep change * fix analyze * fix upserts * fix upserts * made new script an executable * fix path to dev_requirements * fix setup script * fix setup script * fix setup script * fix setup script * staggered startup * fix setup script * fix setup script
1 parent 78e40d4 commit 51e03f8

15 files changed

+152
-35
lines changed

sdk/cosmos/azure-cosmos/tests/workloads/dev.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,20 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
99
- 32 GB RAM
1010
- Ubuntu
1111
- Accelerated networking
12+
1. Give the VM necessary [permissions](https://learn.microsoft.com/azure/cosmos-db/nosql/how-to-grant-data-plane-access?tabs=built-in-definition%2Ccsharp&pivots=azure-interface-cli) to access the Cosmos DB account if using AAD (Optional).
1213
1. Create an Azure App Insights Resource (Optional)
1314
1. Fork and clone this repository
1415
1. Go to azure cosmos folder
1516
- `cd azure-sdk-for-python/sdk/cosmos/azure-cosmos`
1617
1. Install the required packages and create virtual environment
17-
- `sudo apt-get update`
18-
- `sudo apt-get install python3-pip`
19-
- `sudo apt-get install python3.12-venv`
20-
- `python3 -m venv azure-cosmosdb-sdk-environment`
18+
- `setup_env.sh`
2119
- `source azure-cosmosdb-sdk-environment/bin/activate`
22-
- `pip install -r dev_requirements.txt`
23-
- `pip install azure-monitor-opentelemetry`
2420
1. Checkout the branch with the changes to test.
2521
1. Install azure-cosmos
2622
- `pip install .`
2723
1. Go to workloads folder
2824
- `cd tests/workloads`
2925
1. Fill out relevant configs in `workload_configs.py`: key, host, etc
30-
1. Install envoy proxy https://www.envoyproxy.io/docs/envoy/latest/start/install
3126
1. Go to envoy folder and generate envoy configuration file using template. Template files are in `envoy/templates` directory. `<account_name>` is your Cosmos DB account name.
3227
- `cd envoy`
3328
- `./generate_envoy_config.sh <template_file_path> <output_envoy_config_file> <account_name> <write_region> <read_region>`

sdk/cosmos/azure-cosmos/tests/workloads/get-database-account-call.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
import os
4-
import sys
54

65
from workload_utils import create_logger
7-
from workload_configs import COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS
8-
9-
sys.path.append(r"./")
6+
from workload_configs import COSMOS_URI, COSMOS_CREDENTIAL, PREFERRED_LOCATIONS
107

118
from azure.cosmos.aio import CosmosClient as AsyncClient
129
import asyncio
@@ -16,7 +13,7 @@
1613

1714

1815
async def run_workload(client_id: str):
19-
async with AsyncClient(COSMOS_URI, COSMOS_KEY, preferred_locations=PREFERRED_LOCATIONS,
16+
async with AsyncClient(COSMOS_URI, COSMOS_CREDENTIAL, preferred_locations=PREFERRED_LOCATIONS,
2017
enable_diagnostics_logging=True, logger=logger,
2118
user_agent=client_id + "-" + datetime.now().strftime(
2219
"%Y%m%d-%H%M%S")) as client:

sdk/cosmos/azure-cosmos/tests/workloads/initial-setup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
import os
4-
import sys
54

65
from azure.cosmos import PartitionKey, ThroughputProperties
7-
from workload_utils import create_logger
6+
from workload_utils import create_logger, create_random_item
87
from workload_configs import COSMOS_URI, COSMOS_KEY, PREFERRED_LOCATIONS, COSMOS_CONTAINER, COSMOS_DATABASE, \
98
NUMBER_OF_LOGICAL_PARTITIONS, PARTITION_KEY, THROUGHPUT
109

11-
sys.path.append(r"./")
12-
1310
from azure.cosmos.aio import CosmosClient as AsyncClient
1411
import asyncio
1512

@@ -18,11 +15,16 @@
1815
async def write_item_concurrently_initial(container, num_upserts):
1916
tasks = []
2017
for i in range(num_upserts):
21-
tasks.append(container.upsert_item({"id": "test-" + str(i), "pk": "pk-" + str(i)}))
18+
item = create_random_item()
19+
item["id"] = "test-" + str(i)
20+
item["pk"] = "pk-" + str(i)
21+
tasks.append(container.upsert_item(item))
2222
await asyncio.gather(*tasks)
2323

2424

2525
async def run_workload(client_id: str):
26+
# Key always needs to be used for the initial setup to create the database and container as aad for control plane
27+
# operations using the dataplane sdk is not supported.
2628
async with AsyncClient(COSMOS_URI, COSMOS_KEY, preferred_locations=PREFERRED_LOCATIONS,
2729
enable_diagnostics_logging=True, logger=logger,
2830
user_agent=str(client_id) + "-" + datetime.now().strftime("%Y%m%d-%H%M%S")) as client:

sdk/cosmos/azure-cosmos/tests/workloads/r_proxy_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
async def run_workload(client_id, client_logger):
1010
session = create_custom_session()
1111
async with AsyncClient(COSMOS_URI,
12-
COSMOS_KEY,
12+
COSMOS_CREDENTIAL,
1313
multiple_write_locations=USE_MULTIPLE_WRITABLE_LOCATIONS,
1414
preferred_locations=PREFERRED_LOCATIONS,
1515
transport=AioHttpTransport(session=session, session_owner=False),

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_proxy_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
async def run_workload(client_id, client_logger):
1212
session = create_custom_session()
1313
async with AsyncClient(COSMOS_URI,
14-
COSMOS_KEY,
14+
COSMOS_CREDENTIAL,
1515
multiple_write_locations=USE_MULTIPLE_WRITABLE_LOCATIONS,
1616
preferred_locations=PREFERRED_LOCATIONS,
1717
transport=AioHttpTransport(session=session, session_owner=False),

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_sync_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def run_workload(client_id, client_logger):
1111
connectionPolicy = documents.ConnectionPolicy()
1212
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
13-
with CosmosClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
13+
with CosmosClient(COSMOS_URI, COSMOS_CREDENTIAL, connection_policy=connectionPolicy,
1414
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
1515
enable_diagnostics_logging=True, logger=client_logger,
1616
user_agent=get_user_agent(client_id)) as client:

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_with_incorrect_client_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
async def run_workload(client_id, client_logger):
1212
connectionPolicy = documents.ConnectionPolicy()
1313
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
14-
client = AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
14+
client = AsyncClient(COSMOS_URI, COSMOS_CREDENTIAL, connection_policy=connectionPolicy,
1515
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
1616
enable_diagnostics_logging=True, logger=client_logger,
1717
user_agent=get_user_agent(client_id))

sdk/cosmos/azure-cosmos/tests/workloads/r_w_q_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
async def run_workload(client_id, client_logger):
1414
connectionPolicy = documents.ConnectionPolicy()
1515
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
16-
async with AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
16+
async with AsyncClient(COSMOS_URI, COSMOS_CREDENTIAL, connection_policy=connectionPolicy,
1717
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
1818
enable_diagnostics_logging=True, logger=client_logger,
1919
user_agent=get_user_agent(client_id)) as client:

sdk/cosmos/azure-cosmos/tests/workloads/r_workload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
async def run_workload(client_id, client_logger):
1212
connectionPolicy = documents.ConnectionPolicy()
1313
connectionPolicy.UseMultipleWriteLocations = USE_MULTIPLE_WRITABLE_LOCATIONS
14-
async with AsyncClient(COSMOS_URI, COSMOS_KEY, connection_policy=connectionPolicy,
14+
async with AsyncClient(COSMOS_URI, COSMOS_CREDENTIAL, connection_policy=connectionPolicy,
1515
preferred_locations=PREFERRED_LOCATIONS, excluded_locations=CLIENT_EXCLUDED_LOCATIONS,
1616
enable_diagnostics_logging=True, logger=client_logger,
1717
user_agent=get_user_agent(client_id)) as client:

sdk/cosmos/azure-cosmos/tests/workloads/run_workloads.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@ fi
66

77
num_runs=$1
88

9+
echo "[Info] Installing azure-cosmos package..."
10+
pip install ../../.
11+
if [ $? -ne 0 ]; then
12+
echo "[Error] Failed to install azure-cosmos. Exiting."
13+
exit 2
14+
fi
15+
echo "[Info] azure-cosmos installed successfully."
16+
917
# Loop over each Python file in the current directory ending with _workload.py
1018
for file in ./*_workload.py; do
1119
for (( i=0; i<num_runs; i++ )); do
1220
python3 "$file" &
21+
# slow start up
22+
sleep 1
1323
done
1424
done
25+
26+
wait
27+
echo "[Info] All workloads started successfully."

0 commit comments

Comments
 (0)