77 "go.temporal.io/api/serviceerror"
88 "go.temporal.io/server/common"
99 "go.temporal.io/server/common/aggregate"
10+ "go.temporal.io/server/common/dynamicconfig"
1011 "go.temporal.io/server/common/log"
1112 "google.golang.org/grpc"
1213)
5152 HealthSignalAggregatorImpl struct {
5253 status int32
5354
55+ aggregatorEnabled dynamicconfig.BoolPropertyFn
56+
5457 latencyAverage aggregate.MovingWindowAverage
5558 errorRatio aggregate.MovingWindowAverage
5659
@@ -62,19 +65,25 @@ type (
6265
6366// NewHealthSignalAggregator creates a new instance of HealthSignalAggregatorImpl
6467func NewHealthSignalAggregator (
68+ logger log.Logger ,
69+ aggregatorEnabled dynamicconfig.BoolPropertyFn ,
6570 windowSize time.Duration ,
6671 maxBufferSize int ,
67- logger log.Logger ,
6872) * HealthSignalAggregatorImpl {
6973 ret := & HealthSignalAggregatorImpl {
70- latencyAverage : aggregate .NewMovingWindowAvgImpl (windowSize , maxBufferSize ),
71- errorRatio : aggregate .NewMovingWindowAvgImpl (windowSize , maxBufferSize ),
72- logger : logger ,
74+ logger : logger ,
75+ aggregatorEnabled : aggregatorEnabled ,
76+ latencyAverage : aggregate .NewMovingWindowAvgImpl (windowSize , maxBufferSize ),
77+ errorRatio : aggregate .NewMovingWindowAvgImpl (windowSize , maxBufferSize ),
7378 }
7479 return ret
7580}
7681
7782func (s * HealthSignalAggregatorImpl ) Record (latency time.Duration , err error ) {
83+ if ! s .aggregatorEnabled () {
84+ s .logger .Debug ("health signal aggregator is disabled" )
85+ return
86+ }
7887 s .latencyAverage .Record (latency .Milliseconds ())
7988
8089 if isUnhealthyError (err ) {
@@ -85,10 +94,16 @@ func (s *HealthSignalAggregatorImpl) Record(latency time.Duration, err error) {
8594}
8695
8796func (s * HealthSignalAggregatorImpl ) AverageLatency () float64 {
97+ if ! s .aggregatorEnabled () {
98+ s .logger .Debug ("health signal aggregator is disabled" )
99+ }
88100 return s .latencyAverage .Average ()
89101}
90102
91103func (s * HealthSignalAggregatorImpl ) ErrorRatio () float64 {
104+ if ! s .aggregatorEnabled () {
105+ s .logger .Debug ("health signal aggregator is disabled" )
106+ }
92107 return s .errorRatio .Average ()
93108}
94109
@@ -111,17 +126,3 @@ func isUnhealthyError(err error) bool {
111126 }
112127 return false
113128}
114-
115- var NoopHealthSignalAggregator HealthSignalAggregator = newNoopSignalAggregator ()
116-
117- func newNoopSignalAggregator () * NoopSignalAggregator { return & NoopSignalAggregator {} }
118-
119- func (a * NoopSignalAggregator ) Record (_ time.Duration , _ error ) {}
120-
121- func (a * NoopSignalAggregator ) AverageLatency () float64 {
122- return 0
123- }
124-
125- func (* NoopSignalAggregator ) ErrorRatio () float64 {
126- return 0
127- }
0 commit comments