Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Test
run: |
go generate ./api/pb/
go test -failfast -v -timeout=300s -p 1 -coverprofile=profile.cov ./cmd/... ./internal/...
go test -failfast -v -timeout=300s -p 1 -coverprofile=profile.cov ./cmd/... ./pkg/... ./internal/...

- name: Coveralls
uses: coverallsapp/github-action@v2
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ archives:
files:
- "./grafana/**/*"
- "./README.md"
- src: "./internal/metrics/metrics.yaml"
- src: "./pkg/metrics/metrics.yaml"
dst: "metrics.yaml"
- src: "./contrib/sample.sources.yaml"
dst: "sample.sources.yaml"
Expand Down Expand Up @@ -66,7 +66,7 @@ nfpms:
dst: "/etc/pgwatch/grafana"
- src: "./contrib/sample.sources.yaml"
dst: "/etc/pgwatch/sample.sources.yaml"
- src: "./internal/metrics/metrics.yaml"
- src: "./pkg/metrics/metrics.yaml"
dst: "/etc/pgwatch/metrics.yaml"
- src: "./README.md"
dst: "/etc/pgwatch/README.md"
Expand Down
2 changes: 1 addition & 1 deletion api/pb/pgwatch.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ message SyncReq {
}

// SyncOp represents synchronization operations for metrics.
// The actual constants are defined in internal/sinks/types.go
// The actual constants are defined in pkg/sinks/types.go
// and should be used instead of these protobuf-generated constants.
enum SyncOp {
InvalidOp = 0;
Expand Down
6 changes: 3 additions & 3 deletions cmd/pgwatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"sync/atomic"
"syscall"

"github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts"
"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/internal/reaper"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/cmdopts"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/reaper"
"github.com/cybertec-postgresql/pgwatch/v5/internal/webserver"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/pgwatch/main_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/cmdopts"
"github.com/cybertec-postgresql/pgwatch/v5/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ FROM alpine

# Copy over the compiled gatherer
COPY --from=go-builder /pgwatch/pgwatch /pgwatch/
COPY internal/metrics/metrics.yaml /pgwatch/metrics/metrics.yaml
COPY pkg/metrics/metrics.yaml /pgwatch/metrics/metrics.yaml

# Admin UI for configuring servers to be monitored
EXPOSE 8080
Expand Down
2 changes: 1 addition & 1 deletion docker/compose.pgwatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- "9187:9187"
# - "6060:6060" # Uncomment for profiling
volumes:
- "../internal/metrics/metrics.yaml:/etc/pgwatch/metrics.yml"
- "../pkg/metrics/metrics.yaml:/etc/pgwatch/metrics.yml"
- "./bootstrap/.pgpass:/root/.pgpass:ro"
depends_on:
postgres:
Expand Down
2 changes: 1 addition & 1 deletion docker/demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FROM postgres:18-bookworm AS demo

# Copy over the compiled gatherer
COPY --from=go-builder /pgwatch/pgwatch /pgwatch/
COPY internal/metrics/metrics.yaml /pgwatch/metrics/metrics.yaml
COPY pkg/metrics/metrics.yaml /pgwatch/metrics/metrics.yaml

# Install TimescaleDB and extensions
ENV DEBIAN_FRONTEND=noninteractive
Expand Down
16 changes: 8 additions & 8 deletions docs/developer/reaper-batch-consolidation.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ At peak alignment (t = 7200s, all 32 metrics due): **32 → 1 round-trip = 97% r

| File | Lines | Purpose |
|------|-------|---------|
| `internal/reaper/source_reaper.go` | 494 | SourceReaper struct, GCD, batch execution, Run loop |
| `internal/reaper/source_reaper_test.go` | 471 | pgxmock unit tests (12 test functions, 20+ subtests) |
| `internal/reaper/source_reaper_integration_test.go` | 301 | testcontainers integration tests (6 test functions) |
| `internal/reaper/observability.go` | 38 | Prometheus metrics for batch observability |
| `pkg/reaper/source_reaper.go` | 494 | SourceReaper struct, GCD, batch execution, Run loop |
| `pkg/reaper/source_reaper_test.go` | 471 | pgxmock unit tests (12 test functions, 20+ subtests) |
| `pkg/reaper/source_reaper_integration_test.go` | 301 | testcontainers integration tests (6 test functions) |
| `pkg/reaper/observability.go` | 38 | Prometheus metrics for batch observability |

### Modified Files

| File | Changes | Purpose |
|------|---------|---------|
| `internal/db/conn.go` | +1 line | Added `SendBatch` to `PgxPoolIface` interface |
| `internal/reaper/reaper.go` | +21 / -186 lines | Per-source goroutines, simplified cancel management |
| `internal/reaper/database.go` | +303 lines | Batched change detection, `prefetchChangeDetectionData` |
| `internal/reaper/reaper_test.go` | +15 / -14 lines | Updated tests for per-source cancel pattern |
| `pkg/reaper/reaper.go` | +21 / -186 lines | Per-source goroutines, simplified cancel management |
| `pkg/reaper/database.go` | +303 lines | Batched change detection, `prefetchChangeDetectionData` |
| `pkg/reaper/reaper_test.go` | +15 / -14 lines | Updated tests for per-source cancel pattern |

**Total: 4 new files (1,304 lines), 4 modified files (+340 / -200 net)**

Expand Down Expand Up @@ -137,7 +137,7 @@ At peak alignment (t = 7200s, all 32 metrics due): **32 → 1 round-trip = 97% r

### Existing Tests — 0 regressions

All 152 test cases in `internal/reaper/` pass, including all pre-existing tests for `DetectSprocChanges`, `DetectTableChanges`, `DetectIndexChanges`, `DetectPrivilegeChanges`, `DetectConfigurationChanges`, `FetchMetric`, `LoadSources`, `LoadMetrics`, log parser tests, and OS metric tests.
All 152 test cases in `pkg/reaper/` pass, including all pre-existing tests for `DetectSprocChanges`, `DetectTableChanges`, `DetectIndexChanges`, `DetectPrivilegeChanges`, `DetectConfigurationChanges`, `FetchMetric`, `LoadSources`, `LoadMetrics`, log parser tests, and OS metric tests.

---

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/metric_definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ provided by the pgwatch project to cover all typical needs.
However, when monitoring hundreds of hosts, you'd typically want to define **custom metrics and/or presets**
or at least adjust the metric fetching intervals according to your monitoring goals.

You can find the full list in pgwatch's default [metrics.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/metrics/metrics.yaml) file,
You can find the full list in pgwatch's default [metrics.yaml](https://github.com/cybertec-postgresql/pgwatch/blob/master/pkg/metrics/metrics.yaml) file,
for a more user-friendly experience, consider browsing them via the [Web UI](../gallery/webui.md)

!!! tip "Exporting Metric Definitions"
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/docker_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,4 @@ Source file `sources.yaml` in the same directory:
Running this setup you get pgwatch that uses sources from YAML file and
outputs measurements to postgres DB and exposes them for Prometheus
to scrape on port 8080 instead of WebUI (which is disabled by `--web-disable`).
Metrics definition are built-in, you can examine definition in [`internal/metrics/metrics.yaml`](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/metrics/metrics.yaml).
Metrics definition are built-in, you can examine definition in [`pkg/metrics/metrics.yaml`](https://github.com/cybertec-postgresql/pgwatch/blob/master/pkg/metrics/metrics.yaml).
2 changes: 1 addition & 1 deletion internal/db/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
Expand Down
4 changes: 2 additions & 2 deletions internal/testutil/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"errors"

"github.com/cybertec-postgresql/pgwatch/v5/api/pb"
"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"google.golang.org/protobuf/types/known/structpb"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/testutil/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/api/pb"
"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/cybertec-postgresql/pgwatch/v5/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
)

var TestContext = log.WithLogger(context.Background(), log.NewNoopLogger())
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

jsoniter "github.com/json-iterator/go"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
)

