Skip to content

Commit eec03ff

Browse files
Merge pull request #77 from marcoferrer/bugfix-queue-size-metrics
Fix bugs in metric reporting
2 parents 2617169 + 1554b81 commit eec03ff

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

core/metric_registry.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ func NewIntMetricSupplierWrapper(s func() int) MetricSupplier {
2525
})
2626
}
2727

28-
// NewFloat64MetricSupplierWrapper will wrap a int-return value func to a supplier func
28+
// NewUint64MetricSupplierWrapper will wrap a uint64-return value func to a supplier func
29+
func NewUint64MetricSupplierWrapper(s func() uint64) MetricSupplier {
30+
return MetricSupplier(func() (float64, bool) {
31+
val := s()
32+
return float64(val), true
33+
})
34+
}
35+
36+
// NewFloat64MetricSupplierWrapper will wrap a float64-return value func to a supplier func
2937
func NewFloat64MetricSupplierWrapper(s func() float64) MetricSupplier {
3038
return MetricSupplier(func() (float64, bool) {
3139
val := s()
@@ -117,7 +125,7 @@ func NewCommonMetricSampler(registry MetricRegistry, limit Limit, name string, t
117125
// Sample will sample the current sample for metric reporting.
118126
func (s *CommonMetricSampler) Sample(rtt int64, inFlight int, didDrop bool) {
119127
if didDrop {
120-
s.InFlightListener.AddSample(1.0)
128+
s.DropCounterListener.AddSample(1.0)
121129
}
122130
s.RTTListener.AddSample(float64(rtt))
123131
s.InFlightListener.AddSample(float64(inFlight))

limiter/lifo_blocking.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ type LifoBlockingLimiter struct {
177177
maxBacklogSize uint64
178178
maxBacklogTimeout time.Duration
179179

180-
backlog lifoQueue
180+
backlog *lifoQueue
181181
mu sync.RWMutex
182182
}
183183

@@ -203,16 +203,14 @@ func NewLifoBlockingLimiter(
203203
delegate: delegate,
204204
maxBacklogSize: uint64(maxBacklogSize),
205205
maxBacklogTimeout: maxBacklogTimeout,
206-
backlog: lifoQueue{},
206+
backlog: &lifoQueue{},
207207
}
208208

209-
registry.RegisterGauge(core.MetricLifoQueueLimit, func() (value float64, ok bool) {
210-
return float64(maxBacklogSize), true
211-
}, tags...)
209+
registry.RegisterGauge(core.MetricLifoQueueLimit, core.NewIntMetricSupplierWrapper(func() int {
210+
return maxBacklogSize
211+
}), tags...)
212212

213-
registry.RegisterGauge(core.MetricLifoQueueSize, func() (value float64, ok bool) {
214-
return float64(l.backlog.len()), true
215-
}, tags...)
213+
registry.RegisterGauge(core.MetricLifoQueueSize, core.NewUint64MetricSupplierWrapper(l.backlog.len), tags...)
216214

217215
return l
218216
}
@@ -261,7 +259,7 @@ func (l *LifoBlockingLimiter) tryAcquire(ctx context.Context) core.Listener {
261259
// If acquired the caller must call one of the Listener methods when the operation has been completed to release
262260
// the count.
263261
//
264-
// context Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
262+
// ctx Context for the request. The context is used by advanced strategies such as LookupPartitionStrategy.
265263
func (l *LifoBlockingLimiter) Acquire(ctx context.Context) (core.Listener, bool) {
266264
delegateListener := l.tryAcquire(ctx)
267265
if delegateListener == nil {

0 commit comments

Comments
 (0)