Skip to content

Commit e537239

Browse files
committed
Add reminder to integrate with shutdown hook
Signed-off-by: samikshya-chand_data <samikshya.chand@databricks.com>
1 parent b19da8b commit e537239

File tree

1 file changed

+58
-5
lines changed

1 file changed

+58
-5
lines changed

telemetry/DESIGN.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,42 @@ func (c *conn) Close() error {
15801580
}
15811581
```
15821582

1583-
### 9.2 Client Shutdown
1583+
### 9.2 Client Manager Shutdown
1584+
1585+
The `clientManager` now includes a `shutdown()` method that provides graceful cleanup of all telemetry clients on application shutdown. This method:
1586+
1587+
- Closes all active telemetry clients regardless of reference counts
1588+
- Logs warnings for any close failures
1589+
- Clears the clients map to prevent memory leaks
1590+
- Returns the last error encountered (if any)
1591+
1592+
```go
1593+
// shutdown closes all telemetry clients and clears the manager.
1594+
// Integration points will be determined in Phase 4.
1595+
func (m *clientManager) shutdown() error {
1596+
m.mu.Lock()
1597+
defer m.mu.Unlock()
1598+
1599+
var lastErr error
1600+
for host, holder := range m.clients {
1601+
if err := holder.client.close(); err != nil {
1602+
logger.Logger.Warn().Str("host", host).Err(err).Msg("error closing telemetry client during shutdown")
1603+
lastErr = err
1604+
}
1605+
}
1606+
// Clear the map
1607+
m.clients = make(map[string]*clientHolder)
1608+
return lastErr
1609+
}
1610+
```
1611+
1612+
**Integration Options** (to be implemented in Phase 4):
1613+
1614+
1. **Public API**: Export a `Shutdown()` function for applications to call during their shutdown sequence
1615+
2. **Driver Hook**: Integrate with `sql.DB.Close()` or driver cleanup mechanisms
1616+
3. **Signal Handler**: Call from application signal handlers (SIGTERM, SIGINT)
1617+
1618+
### 9.3 Client Shutdown
15841619

15851620
```go
15861621
// close shuts down the telemetry client gracefully.
@@ -1742,12 +1777,25 @@ func BenchmarkInterceptor_Disabled(b *testing.B) {
17421777
- [x] Implement `tags.go` with tag definitions and filtering
17431778
- [x] Add unit tests for configuration and tags
17441779

1745-
### Phase 2: Per-Host Management
1780+
### Phase 2: Per-Host Management ✅ COMPLETED
17461781
- [x] Implement `featureflag.go` with caching and reference counting (PECOBLR-1146)
17471782
- [x] Implement `manager.go` for client management (PECOBLR-1147)
1783+
- [x] Thread-safe singleton pattern with per-host client holders
1784+
- [x] Reference counting for automatic cleanup
1785+
- [x] Error handling for client start failures
1786+
- [x] Shutdown method for graceful application shutdown
1787+
- [x] Comprehensive documentation on thread-safety and connection sharing
17481788
- [x] Implement `client.go` with minimal telemetryClient stub (PECOBLR-1147)
1749-
- [ ] Implement `circuitbreaker.go` with state machine
1750-
- [ ] Add unit tests for all components
1789+
- [x] Thread-safe start() and close() methods
1790+
- [x] Mutex protection for state flags
1791+
- [x] Detailed documentation on concurrent access requirements
1792+
- [x] Add comprehensive unit tests for all components (PECOBLR-1147)
1793+
- [x] Singleton pattern verification
1794+
- [x] Reference counting (increment/decrement/cleanup)
1795+
- [x] Concurrent access tests (100+ goroutines)
1796+
- [x] Shutdown scenarios (empty, with active refs, multiple hosts)
1797+
- [x] Race detector tests passing
1798+
- [ ] Implement `circuitbreaker.go` with state machine (PECOBLR-1148)
17511799

17521800
### Phase 3: Collection & Aggregation
17531801
- [ ] Implement `interceptor.go` for metric collection
@@ -1757,8 +1805,13 @@ func BenchmarkInterceptor_Disabled(b *testing.B) {
17571805

17581806
### Phase 4: Export
17591807
- [ ] Implement `exporter.go` with retry logic
1760-
- [ ] Implement `client.go` for telemetry client
1808+
- [ ] Implement `client.go` for telemetry client with full functionality
17611809
- [ ] Wire up circuit breaker with exporter
1810+
- [ ] Integrate shutdown method into driver lifecycle:
1811+
- [ ] Option 1: Export public `Shutdown()` API for applications to call
1812+
- [ ] Option 2: Hook into `sql.DB.Close()` or driver cleanup
1813+
- [ ] Option 3: Integrate with connection pool shutdown logic
1814+
- [ ] Document shutdown integration points and usage patterns
17621815
- [ ] Add unit tests for export logic
17631816

17641817
### Phase 5: Driver Integration

0 commit comments

Comments
 (0)