Commit 29c881a
authored
[PECOBLR-1147] Implement Client Manager for Per-Host Clients (#305)
## 🥞 Stacked PR
Use this
[link](https://github.com/databricks/databricks-sql-go/pull/305/files?w=1)
to review incremental changes.
- [#304 - Feature Flag Cache
(PECOBLR-1146)](#304)
[[Files
changed](https://github.com/databricks/databricks-sql-go/pull/304/files)]
- [**#305 - Client Manager
(PECOBLR-1147)**](#305)
[[Files
changed](https://github.com/databricks/databricks-sql-go/pull/305/files)]
← This PR
---------
## Summary
Implements per-host client management system with reference counting as
part of the telemetry infrastructure (parent ticket PECOBLR-1143). This
is the second component of Phase 2: Per-Host Management.
## What Changed
- **New File**: `telemetry/client.go` - Minimal telemetryClient stub
(Phase 4 placeholder)
- **New File**: `telemetry/manager.go` - Client manager implementation
- **New File**: `telemetry/manager_test.go` - Comprehensive unit tests
- **Updated**: `telemetry/DESIGN.md` - Updated implementation checklist
## Implementation Details
### Core Components
1. **clientManager** - Singleton managing per-host telemetry clients
- Thread-safe using `sync.RWMutex`
- Maps host → clientHolder
2. **clientHolder** - Per-host state holder
- Holds telemetry client reference
- Reference count for active connections
- Automatic cleanup when ref count reaches zero
3. **telemetryClient** (stub) - Minimal implementation
- Placeholder for Phase 4 (Export)
- Provides `start()` and `close()` methods
- Will be fully implemented later
### Key Features
- ✅ Singleton pattern for global client management
- ✅ One client per host to prevent rate limiting
- ✅ Reference counting tied to connection lifecycle
- ✅ Thread-safe for concurrent access
- ✅ Automatic client cleanup when last connection closes
- ✅ Client start() called on creation
- ✅ Client close() called on removal
### Methods Implemented
- `getClientManager()` - Returns singleton instance
- `getOrCreateClient(host, httpClient, cfg)` - Creates or reuses client,
increments ref count
- `releaseClient(host)` - Decrements ref count, removes when zero
## Test Coverage
- ✅ Singleton pattern verification
- ✅ Reference counting (increment/decrement/cleanup)
- ✅ Multiple hosts management
- ✅ Partial releases
- ✅ Thread-safety under concurrent access (100+ goroutines)
- ✅ Client lifecycle (start/close) verification
- ✅ Non-existent host handling
- ✅ All tests passing with 100% code coverage
## Test Results
\`\`\`
=== RUN TestGetClientManager_Singleton
--- PASS: TestGetClientManager_Singleton (0.00s)
... (all 11 tests passing)
PASS
ok github.com/databricks/databricks-sql-go/telemetry 0.005s
\`\`\`
## Design Alignment
Implementation follows the design document (telemetry/DESIGN.md, section
3.2) exactly. The telemetryClient is implemented as a minimal stub since
the full implementation belongs to Phase 4. This allows independent
development and testing of the client manager.
## Testing Instructions
\`\`\`bash
go test -v ./telemetry -run "TestGetClientManager|TestClientManager"
go test -v ./telemetry # Run all telemetry tests
go build ./telemetry # Verify build
\`\`\`
## Related Links
- Parent Ticket:
[PECOBLR-1143](https://databricks.atlassian.net/browse/PECOBLR-1143)
- This Ticket:
[PECOBLR-1147](https://databricks.atlassian.net/browse/PECOBLR-1147)
- Previous:
[PECOBLR-1146](https://databricks.atlassian.net/browse/PECOBLR-1146) -
Feature Flag Cache (#304)
- Design Doc: \`telemetry/DESIGN.md\`
## Next Steps
After this PR:
- PECOBLR-1148: Circuit Breaker Implementation
[PECOBLR-1143]:
https://databricks.atlassian.net/browse/PECOBLR-1143?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ1 parent 5dbccff commit 29c881a
4 files changed
+643
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1580 | 1580 | | |
1581 | 1581 | | |
1582 | 1582 | | |
1583 | | - | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
1584 | 1619 | | |
1585 | 1620 | | |
1586 | 1621 | | |
| |||
1742 | 1777 | | |
1743 | 1778 | | |
1744 | 1779 | | |
1745 | | - | |
| 1780 | + | |
1746 | 1781 | | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
1750 | 1799 | | |
1751 | 1800 | | |
1752 | 1801 | | |
| |||
1756 | 1805 | | |
1757 | 1806 | | |
1758 | 1807 | | |
1759 | | - | |
| 1808 | + | |
1760 | 1809 | | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
1761 | 1815 | | |
1762 | 1816 | | |
1763 | 1817 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
0 commit comments