|
| 1 | +# Threads Tab Implementation Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document describes the implementation of the Threads tab for the Node page in YDB Embedded UI, which displays detailed thread pool information as requested in issue #2051. |
| 6 | + |
| 7 | +## Features Implemented |
| 8 | + |
| 9 | +- **Complete UI Components**: Thread pools table with all required columns |
| 10 | +- **CPU Usage Visualization**: Progress bars showing system + user CPU usage with color coding |
| 11 | +- **Thread State Visualization**: Horizontal bar chart showing distribution of thread states (R, S, etc.) |
| 12 | +- **Real API Integration**: Connected to RTK Query with auto-refresh and error handling |
| 13 | +- **TypeScript Types**: Complete type definitions for thread pool information |
| 14 | +- **Internationalization**: Full i18n support following project conventions |
| 15 | + |
| 16 | +## Component Structure |
| 17 | + |
| 18 | +``` |
| 19 | +src/containers/Node/Threads/ |
| 20 | +├── Threads.tsx # Main component |
| 21 | +├── Threads.scss # Styling |
| 22 | +├── CpuUsageBar/ # CPU usage visualization |
| 23 | +│ ├── CpuUsageBar.tsx |
| 24 | +│ └── CpuUsageBar.scss |
| 25 | +├── ThreadStatesBar/ # Thread states visualization |
| 26 | +│ ├── ThreadStatesBar.tsx |
| 27 | +│ └── ThreadStatesBar.scss |
| 28 | +└── i18n/ # Internationalization |
| 29 | + ├── en.json |
| 30 | + └── index.ts |
| 31 | +``` |
| 32 | + |
| 33 | +## Data Structure |
| 34 | + |
| 35 | +The component expects thread pool information in the following format: |
| 36 | + |
| 37 | +```typescript |
| 38 | +interface TThreadPoolInfo { |
| 39 | + Name?: string; // Thread pool name (e.g., "AwsEventLoop", "klktmr.IC") |
| 40 | + Threads?: number; // Number of threads in the pool |
| 41 | + SystemUsage?: number; // System CPU usage (0-1 range) |
| 42 | + UserUsage?: number; // User CPU usage (0-1 range) |
| 43 | + MinorPageFaults?: number; // Number of minor page faults |
| 44 | + MajorPageFaults?: number; // Number of major page faults |
| 45 | + States?: Record<string, number>; // Thread states with counts (e.g., {R: 2, S: 1}) |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Backend Integration Required |
| 50 | + |
| 51 | +Currently, the implementation uses mock data. To connect real data, the YDB backend needs to provide detailed thread information through one of these approaches: |
| 52 | + |
| 53 | +### Option 1: New Dedicated Endpoint (Recommended) |
| 54 | + |
| 55 | +``` |
| 56 | +GET /viewer/json/threads?node_id={nodeId} |
| 57 | +``` |
| 58 | + |
| 59 | +Response format: |
| 60 | + |
| 61 | +```json |
| 62 | +{ |
| 63 | + "Threads": [ |
| 64 | + { |
| 65 | + "Name": "AwsEventLoop", |
| 66 | + "Threads": 64, |
| 67 | + "SystemUsage": 0.0, |
| 68 | + "UserUsage": 0.0, |
| 69 | + "MinorPageFaults": 0, |
| 70 | + "MajorPageFaults": 0, |
| 71 | + "States": { |
| 72 | + "S": 64 |
| 73 | + } |
| 74 | + } |
| 75 | + ], |
| 76 | + "ResponseTime": "1234567890", |
| 77 | + "ResponseDuration": 123 |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +### Option 2: Extend Existing Endpoint |
| 82 | + |
| 83 | +Extend `/viewer/json/sysinfo` to include detailed thread information in addition to the current `PoolStats`. |
| 84 | + |
| 85 | +## API Implementation |
| 86 | + |
| 87 | +The frontend API integration is already implemented: |
| 88 | + |
| 89 | +1. **Viewer API**: `getNodeThreads()` method in `src/services/api/viewer.ts` |
| 90 | +2. **Node Store**: RTK Query endpoint in `src/store/reducers/node/node.ts` |
| 91 | +3. **Component**: Connected with auto-refresh in `src/containers/Node/Threads/Threads.tsx` |
| 92 | + |
| 93 | +## Data Mapping |
| 94 | + |
| 95 | +The backend should provide: |
| 96 | + |
| 97 | +- **Thread Pool Name**: From the actual thread pool name |
| 98 | +- **Thread Count**: Number of threads in each pool |
| 99 | +- **CPU Usage**: System and user CPU usage percentages (0-1 range) |
| 100 | +- **Page Faults**: Minor and major page fault counts |
| 101 | +- **Thread States**: Distribution of thread states using Linux process state codes: |
| 102 | + - `R`: Running |
| 103 | + - `S`: Sleeping (interruptible) |
| 104 | + - `D`: Disk sleep (uninterruptible) |
| 105 | + - `Z`: Zombie |
| 106 | + - `T`: Stopped |
| 107 | + - etc. |
| 108 | + |
| 109 | +## Screenshots |
| 110 | + |
| 111 | +The implementation provides a complete table view matching the requirements in the issue: |
| 112 | + |
| 113 | +- Pool name column |
| 114 | +- Thread count column |
| 115 | +- CPU usage with visual progress bar |
| 116 | +- Page fault counts |
| 117 | +- Thread state distribution visualization |
| 118 | + |
| 119 | +## Testing |
| 120 | + |
| 121 | +To test the implementation: |
| 122 | + |
| 123 | +1. Navigate to `/node/{nodeId}/threads` in the YDB Embedded UI |
| 124 | +2. The tab will be available in the node page tabs |
| 125 | +3. Currently shows mock data until backend integration is complete |
| 126 | + |
| 127 | +## Next Steps |
| 128 | + |
| 129 | +1. **Backend Development**: Implement the threads endpoint in YDB backend |
| 130 | +2. **Real Data Integration**: Replace mock data with actual thread information |
| 131 | +3. **Testing**: Verify with real YDB instances |
| 132 | +4. **Performance**: Ensure efficient data collection for thread statistics |
| 133 | + |
| 134 | +## Related Files |
| 135 | + |
| 136 | +- Node page tabs: `src/containers/Node/NodePages.ts` |
| 137 | +- Node page component: `src/containers/Node/Node.tsx` |
| 138 | +- Thread types: `src/types/api/threads.ts` |
| 139 | +- API viewer: `src/services/api/viewer.ts` |
| 140 | +- Node store: `src/store/reducers/node/node.ts` |
0 commit comments