Skip to content

Commit afec888

Browse files
committed
first commit
0 parents  commit afec888

File tree

1 file changed

+329
-0
lines changed

1 file changed

+329
-0
lines changed

README.md

Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
# Slaking
2+
3+
A Kubernetes service that monitors workloads for specific annotations and sends filtered logs to Slack channels based on configurations.
4+
5+
## Features
6+
7+
- **Workload Monitoring**: Watches Kubernetes workloads (Pods, Deployments, StatefulSets, etc.) for specific annotations
8+
- **Log Filtering**: Filters logs based on configurable patterns and criteria
9+
- **Slack Integration**: Sends filtered logs to designated Slack channels
10+
- **Configuration Management**: Supports multiple configurations for different workloads and channels
11+
- **Health Monitoring**: Built-in health checks and metrics
12+
- **Helm Chart**: Complete Helm chart for easy deployment and management
13+
14+
## Architecture
15+
16+
```
17+
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
18+
│ Kubernetes │ │ Slaking │ │ Slack │
19+
│ Workloads │───▶│ Service │───▶│ Channels │
20+
│ (with │ │ │ │ │
21+
│ annotations) │ │ - Watcher │ │ - #alerts │
22+
│ │ │ - Filter │ │ - #errors │
23+
│ │ │ - Forwarder │ │ - #debug │
24+
└─────────────────┘ └──────────────────┘ └─────────────────┘
25+
```
26+
27+
## Deployment Options
28+
29+
### Option 1: Helm Chart (Recommended)
30+
31+
The easiest way to deploy Slaking is using the provided Helm chart:
32+
33+
```bash
34+
# Quick deployment with automated script
35+
./helm-deploy.sh
36+
37+
# Manual Helm deployment
38+
helm install slaking ./helm \
39+
--namespace slaking \
40+
--create-namespace \
41+
--set env.SLACK_TOKEN="xoxb-your-token" \
42+
--set env.SLACK_DEFAULT_CHANNEL="#alerts"
43+
```
44+
45+
**Benefits of Helm deployment:**
46+
- ✅ Easy configuration management
47+
- ✅ Environment-specific values files
48+
- ✅ Automatic RBAC setup
49+
- ✅ Prometheus ServiceMonitor integration
50+
- ✅ Horizontal Pod Autoscaler support
51+
- ✅ Ingress configuration
52+
- ✅ Comprehensive health checks
53+
- ✅ Easy upgrades and rollbacks
54+
55+
### Option 2: Vanilla Kubernetes Manifests
56+
57+
For users who prefer direct Kubernetes manifests:
58+
59+
```bash
60+
# Deploy using vanilla manifests
61+
./deploy.sh
62+
63+
# Or manually
64+
kubectl apply -f k8s/
65+
```
66+
67+
## Configuration
68+
69+
### Workload Annotations
70+
71+
Add these annotations to your Kubernetes workloads:
72+
73+
```yaml
74+
metadata:
75+
annotations:
76+
slaking.enabled: "true"
77+
slaking.channel: "#alerts"
78+
slaking.filters: "error|exception|fatal"
79+
slaking.level: "error"
80+
slaking.include-labels: "app=myapp,environment=prod"
81+
```
82+
83+
### Configuration Options
84+
85+
| Annotation | Description | Default |
86+
|------------|-------------|---------|
87+
| `slaking.enabled` | Enable log forwarding for this workload | `false` |
88+
| `slaking.channel` | Slack channel to send logs to | `#general` |
89+
| `slaking.filters` | Regex patterns to filter logs | `.*` |
90+
| `slaking.level` | Minimum log level (debug, info, warn, error) | `info` |
91+
| `slaking.include-labels` | Comma-separated key=value pairs to include | `""` |
92+
| `slaking.exclude-labels` | Comma-separated key=value pairs to exclude | `""` |
93+
| `slaking.max-lines` | Maximum lines per message | `10` |
94+
| `slaking.cooldown` | Cooldown period between messages (seconds) | `60` |
95+
96+
## Installation
97+
98+
### Prerequisites
99+
100+
- Kubernetes cluster (1.19+)
101+
- kubectl configured and connected to your cluster
102+
- Docker installed and running
103+
- Slack workspace with API access
104+
- Helm 3.0+ (for Helm deployment)
105+
106+
### Quick Start
107+
108+
1. **Clone and install dependencies:**
109+
```bash
110+
cd slack-o-tron
111+
npm install
112+
```
113+
114+
2. **Set up environment variables:**
115+
```bash
116+
cp env.example .env
117+
# Edit .env with your Slack token and other settings
118+
```
119+
120+
3. **Deploy to Kubernetes:**
121+
122+
**Using Helm (Recommended):**
123+
```bash
124+
./helm-deploy.sh
125+
```
126+
127+
**Using vanilla manifests:**
128+
```bash
129+
./deploy.sh
130+
```
131+
132+
4. **Configure your workloads with annotations and watch logs flow to Slack!**
133+
134+
## Development
135+
136+
### Local Development
137+
138+
```bash
139+
npm run dev
140+
```
141+
142+
### Testing
143+
144+
```bash
145+
npm test
146+
```
147+
148+
### Building Docker Image
149+
150+
```bash
151+
npm run build
152+
```
153+
154+
## API Endpoints
155+
156+
- `GET /health` - Health check
157+
- `GET /metrics` - Prometheus metrics
158+
- `POST /config` - Update configuration
159+
- `GET /config` - Get current configuration
160+
- `GET /status` - Service status
161+
162+
## Monitoring
163+
164+
The service exposes Prometheus metrics at `/metrics` for monitoring:
165+
- `slaking_logs_processed_total`
166+
- `slaking_logs_filtered_total`
167+
- `slaking_slack_messages_sent_total`
168+
- `slaking_errors_total`
169+
170+
### Grafana Dashboard
171+
172+
Create a Grafana dashboard with these queries:
173+
174+
```promql
175+
# Log processing rate
176+
rate(slaking_logs_processed_total[5m])
177+
178+
# Error rate
179+
rate(slaking_errors_total[5m])
180+
181+
# Active streams
182+
slaking_active_streams
183+
184+
# Slack message rate
185+
rate(slaking_slack_messages_sent_total[5m])
186+
```
187+
188+
## Advanced Configuration
189+
190+
### Helm Chart Configuration
191+
192+
The Helm chart supports extensive configuration:
193+
194+
```yaml
195+
# values-production.yaml
196+
replicaCount: 3
197+
hpa:
198+
enabled: true
199+
maxReplicas: 5
200+
serviceMonitor:
201+
enabled: true
202+
config:
203+
slack:
204+
defaultChannel: "#prod-alerts"
205+
kubernetes:
206+
namespaces: ["production", "staging"]
207+
```
208+
209+
### Multi-Environment Setup
210+
211+
Create separate values files for different environments:
212+
213+
- `values-production.yaml` - Production settings
214+
- `values-staging.yaml` - Staging settings
215+
- `values-development.yaml` - Development settings
216+
217+
## Troubleshooting
218+
219+
### Common Issues
220+
221+
1. **No logs being sent to Slack**
222+
- Check if annotations are properly set
223+
- Verify Slack token and channel permissions
224+
- Check service logs for errors
225+
226+
2. **Too many messages**
227+
- Adjust cooldown period
228+
- Refine filter patterns
229+
- Set appropriate log levels
230+
231+
3. **Permission denied**
232+
- Ensure proper RBAC configuration
233+
- Check service account permissions
234+
235+
### Debug Mode
236+
237+
**Helm deployment:**
238+
```bash
239+
helm upgrade slaking ./helm \
240+
--namespace slaking \
241+
--set env.LOG_LEVEL=debug
242+
```
243+
244+
**Vanilla deployment:**
245+
```bash
246+
kubectl patch deployment slaking -n slaking \
247+
-p '{"spec":{"template":{"spec":{"containers":[{"name":"slaking","env":[{"name":"LOG_LEVEL","value":"debug"}]}]}}}}'
248+
```
249+
250+
### Testing Configuration
251+
252+
```bash
253+
# Test health endpoint
254+
kubectl port-forward -n slaking svc/slaking 3000:3000
255+
curl http://localhost:3000/health
256+
257+
# Test metrics endpoint
258+
kubectl port-forward -n slaking svc/slaking-metrics 9090:9090
259+
curl http://localhost:9090/metrics
260+
```
261+
262+
## Management Commands
263+
264+
### Helm Deployment
265+
266+
```bash
267+
# Check status
268+
./helm-deploy.sh status
269+
270+
# View logs
271+
./helm-deploy.sh logs
272+
273+
# Test deployment
274+
./helm-deploy.sh test
275+
276+
# Upgrade deployment
277+
./helm-deploy.sh upgrade
278+
279+
# Uninstall
280+
./helm-deploy.sh uninstall
281+
```
282+
283+
### Vanilla Deployment
284+
285+
```bash
286+
# Check status
287+
kubectl get pods -n slaking
288+
289+
# View logs
290+
kubectl logs -n slaking -l app=slaking
291+
292+
# Update deployment
293+
kubectl apply -f k8s/
294+
295+
# Delete deployment
296+
kubectl delete -f k8s/
297+
```
298+
299+
## Security Considerations
300+
301+
### RBAC Permissions
302+
303+
The service requires minimal permissions:
304+
- Read access to pods and their logs
305+
- Watch access to deployments, statefulsets, daemonsets
306+
- Read access to namespaces
307+
308+
### Network Security
309+
310+
- Service runs on ClusterIP by default
311+
- Metrics endpoint is separate for Prometheus scraping
312+
- No external access required
313+
314+
### Secret Management
315+
316+
- Slack token is stored in Kubernetes Secret
317+
- Consider using external secret management (HashiCorp Vault, AWS Secrets Manager, etc.)
318+
319+
## Contributing
320+
321+
1. Fork the repository
322+
2. Create a feature branch
323+
3. Make your changes
324+
4. Add tests
325+
5. Submit a pull request
326+
327+
## License
328+
329+
MIT

0 commit comments

Comments
 (0)