Skip to content

Commit

Permalink
fix otel load test
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan-jaff committed Sep 12, 2024
1 parent b80f27d commit 8870648
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions tests/load_tests/test_otel_load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,37 @@


def test_otel_logging_async():
# this tests time added to make otel logging calls, vs just acompletion calls
try:

os.environ["OTEL_EXPORTER"] = "otlp_http"
os.environ["OTEL_ENDPOINT"] = (
"https://exampleopenaiendpoint-production.up.railway.app/traces"
)
os.environ["OTEL_HEADERS"] = "Authorization=K0BSwd"

# Make 5 calls with an empty success_callback
litellm.success_callback = []
litellm.callbacks = []
litellm._async_success_callback = []
litellm._async_failure_callback = []
litellm._async_failure_callback = []
litellm.failure_callback = []
start_time_empty_callback = asyncio.run(make_async_calls())
print("done with no callback test")

print("starting otel test")
# Make 5 calls with success_callback set to "otel"
litellm.callbacks = ["otel"]
start_time_otel = asyncio.run(make_async_calls())
print("done with otel test")

# Compare the time for both scenarios
print(f"Time taken with success_callback='otel': {start_time_otel}")
print(f"Time taken with empty success_callback: {start_time_empty_callback}")

# Calculate the percentage difference
percentage_diff = (
abs(start_time_otel - start_time_empty_callback)
/ start_time_empty_callback
* 100
)
def single_run():
litellm.callbacks = []
start_time_empty = asyncio.run(make_async_calls())
print(f"Time with empty callback: {start_time_empty}")

# Assert that the difference is not more than 10%
assert (
percentage_diff < 10
), f"Performance difference of {percentage_diff:.2f}% exceeds 10% threshold"
litellm.callbacks = ["otel"]
start_time_otel = asyncio.run(make_async_calls())
print(f"Time with otel callback: {start_time_otel}")

percent_diff = (
abs(start_time_otel - start_time_empty) / start_time_empty * 100
)
print(f"Run performance difference: {percent_diff:.2f}%")
return percent_diff

print(f"Performance difference: {percentage_diff:.2f}%")
percent_diffs = [single_run() for _ in range(3)]
avg_percent_diff = sum(percent_diffs) / len(percent_diffs)

print(f"Percentage differences: {percent_diffs}")
print(f"Average performance difference: {avg_percent_diff:.2f}%")

assert (
avg_percent_diff < 10
), f"Average performance difference of {avg_percent_diff:.2f}% exceeds 10% threshold"

except litellm.Timeout as e:
pass
Expand Down

0 comments on commit 8870648

Please sign in to comment.