@@ -11,8 +11,6 @@ import (
1111 "strings"
1212 "sync"
1313 "time"
14-
15- "github.com/prometheus/client_golang/prometheus"
1614)
1715
1816const (
@@ -42,42 +40,6 @@ const (
4240 ProxyCBStateHalfOpen = 2
4341)
4442
45- // Prometheus metrics for proxy and circuit breaker
46- var (
47- proxyRequestsTotal = prometheus .NewCounter (
48- prometheus.CounterOpts {
49- Name : "proxy_requests_total" ,
50- Help : "Total number of proxy requests" ,
51- },
52- )
53- proxyRetriesTotal = prometheus .NewCounter (
54- prometheus.CounterOpts {
55- Name : "proxy_retries_total" ,
56- Help : "Total number of proxy request retries" ,
57- },
58- )
59- proxyFailuresTotal = prometheus .NewCounterVec (
60- prometheus.CounterOpts {
61- Name : "proxy_failures_total" ,
62- Help : "Total number of proxy failures, labeled by reason" ,
63- },
64- []string {"reason" },
65- )
66- proxyCircuitBreakerState = prometheus .NewGauge (
67- prometheus.GaugeOpts {
68- Name : "proxy_circuit_breaker_state" ,
69- Help : "Proxy circuit breaker state: 0=closed, 1=open, 2=half-open" ,
70- },
71- )
72- )
73-
74- func RegisterProxyMetrics () {
75- prometheus .MustRegister (proxyRequestsTotal )
76- prometheus .MustRegister (proxyRetriesTotal )
77- prometheus .MustRegister (proxyFailuresTotal )
78- prometheus .MustRegister (proxyCircuitBreakerState )
79- }
80-
8143// CircuitBreakerState represents the state of the circuit breaker
8244type CircuitBreakerState int
8345
@@ -272,15 +234,7 @@ func (cb *CircuitBreaker) canExecute() bool {
272234 cb .mutex .RLock ()
273235 defer cb .mutex .RUnlock ()
274236
275- // Set gauge for current state
276- switch cb .state {
277- case CircuitClosed :
278- proxyCircuitBreakerState .Set (ProxyCBStateClosed )
279- case CircuitOpen :
280- proxyCircuitBreakerState .Set (ProxyCBStateOpen )
281- case CircuitHalfOpen :
282- proxyCircuitBreakerState .Set (ProxyCBStateHalfOpen )
283- }
237+ // No metrics to update for circuit breaker state changes
284238
285239 if cb .state == CircuitClosed {
286240 return true
@@ -291,7 +245,6 @@ func (cb *CircuitBreaker) canExecute() bool {
291245 cb .mutex .RUnlock ()
292246 cb .mutex .Lock ()
293247 cb .state = CircuitHalfOpen
294- proxyCircuitBreakerState .Set (ProxyCBStateHalfOpen )
295248 cb .mutex .Unlock ()
296249 cb .mutex .RLock ()
297250 return true
@@ -309,7 +262,6 @@ func (cb *CircuitBreaker) onSuccess() {
309262
310263 cb .failureCount = 0
311264 cb .state = CircuitClosed
312- proxyCircuitBreakerState .Set (ProxyCBStateClosed )
313265}
314266
315267func (cb * CircuitBreaker ) onFailure () {
@@ -321,7 +273,6 @@ func (cb *CircuitBreaker) onFailure() {
321273
322274 if cb .failureCount >= circuitBreakerFailureThreshold {
323275 cb .state = CircuitOpen
324- proxyCircuitBreakerState .Set (ProxyCBStateOpen )
325276 }
326277}
327278
@@ -457,14 +408,10 @@ func (s *ProxyService) makeRequestWithRetry(req *http.Request, body []byte) (*ht
457408 var lastResp * http.Response
458409 var lastErr error
459410
460- // Increment total proxy request metric
461- proxyRequestsTotal .Inc ()
462-
463411 for attempt := 1 ; attempt <= maxChatRetries ; attempt ++ {
464412 // Create a new request for each attempt with the original context
465413 retryReq , err := http .NewRequestWithContext (req .Context (), req .Method , req .URL .String (), bytes .NewBuffer (body ))
466414 if err != nil {
467- proxyFailuresTotal .WithLabelValues ("request_creation" ).Inc ()
468415 return nil , err
469416 }
470417
@@ -479,16 +426,12 @@ func (s *ProxyService) makeRequestWithRetry(req *http.Request, body []byte) (*ht
479426
480427 resp , err := s .httpClient .Do (retryReq )
481428 if err != nil {
482- proxyFailuresTotal .WithLabelValues ("network_error" ).Inc ()
483429 lastErr = err
484430 if attempt == maxChatRetries {
485431 Error ("Request failed after max attempts" , "attempts" , maxChatRetries , "error" , err )
486432 return nil , err
487433 }
488434
489- // Increment retry metric
490- proxyRetriesTotal .Inc ()
491-
492435 // Context-aware waiting instead of blocking sleep
493436 waitTime := time .Duration (baseChatRetryDelay * attempt * attempt ) * time .Second
494437 Warn ("Request failed, retrying" , "attempt" , attempt , "wait_time" , waitTime , "error" , err )
@@ -512,12 +455,6 @@ func (s *ProxyService) makeRequestWithRetry(req *http.Request, body []byte) (*ht
512455 return resp , nil
513456 }
514457
515- // Increment retry metric for retriable status codes
516- proxyRetriesTotal .Inc ()
517-
518- // Increment failure metric for retriable status codes
519- proxyFailuresTotal .WithLabelValues (fmt .Sprintf ("http_%d" , resp .StatusCode )).Inc ()
520-
521458 // Close the response body before retrying
522459 if closeErr := resp .Body .Close (); closeErr != nil {
523460 Warn ("Failed to close response body during retry" , "error" , closeErr )
0 commit comments