Skip to content

Commit

Permalink
fix: further refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Aug 18, 2024
1 parent 6b8fbc1 commit 6c02c16
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/checks/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,25 @@ func (c *LatencyCheck) runCheck() {
return
}

// TODO(polsar): Add support for checking the latency of specific method(s), as specified in the config.
method := LatencyCheckMethod
// TODO(polsar): Get the latency threshold from config.
maxLatency := defaultMaxLatency

runCheck := func() {
c.runCheckForMethod()
c.runCheckForMethod(method, maxLatency)
}

runCheckWithMetrics(runCheck,
c.metricsContainer.LatencyCheckRequests.WithLabelValues(c.upstreamConfig.ID, c.upstreamConfig.HTTPURL),
c.metricsContainer.LatencyCheckDuration.WithLabelValues(c.upstreamConfig.ID, c.upstreamConfig.HTTPURL))
}

func (c *LatencyCheck) runCheckForMethod() {
// This method runs the latency check for the specified method and latency threshold.
func (c *LatencyCheck) runCheckForMethod(method string, maxLatency time.Duration) {
ctx, cancel := context.WithTimeout(context.Background(), RPCRequestTimeout)
defer cancel()

// TODO(polsar): Add support for checking the latency of specific method(s), as specified in the config.
method := LatencyCheckMethod

var val *FailureCounts

func() {
Expand All @@ -151,7 +154,7 @@ func (c *LatencyCheck) runCheckForMethod() {
val.timeoutOrError++

c.metricsContainer.LatencyCheckErrors.WithLabelValues(c.upstreamConfig.ID, c.upstreamConfig.HTTPURL, metrics.HTTPRequest).Inc()
} else if duration > defaultMaxLatency { // TODO(polsar): Get the latency threshold from config.
} else if duration > maxLatency {
val.latencyTooHigh++

c.metricsContainer.LatencyCheckHighLatencies.WithLabelValues(c.upstreamConfig.ID, c.upstreamConfig.HTTPURL, metrics.HTTPRequest).Inc()
Expand Down

0 comments on commit 6c02c16

Please sign in to comment.