Skip to content

Commit

Permalink
feat: each JSON RPC subrequest now counts toward the error rate
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Aug 27, 2024
1 parent 49d13d8 commit 0055b31
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/checks/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,32 +305,38 @@ func (c *LatencyCheck) RecordRequest(data *types.RequestData) {
).Inc()
}

var isError bool // false

if data.HTTPResponseCode >= http.StatusBadRequest {
// No RPC responses are available since the HTTP request errored out.
isError = c.isError(strconv.Itoa(data.HTTPResponseCode), "", "")
c.errorCircuitBreaker.RecordRequest(c.isError(
strconv.Itoa(data.HTTPResponseCode),
"",
"",
)) // HTTP request error
// TODO(polsar): We might want to emit a Prometheus stat like we do for an RPC error below.
} else if data.ResponseBody != nil {

Check failure on line 316 in internal/checks/latency.go

View workflow job for this annotation

GitHub Actions / Code linting with golangci-lint

block should not end with a whitespace (or comment) (wsl)
for _, resp := range data.ResponseBody.GetSubResponses() {
if resp.Error != nil {
// TODO(polsar): Should we ignore this response if it does not correspond to an RPC request?
isError = c.isError("", strconv.Itoa(resp.Error.Code), resp.Error.Message)
if isError {
// Do not ignore this response even if it does not correspond to an RPC request.
if c.isError("", strconv.Itoa(resp.Error.Code), resp.Error.Message) {
c.metricsContainer.LatencyCheckErrors.WithLabelValues(
c.upstreamConfig.ID,
c.upstreamConfig.HTTPURL,
metrics.HTTPRequest,
).Inc()

break
// Even though this is a single HTTP request, we count each RPC JSON subresponse error.
c.errorCircuitBreaker.RecordRequest(true) // JSON RPC subrequest error
} else {
c.errorCircuitBreaker.RecordRequest(false) // JSON RPC subrequest OK
}
}
}

c.errorCircuitBreaker.RecordRequest(false) // HTTP request OK
}
// TODO(polsar): What does it mean when `data.ResponseBody == nil` and no HTTP error occurred?
// How should we handle this case?

c.errorCircuitBreaker.RecordRequest(isError)
c.metricsContainer.Latency.WithLabelValues(
c.upstreamConfig.ID,
c.upstreamConfig.HTTPURL,
Expand Down

0 comments on commit 0055b31

Please sign in to comment.