From 36983d1e72461542e179cdfc3eda6dd733bd8867 Mon Sep 17 00:00:00 2001 From: moksh-solankipy <46241527+moksh-solankipy@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:30:31 +0530 Subject: [PATCH 1/4] chore: add GitHub Actions CI workflow for test and build --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5844ed7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: SQLens CI + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +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: go test -v ./... + + - name: Build Binary + run: go build -v -o bin/sqlens ./cmd/sqlens From 7ab1ccbeb91dabb5bd6a8f5faa10f8292c1a5edc Mon Sep 17 00:00:00 2001 From: moksh-solankipy <46241527+moksh-solankipy@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:34:52 +0530 Subject: [PATCH 2/4] fix: make CI build more robust by disabling CGO and creating bin directory --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5844ed7..5dfccc3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,9 @@ jobs: run: go mod tidy - name: Run Tests - run: go test -v ./... + run: CGO_ENABLED=0 go test -v ./... - name: Build Binary - run: go build -v -o bin/sqlens ./cmd/sqlens + run: | + mkdir -p bin + CGO_ENABLED=0 go build -v -o bin/sqlens ./cmd/sqlens From 76dcec3c91fa295d08cda9c853182a1df0a9abd8 Mon Sep 17 00:00:00 2001 From: moksh-solankipy <46241527+moksh-solankipy@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:35:17 +0530 Subject: [PATCH 3/4] fix: add develop branch to CI trigger --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5dfccc3..37c813d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: SQLens CI on: push: - branches: [ master, main ] + branches: [ master, main, develop ] pull_request: - branches: [ master, main ] + branches: [ master, main, develop ] jobs: build-and-test: From 2e017d00329ecd6df47ff13459ee1443e689c617 Mon Sep 17 00:00:00 2001 From: moksh-solankipy <46241527+moksh-solankipy@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:44:48 +0530 Subject: [PATCH 4/4] fix: correctly track the cmd/sqlens directory and update .gitignore to avoid ignoring it --- .gitignore | 2 +- cmd/sqlens/main.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 cmd/sqlens/main.go diff --git a/.gitignore b/.gitignore index 5c02dce..486159d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ bin/ -sqlens +/sqlens .DS_Store *.log diff --git a/cmd/sqlens/main.go b/cmd/sqlens/main.go new file mode 100644 index 0000000..a1047e0 --- /dev/null +++ b/cmd/sqlens/main.go @@ -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 +}