Skip to content

Commit 752f3cd

Browse files
authored
Envoy Workload Improvements (#42335)
* improve envoy workloads * react to comments * adding markdown file * fix cspell
1 parent 2b12567 commit 752f3cd

16 files changed

+686
-525
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# The MIT License (MIT)
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
import asyncio
4+
from typing import Any
5+
6+
from aiohttp import TCPConnector, ClientRequest, tracing, ClientTimeout, ClientConnectorError, client_proto
7+
8+
9+
class ProxiedTCPConnector(TCPConnector):
10+
"""
11+
A TCP connector that proxies all connections through a specified host and port.
12+
13+
This class extends TrackedTCPConnector to override connection behavior,
14+
routing all traffic through a specified proxy server using non-encrypted http.
15+
"""
16+
17+
def __init__(
18+
self,
19+
*,
20+
proxy_host: str,
21+
proxy_port: int,
22+
**kwargs: Any,
23+
) -> None:
24+
"""
25+
Initialize the ProxiedTCPConnector.
26+
27+
Args:
28+
proxy_host (str): The hostname of the proxy server.
29+
proxy_port (int): The port number of the proxy server.
30+
**kwargs: Additional keyword arguments passed to the base TCPConnector.
31+
"""
32+
super().__init__(**kwargs)
33+
self.__proxy_host = proxy_host
34+
self.__proxy_port = proxy_port
35+
36+
async def _create_direct_connection(
37+
self,
38+
req: ClientRequest,
39+
traces: list[tracing.Trace],
40+
timeout: ClientTimeout,
41+
*,
42+
client_error: type[Exception] = ClientConnectorError,
43+
) -> tuple[asyncio.Transport, client_proto.ResponseHandler]:
44+
"""Override host, port, and schema to use proxy"""
45+
req.url = (
46+
req.url.with_host(self.__proxy_host).with_port(self.__proxy_port).with_scheme("http")
47+
)
48+
return await super()._create_direct_connection(
49+
req,
50+
traces,
51+
timeout,
52+
client_error=client_error,
53+
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
3030
1. Install envoy proxy https://www.envoyproxy.io/docs/envoy/latest/start/install
3131
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.
3232
- `cd envoy`
33-
- `./generate_envoy_config.sh <template_file_path> <output_envoy_config_file> <account_name>`
33+
- `./generate_envoy_config.sh <template_file_path> <output_envoy_config_file> <account_name> <write_region> <read_region>`
3434
1. Start envoy using the generated configuration file
3535
- `mkdir logs`
3636
- `envoy -c <envoy_config_file>.yaml --log-level debug --log-path logs/debug.txt`
@@ -45,6 +45,6 @@ file when run. These logs are named in this format `<file name>-<process id>-<da
4545

4646
### Close Workloads
4747
- If you want to keep the logs and stop the scripts,
48-
`./shutdown_workloads.sh --no-remove-logs`
48+
`./shutdown_workloads.sh --do-not-remove-logs`
4949
- If you want to remove the logs and stop the scripts,
5050
`./shutdown_workloads.sh`

0 commit comments

Comments
 (0)