Skip to content

env variable for cache disable via WAVEFRONT_CACHE_ENABLED#245

Open
rootflo-hardik wants to merge 2 commits into
developfrom
CU-86d2ajrn6-Env-to-disable-cache-in-wavefront
Open

env variable for cache disable via WAVEFRONT_CACHE_ENABLED#245
rootflo-hardik wants to merge 2 commits into
developfrom
CU-86d2ajrn6-Env-to-disable-cache-in-wavefront

Conversation

@rootflo-hardik
Copy link
Copy Markdown
Contributor

@rootflo-hardik rootflo-hardik commented Mar 17, 2026

Summary by CodeRabbit

  • New Features

    • Cache can be toggled on/off via a configuration flag; when off, cache operations become no-ops.
    • Improved logging surfaces cache disabled state and connectivity.
  • Bug Fixes

    • Prevents background subscription/listener setup when the cache is unavailable to avoid unnecessary threads or operations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cff3fea6-de80-4615-b703-d049f5299fc0

📥 Commits

Reviewing files that changed from the base of the PR and between eca6337 and 190ac05.

📒 Files selected for processing (1)
  • wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py

📝 Walkthrough

Walkthrough

Adds a WAVEFRONT_CACHE_ENABLED flag to short-circuit cache methods and avoid Redis operations when disabled, and guards pubsub subscription in channels.py to return early if pubsub is unavailable.

Changes

Cache Manager Feature Flag

Layer / File(s) Summary
Initialization and flag
wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py
Introduces self.cache_enabled from WAVEFRONT_CACHE_ENABLED and logs when cache get/set operations are disabled during init.
Cache operation guards
wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py
Adds early-return guards: add returns False, get_str/get_int return defaults, remove returns False, invalidate_query returns 0 when caching is disabled.
Publish/subscribe conditional handling
wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py, wavefront/server/apps/floware/floware/channels.py
Avoid Redis publish/subscribe actions when caching is disabled; channels now log and return early if pubsub is None, preventing listener/thread setup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A toggle in the burrowed code,
When off, the noisy pipes stay low,
Guards hop in to halt the race,
Pubsub sleeps, no threads to chase,
Logs nibble crumbs of what they know.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding an environment variable (WAVEFRONT_CACHE_ENABLED) to disable the cache system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch CU-86d2ajrn6-Env-to-disable-cache-in-wavefront

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py (1)

35-37: Validate WAVEFRONT_CACHE_ENABLED instead of treating every unknown value as false.

A typo like ture or a whitespace-padded value will silently disable Redis and the listener path. It is safer to normalize and reject invalid inputs explicitly.

Proposed change
-        self.cache_enabled = (
-            os.getenv('WAVEFRONT_CACHE_ENABLED', 'true').lower() == 'true'
-        )
+        raw_cache_enabled = os.getenv(
+            'WAVEFRONT_CACHE_ENABLED', 'true'
+        ).strip().lower()
+        if raw_cache_enabled not in {'true', 'false'}:
+            raise ValueError(
+                'WAVEFRONT_CACHE_ENABLED must be either "true" or "false"'
+            )
+        self.cache_enabled = raw_cache_enabled == 'true'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py`
around lines 35 - 37, The current assignment to cache_enabled silently treats
any non-exact 'true' as false; change it to normalize and validate the
environment value by calling os.getenv('WAVEFRONT_CACHE_ENABLED',
'true').strip().lower(), then if the normalized value is 'true' or 'false' set
self.cache_enabled = (value == 'true'), otherwise log an explicit warning or
raise a ValueError indicating an invalid WAVEFRONT_CACHE_ENABLED value so typos
like 'ture' or whitespace-padded strings are not silently accepted; update the
code that sets cache_enabled to perform this validation and include the variable
name cache_enabled in the log/error message.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py`:
- Around line 200-202: The subscribe() and publish() docstrings currently omit
the behavior when cache_enabled is False (publish returning 0 and subscribe
returning None), so update both docstrings and accompanying type hints to
document and reflect this contract: in cache_manager.py, amend the publish()
docstring to state that when self.cache_enabled is False it is a no-op and
returns 0, and amend the subscribe() docstring and signature to indicate it may
return None (Optional[PubSub]) when cache is disabled; reference the
cache_enabled flag, REDIS_API_SERVICE_UPDATES_CHANNEL, and the
subscribe()/publish() methods so callers (e.g., floware/channels.py) know to
check for None or a 0 result.

