Added CSC metrics export#3911
Merged
vladvildanov merged 6 commits intofeat/observabilityfrom Jan 20, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds Client-Side Caching (CSC) metrics export functionality to redis-py, enabling observability for cache operations including cache hits, misses, evictions, and network bytes saved.
Changes:
- Introduced CSC metric instruments (requests, evictions, network_saved, items gauge) and event-driven observability
- Added CacheProxy wrapper to intercept cache operations and emit observability events
- Moved cache eviction logic from DefaultCache to CacheProxy to enable event emission on evictions
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| redis/cache.py | Added CacheProxy wrapper class to intercept cache operations; moved eviction logic from DefaultCache.set() to CacheProxy.set(); updated CacheFactory to wrap caches in CacheProxy |
| redis/connection.py | Added db and _event_dispatcher attributes to CacheProxyConnection; dispatched OnCacheHitEvent, OnCacheMissEvent, and OnCacheEvictionEvent at appropriate points; wrapped cache_factory output in CacheProxy |
| redis/event.py | Added CSC event classes (OnCacheHitEvent, OnCacheMissEvent, OnCacheInitialisationEvent, OnCacheEvictionEvent) and corresponding listener classes; registered CSC listeners in EventDispatcher |
| redis/observability/attributes.py | Added CSCResult and CSCReason enums; added REDIS_CLIENT_CSC_RESULT and REDIS_CLIENT_CSC_REASON constants; added build_csc_attributes() method |
| redis/observability/metrics.py | Added CSC metric initialization (_init_csc_metrics); added CSC recording methods (record_csc_request, record_csc_eviction, record_csc_network_saved, init_csc_items) |
| redis/observability/recorder.py | Added public recorder functions for CSC metrics (record_csc_request, init_csc_items, record_csc_eviction, record_csc_network_saved) |
| tests/test_cache.py | Added TestUnitCacheProxy test class with comprehensive tests for CacheProxy functionality; removed test_set_evict_lru_cache_key_on_reaching_max_size |
| tests/test_connection.py | Added db and _event_dispatcher mock attributes to test fixtures; added tests for cache hit/miss event emission |
Comments suppressed due to low confidence (1)
redis/connection.py:2567
- Inconsistent cache handling: when cache_factory is used (line 2563), the cache is wrapped in CacheProxy, but when a cache is provided directly via the cache parameter (line 2560), it's used as-is without wrapping. This means directly provided caches won't emit CSC observability events (OnCacheInitialisationEvent, OnCacheEvictionEvent). Either document this difference or ensure both paths result in wrapped caches for consistency.
cache = self._connection_kwargs.get("cache")
if cache is not None:
if not isinstance(cache, CacheInterface):
raise ValueError("Cache must implement CacheInterface")
self.cache = cache
else:
if self._cache_factory is not None:
self.cache = CacheProxy(self._cache_factory.get_cache())
else:
self.cache = CacheFactory(
self._connection_kwargs.get("cache_config")
).get_cache()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Base automatically changed from
vv-connection-adv-metrics
to
feat/observability
January 19, 2026 08:58
vladvildanov
added a commit
that referenced
this pull request
Feb 16, 2026
* Added intrastructure and integration point with OTel (#3864) * Added intrastructure and integration point with OTel * Added check for enabled metric groups * Applied comments * Added export of operation duration metric (#3881) * Added stadalone client metrics export * Added support for cluster client * Removed unused dispatchers and test * Added export of resiliency metrics (#3888) * Added stadalone client metrics export * Added support for cluster client * Added error metric export on fail commands for standalone client * Removed unused dispatchers and test * Added on error metrics export for cluster * Added export of maint notification count metric * Apply comments * Remove redundant Union * Added export of connection basic metrics (#3891) * Added export of connection basic metrics * Added new error category attribute * Update tests/test_observability/test_recorder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/test_observability/test_recorder.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply comments * Applied comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Added pub/sub and stream lag metrics export (#3898) * Added export of connection basic metrics * Added new error category attribute * Added pub/sub and stream lag metrics export * Added metric export form XREAD * Update redis/client.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/event.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Applied comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Added OTel benchmark test (#3903) * Added export of connection basic metrics * Added new error category attribute * Added pub/sub and stream lag metrics export * Added metric export form XREAD * Added benchmark tests * Added error output * Added env variable for otel host * Fixed endpoint * Added iterations and results averaging * Use unsecured gRPC * Added --with-command-metrics argument * Removed incorrect identation * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update benchmarks/otel_benchmark.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Added export of connection advanced metrics (#3910) * Added export of connection advanced metrics * Update tests/test_connection_pool.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/observability/metrics.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Refactored kwargs instead of args --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Added CSC metrics export (#3911) * Added export of connection advanced metrics * Added CSC metrics export * Revert changes * Added observable gauge registry and refactored observables metric export * Fixed case with trackin non-cachable cache tracking * Added memory and CPU usage (#3933) * Added full benchmark tests + fixes * Added Memory and CPU usage calculation * Removed events dispatching overhead, refactored metrics attributes (#3934) * Removed events dispatching overhead, refactored metrics attributes * Fixed incorrect retry attempts, changed indexes to named parameters * Fixed issue with connection attribute and metric recording * Added async recorders and registry (#3950) * Added async recorders and registry * Removed async registry * Added more coverage * Added bucket override configuration (#3952) * Added async recorders and registry * Added bucket override configuration * Removed async registry * Added more coverage * Fixed version constraints, removed ubused imports * Moved module desription on top of file * Remove async instrumentations (#3953) * Fix tests and codestyle * Fixed missing parameters * Fixed tests * Fixed tests * Fixed tests * Marked argument as unused * Fixed tests * Added missing metric export * Fixes units and pool name attribute Signed-off-by: Elena Kolevska <elena@kolevska.com> * Updated test for pool name attribute Signed-off-by: Elena Kolevska <elena@kolevska.com> * Updates more tests Signed-off-by: Elena Kolevska <elena@kolevska.com> * Linter Signed-off-by: Elena Kolevska <elena@kolevska.com> * Added try...except blocks for recorder functions * Added documentation * Updated wordlist * Update redis/cluster.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/connection.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update redis/connection.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update pyproject.toml Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com> * Codestyle fixes * Fixed metric export * Fixed assertions * Added geo failover metric export * Codestyle fixes --------- Signed-off-by: Elena Kolevska <elena@kolevska.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Elena Kolevska <elena@kolevska.com> Co-authored-by: Elena Kolevska <elena-kolevska@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of change
Please provide a description of the change here.
Pull Request check-list
Please make sure to review and check all of these items:
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.