Skip to content

Commit f373d83

Browse files
author
jxu3
committed
Remove Prometheus metrics integration from proxy and circuit breaker
Eliminate Prometheus client dependencies and related metric registration from proxy and circuit breaker code. Update documentation to reflect removal of worker pool metrics and production monitoring. This simplifies the codebase and reduces external dependencies.
1 parent 3d2b34a commit f373d83

File tree

6 files changed

+2
-118
lines changed

6 files changed

+2
-118
lines changed

README.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ This service includes enterprise-grade performance optimizations:
8484

8585
### 📊 Monitoring & Observability
8686
- **Profiling Endpoints**: `/debug/pprof/*` for memory, CPU, and goroutine analysis
87-
- **Enhanced Logging**: Circuit breaker state, request coalescing, worker pool metrics, and performance data
87+
- **Enhanced Logging**: Circuit breaker state, request coalescing, and performance data
8888
- **Health Monitoring**: Detailed `/health` endpoint for load balancer integration
89-
- **Production Metrics**: Built-in support for operational monitoring and worker pool status
9089

9190
## Quickstart with Makefile
9291

@@ -467,42 +466,6 @@ print(response)
467466

468467
## Development
469468

470-
### Project Structure
471-
```
472-
github-copilot-svcs/
473-
├── cmd/
474-
│ └── github-copilot-svcs/
475-
│ └── main.go # Main application entry point
476-
├── internal/ # Private application code
477-
│ ├── auth/
478-
│ │ └── auth.go # GitHub Copilot authentication
479-
│ ├── cli/
480-
│ │ └── cli.go # CLI command handling
481-
│ ├── config/
482-
│ │ └── config.go # Configuration management
483-
│ ├── logger/
484-
│ │ └── logger.go # Structured logging
485-
│ ├── models/
486-
│ │ └── models.go # Model management and mapping
487-
│ ├── proxy/
488-
│ │ └── proxy.go # Reverse proxy implementation
489-
│ └── server/
490-
│ └── server.go # HTTP server and graceful shutdown
491-
├── pkg/ # Public API packages
492-
│ └── transform/
493-
│ └── transform.go # Request/response transformation
494-
├── test/ # Test files organized by type
495-
│ ├── integration/ # Integration tests
496-
│ ├── unit/ # Unit tests
497-
│ └── testutils/ # Test utilities
498-
├── config.example.json # Example configuration
499-
├── docker-compose.yml # Docker Compose setup
500-
├── Dockerfile # Docker image definition
501-
├── Makefile # Build and development tasks
502-
├── go.mod # Go module definition
503-
└── README.md # This documentation
504-
```
505-
506469
### Building from Source
507470
```bash
508471
git clone <repository>

cmd/github-copilot-svcs/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ var version = "dev"
1212
func main() {
1313
// Initialize logger early
1414
internal.Init()
15-
internal.RegisterProxyMetrics()
1615

1716
const minArgsRequired = 2
1817
if len(os.Args) < minArgsRequired {

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ require (
88
github.com/beorn7/perks v1.0.1 // indirect
99
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1010
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
11-
github.com/prometheus/client_golang v1.23.0 // indirect
12-
github.com/prometheus/client_model v0.6.2 // indirect
13-
github.com/prometheus/common v0.65.0 // indirect
14-
github.com/prometheus/procfs v0.16.1 // indirect
1511
golang.org/x/sys v0.33.0 // indirect
1612
google.golang.org/protobuf v1.36.6 // indirect
1713
)

go.sum

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
44
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
55
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
66
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
7-
github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
8-
github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
9-
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
10-
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
11-
github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE=
12-
github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8=
13-
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
14-
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
157
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
168
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
179
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=

internal/proxy.go

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strings"
1212
"sync"
1313
"time"
14-
15-
"github.com/prometheus/client_golang/prometheus"
1614
)
1715

1816
const (
@@ -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
8244
type 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

315267
func (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)

internal/server.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"sync"
1212
"syscall"
1313
"time"
14-
15-
"github.com/prometheus/client_golang/prometheus/promhttp"
1614
)
1715

1816
// Constants for timeout values
@@ -120,7 +118,6 @@ func NewServer(cfg *Config, httpClient *http.Client) *Server {
120118
mux.HandleFunc("/v1/models", modelsService.Handler())
121119
mux.HandleFunc("/v1/chat/completions", proxyService.Handler())
122120
mux.HandleFunc("/health", healthChecker.Handler())
123-
mux.Handle("/metrics", promhttp.Handler())
124121

125122
// Add pprof endpoints for profiling
126123
mux.HandleFunc("/debug/pprof/", http.DefaultServeMux.ServeHTTP)

0 commit comments

Comments
 (0)