Skip to content

Commit 5268be5

Browse files
authored
Merge pull request #22 from MaurUppi/fix/metrics-dns-concurrency-info
fix(metrics): correct dns concurrency in-use gauge semantics
2 parents 9a855c9 + d8f56f4 commit 5268be5

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

control/dns_control.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func (c *DnsController) ConcurrencyInfo() (inUse, limit int) {
298298
if limit == 0 {
299299
return 0, 0
300300
}
301-
inUse = limit - len(c.concurrencyLimiter)
301+
inUse = len(c.concurrencyLimiter)
302302
return
303303
}
304304

control/dns_metrics_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,30 @@ func TestDnsController_HandleWithResponseWriterCountsQuery(t *testing.T) {
166166
t.Fatalf("unexpected response latency count: got=%d want=1", latency.Count)
167167
}
168168
}
169+
170+
func TestDnsController_ConcurrencyInfo(t *testing.T) {
171+
c := &DnsController{
172+
concurrencyLimiter: make(chan struct{}, 3),
173+
}
174+
175+
inUse, limit := c.ConcurrencyInfo()
176+
if limit != 3 || inUse != 0 {
177+
t.Fatalf("unexpected initial concurrency info: inUse=%d limit=%d", inUse, limit)
178+
}
179+
180+
c.concurrencyLimiter <- struct{}{}
181+
c.concurrencyLimiter <- struct{}{}
182+
183+
inUse, limit = c.ConcurrencyInfo()
184+
if limit != 3 || inUse != 2 {
185+
t.Fatalf("unexpected in-use concurrency info: inUse=%d limit=%d", inUse, limit)
186+
}
187+
188+
<-c.concurrencyLimiter
189+
<-c.concurrencyLimiter
190+
191+
inUse, limit = c.ConcurrencyInfo()
192+
if limit != 3 || inUse != 0 {
193+
t.Fatalf("unexpected released concurrency info: inUse=%d limit=%d", inUse, limit)
194+
}
195+
}

0 commit comments

Comments
 (0)