django-cfg 1.4.58__py3-none-any.whl → 1.4.60__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of django-cfg might be problematic. Click here for more details.

Files changed (59) hide show
  1. django_cfg/__init__.py +1 -1
  2. django_cfg/apps/ipc/RPC_LOGGING.md +321 -0
  3. django_cfg/apps/ipc/TESTING.md +539 -0
  4. django_cfg/apps/ipc/__init__.py +12 -3
  5. django_cfg/apps/ipc/admin.py +212 -0
  6. django_cfg/apps/ipc/migrations/0001_initial.py +137 -0
  7. django_cfg/apps/ipc/migrations/__init__.py +0 -0
  8. django_cfg/apps/ipc/models.py +221 -0
  9. django_cfg/apps/ipc/serializers/__init__.py +10 -0
  10. django_cfg/apps/ipc/serializers/serializers.py +114 -0
  11. django_cfg/apps/ipc/services/client/client.py +83 -4
  12. django_cfg/apps/ipc/services/logging.py +239 -0
  13. django_cfg/apps/ipc/services/monitor.py +5 -3
  14. django_cfg/apps/ipc/static/django_cfg_ipc/js/dashboard/main.mjs +269 -0
  15. django_cfg/apps/ipc/static/django_cfg_ipc/js/dashboard/overview.mjs +259 -0
  16. django_cfg/apps/ipc/static/django_cfg_ipc/js/dashboard/testing.mjs +375 -0
  17. django_cfg/apps/ipc/templates/django_cfg_ipc/components/methods_content.html +22 -0
  18. django_cfg/apps/ipc/templates/django_cfg_ipc/components/notifications_content.html +9 -0
  19. django_cfg/apps/ipc/templates/django_cfg_ipc/components/overview_content.html +9 -0
  20. django_cfg/apps/ipc/templates/django_cfg_ipc/components/requests_content.html +23 -0
  21. django_cfg/apps/ipc/templates/django_cfg_ipc/components/stat_cards.html +50 -0
  22. django_cfg/apps/ipc/templates/django_cfg_ipc/components/system_status.html +47 -0
  23. django_cfg/apps/ipc/templates/django_cfg_ipc/components/tab_navigation.html +29 -0
  24. django_cfg/apps/ipc/templates/django_cfg_ipc/components/testing_tools.html +184 -0
  25. django_cfg/apps/ipc/templates/django_cfg_ipc/pages/dashboard.html +56 -0
  26. django_cfg/apps/ipc/urls.py +4 -2
  27. django_cfg/apps/ipc/views/__init__.py +7 -2
  28. django_cfg/apps/ipc/views/dashboard.py +1 -1
  29. django_cfg/apps/ipc/views/{viewsets.py → monitoring.py} +17 -11
  30. django_cfg/apps/ipc/views/testing.py +285 -0
  31. django_cfg/core/backends/__init__.py +1 -0
  32. django_cfg/core/backends/smtp.py +69 -0
  33. django_cfg/middleware/authentication.py +157 -0
  34. django_cfg/models/api/drf/config.py +2 -2
  35. django_cfg/models/services/email.py +11 -1
  36. django_cfg/modules/django_client/system/generate_mjs_clients.py +1 -1
  37. django_cfg/modules/django_dashboard/sections/widgets.py +209 -0
  38. django_cfg/modules/django_unfold/callbacks/main.py +43 -18
  39. django_cfg/modules/django_unfold/dashboard.py +41 -4
  40. django_cfg/pyproject.toml +1 -1
  41. django_cfg/static/js/api/index.mjs +8 -3
  42. django_cfg/static/js/api/ipc/client.mjs +40 -0
  43. django_cfg/static/js/api/knowbase/client.mjs +309 -0
  44. django_cfg/static/js/api/knowbase/index.mjs +13 -0
  45. django_cfg/static/js/api/payments/client.mjs +46 -1215
  46. django_cfg/static/js/api/types.mjs +164 -337
  47. django_cfg/templates/admin/index.html +8 -0
  48. django_cfg/templates/admin/layouts/dashboard_with_tabs.html +13 -1
  49. django_cfg/templates/admin/sections/widgets_section.html +129 -0
  50. django_cfg/templates/admin/snippets/tabs/widgets_tab.html +38 -0
  51. django_cfg/utils/smart_defaults.py +1 -1
  52. {django_cfg-1.4.58.dist-info → django_cfg-1.4.60.dist-info}/METADATA +1 -1
  53. {django_cfg-1.4.58.dist-info → django_cfg-1.4.60.dist-info}/RECORD +58 -31
  54. django_cfg/apps/ipc/templates/django_cfg_ipc/dashboard.html +0 -202
  55. /django_cfg/apps/ipc/static/django_cfg_ipc/js/{dashboard.mjs → dashboard.mjs.old} +0 -0
  56. /django_cfg/apps/ipc/templates/django_cfg_ipc/{base.html → layout/base.html} +0 -0
  57. {django_cfg-1.4.58.dist-info → django_cfg-1.4.60.dist-info}/WHEEL +0 -0
  58. {django_cfg-1.4.58.dist-info → django_cfg-1.4.60.dist-info}/entry_points.txt +0 -0
  59. {django_cfg-1.4.58.dist-info → django_cfg-1.4.60.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,539 @@
1
+ # IPC/RPC Testing Tools
2
+
3
+ **Production-grade load testing and debugging tools for Django-CFG RPC system.**
4
+
5
+ ---
6
+
7
+ ## 🎯 Overview
8
+
9
+ The IPC app now includes comprehensive testing tools for validating RPC communication between Django and WebSocket servers:
10
+
11
+ - **Test RPC Client** - Send individual RPC requests with response inspection
12
+ - **Load Testing Tool** - Emulate production load with concurrent requests
13
+ - **Real-time Monitoring** - Track test progress and performance metrics
14
+ - **Beautiful UI** - Tab-based interface with Material Design
15
+
16
+ ---
17
+
18
+ ## 📁 Architecture
19
+
20
+ ### Template Structure
21
+
22
+ ```
23
+ templates/django_cfg_ipc/
24
+ ├── layout/
25
+ │ └── base.html # Base template with navbar
26
+ ├── pages/
27
+ │ └── dashboard.html # Main dashboard page
28
+ ├── components/
29
+ │ ├── stat_cards.html # Statistics overview cards
30
+ │ ├── system_status.html # Redis/Stream health indicators
31
+ │ ├── tab_navigation.html # Tab switcher with badges
32
+ │ ├── overview_content.html # Overview tab content
33
+ │ ├── requests_content.html # Recent requests table
34
+ │ ├── notifications_content.html # Notification statistics
35
+ │ ├── methods_content.html # Method statistics table
36
+ │ └── testing_tools.html # Testing tools tab
37
+ ├── widgets/
38
+ └── partials/
39
+ ```
40
+
41
+ ### Backend Structure
42
+
43
+ ```
44
+ views/
45
+ ├── __init__.py # Exports all viewsets
46
+ ├── dashboard.py # Dashboard view
47
+ ├── monitoring.py # RPCMonitorViewSet
48
+ └── testing.py # RPCTestingViewSet
49
+ ```
50
+
51
+ ---
52
+
53
+ ## 🧪 Test RPC Client
54
+
55
+ ### Purpose
56
+
57
+ Send individual RPC requests for:
58
+ - Debugging method implementations
59
+ - Validating parameter schemas
60
+ - Measuring response times
61
+ - Inspecting response payloads
62
+
63
+ ### Features
64
+
65
+ - **Method Selection**: Dropdown with available RPC methods
66
+ - **Timeout Configuration**: 1-60 seconds
67
+ - **JSON Parameter Editor**: Syntax-highlighted textarea
68
+ - **Response Inspection**: Formatted JSON output
69
+ - **Error Handling**: Clear error messages with stack traces
70
+
71
+ ### Usage Example
72
+
73
+ 1. Navigate to **Testing** tab
74
+ 2. Select RPC method (e.g., `notification.send`)
75
+ 3. Edit parameters JSON:
76
+ ```json
77
+ {
78
+ "user_id": "test-123",
79
+ "type": "test",
80
+ "title": "Test Notification",
81
+ "message": "This is a test message"
82
+ }
83
+ ```
84
+ 4. Set timeout (default: 10s)
85
+ 5. Click **Send Request**
86
+ 6. Inspect response:
87
+ - Success: Green badge + response JSON
88
+ - Failed: Red badge + error message
89
+ - Duration: Response time in milliseconds
90
+
91
+ ### API Endpoint
92
+
93
+ ```http
94
+ POST /cfg/ipc/test/send
95
+ Content-Type: application/json
96
+
97
+ {
98
+ "method": "notification.send",
99
+ "params": {
100
+ "user_id": "test-123",
101
+ "type": "test",
102
+ "title": "Test Notification",
103
+ "message": "Hello"
104
+ },
105
+ "timeout": 10
106
+ }
107
+ ```
108
+
109
+ **Response:**
110
+
111
+ ```json
112
+ {
113
+ "success": true,
114
+ "duration_ms": 45.23,
115
+ "response": {
116
+ "sent": true,
117
+ "message_id": "abc-123"
118
+ },
119
+ "error": null,
120
+ "correlation_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479"
121
+ }
122
+ ```
123
+
124
+ ---
125
+
126
+ ## 🔥 Load Testing Tool
127
+
128
+ ### Purpose
129
+
130
+ Emulate production traffic to:
131
+ - Validate system performance under load
132
+ - Identify bottlenecks
133
+ - Test concurrent request handling
134
+ - Measure throughput (RPS)
135
+
136
+ ### Features
137
+
138
+ - **Configurable Volume**: 1-10,000 requests
139
+ - **Concurrency Control**: 1-100 concurrent requests
140
+ - **Method Selection**: Test any RPC method
141
+ - **Real-time Progress**: Progress bar + statistics
142
+ - **Live Metrics**:
143
+ - Success/Failed counts
144
+ - Average response time
145
+ - Requests per second (RPS)
146
+ - Elapsed time
147
+
148
+ ### Usage Example
149
+
150
+ 1. Navigate to **Testing** tab → **Load Testing Tool**
151
+ 2. Configure test parameters:
152
+ - **Total Requests**: 100
153
+ - **Concurrent Requests**: 10
154
+ - **Test Method**: `notification.send`
155
+ 3. Click **Start Load Test**
156
+ 4. Monitor progress:
157
+ - Progress bar (0/100 → 100/100)
158
+ - Success: Green counter
159
+ - Failed: Red counter
160
+ - Avg Time: Purple badge (ms)
161
+ - RPS: Purple badge (requests/sec)
162
+ 5. Click **Stop Test** to abort early (optional)
163
+
164
+ ### API Endpoints
165
+
166
+ #### Start Load Test
167
+
168
+ ```http
169
+ POST /cfg/ipc/test/load/start
170
+ Content-Type: application/json
171
+
172
+ {
173
+ "method": "notification.send",
174
+ "total_requests": 100,
175
+ "concurrency": 10,
176
+ "params": {
177
+ "user_id": "load-test",
178
+ "type": "test"
179
+ }
180
+ }
181
+ ```
182
+
183
+ **Response:**
184
+
185
+ ```json
186
+ {
187
+ "test_id": "abc123ef",
188
+ "started": true,
189
+ "message": "Load test started with 100 requests at 10 concurrency"
190
+ }
191
+ ```
192
+
193
+ #### Get Load Test Status
194
+
195
+ ```http
196
+ GET /cfg/ipc/test/load/status
197
+ ```
198
+
199
+ **Response:**
200
+
201
+ ```json
202
+ {
203
+ "test_id": "abc123ef",
204
+ "running": true,
205
+ "progress": 45,
206
+ "total": 100,
207
+ "success_count": 43,
208
+ "failed_count": 2,
209
+ "avg_duration_ms": 52.34,
210
+ "elapsed_time": 4.56,
211
+ "rps": 9.87
212
+ }
213
+ ```
214
+
215
+ #### Stop Load Test
216
+
217
+ ```http
218
+ POST /cfg/ipc/test/load/stop
219
+ ```
220
+
221
+ **Response:**
222
+
223
+ ```json
224
+ {
225
+ "message": "Load test stopped",
226
+ "progress": 45,
227
+ "total": 100
228
+ }
229
+ ```
230
+
231
+ ---
232
+
233
+ ## 📊 Metrics & Statistics
234
+
235
+ ### Real-time Stats
236
+
237
+ The load testing tool provides 4 live metrics:
238
+
239
+ | Metric | Description | Color |
240
+ |--------|-------------|-------|
241
+ | **Success** | Successful RPC calls | Blue |
242
+ | **Failed** | Failed RPC calls | Red |
243
+ | **Avg Time** | Average response time (ms) | Green |
244
+ | **RPS** | Requests per second | Purple |
245
+
246
+ ### Performance Benchmarks
247
+
248
+ Typical performance on standard hardware:
249
+
250
+ - **Single Request**: 20-50ms
251
+ - **10 Concurrent**: ~30-60ms avg
252
+ - **100 Concurrent**: ~50-100ms avg
253
+ - **Throughput**: 50-200 RPS (depends on method)
254
+
255
+ ### Error Tracking
256
+
257
+ Failed requests log:
258
+ - Error type (timeout, connection, remote error)
259
+ - Error message
260
+ - Duration until failure
261
+ - Stack trace (in Django logs)
262
+
263
+ ---
264
+
265
+ ## 🔒 Security & Permissions
266
+
267
+ ### Authentication
268
+
269
+ All testing endpoints require:
270
+ - **Django Admin Access**: `IsAdminUser` permission
271
+ - **Staff Status**: `request.user.is_staff = True`
272
+
273
+ ### Rate Limiting
274
+
275
+ To prevent abuse:
276
+ - **Max Total Requests**: 10,000 per test
277
+ - **Max Concurrency**: 100 simultaneous requests
278
+ - **Global Limit**: One active load test at a time
279
+
280
+ ### Safety Features
281
+
282
+ 1. **Thread Isolation**: Load tests run in background threads
283
+ 2. **Graceful Shutdown**: Stop button terminates test safely
284
+ 3. **Resource Cleanup**: Daemon threads auto-cleanup on exit
285
+ 4. **Error Boundaries**: Exceptions don't crash test runner
286
+
287
+ ---
288
+
289
+ ## 🧩 Integration with RPC Logging
290
+
291
+ All test requests are logged to `RPCLog` model if logging is enabled:
292
+
293
+ ```python
294
+ # View logs in Django Admin
295
+ /admin/django_cfg_ipc/rpclog/
296
+
297
+ # Filter by test runs
298
+ RPCLog.objects.filter(params___test_id='abc123ef')
299
+
300
+ # Analyze performance
301
+ stats = RPCLog.objects.stats_by_method()
302
+ ```
303
+
304
+ Benefits:
305
+ - Full request/response history
306
+ - Performance metrics per method
307
+ - Error analysis
308
+ - User attribution
309
+
310
+ ---
311
+
312
+ ## 🎨 UI Components
313
+
314
+ ### Tab Navigation
315
+
316
+ 5 tabs with badge counters:
317
+ - **Overview**: System summary
318
+ - **Recent Requests**: Last 50 RPC calls
319
+ - **Notifications**: Notification statistics
320
+ - **Methods**: Method-level stats
321
+ - **Testing**: Test tools (new!)
322
+
323
+ ### Testing Tools Tab
324
+
325
+ Two sections:
326
+ 1. **RPC Test Client** (top)
327
+ 2. **Load Testing Tool** (bottom)
328
+
329
+ ### Material Icons
330
+
331
+ Icons used:
332
+ - `send` - Send request
333
+ - `science` - Testing tools
334
+ - `speed` - Load testing
335
+ - `play_arrow` - Start test
336
+ - `stop` - Stop test
337
+ - `check_circle` - Success
338
+ - `error` - Failed
339
+
340
+ ---
341
+
342
+ ## 📝 JavaScript Integration
343
+
344
+ ### API Client Usage
345
+
346
+ ```javascript
347
+ // Import generated API client
348
+ import { api } from '/static/js/api/index.mjs';
349
+
350
+ // Send test RPC request
351
+ const result = await api.ipcTestSendCreate({
352
+ method: 'notification.send',
353
+ params: { user_id: '123' },
354
+ timeout: 10
355
+ });
356
+
357
+ // Start load test
358
+ const test = await api.ipcTestLoadStartCreate({
359
+ method: 'notification.send',
360
+ total_requests: 100,
361
+ concurrency: 10,
362
+ params: {}
363
+ });
364
+
365
+ // Poll status
366
+ setInterval(async () => {
367
+ const status = await api.ipcTestLoadStatusRetrieve();
368
+ updateUI(status);
369
+ }, 500);
370
+
371
+ // Stop test
372
+ await api.ipcTestLoadStopCreate();
373
+ ```
374
+
375
+ ### Event Handlers
376
+
377
+ ```javascript
378
+ // Send Test Request
379
+ document.getElementById('send-test-rpc').addEventListener('click', async () => {
380
+ const method = document.getElementById('test-method').value;
381
+ const params = JSON.parse(document.getElementById('test-params').value);
382
+ const timeout = parseInt(document.getElementById('test-timeout').value);
383
+
384
+ const result = await api.ipcTestSendCreate({ method, params, timeout });
385
+
386
+ displayResult(result);
387
+ });
388
+
389
+ // Start Load Test
390
+ document.getElementById('start-load-test').addEventListener('click', async () => {
391
+ const method = document.getElementById('load-method').value;
392
+ const total_requests = parseInt(document.getElementById('load-total-requests').value);
393
+ const concurrency = parseInt(document.getElementById('load-concurrency').value);
394
+
395
+ await api.ipcTestLoadStartCreate({
396
+ method,
397
+ total_requests,
398
+ concurrency,
399
+ params: {}
400
+ });
401
+
402
+ startPolling();
403
+ });
404
+ ```
405
+
406
+ ---
407
+
408
+ ## 🚀 Best Practices
409
+
410
+ ### 1. Start Small
411
+
412
+ Begin with:
413
+ - 10 total requests
414
+ - 2-5 concurrency
415
+ - Simple methods (e.g., `notification.send`)
416
+
417
+ Gradually increase load.
418
+
419
+ ### 2. Monitor System Resources
420
+
421
+ Watch for:
422
+ - Redis memory usage
423
+ - WebSocket server CPU
424
+ - Django process count
425
+ - Network bandwidth
426
+
427
+ Use `htop`, `redis-cli INFO`, Docker stats.
428
+
429
+ ### 3. Test in Isolation
430
+
431
+ Avoid load testing in production during:
432
+ - Peak traffic hours
433
+ - Active user sessions
434
+ - Critical operations
435
+
436
+ ### 4. Analyze Results
437
+
438
+ After each test:
439
+ 1. Review RPC logs in admin
440
+ 2. Check error messages
441
+ 3. Identify bottlenecks
442
+ 4. Optimize slow methods
443
+
444
+ ### 5. Cleanup
445
+
446
+ After testing:
447
+ ```python
448
+ # Delete test logs
449
+ RPCLog.objects.filter(params___test_id__isnull=False).delete()
450
+
451
+ # Clear Redis stream (optional)
452
+ # WARNING: Deletes all pending requests!
453
+ ```
454
+
455
+ ---
456
+
457
+ ## 🐛 Troubleshooting
458
+
459
+ ### Load Test Not Starting
460
+
461
+ **Symptoms**: 409 Conflict error
462
+
463
+ **Cause**: Previous test still running
464
+
465
+ **Fix**:
466
+ ```http
467
+ POST /cfg/ipc/test/load/stop
468
+ ```
469
+
470
+ ### Timeout Errors
471
+
472
+ **Symptoms**: All requests timeout
473
+
474
+ **Causes**:
475
+ - WebSocket server not running
476
+ - Redis connection issues
477
+ - Network problems
478
+
479
+ **Fix**:
480
+ 1. Check WebSocket server logs
481
+ 2. Verify Redis connectivity
482
+ 3. Test with single request first
483
+
484
+ ### High Failure Rate
485
+
486
+ **Symptoms**: >50% failed requests
487
+
488
+ **Causes**:
489
+ - Method not implemented
490
+ - Invalid parameters
491
+ - Server overload
492
+
493
+ **Fix**:
494
+ 1. Test method with single request
495
+ 2. Validate parameter schema
496
+ 3. Reduce concurrency
497
+
498
+ ---
499
+
500
+ ## 📚 Reference
501
+
502
+ ### Available RPC Methods
503
+
504
+ | Method | Purpose | Avg Duration |
505
+ |--------|---------|--------------|
506
+ | `notification.send` | Send notification to user | 20-50ms |
507
+ | `notification.broadcast` | Broadcast to all users | 30-80ms |
508
+ | `workspace.file_changed` | Notify file change | 15-40ms |
509
+ | `session.message` | Send session message | 20-45ms |
510
+
511
+ ### HTTP Status Codes
512
+
513
+ | Code | Meaning | Action |
514
+ |------|---------|--------|
515
+ | 200 | Success | Request processed |
516
+ | 400 | Bad Request | Check parameters |
517
+ | 409 | Conflict | Stop existing test |
518
+ | 500 | Server Error | Check server logs |
519
+ | 503 | Service Unavailable | Check Redis/WebSocket |
520
+
521
+ ---
522
+
523
+ ## 🔮 Future Enhancements
524
+
525
+ Planned features:
526
+ - [ ] Test result history
527
+ - [ ] Export test reports (CSV/JSON)
528
+ - [ ] Custom parameter templates
529
+ - [ ] Scheduled load tests
530
+ - [ ] Performance regression alerts
531
+ - [ ] WebSocket connection testing
532
+ - [ ] Stress testing mode (max load)
533
+
534
+ ---
535
+
536
+ **Status**: ✅ Production Ready
537
+ **Django-CFG Version**: 2.0+
538
+ **Python Version**: 3.10+
539
+ **Last Updated**: 2025-10-23
@@ -1,5 +1,5 @@
1
1
  """
2
- Django-CFG RPC Client Module.
2
+ Django-CFG IPC/RPC Module.
3
3
 
4
4
  Lightweight synchronous RPC client for Django applications to communicate
5
5
  with django-cfg-rpc WebSocket servers via Redis.
@@ -10,9 +10,11 @@ Key Features:
10
10
  - ✅ Automatic connection pooling
11
11
  - ✅ Optional dependency on django-cfg-rpc
12
12
  - ✅ Graceful fallback if django-cfg-rpc not installed
13
+ - ✅ Automatic RPC logging to database
14
+ - ✅ Beautiful admin interface with Unfold
13
15
 
14
16
  Example:
15
- >>> from django_cfg.modules.django_ipc_client import get_rpc_client
17
+ >>> from django_cfg.apps.ipc import get_rpc_client
16
18
  >>> from django_ipc.models import NotificationRequest, NotificationResponse
17
19
  >>>
18
20
  >>> rpc = get_rpc_client()
@@ -24,7 +26,8 @@ Example:
24
26
  ... title="Order Confirmed",
25
27
  ... message="Your order has been confirmed"
26
28
  ... ),
27
- ... result_model=NotificationResponse
29
+ ... result_model=NotificationResponse,
30
+ ... user=request.user # For logging
28
31
  ... )
29
32
  """
30
33
 
@@ -37,6 +40,9 @@ from .services.client.exceptions import (
37
40
  RPCTimeoutError,
38
41
  )
39
42
 
43
+ # Logging utilities
44
+ from .services.logging import RPCLogger, RPCLogContext
45
+
40
46
  __all__ = [
41
47
  # Client
42
48
  "DjangoCfgRPCClient",
@@ -48,4 +54,7 @@ __all__ = [
48
54
  "RPCRemoteError",
49
55
  "RPCConnectionError",
50
56
  "RPCConfigurationError",
57
+ # Logging
58
+ "RPCLogger",
59
+ "RPCLogContext",
51
60
  ]