MCPcopy
hub / github.com/redis/go-redis / SetAllMetricCallbacks

Function SetAllMetricCallbacks

internal/pool/pool.go:189–215  ·  view source on GitHub ↗

SetAllMetricCallbacks sets all metric callbacks atomically. Pass nil to clear all callbacks (disable metrics). This ensures all callbacks are set together under a single lock, preventing inconsistent state during registration. Note on thread safety: After returning, there is a small window where co

(callbacks *MetricCallbacks)

Source from the content-addressed store, hash-verified

187// or be missed during the transition. The callbacks themselves are immutable
188// function pointers, so calling an "old" callback is safe.
189func SetAllMetricCallbacks(callbacks *MetricCallbacks) {
190 metricCallbackMu.Lock()
191 defer metricCallbackMu.Unlock()
192
193 if callbacks == nil {
194 metricConnectionCreateTimeCallback = nil
195 metricConnectionRelaxedTimeoutCallback = nil
196 metricConnectionHandoffCallback = nil
197 metricErrorCallback = nil
198 metricMaintenanceNotificationCallback = nil
199 metricConnectionWaitTimeCallback = nil
200 metricConnectionClosedCallback = nil
201 metricConnectionCountCallback = nil
202 metricPendingRequestsCallback = nil
203 return
204 }
205
206 metricConnectionCreateTimeCallback = callbacks.ConnectionCreateTime
207 metricConnectionRelaxedTimeoutCallback = callbacks.ConnectionRelaxedTimeout
208 metricConnectionHandoffCallback = callbacks.ConnectionHandoff
209 metricErrorCallback = callbacks.Error
210 metricMaintenanceNotificationCallback = callbacks.MaintenanceNotification
211 metricConnectionWaitTimeCallback = callbacks.ConnectionWaitTime
212 metricConnectionClosedCallback = callbacks.ConnectionClosed
213 metricConnectionCountCallback = callbacks.ConnectionCount
214 metricPendingRequestsCallback = callbacks.PendingRequests
215}
216
217// getMetricConnectionStateChangeCallback returns the metric callback for connection state changes.
218func getMetricConnectionStateChangeCallback() func(ctx context.Context, cn *Conn, fromState, toState string) {

Callers 2

sentinel_test.goFile · 0.92
SetGlobalRecorderFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected