Skip to content

Commit

Permalink
add oltp from locust
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Hellegouarch <[email protected]>
  • Loading branch information
Lawouach committed Aug 3, 2023
1 parent e4e0f1d commit f8c97bc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## [Unreleased][]

[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-reliably/compare/0.60.0...HEAD
[Unreleased]: https://github.com/chaostoolkit-incubator/chaostoolkit-reliably/compare/0.61.0...HEAD

## [0.61.0][]

[0.61.0]: https://github.com/chaostoolkit-incubator/chaostoolkit-reliably/compare/0.60.0...0.61.0

### Added

* OLTP support in the load test

## [0.60.0][]

Expand Down
12 changes: 12 additions & 0 deletions chaosreliably/activities/load/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def inject_gradual_traffic_into_endpoint(
vu_per_second_rate: int = 1,
test_duration: int = 30,
results_json_filepath: Optional[str] = None,
enable_opentracing: bool = False,
configuration: Configuration = None,
secrets: Secrets = None,
) -> Dict[str, Any]:
Expand Down Expand Up @@ -65,6 +66,17 @@ def inject_gradual_traffic_into_endpoint(
if test_bearer_token:
env["RELIABLY_LOCUST_ENDPOINT_TOKEN"] = test_bearer_token

if enable_opentracing:
c = configuration
env["RELIABLY_LOCUST_ENABLE_OLTP"] = "true"
env["OTEL_VENDOR"] = c.get("otel_vendor", os.getenv("OTEL_VENDOR"))
env["CHAOSTOOLKIT_OTEL_GCP_SA"] = c.get(
"otel_gcp_service_account", os.getenv("CHAOSTOOLKIT_OTEL_GCP_SA")
)
env["CHAOSTOOLKIT_OTEL_GCP_PROJECT_ID"] = c.get(
"otel_gcp_project_id", os.getenv("CHAOSTOOLKIT_OTEL_GCP_PROJECT_ID")
)

results = {}

with tempfile.TemporaryDirectory() as d:
Expand Down
29 changes: 29 additions & 0 deletions chaosreliably/activities/load/scripts/step_load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

from locust import HttpUser, LoadTestShape, TaskSet, between, task

try:
# these will be available when `chaostoolkit-opentracing` is also
# installed
from chaosopentracing import oltp

HAS_OLTP = True
except ImportError:
HAS_OLTP = False


class UserTasks(TaskSet):
@task
Expand Down Expand Up @@ -37,3 +46,23 @@ def tick(self) -> Optional[Any]:

current_step = math.floor(run_time / self.step_time) + 1
return (current_step * self.step_load, self.spawn_rate)


def initialize_otel_tracing() -> None:
enable_oltp = os.getenv("RELIABLY_LOCUST_ENABLE_OLTP")
if not enable_oltp:
return

if enable_oltp.lower() not in (
"1",
"t",
"true",
):
return

oltp.configure_traces(configuration={})
oltp.configure_instrumentations(trace_request=True, trace_urllib3=True)


if HAS_OLTP:
initialize_otel_tracing()
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ ignore_missing_imports = True

[mypy-importlib.metadata]
ignore_missing_imports = True

[mypy-chaosopentracing.*]
ignore_missing_imports = True

0 comments on commit f8c97bc

Please sign in to comment.