Skip to content

Conversation

@samikshya-db
Copy link
Collaborator

Summary

Implement Phase 2 (Per-Host Management - Part 1) of telemetry for the Go driver: feature flag cache with reference counting to prevent rate limiting.

Changes

  • Add featureFlagCache struct with singleton pattern for global cache management
  • Implement featureFlagContext struct with per-host state (enabled flag, lastFetched, refCount)
  • Add getOrCreateContext() to increment reference count when connections open
  • Add releaseContext() to decrement reference count and cleanup when connections close
  • Implement isTelemetryEnabled() with 15-minute TTL cache and automatic refresh
  • Add fetchFeatureFlag() for HTTP integration with Databricks feature flag API
  • Include fallback to cached value on fetch errors for resilience
  • Add comprehensive unit tests (26 tests, 100% pass rate)

Key Features

  • Per-host caching: Prevents rate limiting from multiple connections to same host
  • Reference counting: Automatic cleanup when last connection closes
  • 15-minute TTL: Automatic cache expiration and refresh
  • Thread-safe: Uses sync.RWMutex for concurrent access
  • Fail-safe: Falls back to cached value when HTTP fetch fails
  • Non-blocking: Designed for lazy fetch when telemetry needs flag value

Testing

  • ✅ All 26 unit tests passing (including 12 previous config/tags tests)
  • ✅ Reference counting verified (increment/decrement/cleanup at zero)
  • ✅ Cache expiration and refresh tested
  • ✅ Concurrent access safety validated (100 goroutines)
  • ✅ HTTP fetch success/failure scenarios covered
  • ✅ Multiple host management tested
  • ✅ Build successful with no errors

JIRA

Closes PECOBLR-1146
Part of PECOBLR-1143

Design Document

See telemetry/DESIGN.md Section 3.1 for detailed design specification.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Implements per-host feature flag caching with reference counting for telemetry control.

Key features:
- Per-host singleton cache to prevent rate limiting
- Reference counting tied to connection lifecycle
- 15-minute TTL with automatic refresh
- Thread-safe concurrent access using RWMutex
- HTTP integration with Databricks feature flag API
- Fallback to cached value on fetch errors

Comprehensive test coverage includes:
- Reference counting increment/decrement
- Cache expiration and refresh logic
- Concurrent access safety
- HTTP fetch success/failure scenarios
- Multiple host management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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