Commit d6fd5f6
Add ODS counter for idle timeout connection terminations
Summary:
When `ThriftServer::setIdleTimeout()` is configured, connections that remain
idle for the specified duration are terminated via
`RocketServerConnection::timeoutExpired()`. Currently there is no counter
tracking these events. Adding one gives service owners visibility into idle
timeout behavior, following the same pattern as `thrift.dropped_conns`,
`thrift.rejected_conns`, and `thrift.accepted_connections`.
## Implementation
### 1. Add `connClosedByIdleTimeout()` to `TServerObserver`
**File:** `fbcode/thrift/lib/cpp/server/TServerObserver.h`
New virtual method after `connClosed`:
```cpp
virtual void connClosedByIdleTimeout() {}
```
### 2. Add timeseries field + override to `TServerCounters`
**File:** `fbcode/common/fb303/cpp/TServerCounters.h`
- New field `idleTimeoutConns_` (after `rejectedConns_`)
- New override declaration `connClosedByIdleTimeout()`
### 3. Wire up timeseries creation + callback in `TServerCounters.cpp`
**File:** `fbcode/common/fb303/cpp/TServerCounters.cpp`
- In `setupCounters()`: `idleTimeoutConns_ = makeTimeseries(prefix + ".idle_timeout_conns", COUNT);`
- New implementation of `connClosedByIdleTimeout()` that increments the timeseries
### 4. Add `onIdleTimeout()` callback to `RocketServerHandler`
**File:** `fbcode/thrift/lib/cpp2/transport/rocket/server/RocketServerHandler.h`
New virtual method after `connectionClosing()`:
```cpp
virtual void onIdleTimeout() {}
```
### 5. Override in `ThriftRocketServerHandler`
**Files:**
- `ThriftRocketServerHandler.h` — declaration: `void onIdleTimeout() final;`
- `ThriftRocketServerHandler.cpp` — implementation calls `observer->connClosedByIdleTimeout()`
### 6. Call from `RocketServerConnection::timeoutExpired()`
**File:** `fbcode/thrift/lib/cpp2/transport/rocket/server/RocketServerConnection.cpp`
Added `frameHandler_->onIdleTimeout()` call before `closeWhenIdle()` in `timeoutExpired()`.
### 7. Update `FakeServerObserver` for testing
**File:** `fbcode/thrift/lib/cpp2/transport/core/testutil/FakeServerObserver.h`
- New atomic counter `connClosedByIdleTimeout_`
- New override `connClosedByIdleTimeout()` that increments the counter
### 8. Add test verification
**File:** `fbcode/thrift/lib/cpp2/test/server/ThriftServerTest.cpp`
Updated `ConnectionIdleTimeoutTest` to attach a `FakeServerObserver`, verify
the counter is 0 before idle timeout, and verify it increments to 1 after the
connection is terminated.
## ODS Counter Name
The counter will be published as `thrift.idle_timeout_conns` (with aggregation
suffixes like `.count.60`, `.count.600`, `.count.3600`).
## Files Modified
| File | Change |
|------|--------|
| `thrift/lib/cpp/server/TServerObserver.h` | New virtual method |
| `common/fb303/cpp/TServerCounters.h` | New field + override decl |
| `common/fb303/cpp/TServerCounters.cpp` | Create timeseries + impl |
| `thrift/lib/cpp2/transport/rocket/server/RocketServerHandler.h` | New virtual method |
| `thrift/lib/cpp2/transport/rocket/server/ThriftRocketServerHandler.h` | Override decl |
| `thrift/lib/cpp2/transport/rocket/server/ThriftRocketServerHandler.cpp` | Override impl |
| `thrift/lib/cpp2/transport/rocket/server/RocketServerConnection.cpp` | Call onIdleTimeout() |
| `thrift/lib/cpp2/transport/core/testutil/FakeServerObserver.h` | New counter + override |
| `thrift/lib/cpp2/test/server/ThriftServerTest.cpp` | Verify counter in test |
| `thrift/lib/cpp2/test/BUCK` | Add mocks dep |
Reviewed By: sazonovkirill
Differential Revision: D95074970
fbshipit-source-id: e263c7b46be62b8e46aa7ec41e23451d19ef718a1 parent 5fdaecf commit d6fd5f6
7 files changed
Lines changed: 25 additions & 0 deletions
File tree
- third-party/thrift/src/thrift/lib
- cpp2
- test/server
- transport
- core/testutil
- rocket/server
- cpp/server
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
162 | 164 | | |
163 | 165 | | |
164 | 166 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
2315 | 2316 | | |
2316 | 2317 | | |
2317 | 2318 | | |
| 2319 | + | |
| 2320 | + | |
2318 | 2321 | | |
2319 | 2322 | | |
| 2323 | + | |
| 2324 | + | |
2320 | 2325 | | |
2321 | 2326 | | |
2322 | 2327 | | |
| |||
2327 | 2332 | | |
2328 | 2333 | | |
2329 | 2334 | | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
2330 | 2340 | | |
2331 | 2341 | | |
2332 | 2342 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| 67 | + | |
| 68 | + | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
988 | 988 | | |
989 | 989 | | |
990 | 990 | | |
| 991 | + | |
991 | 992 | | |
992 | 993 | | |
993 | 994 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
563 | 563 | | |
564 | 564 | | |
565 | 565 | | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
566 | 572 | | |
567 | 573 | | |
568 | 574 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
0 commit comments