kukuy 1.5.0 → 1.9.0
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.
- package/README.md +159 -188
- package/balancer.log +30 -0
- package/certs/auto/certificate.crt +22 -0
- package/certs/auto/private.key +28 -0
- package/kukuy-plugins/README.md +125 -0
- package/kukuy-plugins/cache-plugin/index.js +477 -0
- package/kukuy-plugins/cache-plugin/manifest.json +17 -0
- package/kukuy-plugins/ejemplo-plugin/index.js +41 -0
- package/kukuy-plugins/ejemplo-plugin/manifest.json +11 -0
- package/kukuy-plugins/health-checker/index.js +168 -0
- package/kukuy-plugins/health-checker/manifest.json +16 -0
- package/kukuy-plugins/health-monitor/index.js +58 -0
- package/kukuy-plugins/health-monitor/manifest.json +16 -0
- package/kukuy-plugins/redirect-plugin/index.js +172 -0
- package/kukuy-plugins/redirect-plugin/manifest.json +15 -0
- package/package.json +7 -3
- package/servers_real.json +5 -0
- package/src/core/Balancer.js +176 -39
- package/src/core/ServerPool.js +2 -2
- package/src/extensibility/ExtendedFilterChain.js +90 -0
- package/src/extensibility/ExtendedHookManager.js +87 -0
- package/src/extensibility/FilterChain.js +2 -9
- package/src/extensibility/HookManager.js +1 -0
- package/src/extensibility/PostStartupExtension.js +97 -0
- package/src/plugins/PluginManager.js +231 -0
- package/src/utils/HealthChecker.js +61 -6
- package/.ctagsd/ctagsd.json +0 -954
- package/.ctagsd/file_list.txt +0 -100
- package/.ctagsd/tags.db +0 -0
- package/CHANGELOG.md +0 -125
- package/LICENSE +0 -680
- package/README-SSL.md +0 -165
- package/captura.png +0 -0
- package/kukuu1.webp +0 -0
- package/kukuy.workspace +0 -11
- package/optimize-mariadb.sh +0 -152
- package/restart-balancer.sh +0 -10
- package/scripts/load_test.py +0 -151
- package/stress-test.js +0 -190
- package/test_optimization.js +0 -54
package/README.md
CHANGED
|
@@ -1,65 +1,29 @@
|
|
|
1
|
-
# KUKUY
|
|
1
|
+
# KUKUY - Balanceador de Carga
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
KUKUY es un sistema de balanceo de carga backend desarrollado en Node.js que permite distribuir solicitudes entre múltiples servidores backend utilizando diferentes algoritmos de balanceo. El sistema incluye características avanzadas como soporte para hooks, filtros, rutas personalizadas y un panel de control web.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Características Principales
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
O para instalarlo localmente en tu proyecto:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
npm install kukuy
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Características
|
|
27
|
-
|
|
28
|
-
- Distribución de carga usando algoritmo RoundRobin
|
|
29
|
-
- Soporte para HTTP y HTTPS
|
|
30
|
-
- Configuración mediante variables de entorno
|
|
31
|
-
- Arquitectura modular con soporte para hooks y filtros
|
|
32
|
-
- Verificación de salud de servidores backend
|
|
33
|
-
- Enrutamiento basado en patrones
|
|
34
|
-
- Sistema de logging detallado para servidores online/offline
|
|
35
|
-
- Caching de respuestas para mejorar el rendimiento
|
|
36
|
-
- Panel de control web para monitoreo
|
|
37
|
-
|
|
38
|
-
## Instalación
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
npm install
|
|
42
|
-
```
|
|
7
|
+
- **Algoritmos de Balanceo**: Soporta algoritmos como Round Robin e IP Hash
|
|
8
|
+
- **Soporte para HTTPS/SSL**: Capacidad de manejar conexiones seguras
|
|
9
|
+
- **Panel de Control Web**: Interfaz gráfica para monitorear el estado del sistema
|
|
10
|
+
- **Sistema de Plugins**: Arquitectura extensible mediante plugins
|
|
11
|
+
- **Hooks y Filtros**: Capacidad para interceptar y modificar solicitudes/responses
|
|
12
|
+
- **Sistema de Cache Robusto**: Almacenamiento en memoria con TTL configurable y política LRU
|
|
13
|
+
- **Rutas Personalizadas**: Configuración flexible de rutas para diferentes grupos de servidores
|
|
14
|
+
- **Monitoreo en Tiempo Real**: Métricas detalladas sobre rendimiento y estado de servidores
|
|
15
|
+
- **Reintento Inteligente**: Reenvío automático de solicitudes a servidores alternativos en caso de fallo
|
|
16
|
+
- **Verificación de Salud Periódica**: Sistema automatizado que verifica regularmente la salud de los servidores backend
|
|
17
|
+
- **Monitoreo de Eventos de Salud**: Registro y seguimiento detallado de eventos relacionados con la verificación de salud
|
|
43
18
|
|
|
44
19
|
## Configuración
|
|
45
20
|
|
|
46
|
-
|
|
21
|
+
### Archivos de Configuración
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
- `BALANCER_HTTPS_PORT`: Puerto para conexiones HTTPS (opcional)
|
|
50
|
-
- `CONFIG_FILE_PATH`: Ruta al archivo de configuración de servidores (por defecto: ./servers.json)
|
|
51
|
-
- `ROUTES_FILE_PATH`: Ruta al archivo de configuración de rutas (por defecto: ./routes.json)
|
|
52
|
-
- `LOAD_BALANCING_ALGORITHM`: Algoritmo de balanceo a usar ('roundrobin' o 'iphash') (por defecto: 'roundrobin')
|
|
53
|
-
- `SSL_CERT_PATH`: Ruta al certificado SSL (requerido para HTTPS)
|
|
54
|
-
- `SSL_KEY_PATH`: Ruta a la llave privada SSL (requerido para HTTPS)
|
|
55
|
-
- `HEALTH_CHECK_INTERVAL`: Intervalo para verificación de salud en ms (por defecto: 30000)
|
|
56
|
-
- `LOG_LEVEL`: Nivel de logging (info, warn, error, debug) (por defecto: info)
|
|
57
|
-
- `LOG_FILE_PATH`: Ruta al archivo de logs (por defecto: ./balancer.log)
|
|
23
|
+
El sistema utiliza varios archivos de configuración:
|
|
58
24
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### servers.json
|
|
62
|
-
Define los servidores backend:
|
|
25
|
+
#### `servers.json`
|
|
26
|
+
Define los servidores backend a los que se distribuirán las solicitudes:
|
|
63
27
|
|
|
64
28
|
```json
|
|
65
29
|
{
|
|
@@ -67,21 +31,24 @@ Define los servidores backend:
|
|
|
67
31
|
{
|
|
68
32
|
"url": "http://localhost:3001",
|
|
69
33
|
"weight": 1,
|
|
70
|
-
"tags": ["api"]
|
|
71
|
-
"active": true
|
|
34
|
+
"tags": ["api"]
|
|
72
35
|
},
|
|
73
36
|
{
|
|
74
37
|
"url": "http://localhost:3002",
|
|
75
38
|
"weight": 1,
|
|
76
|
-
"tags": ["api"]
|
|
77
|
-
|
|
39
|
+
"tags": ["api"]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"url": "http://localhost:3003",
|
|
43
|
+
"weight": 1,
|
|
44
|
+
"tags": ["web"]
|
|
78
45
|
}
|
|
79
46
|
]
|
|
80
47
|
}
|
|
81
48
|
```
|
|
82
49
|
|
|
83
|
-
|
|
84
|
-
Define las
|
|
50
|
+
#### `routes.json`
|
|
51
|
+
Define las rutas y a qué grupo de servidores deben dirigirse:
|
|
85
52
|
|
|
86
53
|
```json
|
|
87
54
|
{
|
|
@@ -100,173 +67,177 @@ Define las reglas de enrutamiento para dirigir solicitudes específicas a grupos
|
|
|
100
67
|
}
|
|
101
68
|
```
|
|
102
69
|
|
|
103
|
-
|
|
104
|
-
- Las rutas definen patrones de URL (usando comodín `*`) y métodos HTTP permitidos
|
|
105
|
-
- El campo `target` especifica la etiqueta de servidores backend a los que se dirigirá la solicitud
|
|
106
|
-
- Por ejemplo, todas las solicitudes que empiezan con `/api/` se enviarán solo a servidores que tengan la etiqueta "api"
|
|
107
|
-
- Las solicitudes que no coincidan con ninguna ruta específica se distribuirán entre todos los servidores disponibles
|
|
108
|
-
|
|
109
|
-
## Uso
|
|
70
|
+
### Variables de Entorno
|
|
110
71
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
72
|
+
- `LOAD_BALANCING_ALGORITHM`: Algoritmo de balanceo ('roundrobin' o 'iphash')
|
|
73
|
+
- `BALANCER_HTTP_PORT`: Puerto HTTP del balanceador (por defecto 8080)
|
|
74
|
+
- `BALANCER_HTTPS_PORT`: Puerto HTTPS del balanceador
|
|
75
|
+
- `CONFIG_FILE_PATH`: Ruta al archivo de configuración de servidores
|
|
76
|
+
- `ROUTES_FILE_PATH`: Ruta al archivo de configuración de rutas
|
|
77
|
+
- `SSL_CERT_PATH`: Ruta al certificado SSL
|
|
78
|
+
- `SSL_KEY_PATH`: Ruta a la llave privada SSL
|
|
79
|
+
- `DASHBOARD_PORT`: Puerto del panel de control web (por defecto 8082)
|
|
80
|
+
- `WEBSOCKET_PORT`: Puerto del servidor WebSocket (por defecto 8083)
|
|
81
|
+
- `HEALTH_CHECK_INTERVAL`: Intervalo de verificación de salud de servidores (en milisegundos, por defecto 30000)
|
|
82
|
+
- `LOG_LEVEL`: Nivel de logging (por defecto 'info')
|
|
115
83
|
|
|
116
|
-
|
|
117
|
-
```bash
|
|
118
|
-
npm run dev
|
|
119
|
-
```
|
|
84
|
+
## Algoritmos de Balanceo
|
|
120
85
|
|
|
121
|
-
###
|
|
122
|
-
|
|
123
|
-
BALANCER_HTTP_PORT=9090 BALANCER_HTTPS_PORT=9443 CONFIG_FILE_PATH=./my-servers.json npm start
|
|
124
|
-
```
|
|
86
|
+
### Round Robin
|
|
87
|
+
Distribuye las solicitudes de forma equitativa entre todos los servidores disponibles, ciclando secuencialmente.
|
|
125
88
|
|
|
126
|
-
###
|
|
127
|
-
|
|
128
|
-
# Usar algoritmo RoundRobin (predeterminado)
|
|
129
|
-
LOAD_BALANCING_ALGORITHM=roundrobin npm start
|
|
89
|
+
### IP Hash
|
|
90
|
+
Utiliza la dirección IP del cliente para determinar a qué servidor se enviará la solicitud, asegurando que las solicitudes del mismo cliente siempre vayan al mismo servidor.
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
LOAD_BALANCING_ALGORITHM=iphash npm start
|
|
133
|
-
```
|
|
92
|
+
## Scripts de Inicio
|
|
134
93
|
|
|
135
|
-
|
|
94
|
+
El proyecto incluye scripts preconfigurados para iniciar el balanceador:
|
|
136
95
|
|
|
137
|
-
|
|
96
|
+
### `start-roundrobin.sh`
|
|
97
|
+
Inicia el balanceador con el algoritmo Round Robin:
|
|
138
98
|
```bash
|
|
139
99
|
./start-roundrobin.sh
|
|
140
100
|
```
|
|
141
101
|
|
|
142
|
-
|
|
102
|
+
### `start-iphash.sh`
|
|
103
|
+
Inicia el balanceador con el algoritmo IP Hash:
|
|
143
104
|
```bash
|
|
144
105
|
./start-iphash.sh
|
|
145
106
|
```
|
|
146
107
|
|
|
147
|
-
|
|
108
|
+
### `start-ssl.sh` y `start-ssl-config.sh`
|
|
109
|
+
Scripts para iniciar el balanceador con soporte SSL/TLS.
|
|
148
110
|
|
|
149
|
-
|
|
111
|
+
## Panel de Control Web
|
|
150
112
|
|
|
151
|
-
|
|
113
|
+
KUKUY incluye un panel de control web accesible en `http://localhost:8082` (por defecto) que muestra:
|
|
152
114
|
|
|
153
|
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
156
|
-
-
|
|
157
|
-
-
|
|
115
|
+
- Estado general del sistema
|
|
116
|
+
- Métricas de rendimiento (RPS, tiempo de respuesta promedio)
|
|
117
|
+
- Estado de los servidores backend
|
|
118
|
+
- Información sobre el algoritmo de balanceo actual
|
|
119
|
+
- Gráficos de uso reciente
|
|
158
120
|
|
|
159
|
-
|
|
160
|
-
```json
|
|
161
|
-
{
|
|
162
|
-
"serverStats": {
|
|
163
|
-
"1": {
|
|
164
|
-
"id": 1,
|
|
165
|
-
"totalRequests": 10,
|
|
166
|
-
"successfulRequests": 10,
|
|
167
|
-
"failedRequests": 0,
|
|
168
|
-
"totalResponseTime": 1250,
|
|
169
|
-
"minResponseTime": 5,
|
|
170
|
-
"maxResponseTime": 346,
|
|
171
|
-
"avgResponseTime": 125,
|
|
172
|
-
"responseCodes": {"200": 10},
|
|
173
|
-
"lastActive": 1769298297602,
|
|
174
|
-
"responseTimes": [346, 7, 7, 12, 45, 67, 89, 102, 115, 120]
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## Hooks Disponibles
|
|
121
|
+
## Sistema de Plugins
|
|
181
122
|
|
|
182
|
-
|
|
183
|
-
- `onServerSelected`: Se ejecuta después de seleccionar un servidor backend
|
|
184
|
-
- `onResponseSent`: Se ejecuta cuando se envía la respuesta al cliente
|
|
185
|
-
- `onServerError`: Se ejecuta cuando ocurre un error con un servidor backend
|
|
123
|
+
La arquitectura de KUKUY permite extender su funcionalidad mediante plugins. Los plugins se colocan en el directorio `kukuy-plugins/` y deben incluir un archivo `manifest.json` con la configuración del plugin.
|
|
186
124
|
|
|
187
|
-
##
|
|
125
|
+
## Plugins de Verificación de Salud
|
|
188
126
|
|
|
189
|
-
|
|
190
|
-
- `RateLimitFilter`: Control de límite de peticiones
|
|
191
|
-
- `LoggingFilter`: Registro de solicitudes
|
|
192
|
-
- `CachingFilter`: Caché de respuestas
|
|
127
|
+
KUKUY incluye dos plugins especializados para la gestión de la salud de los servidores backend:
|
|
193
128
|
|
|
194
|
-
|
|
129
|
+
### Plugin de Verificación de Salud Periódica (`health-checker`)
|
|
195
130
|
|
|
196
|
-
|
|
197
|
-
- `Balancer.js`: Punto de entrada principal del sistema
|
|
198
|
-
- `ServerPool.js`: Gestión del conjunto de servidores backend
|
|
199
|
-
- `RequestHandler.js`: Manejo de solicitudes entrantes (integrado en Balancer.js)
|
|
131
|
+
Este plugin implementa un sistema de verificación de salud proactivo que:
|
|
200
132
|
|
|
201
|
-
|
|
202
|
-
-
|
|
203
|
-
- `
|
|
204
|
-
-
|
|
205
|
-
-
|
|
133
|
+
- Verifica la salud de todos los servidores backend en intervalos regulares
|
|
134
|
+
- Utiliza la configuración `HEALTH_CHECK_INTERVAL` para determinar la frecuencia de verificación
|
|
135
|
+
- Se comunica con el endpoint `/health` de cada servidor para determinar su estado
|
|
136
|
+
- Actualiza dinámicamente el estado de salud de los servidores en el pool
|
|
137
|
+
- Integra con el sistema de hooks para notificar eventos de salud
|
|
206
138
|
|
|
207
|
-
###
|
|
208
|
-
- `ConfigManager.js`: Lee y procesa variables de entorno
|
|
209
|
-
- `RouteLoader.js`: Carga rutas y paths desde archivos de configuración
|
|
139
|
+
### Plugin de Monitoreo de Eventos de Salud (`health-monitor`)
|
|
210
140
|
|
|
211
|
-
|
|
212
|
-
- `HttpBalancer.js`: Manejo de conexiones HTTP
|
|
213
|
-
- `HttpsBalancer.js`: Manejo de conexiones HTTPS
|
|
141
|
+
Este plugin proporciona monitoreo y registro detallado de los eventos relacionados con la salud de los servidores:
|
|
214
142
|
|
|
215
|
-
|
|
216
|
-
-
|
|
217
|
-
-
|
|
143
|
+
- Registra eventos cuando comienza una verificación de salud
|
|
144
|
+
- Muestra el resultado de las verificaciones (saludable/no saludable)
|
|
145
|
+
- Captura y registra errores, timeouts y excepciones durante las verificaciones
|
|
146
|
+
- Proporciona alertas cuando un servidor no está saludable
|
|
147
|
+
- Muestra información detallada sobre el estado de los servidores
|
|
218
148
|
|
|
219
|
-
|
|
220
|
-
- `Logger.js`: Sistema de logging
|
|
221
|
-
- `BalancerLogger.js`: Sistema de logging detallado para servidores online/offline
|
|
222
|
-
- `HealthChecker.js`: Verificación de estado de servidores backend
|
|
223
|
-
- `MetricsCollector.js`: Recolección de métricas de rendimiento
|
|
149
|
+
Ambos plugins trabajan juntos para proporcionar un sistema completo de monitoreo de salud que va más allá de la verificación reactiva (solo cuando un servidor falla) hacia un enfoque proactivo que mantiene un seguimiento constante del estado de los servidores backend.
|
|
224
150
|
|
|
225
|
-
|
|
151
|
+
### Estructura de un Plugin
|
|
226
152
|
|
|
227
|
-
|
|
228
|
-
- **Hot Reload de Configuración**: Actualización de configuración sin reinicio (requiere implementación de listeners de cambio de archivos)
|
|
229
|
-
- **API REST para Gestión de Servidores**: Endpoint para añadir/eliminar servidores dinámicamente
|
|
230
|
-
- **Sistema de Alertas**: Notificaciones cuando servidores caen o se recuperan
|
|
231
|
-
- **Soporte para WebSocket**: Balanceo de conexiones WebSocket
|
|
232
|
-
- **Compresión de Respuestas**: Soporte para Gzip/Brotli
|
|
233
|
-
- **Persistencia de Sesión**: Sticky sessions basadas en cookies o IP
|
|
153
|
+
Un plugin típico incluye:
|
|
234
154
|
|
|
235
|
-
|
|
236
|
-
-
|
|
237
|
-
- **Least Connections**: Enviar a servidor con menos conexiones
|
|
238
|
-
- **IP Hash**: Distribución basada en dirección IP del cliente
|
|
155
|
+
- `manifest.json`: Metadatos del plugin
|
|
156
|
+
- `index.js`: Código principal del plugin con funciones `init()` y `deinit()`
|
|
239
157
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
158
|
+
Ejemplo de `manifest.json`:
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"name": "Nombre del Plugin",
|
|
162
|
+
"version": "1.0.0",
|
|
163
|
+
"description": "Descripción del plugin",
|
|
164
|
+
"author": "Autor",
|
|
165
|
+
"main": "index.js",
|
|
166
|
+
"kukuyVersion": "^1.6.0",
|
|
167
|
+
"hooks": ["onRequestReceived", "onResponseSent"],
|
|
168
|
+
"filters": ["request_processing"],
|
|
169
|
+
"enabled": true
|
|
170
|
+
}
|
|
246
171
|
```
|
|
247
172
|
|
|
248
|
-
##
|
|
249
|
-
|
|
250
|
-
###
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
173
|
+
## Hooks y Filtros
|
|
174
|
+
|
|
175
|
+
### Hooks
|
|
176
|
+
Permiten ejecutar código en puntos específicos del ciclo de vida de una solicitud:
|
|
177
|
+
- `onRequestReceived`: Cuando se recibe una solicitud
|
|
178
|
+
- `onServerSelected`: Después de seleccionar un servidor destino
|
|
179
|
+
- `onResponseReady`: Antes de enviar la respuesta al cliente (permite interceptar la respuesta del servidor backend)
|
|
180
|
+
- `onResponseSent`: Después de enviar la respuesta al cliente
|
|
181
|
+
- `onServerError`: Cuando ocurre un error con un servidor backend
|
|
182
|
+
|
|
183
|
+
### Filtros
|
|
184
|
+
Permiten interceptar y potencialmente modificar o bloquear solicitudes antes de que sean procesadas:
|
|
185
|
+
- Se pueden aplicar filtros de solicitud (`request_processing`)
|
|
186
|
+
- Permiten implementar lógica de seguridad, autenticación, etc.
|
|
187
|
+
- Soportan prioridades para controlar el orden de ejecución
|
|
188
|
+
|
|
189
|
+
### Sistema de Cache Robusto
|
|
190
|
+
KUKUY incluye un sistema avanzado de cache que:
|
|
191
|
+
- Almacena respuestas en memoria con TTL (Time To Live) configurable
|
|
192
|
+
- Implementa política LRU (Least Recently Used) para manejo de espacio
|
|
193
|
+
- Permite configurar métodos HTTP cacheables (por defecto: GET)
|
|
194
|
+
- Soporta códigos de estado cacheables (por defecto: 200, 201, 204)
|
|
195
|
+
- Incluye limpieza automática de entradas expiradas
|
|
196
|
+
- Ofrece estadísticas detalladas sobre el uso de la caché
|
|
197
|
+
- Se integra completamente con el sistema de hooks y filtros
|
|
198
|
+
|
|
199
|
+
Los plugins de cache pueden:
|
|
200
|
+
- Interceptar solicitudes para verificar si están en caché
|
|
201
|
+
- Almacenar respuestas del servidor backend en caché
|
|
202
|
+
- Servir respuestas directamente desde la caché sin contactar al servidor backend
|
|
203
|
+
- Configurar TTL por defecto y reglas de expiración
|
|
204
|
+
- Implementar compresión opcional de contenido cacheado
|
|
205
|
+
- Tienen la máxima prioridad (0) para asegurar que se ejecuten antes que otros plugins
|
|
206
|
+
|
|
207
|
+
### Jerarquía de Prioridades
|
|
208
|
+
- **Prioridad 0**: Plugin de cache (máxima prioridad)
|
|
209
|
+
- **Prioridad 1-4**: Otros plugins críticos
|
|
210
|
+
- **Prioridad 5**: Plugin de ejemplo y otros plugins estándar
|
|
211
|
+
- **Prioridad 6-9**: Plugins de funcionalidad intermedia
|
|
212
|
+
- **Prioridad 10+**: Manejadores de errores y eventos especiales
|
|
213
|
+
|
|
214
|
+
## Seguridad
|
|
215
|
+
|
|
216
|
+
- El sistema incluye mecanismos para marcar servidores como fallidos temporalmente
|
|
217
|
+
- Implementa reintento inteligente hacia servidores alternativos
|
|
218
|
+
- Permite configurar límites de intentos fallidos antes de excluir un servidor
|
|
219
|
+
|
|
220
|
+
## Monitoreo y Métricas
|
|
221
|
+
|
|
222
|
+
KUKUY proporciona métricas detalladas sobre:
|
|
223
|
+
- Solicitudes totales procesadas
|
|
224
|
+
- RPS (Solicitudes por segundo) acumulado e instantáneo
|
|
225
|
+
- Tiempo de respuesta promedio
|
|
226
|
+
- Tasa de éxito
|
|
227
|
+
- Estado de salud de los servidores
|
|
228
|
+
- Uso de recursos del sistema (CPU, memoria)
|
|
254
229
|
|
|
255
230
|
## Licencia
|
|
256
231
|
|
|
257
|
-
Este proyecto está licenciado bajo la Licencia
|
|
232
|
+
Este proyecto está licenciado bajo la Licencia GPL-3.0 o posterior.
|
|
258
233
|
|
|
259
|
-
|
|
234
|
+
## Autor
|
|
260
235
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
236
|
+
Benjamín Sánchez Cárdenas
|
|
237
|
+
Email de contacto: bytedogssyndicate@gmail.com
|
|
238
|
+
Página web oficial: https://bsanchez.unaux.com/
|
|
239
|
+
Repositorio oficial: https://gitlab.com/bytedogssyndicate1/kukuy
|
|
265
240
|
|
|
266
|
-
|
|
267
|
-
SIN NINGUNA GARANTÍA; ni siquiera la garantía implícita de
|
|
268
|
-
COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR.
|
|
269
|
-
Consulte la Licencia Pública General GNU para obtener más detalles.
|
|
241
|
+
## Contribuciones
|
|
270
242
|
|
|
271
|
-
|
|
272
|
-
junto con este programa. Si no, consulte <https://www.gnu.org/licenses/>.
|
|
243
|
+
Las contribuciones son bienvenidas. Por favor, abre un issue o pull request para discutir cambios propuestos.
|
package/balancer.log
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{"timestamp":"2026-01-30T19:04:05.202Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":631,"statusCode":200}}
|
|
2
|
+
{"timestamp":"2026-01-30T19:04:34.272Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":56,"statusCode":200}}
|
|
3
|
+
{"timestamp":"2026-01-30T20:17:23.725Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":727,"statusCode":200}}
|
|
4
|
+
{"timestamp":"2026-01-30T20:17:24.900Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":525,"statusCode":200}}
|
|
5
|
+
{"timestamp":"2026-01-30T20:17:38.252Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":663,"statusCode":200}}
|
|
6
|
+
{"timestamp":"2026-01-30T20:17:39.346Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":524,"statusCode":200}}
|
|
7
|
+
{"timestamp":"2026-01-30T20:17:47.856Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":58,"statusCode":200}}
|
|
8
|
+
{"timestamp":"2026-01-30T20:17:48.459Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":55,"statusCode":200}}
|
|
9
|
+
{"timestamp":"2026-01-30T20:17:51.323Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":81,"statusCode":200}}
|
|
10
|
+
{"timestamp":"2026-01-30T20:17:51.938Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":39,"statusCode":200}}
|
|
11
|
+
{"timestamp":"2026-01-30T20:17:57.742Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":73,"statusCode":200}}
|
|
12
|
+
{"timestamp":"2026-01-30T20:17:58.347Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":52,"statusCode":200}}
|
|
13
|
+
{"timestamp":"2026-01-30T20:18:16.831Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":98,"statusCode":200}}
|
|
14
|
+
{"timestamp":"2026-01-30T20:18:17.792Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":400,"statusCode":200}}
|
|
15
|
+
{"timestamp":"2026-01-30T20:21:10.507Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":135,"statusCode":200}}
|
|
16
|
+
{"timestamp":"2026-01-30T20:21:11.101Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":47,"statusCode":200}}
|
|
17
|
+
{"timestamp":"2026-01-30T20:21:27.474Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":35,"statusCode":200}}
|
|
18
|
+
{"timestamp":"2026-01-30T20:21:28.076Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":53,"statusCode":200}}
|
|
19
|
+
{"timestamp":"2026-01-30T20:22:15.368Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":121,"statusCode":200}}
|
|
20
|
+
{"timestamp":"2026-01-30T20:22:16.014Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":58,"statusCode":200}}
|
|
21
|
+
{"timestamp":"2026-01-30T20:22:29.162Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":48,"statusCode":200}}
|
|
22
|
+
{"timestamp":"2026-01-30T20:22:29.742Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":37,"statusCode":200}}
|
|
23
|
+
{"timestamp":"2026-01-30T20:23:10.703Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":123,"statusCode":200}}
|
|
24
|
+
{"timestamp":"2026-01-30T20:23:11.347Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":82,"statusCode":200}}
|
|
25
|
+
{"timestamp":"2026-01-30T20:23:25.118Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":32,"statusCode":200}}
|
|
26
|
+
{"timestamp":"2026-01-30T20:23:25.726Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":29,"statusCode":200}}
|
|
27
|
+
{"timestamp":"2026-01-30T20:26:32.857Z","level":"INFO","message":"Servidor ONLINE - ID: 1, URL: http://localhost:3434","eventType":"target_online","serverId":1,"serverUrl":"http://localhost:3434","request":{"url":"/track/registerSession","method":"POST","responseTime":145,"statusCode":200}}
|
|
28
|
+
{"timestamp":"2026-01-30T20:26:33.445Z","level":"INFO","message":"Servidor ONLINE - ID: 2, URL: http://localhost:8765","eventType":"target_online","serverId":2,"serverUrl":"http://localhost:8765","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":27,"statusCode":200}}
|
|
29
|
+
{"timestamp":"2026-01-30T20:26:36.917Z","level":"INFO","message":"Servidor ONLINE - ID: 3, URL: http://localhost:5445","eventType":"target_online","serverId":3,"serverUrl":"http://localhost:5445","request":{"url":"/track/registerSession","method":"POST","responseTime":73,"statusCode":200}}
|
|
30
|
+
{"timestamp":"2026-01-30T20:26:37.556Z","level":"INFO","message":"Servidor ONLINE - ID: 4, URL: http://localhost:6666","eventType":"target_online","serverId":4,"serverUrl":"http://localhost:6666","request":{"url":"/track/insertSiteFlow","method":"POST","responseTime":28,"statusCode":200}}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIDtzCCAp+gAwIBAgIUFTU+RfyHp2GmFigOSZ9AiN8SGLcwDQYJKoZIhvcNAQEL
|
|
3
|
+
BQAwazELMAkGA1UEBhMCRVMxDzANBgNVBAgMBk1hZHJpZDEPMA0GA1UEBwwGTWFk
|
|
4
|
+
cmlkMQ4wDAYDVQQKDAVLdWt1eTEWMBQGA1UECwwNSVQgRGVwYXJ0bWVudDESMBAG
|
|
5
|
+
A1UEAwwJbG9jYWxob3N0MB4XDTI2MDEyNjAxNTU1NFoXDTI3MDEyNjAxNTU1NFow
|
|
6
|
+
azELMAkGA1UEBhMCRVMxDzANBgNVBAgMBk1hZHJpZDEPMA0GA1UEBwwGTWFkcmlk
|
|
7
|
+
MQ4wDAYDVQQKDAVLdWt1eTEWMBQGA1UECwwNSVQgRGVwYXJ0bWVudDESMBAGA1UE
|
|
8
|
+
AwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlN3F
|
|
9
|
+
rAiKzKOIybQsmGIF+sBmfgkqsC/jq3EBsOnIDXG2Kz0AVLNCD1nxTmYB06x7TN7V
|
|
10
|
+
xCSXiaGJEAW2v2+CLOpiFtO9S9hnxsoENN3DI/ZNYVBD5QbPFdkyTUw31iq8Vdhp
|
|
11
|
+
tkrxwnY7q7S/Ss1BEKxL/y0f4bSD9bXAYbTJRFlx5bv8KE0+Opr3EywGmyd9Fwwq
|
|
12
|
+
Zf4+z19kc4/ILmguzrMTZ9MblzKN5VAxoQ+h5SzKY/pgIPTX9Y25ciKwlN8nPrYs
|
|
13
|
+
32CfFVqyH1sWY+hz8nhPIqJ++R12cofTyjBkfUoo7hE87wsIITmttxA9gJfd9k2j
|
|
14
|
+
jy6ebm40SGaHXjU7twIDAQABo1MwUTAdBgNVHQ4EFgQUYK1YQGMWkT9TpbPspqtu
|
|
15
|
+
tWzX3EMwHwYDVR0jBBgwFoAUYK1YQGMWkT9TpbPspqtutWzX3EMwDwYDVR0TAQH/
|
|
16
|
+
BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEADQWlR94ZUUSv+nYzpvhyonnxDoy+
|
|
17
|
+
YU4MATcisHc6HnbLUdwX95dSzIFLg/aurqcadWTL6q2RQusUpfpNdVPJXvXUXz/W
|
|
18
|
+
ebk1Q97qcz8jFp9hbZxb93mrmJE0JccMU36WZPVM8J9K8p11JABn+sJRQFIAOauU
|
|
19
|
+
C7ETVs84+b3JNLGH9Y3cJpB6Jm7DntFXZmp6Ehe8On4SwqIRfN11CKQs7SqcHXts
|
|
20
|
+
X6tgXisc7HskSbXXG5oSHKz+uwngH2V85RH/pKgly80IRT3FbPzFRBdSCDk6B4PM
|
|
21
|
+
Bqow/h9NX65Vd5aRFpsmje4eqrO2g0YQsPmpVAndIstn+HlW5YyLAb5dmA==
|
|
22
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-----BEGIN PRIVATE KEY-----
|
|
2
|
+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCU3cWsCIrMo4jJ
|
|
3
|
+
tCyYYgX6wGZ+CSqwL+OrcQGw6cgNcbYrPQBUs0IPWfFOZgHTrHtM3tXEJJeJoYkQ
|
|
4
|
+
Bba/b4Is6mIW071L2GfGygQ03cMj9k1hUEPlBs8V2TJNTDfWKrxV2Gm2SvHCdjur
|
|
5
|
+
tL9KzUEQrEv/LR/htIP1tcBhtMlEWXHlu/woTT46mvcTLAabJ30XDCpl/j7PX2Rz
|
|
6
|
+
j8guaC7OsxNn0xuXMo3lUDGhD6HlLMpj+mAg9Nf1jblyIrCU3yc+tizfYJ8VWrIf
|
|
7
|
+
WxZj6HPyeE8ion75HXZyh9PKMGR9SijuETzvCwghOa23ED2Al932TaOPLp5ubjRI
|
|
8
|
+
ZodeNTu3AgMBAAECggEAIXLhNwHmWgvGsPeca5Le4BQ6E0ixAEyKXduy8xLcYfTy
|
|
9
|
+
Zy26NM3gYn2lpCV0dKDVRZTuODe2mvSiTOjTwpjmCXySlKl356JU0wxSPKS1c4+k
|
|
10
|
+
nGCCGORaRID8dfTRuPv6PFm3iv+06apSRwcCUmbjH0FvhAMaHkdGvT9c3jdWX9ZX
|
|
11
|
+
YpHtnQQzWQSdNByT6ELqUCD2lw9AtzRSdvMDEZ/H7WfepcJ8jNNAzLkNQIuezDR1
|
|
12
|
+
ciFA5dDhT8vOkEBV1LiQz0uUscsyefhDG1rUmFJxUng9IW2qNFEKxBfiWdZIGEK3
|
|
13
|
+
PInBm4QpOLHh1q6+XK2yeRSnw8uMfgPlDQgr5cGDYQKBgQDKLD01Letd0URs0INL
|
|
14
|
+
LRLox/k8GrCKEDXl+y7EvbWnLriDck4I+fkuQKenxQdVCBCOKGRgm92j3Y8vB+9I
|
|
15
|
+
QU8lIzohgAUt5GAm+7ZNdwbTX3hYmUmIFXdZEvIBZ61Xw+ghwSWh44Af5S8w4xoi
|
|
16
|
+
C5ewa4iBvSApOHzs6Q6/Tf8WYQKBgQC8gEATZNmiXH3ITYdGVmEY5uzqRyJIXt3y
|
|
17
|
+
BbfFooZc31daUx4HDnjgzdY8I5cr3JfNy1HvpXcLMWH79nRbEcwvaiKkqkvaGxHW
|
|
18
|
+
e6NTTkU46P4lAwtzsfM7eQrtRnfJGLUF7ZQzc/W05BkdyLq2Fmrox8Mt01rZs9Yo
|
|
19
|
+
R+4tv5LZFwKBgQCJ9uSSDNMIg81RAH4IaCr2Rbj0ZjZBEUzms6G3yspS21Q5B2Dv
|
|
20
|
+
ST7dbGu81nzpbwZ1LGVLdDItJ/4VFzIYOdE7w61gvQ9LwQRItg8zD93NkuH6fCis
|
|
21
|
+
wBFg7MfPY6PsN5mKp1b6AdkmauzoTKJBx21tjARsnNZ8qrq9pVFWBXDlIQKBgQC1
|
|
22
|
+
bOa/A9DoEQdLEzuAukCn/BLIhgB8ETqi51fyEzQpDRkBKYB8IDS9gb+RkFu+bol5
|
|
23
|
+
HBjXg7UpA7WgEZv5zw5sEEYZoIJzAJzRh5wx4OKFHNMHAoAyMXK+qgiXSLyfw3Tv
|
|
24
|
+
qLN8Nj6lhOibnwf9m2P4edPkNkl5wTn8+QZH59vJrwKBgDi7kLHz+fLxM6BYQ92F
|
|
25
|
+
mRgxHoY1Cj0jpPEGx+9A7e8f2zQUSb9nUU0et0NHmiGmgkUTqVwy7lWGFSXjvoaz
|
|
26
|
+
Vm1UrDskAbngwmSHpPDeBZTOHHR9PRyPWdJqUzJjk7boQK9gK65BeYLkY9klJFIN
|
|
27
|
+
bWZG2VQiV6rOcc/8WWgZtlrG
|
|
28
|
+
-----END PRIVATE KEY-----
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Plugins de Kukuy
|
|
2
|
+
|
|
3
|
+
Este directorio contiene plugins para extender la funcionalidad del balanceador Kukuy.
|
|
4
|
+
|
|
5
|
+
## Plugins Disponibles
|
|
6
|
+
|
|
7
|
+
### 1. Plugin de Cache Robusto (`cache-plugin`)
|
|
8
|
+
|
|
9
|
+
Este plugin implementa un sistema de cache robusto que permite almacenar en caché las respuestas del servidor backend para mejorar el rendimiento.
|
|
10
|
+
|
|
11
|
+
#### Características:
|
|
12
|
+
- Soporta diferentes métodos HTTP cacheables (por defecto: GET)
|
|
13
|
+
- Configurable mediante variables de entorno
|
|
14
|
+
- Implementa LRU (Least Recently Used) para manejar el tamaño máximo de caché
|
|
15
|
+
- Soporta TTL (Time To Live) configurable
|
|
16
|
+
- Limpieza automática de entradas expiradas
|
|
17
|
+
|
|
18
|
+
#### Variables de entorno:
|
|
19
|
+
- `CACHE_MAX_SIZE`: Número máximo de entradas en la caché (por defecto: 100)
|
|
20
|
+
- `CACHE_DEFAULT_TTL`: Tiempo de vida por defecto en milisegundos (por defecto: 300000 - 5 minutos)
|
|
21
|
+
- `CACHE_ENABLE_COMPRESSION`: Habilitar compresión (por defecto: false)
|
|
22
|
+
- `CACHEABLE_METHODS`: Métodos HTTP cacheables separados por coma (por defecto: GET)
|
|
23
|
+
- `CACHEABLE_STATUS_CODES`: Códigos de estado cacheables separados por coma (por defecto: 200,201,204)
|
|
24
|
+
|
|
25
|
+
#### Uso:
|
|
26
|
+
El plugin se activa automáticamente si está habilitado en el manifest.json.
|
|
27
|
+
|
|
28
|
+
### 2. Plugin de Redirección (`redirect-plugin`)
|
|
29
|
+
|
|
30
|
+
Este plugin permite implementar reglas de redirección personalizadas.
|
|
31
|
+
|
|
32
|
+
#### Características:
|
|
33
|
+
- Soporta patrones de URL con expresiones regulares
|
|
34
|
+
- Tipos de redirección: temporal (302) y permanente (301)
|
|
35
|
+
- Configurable mediante variables de entorno
|
|
36
|
+
|
|
37
|
+
#### Variables de entorno:
|
|
38
|
+
- `REDIRECT_RULES`: Reglas de redirección en formato JSON
|
|
39
|
+
|
|
40
|
+
#### Ejemplo de regla de redirección:
|
|
41
|
+
```json
|
|
42
|
+
[
|
|
43
|
+
{
|
|
44
|
+
"pattern": "/old-page",
|
|
45
|
+
"target": "/new-page",
|
|
46
|
+
"type": "permanent"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"pattern": "^/api/v1/(.*)$",
|
|
50
|
+
"target": "/api/v2/$1",
|
|
51
|
+
"type": "temporary"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Cómo Crear un Nuevo Plugin
|
|
57
|
+
|
|
58
|
+
Para crear un nuevo plugin, sigue estos pasos:
|
|
59
|
+
|
|
60
|
+
1. Crea un directorio con el nombre de tu plugin en `kukuy-plugins/`
|
|
61
|
+
2. Crea un archivo `manifest.json` con la información del plugin
|
|
62
|
+
3. Crea un archivo `index.js` con la lógica del plugin
|
|
63
|
+
|
|
64
|
+
### Estructura de un Plugin
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
kukuy-plugins/
|
|
68
|
+
└── nombre-del-plugin/
|
|
69
|
+
├── manifest.json
|
|
70
|
+
└── index.js
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Ejemplo de `manifest.json`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"name": "Mi Plugin",
|
|
78
|
+
"version": "1.0.0",
|
|
79
|
+
"description": "Descripción de mi plugin",
|
|
80
|
+
"author": "Autor",
|
|
81
|
+
"main": "index.js",
|
|
82
|
+
"kukuyVersion": "^1.6.0",
|
|
83
|
+
"hooks": ["onRequestReceived", "onResponseSent"],
|
|
84
|
+
"filters": ["request_processing"],
|
|
85
|
+
"enabled": true
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Ejemplo de `index.js`:
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
async function init(balancer) {
|
|
93
|
+
console.log('Inicializando mi plugin...');
|
|
94
|
+
|
|
95
|
+
const extension = balancer.getPostStartupExtension();
|
|
96
|
+
|
|
97
|
+
// Registrar filtros y hooks
|
|
98
|
+
extension.registerFilter('request_processing', async (data) => {
|
|
99
|
+
// Lógica del filtro
|
|
100
|
+
return { allowed: true };
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
extension.registerHook('onRequestReceived', async ({ req, res }) => {
|
|
104
|
+
// Lógica del hook
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function deinit(balancer) {
|
|
109
|
+
console.log('Desactivando mi plugin...');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = { init, deinit };
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Hooks Disponibles
|
|
116
|
+
|
|
117
|
+
- `onRequestReceived`: Se ejecuta cuando se recibe una solicitud
|
|
118
|
+
- `onServerSelected`: Se ejecuta después de seleccionar el servidor
|
|
119
|
+
- `onResponseReady`: Se ejecuta cuando la respuesta del servidor backend está lista
|
|
120
|
+
- `onResponseSent`: Se ejecuta antes de enviar la respuesta al cliente
|
|
121
|
+
- `onServerError`: Se ejecuta cuando ocurre un error
|
|
122
|
+
|
|
123
|
+
## Filtros Disponibles
|
|
124
|
+
|
|
125
|
+
- `request_processing`: Se aplica al procesamiento de solicitudes
|