Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: SQLens CI

on:
push:
branches: [ master, main, develop ]
pull_request:
branches: [ master, main, develop ]

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true

- name: Install dependencies
run: go mod tidy

- name: Run Tests
run: CGO_ENABLED=0 go test -v ./...

- name: Build Binary
run: |
mkdir -p bin
CGO_ENABLED=0 go build -v -o bin/sqlens ./cmd/sqlens
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin/
sqlens
/sqlens
.DS_Store
*.log
65 changes: 65 additions & 0 deletions cmd/sqlens/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"context"
"log/slog"
"os"
"os/signal"
"syscall"
"time"

"github.com/sqlens/sqlens/analyzer"
"github.com/sqlens/sqlens/config"
"github.com/sqlens/sqlens/proxy"
"github.com/sqlens/sqlens/store"
"github.com/sqlens/sqlens/web"
)

func main() {
cfg := config.LoadConfig()

// Initialize Storage
memStore := store.NewMemoryStore()

// Initialize Analyzer Pipeline
pipeline := analyzer.NewPipeline(
analyzer.NewFingerprintAnalyzer(),
analyzer.NewN1DetectorAnalyzer(
time.Duration(cfg.N1WindowSecs)*time.Second,
cfg.N1Threshold,
),
)

// Initialize TCP Proxy
proxyServer := proxy.NewServer(cfg.ListenAddr, cfg.TargetAddr, pipeline, memStore)

// Initialize Web Dashboard
webServer := web.NewServer(":8080", memStore)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Start servers
go func() {
if err := webServer.Start(); err != nil {
slog.Error("Web server failed", "err", err)
}
}()

go func() {
if err := proxyServer.Start(ctx); err != nil {
slog.Error("Proxy server failed", "err", err)
}
}()

slog.Info("SQLens started", "web", ":8080", "proxy", cfg.ListenAddr, "target", cfg.TargetAddr)

// Graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan

slog.Info("Shutting down SQLens...")
cancel()
time.Sleep(time.Second) // wait for cleanup
}
Loading