func (s *WebUIServer) handleMetrics(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/testutil"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

jsoniter "github.com/json-iterator/go"

"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
)

func (s *WebUIServer) handleSources(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/cybertec-postgresql/pgwatch/v5/internal/testutil"
jsoniter "github.com/json-iterator/go"
"github.com/stretchr/testify/assert"
Expand Down
6 changes: 3 additions & 3 deletions internal/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/db"
"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
)

//go:embed build
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/webserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/wslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/gorilla/websocket"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/wslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
6 changes: 3 additions & 3 deletions internal/cmdopts/cmdconfig.go → pkg/cmdopts/cmdconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"

"github.com/cybertec-postgresql/pgwatch/v5/internal/db"
"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
)

type ConfigCommand struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"testing"
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/cybertec-postgresql/pgwatch/v5/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions internal/cmdopts/cmdoptions.go → pkg/cmdopts/cmdoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/cybertec-postgresql/pgwatch/v5/internal/db"
"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/cybertec-postgresql/pgwatch/v5/internal/webserver"
flags "github.com/jessevdk/go-flags"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
flags "github.com/jessevdk/go-flags"
"github.com/stretchr/testify/assert"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmdopts/cmdsource.go → pkg/cmdopts/cmdsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"net/url"

"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
)

type SourceCommand struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/db"
"github.com/cybertec-postgresql/pgwatch/v5/internal/sources"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/sources"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pashagolub/pgxmock/v4"
"github.com/stretchr/testify/assert"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

formatter "github.com/cybertec-postgresql/pgwatch/v5/internal/log"
formatter "github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/sirupsen/logrus"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion internal/log/log_test.go → pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/log"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/log"
"github.com/jackc/pgx/v5/tracelog"
"github.com/stretchr/testify/assert"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"testing"

"github.com/cybertec-postgresql/pgwatch/v5/internal/metrics"
"github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics"
"github.com/stretchr/testify/assert"
)

Expand Down
File renamed without changes.
Loading
Loading