Skip to content

Commit

Permalink
feat: prometheus metrics for counting ok requests
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Oct 16, 2024
1 parent 6ea93a1 commit 7d3c6c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/checks/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ func (c *ErrorCheck) RecordRequest(data *types.RequestData) bool {
// Even though this is a single HTTP request, we count each RPC JSON subresponse error.
c.errorCircuitBreaker.RecordResponse(true) // JSON RPC subrequest error
} else {
c.metricsContainer.ErrorLatencyCheckNoErrors.WithLabelValues(
c.upstreamConfig.ID,
c.upstreamConfig.HTTPURL,
metrics.HTTPRequest,
data.Method,
).Inc()

c.errorCircuitBreaker.RecordResponse(false) // JSON RPC subrequest OK
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/checks/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ func (c *LatencyCheck) RecordRequest(data *types.RequestData) bool {
).Inc()

isHighLatency = true
} else {
c.metricsContainer.ErrorLatencyCheckOkLatencies.WithLabelValues(
c.upstreamConfig.ID,
c.upstreamConfig.HTTPURL,
metrics.HTTPRequest,
data.Method,
).Inc()
}
}

Expand Down
26 changes: 24 additions & 2 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ var (
[]string{"chain_name", "upstream_id", "url", "errorType", "method"},
)

errorLatencyStatusCheckNoErrors = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: "healthcheck",
Name: "latency_check_no_errors",
Help: "No errors of upstream requests.",
},
[]string{"chain_name", "upstream_id", "url", "errorType", "method"},
)

errorLatencyStatusHighLatencies = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricsNamespace,
Expand All @@ -269,6 +279,16 @@ var (
[]string{"chain_name", "upstream_id", "url", "errorType", "method"},
)

errorLatencyStatusOkLatencies = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: "healthcheck",
Name: "latency_check_ok_latency",
Help: "Latency of upstream OK.",
},
[]string{"chain_name", "upstream_id", "url", "errorType", "method"},
)

// System metrics
fileDescriptorsUsed = promauto.NewGauge(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -305,9 +325,9 @@ type Container struct {
SyncStatusCheckErrors *prometheus.CounterVec

ErrorLatency *prometheus.GaugeVec
ErrorLatencyCheckRequests *prometheus.CounterVec
ErrorLatencyCheckDuration prometheus.ObserverVec
ErrorLatencyCheckNoErrors *prometheus.CounterVec
ErrorLatencyCheckErrors *prometheus.CounterVec
ErrorLatencyCheckOkLatencies *prometheus.CounterVec
ErrorLatencyCheckHighLatencies *prometheus.CounterVec
}

Expand Down Expand Up @@ -343,7 +363,9 @@ func NewContainer(chainName string) *Container {

result.ErrorLatency = errorLatencyStatus.MustCurryWith(presetLabels)
result.ErrorLatencyCheckErrors = errorLatencyStatusCheckErrors.MustCurryWith(presetLabels)
result.ErrorLatencyCheckNoErrors = errorLatencyStatusCheckNoErrors.MustCurryWith(presetLabels)
result.ErrorLatencyCheckHighLatencies = errorLatencyStatusHighLatencies.MustCurryWith(presetLabels)
result.ErrorLatencyCheckOkLatencies = errorLatencyStatusOkLatencies.MustCurryWith(presetLabels)

return result
}
Expand Down

0 comments on commit 7d3c6c2

Please sign in to comment.