Skip to content

Commit 6ca34ff

Browse files
author
humingcheng
committed
Use new api of go-chassis to get circuit breaker status, to prevent uncontrollable increment of goroutine
1 parent fd971cf commit 6ca34ff

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

csemonitor.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/ServiceComb/go-chassis/core/config"
1212
"github.com/ServiceComb/go-chassis/core/lager"
1313
"github.com/ServiceComb/go-chassis/core/registry"
14-
"github.com/ServiceComb/go-chassis/third_party/forked/afex/hystrix-go/hystrix"
1514
"github.com/rcrowley/go-metrics"
1615
)
1716

@@ -102,7 +101,11 @@ func (reporter *Reporter) Run() {
102101
if len(monitorData.Interfaces) != 0 {
103102
count++
104103
if count == 10 {
105-
hystrix.Flush()
104+
reporter.Registry.Each(func(s string, i interface{}) {
105+
if c, ok := i.(metrics.Counter); ok {
106+
c.Clear()
107+
}
108+
})
106109
count = 0
107110
}
108111
}

monitorData.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ func (monitorData *MonitorData) appendInterfaceInfo(name string, i interface{})
9292
interfaceInfo.successCount = metric.Count()
9393
}
9494

95-
cb, _, _ := hystrix.GetCircuit(getInterfaceName(name))
96-
if cb.IsOpen() {
97-
interfaceInfo.IsCircuitBreakerOpen = true
98-
} else {
95+
if isCBOpen, err := hystrix.IsCircuitBreakerOpen(getInterfaceName(name)); err != nil {
9996
interfaceInfo.IsCircuitBreakerOpen = false
97+
} else {
98+
interfaceInfo.IsCircuitBreakerOpen = isCBOpen
10099
}
101100

102101
qps := (float64(interfaceInfo.Total) * (1 - math.Exp(-5.0/60.0/1)))

0 commit comments

Comments
 (0)