---

Nitpick comments:
In
`@wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py`:
- Around line 35-37: The current assignment to cache_enabled silently treats any
non-exact 'true' as false; change it to normalize and validate the environment
value by calling os.getenv('WAVEFRONT_CACHE_ENABLED', 'true').strip().lower(),
then if the normalized value is 'true' or 'false' set self.cache_enabled =
(value == 'true'), otherwise log an explicit warning or raise a ValueError
indicating an invalid WAVEFRONT_CACHE_ENABLED value so typos like 'ture' or
whitespace-padded strings are not silently accepted; update the code that sets
cache_enabled to perform this validation and include the variable name
cache_enabled in the log/error message.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a8f63864-056f-4466-a02e-11ee029d2080

📥 Commits

Reviewing files that changed from the base of the PR and between 6baf88a and eca6337.

📒 Files selected for processing (2)
  • wavefront/server/apps/floware/floware/channels.py
  • wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py

Comment on lines +200 to +202
if not self.cache_enabled:
return 0

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== CacheManager publish/subscribe call sites ==="
rg -n -C3 '\bcache_manager\.(publish|subscribe)\s*\(' wavefront

echo
echo "=== Redis API update channel usage ==="
rg -n -C3 'REDIS_API_SERVICE_UPDATES_CHANNEL|process_message\s*\(' wavefront

echo
echo "=== CommonCache / subscribe contract ==="
rg -n -C3 '\bclass CommonCache\b|\bdef subscribe\s*\(' wavefront

echo
echo "=== Publisher / processor sources ==="
fd 'api_change_publisher\.py$' wavefront -x sed -n '1,220p' {}
fd 'api_change_processor\.py$' wavefront -x sed -n '1,260p' {}

Repository: rootflo/wavefront

Length of output: 11393


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Full publish and subscribe methods ==="
sed -n '195,250p' wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py

echo
echo "=== Check return type hints for subscribe method ==="
rg -n 'def subscribe' wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py -A 50 | head -60

echo
echo "=== Any other usages of cache_manager.publish/subscribe beyond API updates ==="
rg -n '\.publish\(|\.subscribe\(' wavefront --type py | grep -v 'test' | grep -v '.pyc'

Repository: rootflo/wavefront

Length of output: 5441


Update subscribe() and publish() docstrings to document behavior when cache is disabled.

The cache_enabled flag at lines 200–202 and 211–237 disables more than key/value caching. The REDIS_API_SERVICE_UPDATES_CHANNEL carries API service updates (create/update/delete operations that reload/remove services in the proxy router), which is critical infrastructure—not cache invalidation.

  • publish() becomes a no-op (returns 0) when cache is off, silencing service updates across the system.
  • subscribe() returns None instead of a PubSub object, but the docstring only documents the normal case and omits this behavior. Callers must check for None explicitly (as floware/channels.py line 22 does).

Either document the optional None return in both methods' docstrings, or reconsider whether disabling pub/sub is the right behavior when cache is disabled. If the current design is intentional, make the contract explicit in the type hints and docstrings.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@wavefront/server/modules/db_repo_module/db_repo_module/cache/cache_manager.py`
around lines 200 - 202, The subscribe() and publish() docstrings currently omit
the behavior when cache_enabled is False (publish returning 0 and subscribe
returning None), so update both docstrings and accompanying type hints to
document and reflect this contract: in cache_manager.py, amend the publish()
docstring to state that when self.cache_enabled is False it is a no-op and
returns 0, and amend the subscribe() docstring and signature to indicate it may
return None (Optional[PubSub]) when cache is disabled; reference the
cache_enabled flag, REDIS_API_SERVICE_UPDATES_CHANNEL, and the
subscribe()/publish() methods so callers (e.g., floware/channels.py) know to
check for None or a 0 result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootflo-hardik Lets not disable publish and subscribe

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment on lines +200 to +202
if not self.cache_enabled:
return 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootflo-hardik Lets not disable publish and subscribe

socket_timeout=socket_timeout,
socket_keepalive=socket_keepalive,
pool_size=pool_size,
self.cache_enabled = (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DId you test this? Is it working fine with cache disabled ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants