Backend API service for the Grafana Hover Tracker Panel plugin. Analyzes log data using KL divergence to identify anomalous patterns.
- KL Divergence Analysis: Identifies anomalous log patterns by comparing current and baseline time windows
- ClickHouse Integration: Efficient log storage and querying
- Auto-table Creation: Automatically creates required database tables from schema
- Multi-platform: Builds for Linux, macOS, and Windows (amd64 and arm64)
- REST API: Simple HTTP API for Grafana integration
- Comprehensive Tests: Unit tests for all core functionality
cmd/main.go - HTTP server entry point
internal/
├── api/ - HTTP handlers and request validation
├── analyzer/ - Log analysis and KL divergence
├── clickhouse/ - Database client
└── config/ - Configuration loading
schema/ - ClickHouse schema (git submodule)
- Go 1.23+
- ClickHouse (for production)
- Docker (for testing with ClickHouse)
# Install dependencies
go mod download
# Run development server
mage dev
# Run tests
mage test
# Run tests with coverage
mage testCoverage# Build for current platform
mage build
# Build for all platforms
mage buildAll
# Install to ../grafana-hover-tracker-panel/bin/
mage install
# Clean build artifacts
mage cleanCreate config.toml:
[server]
host = "127.0.0.1"
port = 8080
[clickhouse]
url = "http://localhost:8123"
user = ""
password = ""
database = "default"For testing, use the included docker-compose:
docker-compose -f docker-compose.test.yml up -dThe service will automatically create required tables from the schema on startup.
Analyzes logs for anomalies in a given time window.
Request:
{
"org": "my-org",
"dashboard": "my-dashboard",
"panel_title": "my-panel",
"metric_name": "A-series",
"start_time": "2025-10-22T04:00:00Z",
"end_time": "2025-10-22T05:00:00Z"
}Response:
{
"log_groups": [
{
"representative_logs": ["ERROR: Out of memory", "ERROR: OOM killer invoked"],
"relative_change": 1.5
}
]
}Tests cover:
- KL divergence calculations
- Relative change calculations
- Log analyzer logic (window calculation, sorting, grouping)
- API request validation
- Error handling and response formatting
# Run all tests
mage test
# Run with coverage report
mage testCoverage
# Run specific package tests
go test -v ./internal/analyzerBinaries are built for all platforms:
linux/amd64linux/arm64darwin/amd64(Intel Mac)darwin/arm64(Apple Silicon)windows/amd64
mage buildAllAll binaries are statically compiled with CGO_ENABLED=0 for easy deployment.
- Set up ClickHouse
- Create
config.tomlwith production settings - Run the binary:
./grafana-plugin-apiThe service will:
- Load configuration
- Connect to ClickHouse
- Verify/create required tables
- Start HTTP server
mage build # Build for current platform
mage buildAll # Build for all platforms
mage install # Build and install to bin/
mage clean # Remove build artifacts
mage test # Run tests
mage testCoverage # Run tests with coverage
mage tidy # Run go mod tidy
mage dev # Run development server