forked from mrckndt/CS-Repro-Mattermost
switching out promtail for alloy (#22)
* rework grafana log ingestion using alloy * fix docker-compose.yml formatting
This commit is contained in:
45
files/alloy/README.md
Normal file
45
files/alloy/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Alloy Log Agent Configuration
|
||||
|
||||
This directory contains the configuration for Grafana Alloy, which has replaced Promtail as the log agent in this environment.
|
||||
|
||||
## Key Differences
|
||||
|
||||
- Alloy uses a component-based configuration format with `.alloy` extension
|
||||
- The web UI is available at http://localhost:9080
|
||||
- Alloy can handle logs, metrics, and traces in one agent
|
||||
- Configuration is more flexible with the River language
|
||||
|
||||
## Configuration Explanation
|
||||
|
||||
The `config.alloy` file follows the component-based model where:
|
||||
|
||||
1. `loki.source.file` components directly collect logs from Mattermost log files
|
||||
2. `loki.process` component parses and labels the JSON logs
|
||||
3. `loki.write` component sends the logs to Loki
|
||||
|
||||
## Current Setup
|
||||
|
||||
Our configuration:
|
||||
- Monitors Mattermost logs directly from mounted volumes
|
||||
- Labels all logs with `job="mattermost"` for Grafana dashboard compatibility
|
||||
- Extracts log level, message, and other metadata from JSON logs
|
||||
- Sends logs to Loki service
|
||||
|
||||
## Converting Promtail Config to Alloy
|
||||
|
||||
If you need to update the configuration, you can convert Promtail configs to Alloy format with:
|
||||
|
||||
```bash
|
||||
# Example using the alloy CLI (if installed locally)
|
||||
alloy convert --source-format=promtail --output=config.alloy promtail-config.yaml
|
||||
```
|
||||
|
||||
## Important Syntax Notes
|
||||
|
||||
- The River language used by Alloy requires commas at the end of each key-value pair in objects
|
||||
- Trailing commas in lists and objects are supported and recommended
|
||||
|
||||
## More Information
|
||||
|
||||
- [Grafana Alloy Documentation](https://grafana.com/docs/alloy/latest/)
|
||||
- [Migrating from Promtail to Alloy](https://grafana.com/docs/loki/latest/send-data/alloy/migrate-from-promtail/)
|
||||
59
files/alloy/config.alloy
Normal file
59
files/alloy/config.alloy
Normal file
@@ -0,0 +1,59 @@
|
||||
// File-based log sources
|
||||
loki.source.file "mattermost_logs" {
|
||||
targets = [
|
||||
{ "__path__" = "/mattermost/logs/mattermost.log", "filename" = "/logs-node-1/mattermost.log", "job" = "mattermost" },
|
||||
]
|
||||
forward_to = [loki.process.mm_logs_processor.receiver]
|
||||
}
|
||||
|
||||
loki.source.file "mattermost_advanced_logs" {
|
||||
targets = [
|
||||
{ "__path__" = "/mattermost/logs/advancedLogs.log", "filename" = "/logs-node-1/advancedLogs.log", "job" = "mattermost" },
|
||||
]
|
||||
forward_to = [loki.process.mm_logs_processor.receiver]
|
||||
}
|
||||
|
||||
loki.source.file "mattermost_ldap_logs" {
|
||||
targets = [
|
||||
{ "__path__" = "/mattermost/logs/advancedLdapLogs.log", "filename" = "/logs-node-1/advancedLdapLogs.log", "job" = "mattermost" },
|
||||
]
|
||||
forward_to = [loki.process.mm_logs_processor.receiver]
|
||||
}
|
||||
|
||||
// Process Mattermost logs
|
||||
loki.process "mm_logs_processor" {
|
||||
// First, try to parse as JSON
|
||||
stage.json {
|
||||
expressions = {
|
||||
ts = "timestamp",
|
||||
log_level = "level",
|
||||
log_msg = "msg",
|
||||
log_caller = "caller",
|
||||
}
|
||||
}
|
||||
|
||||
// Set labels based on extracted fields
|
||||
stage.labels {
|
||||
values = {
|
||||
level = "log_level",
|
||||
}
|
||||
}
|
||||
|
||||
forward_to = [loki.write.loki.receiver]
|
||||
}
|
||||
|
||||
// API endpoint for direct log pushing
|
||||
loki.source.api "push_api" {
|
||||
http {
|
||||
listen_address = "0.0.0.0"
|
||||
listen_port = 9999
|
||||
}
|
||||
forward_to = [loki.write.loki.receiver]
|
||||
}
|
||||
|
||||
// Send all logs to Loki
|
||||
loki.write "loki" {
|
||||
endpoint {
|
||||
url = "http://loki:3100/loki/api/v1/push"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user