Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #176 from 0xProject/marcin/metrics
Browse files Browse the repository at this point in the history
Metric clean up
  • Loading branch information
eitu5ami authored Feb 20, 2024
2 parents a75630b + cf8a268 commit 92ce9db
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Proxy struct {

metricRequestDuration *prometheus.HistogramVec
metricRequestErrors *prometheus.CounterVec
metricResponseStatus *prometheus.CounterVec
}

func NewProxy(config Config) *Proxy {
Expand Down Expand Up @@ -57,13 +56,6 @@ func NewProxy(config Config) *Proxy {
"provider",
"type",
}),
metricResponseStatus: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "zeroex_rpc_gateway_target_response_status_total",
Help: "Total number of responses with a statuscode label",
}, []string{
"provider",
"status_code",
}),
}

for _, target := range config.Targets {
Expand Down Expand Up @@ -118,7 +110,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

for _, target := range p.targets {
if !p.hcm.IsHealthy(target.Config.Name) {
if !p.hcm.IsHealthy(target.Name()) {
continue
}
start := time.Now()
Expand All @@ -129,9 +121,9 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.timeoutHandler(target).ServeHTTP(pw, r)

if p.HasNodeProviderFailed(pw.statusCode) {
p.metricRequestDuration.WithLabelValues(target.Config.Name, r.Method, strconv.Itoa(pw.statusCode)).
p.metricRequestDuration.WithLabelValues(target.Name(), r.Method, strconv.Itoa(pw.statusCode)).
Observe(time.Since(start).Seconds())
p.metricRequestErrors.WithLabelValues(target.Config.Name, "rerouted").Inc()
p.metricRequestErrors.WithLabelValues(target.Name(), "rerouted").Inc()

continue
}
Expand All @@ -140,8 +132,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(pw.statusCode)
w.Write(pw.body.Bytes()) // nolint:errcheck

p.metricResponseStatus.WithLabelValues(target.Config.Name, strconv.Itoa(pw.statusCode)).Inc()
p.metricRequestDuration.WithLabelValues(target.Config.Name, r.Method, strconv.Itoa(pw.statusCode)).
p.metricRequestDuration.WithLabelValues(target.Name(), r.Method, strconv.Itoa(pw.statusCode)).
Observe(time.Since(start).Seconds())

return
Expand Down

0 comments on commit 92ce9db

Please sign in to comment.