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

Metric clean up #176

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading