Skip to content

Commit

Permalink
Add test and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingosse committed Oct 29, 2024
1 parent 78f98fd commit faf6994
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,22 @@ Returns the tracer-flares in the following json format:

If there was an error parsing the tracer-flare form, that will be recorded under `error`.

### /test/settings (POST)

Allows to change some settings on the fly.
This endpoint takes a POST request with a json content listing the keys and values to apply.

```json
{ 'key': value }
```

Supported keys:
- `trace_request_delay`: sets a delay to apply to trace and telemetry requests

```
curl -X POST 'http://0.0.0.0:8126/test/settings' -d '{ "trace_request_delay": 5 }'
```

## Development

### Prerequisites
Expand Down
2 changes: 1 addition & 1 deletion ddapm_test_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ async def handle_settings(self, request: Request) -> web.Response:
# First pass to validate the data
for key in data:
if key not in request.app:
return web.HTTPUnprocessableEntity(text=f"Unknown key: {key}")
return web.HTTPUnprocessableEntity(text=f"Unknown key: '{key}'")

# Second pass to apply the config
for key in data:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,37 @@ def test_uds(tmp_path, available_port):
pass
else:
raise Exception("Test agent failed to start")


async def test_post_known_settings(
agent
):
resp = await agent.post(
"/test/settings",
data='{ "trace_request_delay": 5 }',
)

assert resp.status == 202, await resp.text()
assert agent.app["trace_request_delay"] == 5

resp = await agent.post(
"/test/settings",
data='{ "trace_request_delay": 0 }',
)

assert resp.status == 202, await resp.text()
assert agent.app["trace_request_delay"] == 0


async def test_post_unknown_settings(
agent,
):
resp = await agent.post(
"/test/settings",
data='{ "dummy_setting": 5 }',
)

assert resp.status == 422
text = await resp.text()
assert text == "Unknown key: 'dummy_setting'"
assert 'dummy_setting' not in agent.app

0 comments on commit faf6994

Please sign in to comment.