Skip to content

Commit

Permalink
Allow setting Judoscale log level using an env var
Browse files Browse the repository at this point in the history
You can now set Judoscale's log level without a code change using the `JUDOSCALE_LOG_LEVEL` env var. This is useful when troubleshooting your Judoscale adapter behavior.
  • Loading branch information
adamlogic committed Sep 19, 2023
1 parent 90f0027 commit 996fe93
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ JUDOSCALE = {

> :warning: **NOTE:** Django-RQ enables configuring RQ such that different queues and workers use _different_ Redis instances. Judoscale currently only supports connecting to and monitoring queue latency on a single Redis instance.

## Debugging & troubleshooting

If Judoscale is not recognizing your adapter installation or if you're not seeing expected metrics in Judoscale, you'll want to check the logging output. Here's how you'd do that on Heroku.

First, enable debug logging:

```sh
heroku config:set JUDOSCALE_LOG_LEVEL=debug
```

Then, tail your logs while your app initializes:

```sh
heroku logs --tail | grep Judoscale
```

You should see Judoscale collecting and reporting metrics every 10 seconds from every running process. If the issue is not clear from the logs, email help@judoscale.com for support. Please include any logging you've collected and any other behavior you've observed.

## Development

This repo includes a `sample-apps` directory containing apps you can run locally. These apps use the `judoscale` adapter, but they override `API_BASE_URL` so they're not connected to the real Judoscale API. Instead, they post API requests to https://requestinspector.com so you can observe the API behavior.
Expand Down
6 changes: 5 additions & 1 deletion judoscale/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def __init__(
API_BASE_URL=api_base_url,
)

for key in {"LOG_LEVEL", "RQ", "CELERY"}:
for key in {"RQ", "CELERY"}:
if key in env:
initialdata[key] = env[key]

initialdata["LOG_LEVEL"] = env.get(
"JUDOSCALE_LOG_LEVEL", env.get("LOG_LEVEL", initialdata["LOG_LEVEL"])
)

super().__init__(initialdata)
self._prepare_logging()

Expand Down
2 changes: 1 addition & 1 deletion sample-apps/django_sample/bin/heroku
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

heroku local --procfile Procfile.heroku
JUDOSCALE_LOG_LEVEL=debug heroku local --procfile Procfile.heroku
2 changes: 1 addition & 1 deletion sample-apps/django_sample/bin/render
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

heroku local --procfile Procfile.render
JUDOSCALE_LOG_LEVEL=debug heroku local --procfile Procfile.render
2 changes: 1 addition & 1 deletion sample-apps/django_sample/django_sample/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# This sample app is intended to be run locally, so Judoscale API requests are
# sent to a mock endpoint.
"API_BASE_URL": "https://requestinspector.com/inspect/judoscale-django",
"LOG_LEVEL": "DEBUG",
# "LOG_LEVEL": "DEBUG",
"REPORT_INTERVAL_SECONDS": 15,
}

Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def test_on_ecs(self):
assert config["LOG_LEVEL"] == "WARN"
assert config["API_BASE_URL"] == "https://adapter.judoscale.com/api/srv-123"

def test_judoscale_log_level_env(self):
fake_env = {
"DYNO": "web.1",
"LOG_LEVEL": "INFO",
"JUDOSCALE_LOG_LEVEL": "WARN",
"JUDOSCALE_URL": "https://api.example.com",
}
config = Config.for_heroku(fake_env)

assert config["RUNTIME_CONTAINER"] == "web.1"
assert config["LOG_LEVEL"] == "WARN"
assert config["API_BASE_URL"] == "https://api.example.com"

def test_is_enabled(self):
config = Config(None, "", {})
assert not config.is_enabled
Expand Down

0 comments on commit 996fe93

Please sign in to comment.