Commit f7051be
[automatic failover] Implement sliding time window metrics tracker (#3521)
* abstract clock for easy testing
* Improve LockFreeSlidingWindowMetrics: fix bugs and add tests
Bug Fixes:
- Fix: Ensure snapshot metrics remain accurate after a full window rotation
- Fix: events recorded exactly at bucket boundaries were miscounted
- Enforce window size % bucket size == 0
- Move LockFreeSlidingWindowMetricsUnitTests to correct package
(io.lettuce.core.failover.metrics)
* remove unused reset methods
* extract interface for MetricsSnapshot
- remove snapshotTime - not used & not correctly calcualted
- remove reset metrics - unused as of now
* add LockFreeSlidingWindowMetrics benchmark test
* performance tests moved to metrics package
* replace with port from reselience4j
* update copyrights
* format
* clean up javadocs
* clean up
- fix incorrect javadoc
- fix failing benchmark
* [automatic failover] Hide failover metrics implementation
- CircuitBreakerMetrics, MetricsSnapshot - public
- metrics implementation details stay inside io.lettuce.core.failover.metrics
- Update CircuitBreaker to obtain its metrics via CircuitBreakerMetricsFactory.createLockFree()
* Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* rename createLockFree -> createDefaultMetrics
* address review comments by @atakavci
- remove CircuitBreakerMetrics, CircuitBreakerMetricsImpl
- rename SlidingWindowMetrics -> CircuitBreakerMetrics
* format
* Enforce min-window size of 2 buckets
Current implementation requires at least 2 buckets window
With windowSize=1, only one node is created with next=null
When updateWindow() advances the window it sets HEAD to headNext, which is null for a single-node window
On the next call to updateWindow(), tries to access head.next but head is now null, causing:
NullPointerException: Cannot read field "next" because "head" is null
* Clean-up benchmark
- benchmark matrix
threads (1,4)
window_size ("2", "30", "180")
- performs 1_000_000 ops in simulated 5min test window
- benchmark record events
- benchmark record & read snapshot
* remove MetricsPerformanceTests.java
- no reliable way to assert on performance, instead added basic benchmark test to benchmark recording/snapshot reading average times
- gc benchmarks are available for local testing
* reset method removed
* Apply suggestion from @Copilot
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Apply suggestion from @atakavci
Co-authored-by: atakavci <a_takavci@yahoo.com>
* Update src/main/java/io/lettuce/core/failover/metrics/CircuitBreakerMetrics.java
Co-authored-by: Tihomir Krasimirov Mateev <tihomir.mateev@redis.com>
* add missing license header and javadoc
* add missing license header and javadoc
* correct author for jmh failover metrics
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: atakavci <a_takavci@yahoo.com>
Co-authored-by: Tihomir Krasimirov Mateev <tihomir.mateev@redis.com>1 parent c2890be commit f7051be
File tree
23 files changed
+1336
-943
lines changed- src
- main/java/io/lettuce/core/failover
- metrics
- test
- java/io/lettuce/core/failover
- metrics
- jmh/io/lettuce/core/failover/metrics
23 files changed
+1336
-943
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
1299 | | - | |
| 1299 | + | |
1300 | 1300 | | |
1301 | 1301 | | |
1302 | 1302 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
Lines changed: 11 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
18 | | - | |
| 21 | + | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | | - | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | | - | |
29 | | - | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 38 | | |
Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
0 commit comments