Skip to content

Commit dc3b73b

Browse files
JoshVanLcicoyledapr-bot
authored
App health: Remove ratelimiter (dapr#8586)
Removes the 1 second app health rate limiter. There is no reason for this rate limiter to exist. Signed-off-by: joshvanl <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Co-authored-by: Dapr Bot <[email protected]>
1 parent 5e75e16 commit dc3b73b

File tree

3 files changed

+0
-86
lines changed

3 files changed

+0
-86
lines changed

pkg/apphealth/health.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,6 @@ func (h *AppHealth) ReportHealth(status *Status) {
155155
return
156156
}
157157

158-
// Limit health reports to 1 per second
159-
if !h.ratelimitReports() {
160-
return
161-
}
162-
163158
// Channel is buffered, so make sure that this doesn't block
164159
// Just in case another report is being worked on!
165160
select {
@@ -205,32 +200,6 @@ func (h *AppHealth) doProbe(parentCtx context.Context) {
205200
}
206201
}
207202

208-
// Returns true if the health report can be saved. Only 1 report per second at most is allowed.
209-
func (h *AppHealth) ratelimitReports() bool {
210-
var (
211-
swapped bool
212-
attempts uint8
213-
)
214-
215-
now := h.clock.Now().UnixMicro()
216-
217-
// Attempts at most 2 times before giving up, as the report may be stale at that point
218-
for !swapped && attempts < 2 {
219-
attempts++
220-
221-
// If the last report was less than `reportMinInterval` ago, nothing to do here
222-
prev := h.lastReport.Load()
223-
if prev > now-reportMinInterval.Microseconds() {
224-
return false
225-
}
226-
227-
swapped = h.lastReport.CompareAndSwap(prev, now)
228-
}
229-
230-
// If we couldn't do the swap after 2 attempts, just return false
231-
return swapped
232-
}
233-
234203
func (h *AppHealth) setResult(ctx context.Context, status *Status) {
235204
h.lastReport.Store(h.clock.Now().UnixMicro())
236205

pkg/apphealth/health_test.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -121,56 +121,6 @@ func TestAppHealth_setResult(t *testing.T) {
121121
assert.Equal(t, threshold+3, h.failureCount.Load())
122122
}
123123

124-
func TestAppHealth_ratelimitReports(t *testing.T) {
125-
clock := clocktesting.NewFakeClock(time.Now())
126-
h := New(config.AppHealthConfig{}, nil)
127-
h.clock = clock
128-
129-
// First run should always succeed
130-
require.True(t, h.ratelimitReports())
131-
132-
// Run again without waiting
133-
require.False(t, h.ratelimitReports())
134-
require.False(t, h.ratelimitReports())
135-
136-
// Step and test
137-
clock.Step(reportMinInterval)
138-
require.True(t, h.ratelimitReports())
139-
require.False(t, h.ratelimitReports())
140-
141-
// Run tests for 1 second, constantly
142-
// Should succeed only 10 times.
143-
clock.Step(reportMinInterval)
144-
firehose := func(start time.Time, step time.Duration) (passed int64) {
145-
for clock.Now().Sub(start) < time.Second*10 {
146-
if h.ratelimitReports() {
147-
passed++
148-
}
149-
clock.Step(step)
150-
}
151-
return passed
152-
}
153-
154-
passed := firehose(clock.Now(), 10*time.Millisecond)
155-
assert.Equal(t, int64(10), passed)
156-
157-
// Repeat, but run with 3 parallel goroutines
158-
wg := sync.WaitGroup{}
159-
totalPassed := atomic.Int64{}
160-
start := clock.Now()
161-
wg.Add(3)
162-
for range 3 {
163-
go func() {
164-
totalPassed.Add(firehose(start, 3*time.Millisecond))
165-
wg.Done()
166-
}()
167-
}
168-
wg.Wait()
169-
passed = totalPassed.Load()
170-
assert.GreaterOrEqual(t, passed, int64(8))
171-
assert.LessOrEqual(t, passed, int64(12))
172-
}
173-
174124
func Test_StartProbes(t *testing.T) {
175125
t.Run("closing context should return", func(t *testing.T) {
176126
ctx, cancel := context.WithCancel(t.Context())

pkg/apphealth/status.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ package apphealth
1616

1717
import "time"
1818

19-
const (
20-
// reportMinInterval is the minimum interval between health reports.
21-
reportMinInterval = time.Second
22-
)
23-
2419
type Status struct {
2520
IsHealthy bool `json:"ishealthy"`
2621
TimeUnix int64 `json:"timeUnix"`

0 commit comments

Comments
 (0)