Skip to content

Commit 01fb5e7

Browse files
authored
Observability: implement tracing for http requests (#329)
* Corrections on test setup and tests * Support for env vars: RUNPOD_API_BASE_URL & RUNPOD_ENDPOINT_BASE_URL * Added TRACE level logging (X-Request-ID=job_id for tracing) * Introducing runpod.http_client (async|sync) + tracer * In order to trace async calls, any asyncio.ClientSession is now using AsyncClientSession * In order to trace sync calls, any requests.Session use is now using SyncClientSession * FibonacciRetry for a less aggressive retry strategy * Workaround: cryptography.utils.CryptographyDeprecationWarning `cryptography.utils.CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0` See paramiko/paramiko#2419
1 parent 335fee5 commit 01fb5e7

33 files changed

Lines changed: 751 additions & 132 deletions

.github/workflows/CI-pylint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Install Dependencies
3232
run: |
3333
python -m pip install --upgrade pip
34-
pip install .[test]
34+
pip install '.[test]'
3535
3636
- name: Pylint Source
37-
run: pylint --ignore-paths='build/*' --ignore='_version.py' $(find . -type f -name '*.py') \
37+
run: pylint $(git ls-files '*.py')

.github/workflows/CI-pytests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install Dependencies
3131
run: |
3232
python -m pip install --upgrade pip
33-
pip install .[test]
33+
pip install '.[test]'
3434
3535
- name: Run Tests
36-
run: pytest --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=100 -W error -p no:cacheprovider -p no:unraisableexception
36+
run: pytest --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=98 -W error -p no:cacheprovider -p no:unraisableexception

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Here is a quick guide on how to contribute code to this project:
3535
6. Run tests to ensure that your changes do not break any existing functionality. You can run tests using the following command:
3636

3737
```bash
38-
pip install .[test]
38+
pip install '.[test]'
3939
pytest
4040
```
4141

examples/endpoints/asyncio_job_request.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"""
44

55
import asyncio
6-
import aiohttp
76

87
import runpod
9-
from runpod import AsyncioEndpoint, AsyncioJob
8+
from runpod import http_client, AsyncioEndpoint, AsyncioJob
109

1110
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # For Windows Users
1211

@@ -17,7 +16,7 @@ async def main():
1716
'''
1817
Function to run the example.
1918
'''
20-
async with aiohttp.ClientSession() as session:
19+
async with http_client.AsyncClientSession() as session:
2120
# Invoke API
2221
payload = {}
2322
endpoint = AsyncioEndpoint("ENDPOINT_ID", session)

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ runpod = "runpod.cli.entry:runpod_cli"
5454
test = [
5555
"asynctest",
5656
"nest_asyncio",
57-
"pylint",
58-
"pytest",
57+
"pylint==3.2.5",
58+
"pytest-asyncio",
5959
"pytest-cov",
6060
"pytest-timeout",
61-
"pytest-asyncio",
61+
"pytest-watch",
62+
"pytest",
6263
]
6364

6465
[build-system]

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = --durations=10 --cov-config=.coveragerc --timeout=120 --timeout_method=thread --cov=runpod --cov-report=xml --cov-report=term-missing --cov-fail-under=98 -W error -p no:cacheprovider -p no:unraisableexception
3+
python_files = tests.py test_*.py *_test.py
4+
norecursedirs = venv *.egg-info .git build

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ backoff >= 2.2.1
55
boto3 >= 1.26.165
66
click >= 8.1.7
77
colorama >= 0.2.5, < 0.4.7
8+
cryptography < 43.0.0
89
fastapi[all] >= 0.94.0
910
paramiko >= 3.3.1
1011
prettytable >= 3.9.0

runpod/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
else:
4343
api_key = None # pylint: disable=invalid-name
4444

45-
api_url_base = "https://api.runpod.io" # pylint: disable=invalid-name
46-
47-
endpoint_url_base = "https://api.runpod.ai/v2" # pylint: disable=invalid-name
45+
endpoint_url_base = os.environ.get("RUNPOD_ENDPOINT_BASE_URL", "https://api.runpod.ai/v2") # pylint: disable=invalid-name
4846

4947

5048
# --------------------------- Force Logging Levels --------------------------- #

runpod/api/graphql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import json
6+
import os
67
from typing import Any, Dict
78

89
import requests
@@ -18,7 +19,8 @@ def run_graphql_query(query: str) -> Dict[str, Any]:
1819
Run a GraphQL query
1920
'''
2021
from runpod import api_key # pylint: disable=import-outside-toplevel, cyclic-import
21-
url = f"https://api.runpod.io/graphql?api_key={api_key}"
22+
api_url_base = os.environ.get("RUNPOD_API_BASE_URL", "https://api.runpod.io")
23+
url = f"{api_url_base}/graphql?api_key={api_key}"
2224

2325
headers = {
2426
"Content-Type": "application/json",

runpod/cli/groups/pod/commands.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,23 @@ def create_new_pod(name, image, gpu_type, gpu_count, support_public_ip): # pylin
3333
'''
3434
Creates a pod.
3535
'''
36+
kwargs = {
37+
"gpu_count": gpu_count,
38+
"support_public_ip": support_public_ip,
39+
}
40+
3641
if not name:
3742
name = click.prompt('Enter pod name', default='RunPod-CLI-Pod')
3843

3944
quick_launch = click.confirm('Would you like to launch default pod?', abort=True)
4045
if quick_launch:
4146
image = 'runpod/base:0.0.0'
4247
gpu_type = 'NVIDIA GeForce RTX 3090'
43-
ports ='22/tcp'
48+
kwargs["ports"] ='22/tcp'
4449

4550
click.echo('Launching default pod...')
4651

47-
new_pod = create_pod(name, image, gpu_type,
48-
gpu_count=gpu_count, support_public_ip=support_public_ip, ports=ports)
52+
new_pod = create_pod(name, image, gpu_type, **kwargs)
4953

5054
click.echo(f'Pod {new_pod["id"]} has been created.')
5155

0 commit comments

Comments
 (0)