Skip to content

Commit 0a0daa1

Browse files
tvaron3Copilot
andauthored
Change Workloads For Circuit Breaker (#40843)
* change workloads based on feedback * Update sdk/cosmos/azure-cosmos/tests/workloads/dev.md Co-authored-by: Copilot <[email protected]> * Update sdk/cosmos/azure-cosmos/tests/workloads/workload_utils.py Co-authored-by: Copilot <[email protected]> * react to comments --------- Co-authored-by: Copilot <[email protected]>
1 parent 5a5ff63 commit 0a0daa1

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ This directory contains the scale testing workloads for the SDK. The workloads a
33
and scalability of the SDK under various conditions. There are different types of workloads and each will create a log
44
file when run. These logs are named in this format `<file name>-<process id>-<date time>.log`.
55

6-
### Setup VM
6+
### Setup Scale Testing
77
1. Create a VM in Azure with the following configuration:
88
- 8 vCPUs
99
- 32 GB RAM
1010
- Ubuntu
1111
- Accelerated networking
12+
1. Create an Azure App Insights Resource (Optional)
1213
1. Fork and clone this repository
1314
1. Go to azure cosmos folder
1415
- `cd azure-sdk-for-python/sdk/cosmos/azure-cosmos`
@@ -19,6 +20,7 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
1920
- `python3 -m venv azure-cosmosdb-sdk-environment`
2021
- `source azure-cosmosdb-sdk-environment/bin/activate`
2122
- `pip install -r dev_requirements.txt`
23+
- `pip install azure-monitor-opentelemetry`
2224
1. Checkout the branch with the changes to test.
2325
1. Install azure-cosmos
2426
- `pip install .`
@@ -40,3 +42,9 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
4042
### Monitor Run
4143
- `ps -eaf | grep "python3"` to see the running processes
4244
- `tail -f <log_file>` to see the logs in real time
45+
46+
### Close Workloads
47+
- If you want to keep the logs and stop the scripts,
48+
`./shutdown_workloads.sh --no-remove-logs`
49+
- If you want to remove the logs and stop the scripts,
50+
`./shutdown_workloads.sh`

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
3-
import os
43
import sys
54

65
from azure.cosmos import documents
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
#!/bin/bash
22
# cspell:disable
3+
4+
NO_REMOVE_LOGS=false
5+
6+
while [[ "$#" -gt 0 ]]; do
7+
case $1 in
8+
--no-remove-logs)
9+
NO_REMOVE_LOGS=true
10+
;;
11+
*)
12+
echo "Unknown parameter: $1"
13+
exit 1
14+
;;
15+
esac
16+
shift
17+
done
18+
319
# Kill all python3 processes
420
pkill -f "python3 ./r_"
521
pkill -f "python3 ./w_"
622

7-
# Remove all files with .logs in their filename
8-
rm -f *.log*
23+
if [ "$NO_REMOVE_LOGS" = false ]; then
24+
# Remove all files with .log in their filename
25+
rm -f *.log*
26+
# Remove envoy log files
27+
rm envoy/logs/*
28+
fi

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Replace with your Cosmos DB details
4+
import logging
5+
46
PREFERRED_LOCATIONS = []
57
CLIENT_EXCLUDED_LOCATIONS = []
68
REQUEST_EXCLUDED_LOCATIONS = []
@@ -9,6 +11,10 @@
911
COSMOS_KEY = ""
1012
COSMOS_CONTAINER = "scale_cont"
1113
COSMOS_DATABASE = "scale_db"
14+
USER_AGENT_PREFIX = ""
15+
LOG_LEVEL = logging.DEBUG
16+
APP_INSIGHTS_CONNECTION_STRING = ""
17+
CIRCUIT_BREAKER_ENABLED = False
1218
USE_MULTIPLE_WRITABLE_LOCATIONS = False
1319
CONCURRENT_REQUESTS = 100
1420
CONCURRENT_QUERIES = 2

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# The MIT License (MIT)
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
import asyncio
4-
import logging
54
import os
65
import random
76
from datetime import datetime
87
from logging.handlers import RotatingFileHandler
9-
from workload_configs import NUMBER_OF_LOGICAL_PARTITIONS, PARTITION_KEY
8+
9+
from azure.monitor.opentelemetry import configure_azure_monitor
10+
from workload_configs import *
1011

1112
_NOISY_ERRORS = set([404, 409, 412])
1213
_NOISY_SUB_STATUS_CODES = set([0, None])
1314
_REQUIRED_ATTRIBUTES = ["resource_type", "verb", "operation_type", "status_code", "sub_status_code", "duration"]
1415

1516
def get_user_agent(client_id):
16-
return str(client_id) + "-" + datetime.now().strftime("%Y%m%d-%H%M%S")
17+
prefix = USER_AGENT_PREFIX + "-" if USER_AGENT_PREFIX else ""
18+
return prefix + str(client_id) + "-" + datetime.now().strftime("%Y%m%d-%H%M%S")
1719

1820
def get_random_item():
1921
random_int = random.randint(0, NUMBER_OF_LOGICAL_PARTITIONS)
@@ -103,15 +105,21 @@ async def perform_query_concurrently(container, excluded_locations):
103105
items = [item async for item in results]
104106

105107
def create_logger(file_name):
106-
logger = logging.getLogger('azure.cosmos')
108+
os.environ["AZURE_COSMOS_ENABLE_CIRCUIT_BREAKER"] = str(CIRCUIT_BREAKER_ENABLED)
109+
logger = logging.getLogger()
110+
if APP_INSIGHTS_CONNECTION_STRING:
111+
configure_azure_monitor(
112+
logger_name="azure.cosmos",
113+
connection_string=APP_INSIGHTS_CONNECTION_STRING,
114+
)
107115
prefix = os.path.splitext(file_name)[0] + "-" + str(os.getpid())
108116
# Create a rotating file handler
109117
handler = RotatingFileHandler(
110-
"log-" + prefix + "-" + datetime.now().strftime("%Y%m%d-%H%M%S") + '.log',
118+
"log-" + get_user_agent(prefix) + '.log',
111119
maxBytes=1024 * 1024 * 10, # 10 mb
112-
backupCount=3
120+
backupCount=2
113121
)
114-
logger.setLevel(logging.DEBUG)
122+
logger.setLevel(LOG_LEVEL)
115123
# create filters for the logger handler to reduce the noise
116124
workload_logger_filter = WorkloadLoggerFilter()
117125
handler.addFilter(workload_logger_filter)

0 commit comments

Comments
 (0)