diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c403e615a1..a33106fad5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml index 0a91e2ecec..e5e090db02 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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" @@ -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" diff --git a/api/pb/pgwatch.proto b/api/pb/pgwatch.proto index a75ea3787e..d33db56425 100644 --- a/api/pb/pgwatch.proto +++ b/api/pb/pgwatch.proto @@ -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; diff --git a/cmd/pgwatch/main.go b/cmd/pgwatch/main.go index ebfcc923ef..b3d4978640 100644 --- a/cmd/pgwatch/main.go +++ b/cmd/pgwatch/main.go @@ -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" ) diff --git a/cmd/pgwatch/main_integration_test.go b/cmd/pgwatch/main_integration_test.go index 6b6d0e7f26..e68a73b91f 100644 --- a/cmd/pgwatch/main_integration_test.go +++ b/cmd/pgwatch/main_integration_test.go @@ -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" diff --git a/docker/Dockerfile b/docker/Dockerfile index eef902242c..5541abee81 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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 diff --git a/docker/compose.pgwatch.yml b/docker/compose.pgwatch.yml index 0e3c7ef4c5..c4af21d9ee 100644 --- a/docker/compose.pgwatch.yml +++ b/docker/compose.pgwatch.yml @@ -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: diff --git a/docker/demo/Dockerfile b/docker/demo/Dockerfile index cce813b428..ec9adb0ec5 100644 --- a/docker/demo/Dockerfile +++ b/docker/demo/Dockerfile @@ -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 diff --git a/docs/developer/reaper-batch-consolidation.md b/docs/developer/reaper-batch-consolidation.md index 6d6f53b3aa..27797254a6 100644 --- a/docs/developer/reaper-batch-consolidation.md +++ b/docs/developer/reaper-batch-consolidation.md @@ -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)** @@ -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. --- diff --git a/docs/reference/metric_definitions.md b/docs/reference/metric_definitions.md index 01ebd64102..3c68e6514b 100644 --- a/docs/reference/metric_definitions.md +++ b/docs/reference/metric_definitions.md @@ -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" diff --git a/docs/tutorial/docker_installation.md b/docs/tutorial/docker_installation.md index d2191a7579..67590ea81f 100644 --- a/docs/tutorial/docker_installation.md +++ b/docs/tutorial/docker_installation.md @@ -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). diff --git a/internal/db/bootstrap.go b/internal/db/bootstrap.go index e8c2a225aa..8a5b8aa2a3 100644 --- a/internal/db/bootstrap.go +++ b/internal/db/bootstrap.go @@ -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" diff --git a/internal/testutil/mocks.go b/internal/testutil/mocks.go index d5a5917ae6..48cc8e9d03 100644 --- a/internal/testutil/mocks.go +++ b/internal/testutil/mocks.go @@ -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" ) diff --git a/internal/testutil/mocks_test.go b/internal/testutil/mocks_test.go index 248abddae5..63f4dc057a 100644 --- a/internal/testutil/mocks_test.go +++ b/internal/testutil/mocks_test.go @@ -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" diff --git a/internal/testutil/types.go b/internal/testutil/types.go index 34e53964ad..7d82ea0f4a 100644 --- a/internal/testutil/types.go +++ b/internal/testutil/types.go @@ -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()) diff --git a/internal/webserver/metric.go b/internal/webserver/metric.go index 08a7211019..5d0ddbe7ad 100644 --- a/internal/webserver/metric.go +++ b/internal/webserver/metric.go @@ -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) { diff --git a/internal/webserver/metric_test.go b/internal/webserver/metric_test.go index e1151c8ded..45e75699ae 100644 --- a/internal/webserver/metric_test.go +++ b/internal/webserver/metric_test.go @@ -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" diff --git a/internal/webserver/source.go b/internal/webserver/source.go index cffc9f4e9a..b47fe8a5a4 100644 --- a/internal/webserver/source.go +++ b/internal/webserver/source.go @@ -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) { diff --git a/internal/webserver/source_test.go b/internal/webserver/source_test.go index a13c8831b2..3f42cbbc16 100644 --- a/internal/webserver/source_test.go +++ b/internal/webserver/source_test.go @@ -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" diff --git a/internal/webserver/webserver.go b/internal/webserver/webserver.go index 08794913c0..68b805f0ea 100644 --- a/internal/webserver/webserver.go +++ b/internal/webserver/webserver.go @@ -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 diff --git a/internal/webserver/webserver_test.go b/internal/webserver/webserver_test.go index fd1a761614..64a6eef1ae 100644 --- a/internal/webserver/webserver_test.go +++ b/internal/webserver/webserver_test.go @@ -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" ) diff --git a/internal/webserver/wslog.go b/internal/webserver/wslog.go index 03f6adb9e5..199e3f2db2 100644 --- a/internal/webserver/wslog.go +++ b/internal/webserver/wslog.go @@ -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" ) diff --git a/internal/webserver/wslog_test.go b/internal/webserver/wslog_test.go index dcc1f5ddf3..fcb2f98882 100644 --- a/internal/webserver/wslog_test.go +++ b/internal/webserver/wslog_test.go @@ -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" diff --git a/internal/cmdopts/cmdconfig.go b/pkg/cmdopts/cmdconfig.go similarity index 95% rename from internal/cmdopts/cmdconfig.go rename to pkg/cmdopts/cmdconfig.go index 2180555c52..845821b7b3 100644 --- a/internal/cmdopts/cmdconfig.go +++ b/pkg/cmdopts/cmdconfig.go @@ -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 { diff --git a/internal/cmdopts/cmdconfig_integration_test.go b/pkg/cmdopts/cmdconfig_integration_test.go similarity index 90% rename from internal/cmdopts/cmdconfig_integration_test.go rename to pkg/cmdopts/cmdconfig_integration_test.go index 74ad667239..91cb8deb6b 100644 --- a/internal/cmdopts/cmdconfig_integration_test.go +++ b/pkg/cmdopts/cmdconfig_integration_test.go @@ -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" diff --git a/internal/cmdopts/cmdconfig_test.go b/pkg/cmdopts/cmdconfig_test.go similarity index 98% rename from internal/cmdopts/cmdconfig_test.go rename to pkg/cmdopts/cmdconfig_test.go index 0a7c98cb30..abc01482fb 100644 --- a/internal/cmdopts/cmdconfig_test.go +++ b/pkg/cmdopts/cmdconfig_test.go @@ -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" ) diff --git a/internal/cmdopts/cmdmetric.go b/pkg/cmdopts/cmdmetric.go similarity index 100% rename from internal/cmdopts/cmdmetric.go rename to pkg/cmdopts/cmdmetric.go diff --git a/internal/cmdopts/cmdmetric_test.go b/pkg/cmdopts/cmdmetric_test.go similarity index 100% rename from internal/cmdopts/cmdmetric_test.go rename to pkg/cmdopts/cmdmetric_test.go diff --git a/internal/cmdopts/cmdoptions.go b/pkg/cmdopts/cmdoptions.go similarity index 96% rename from internal/cmdopts/cmdoptions.go rename to pkg/cmdopts/cmdoptions.go index d0aaf85e2e..4e4de6bd13 100644 --- a/internal/cmdopts/cmdoptions.go +++ b/pkg/cmdopts/cmdoptions.go @@ -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" ) diff --git a/internal/cmdopts/cmdoptions_test.go b/pkg/cmdopts/cmdoptions_test.go similarity index 96% rename from internal/cmdopts/cmdoptions_test.go rename to pkg/cmdopts/cmdoptions_test.go index 7a22291adb..4ed16af50b 100644 --- a/internal/cmdopts/cmdoptions_test.go +++ b/pkg/cmdopts/cmdoptions_test.go @@ -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" ) diff --git a/internal/cmdopts/cmdsource.go b/pkg/cmdopts/cmdsource.go similarity index 98% rename from internal/cmdopts/cmdsource.go rename to pkg/cmdopts/cmdsource.go index ff7a8f45a4..759cfbd652 100644 --- a/internal/cmdopts/cmdsource.go +++ b/pkg/cmdopts/cmdsource.go @@ -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 { diff --git a/internal/cmdopts/cmdsource_test.go b/pkg/cmdopts/cmdsource_test.go similarity index 97% rename from internal/cmdopts/cmdsource_test.go rename to pkg/cmdopts/cmdsource_test.go index feb122da4f..838bce3616 100644 --- a/internal/cmdopts/cmdsource_test.go +++ b/pkg/cmdopts/cmdsource_test.go @@ -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" diff --git a/internal/cmdopts/doc.go b/pkg/cmdopts/doc.go similarity index 100% rename from internal/cmdopts/doc.go rename to pkg/cmdopts/doc.go diff --git a/internal/log/cmdopts.go b/pkg/log/cmdopts.go similarity index 100% rename from internal/log/cmdopts.go rename to pkg/log/cmdopts.go diff --git a/internal/log/doc.go b/pkg/log/doc.go similarity index 100% rename from internal/log/doc.go rename to pkg/log/doc.go diff --git a/internal/log/formatter.go b/pkg/log/formatter.go similarity index 100% rename from internal/log/formatter.go rename to pkg/log/formatter.go diff --git a/internal/log/formatter_test.go b/pkg/log/formatter_test.go similarity index 99% rename from internal/log/formatter_test.go rename to pkg/log/formatter_test.go index ecb87caef5..40636dacdc 100644 --- a/internal/log/formatter_test.go +++ b/pkg/log/formatter_test.go @@ -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" ) diff --git a/internal/log/log.go b/pkg/log/log.go similarity index 100% rename from internal/log/log.go rename to pkg/log/log.go diff --git a/internal/log/log_broker_hook.go b/pkg/log/log_broker_hook.go similarity index 100% rename from internal/log/log_broker_hook.go rename to pkg/log/log_broker_hook.go diff --git a/internal/log/log_broker_hook_test.go b/pkg/log/log_broker_hook_test.go similarity index 100% rename from internal/log/log_broker_hook_test.go rename to pkg/log/log_broker_hook_test.go diff --git a/internal/log/log_file_test.go b/pkg/log/log_file_test.go similarity index 100% rename from internal/log/log_file_test.go rename to pkg/log/log_file_test.go diff --git a/internal/log/log_test.go b/pkg/log/log_test.go similarity index 94% rename from internal/log/log_test.go rename to pkg/log/log_test.go index cda02182cd..7fd230003e 100644 --- a/internal/log/log_test.go +++ b/pkg/log/log_test.go @@ -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" ) diff --git a/internal/metrics/cmdopts.go b/pkg/metrics/cmdopts.go similarity index 100% rename from internal/metrics/cmdopts.go rename to pkg/metrics/cmdopts.go diff --git a/internal/metrics/cmdopts_test.go b/pkg/metrics/cmdopts_test.go similarity index 100% rename from internal/metrics/cmdopts_test.go rename to pkg/metrics/cmdopts_test.go diff --git a/internal/metrics/default.go b/pkg/metrics/default.go similarity index 100% rename from internal/metrics/default.go rename to pkg/metrics/default.go diff --git a/internal/metrics/default_test.go b/pkg/metrics/default_test.go similarity index 96% rename from internal/metrics/default_test.go rename to pkg/metrics/default_test.go index 8c2e128c09..50a0b5f5f4 100644 --- a/internal/metrics/default_test.go +++ b/pkg/metrics/default_test.go @@ -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" ) diff --git a/internal/metrics/doc.go b/pkg/metrics/doc.go similarity index 100% rename from internal/metrics/doc.go rename to pkg/metrics/doc.go diff --git a/internal/metrics/metrics.yaml b/pkg/metrics/metrics.yaml similarity index 99% rename from internal/metrics/metrics.yaml rename to pkg/metrics/metrics.yaml index 78bfe084b9..333f1b45ba 100644 --- a/internal/metrics/metrics.yaml +++ b/pkg/metrics/metrics.yaml @@ -1886,9 +1886,9 @@ metrics: */ settings: description: > - This metric collects various PostgreSQL server settings and configurations. - It provides insights into the server's configuration, including version, memory settings, and other important parameters. - This metric is useful for monitoring server settings and ensuring optimal performance. + DEPRECATED: use 'settings_num' instead. This metric returns most configuration values as text columns, + which causes Prometheus label cardinality explosion (each config change creates a new time series). + Kept for backward compatibility only — it is no longer included in any built-in preset. sqls: 14: | with qs as ( @@ -1945,6 +1945,32 @@ metrics: (select setting::float8 from qs where name = 'autovacuum_vacuum_threshold') as autovacuum_vacuum_threshold, (select setting::float8 from qs where name = 'autovacuum_analyze_scale_factor') as autovacuum_analyze_scale_factor, (select setting::float8 from qs where name = 'autovacuum_analyze_threshold') as autovacuum_analyze_scale_factor + settings_num: + description: > + Exports all PostgreSQL settings (including extension and user-defined parameters) as numeric values, + one row per setting. Boolean settings are converted to 1/0, integer and real settings are cast to + float8, and enum settings are represented as the 1-based ordinal position of the current value + within the setting's list of valid values (enumvals). The setting name is exposed as a tag so each + parameter becomes its own Prometheus time series, avoiding the cardinality explosion caused by the + legacy 'settings' metric which returned all values as labels. + sqls: + 11: | + select /* pgwatch_generated */ + (extract(epoch from now()) * 1e9)::int8 as epoch_ns, + name as tag_name, + case vartype + when 'integer' then setting::float8 + when 'real' then setting::float8 + when 'bool' then (case setting when 'on' then 1 else 0 end)::float8 + when 'enum' then array_position(enumvals, setting)::float8 + end as value + from pg_settings + where vartype in ('integer', 'real', 'bool', 'enum') + and setting is not null + order by name + gauges: + - value + is_instance_level: true smart_health_per_disk: description: > This metric collects SMART health status for all disk devices using the `smartmontools` utility. @@ -4211,7 +4237,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 60 stat_statements: 180 @@ -4238,7 +4264,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 30 stat_statements: 180 @@ -4263,7 +4289,7 @@ presets: replication: 60 replication_slots: 60 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_ssl: 60 stat_statements: 180 @@ -4301,7 +4327,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 30 stat_statements: 180 @@ -4348,7 +4374,7 @@ presets: replication_slots: 120 sequence_health: 3600 server_log_event_counts: 60 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 30 stat_ssl: 120 @@ -4376,7 +4402,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_statements: 180 stat_statements_calls: 60 @@ -4428,7 +4454,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 30 stat_statements: 180 @@ -4471,7 +4497,7 @@ presets: replication: 120 replication_slots: 120 sequence_health: 3600 - settings: 7200 + settings_num: 7200 sproc_stats: 180 stat_activity: 30 stat_statements: 180 @@ -4530,7 +4556,7 @@ presets: replication_slots: 30 sequence_health: 30 server_log_event_counts: 30 - settings: 30 + settings_num: 30 smart_health_per_disk: 30 sproc_hashes: 30 sproc_stats: 30 diff --git a/internal/metrics/postgres.go b/pkg/metrics/postgres.go similarity index 100% rename from internal/metrics/postgres.go rename to pkg/metrics/postgres.go diff --git a/internal/metrics/postgres_schema.go b/pkg/metrics/postgres_schema.go similarity index 98% rename from internal/metrics/postgres_schema.go rename to pkg/metrics/postgres_schema.go index f9fbd19117..8ff19fb933 100644 --- a/internal/metrics/postgres_schema.go +++ b/pkg/metrics/postgres_schema.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/cybertec-postgresql/pgwatch/v5/internal/db" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" migrator "github.com/cybertec-postgresql/pgx-migrator" "github.com/jackc/pgx/v5" ) diff --git a/internal/metrics/postgres_schema.sql b/pkg/metrics/postgres_schema.sql similarity index 100% rename from internal/metrics/postgres_schema.sql rename to pkg/metrics/postgres_schema.sql diff --git a/internal/metrics/postgres_schema_test.go b/pkg/metrics/postgres_schema_test.go similarity index 100% rename from internal/metrics/postgres_schema_test.go rename to pkg/metrics/postgres_schema_test.go diff --git a/internal/metrics/postgres_test.go b/pkg/metrics/postgres_test.go similarity index 99% rename from internal/metrics/postgres_test.go rename to pkg/metrics/postgres_test.go index 0e4dc0c4e9..f2a05306a4 100644 --- a/internal/metrics/postgres_test.go +++ b/pkg/metrics/postgres_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/jackc/pgx/v5/pgconn" "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" diff --git a/internal/metrics/types.go b/pkg/metrics/types.go similarity index 100% rename from internal/metrics/types.go rename to pkg/metrics/types.go diff --git a/internal/metrics/types_test.go b/pkg/metrics/types_test.go similarity index 99% rename from internal/metrics/types_test.go rename to pkg/metrics/types_test.go index 2fe55c8906..669269604f 100644 --- a/internal/metrics/types_test.go +++ b/pkg/metrics/types_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" "github.com/jackc/pgx/v5" "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" diff --git a/internal/metrics/yaml.go b/pkg/metrics/yaml.go similarity index 100% rename from internal/metrics/yaml.go rename to pkg/metrics/yaml.go diff --git a/internal/metrics/yaml_test.go b/pkg/metrics/yaml_test.go similarity index 99% rename from internal/metrics/yaml_test.go rename to pkg/metrics/yaml_test.go index 3864591c6c..b1e3a1838e 100644 --- a/internal/metrics/yaml_test.go +++ b/pkg/metrics/yaml_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v3" ) diff --git a/internal/reaper/cache.go b/pkg/reaper/cache.go similarity index 94% rename from internal/reaper/cache.go rename to pkg/reaper/cache.go index 0db4ce3d84..846bf70fb0 100644 --- a/internal/reaper/cache.go +++ b/pkg/reaper/cache.go @@ -4,7 +4,7 @@ import ( "sync" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" ) var lastSQLFetchError sync.Map diff --git a/internal/reaper/cache_test.go b/pkg/reaper/cache_test.go similarity index 97% rename from internal/reaper/cache_test.go rename to pkg/reaper/cache_test.go index e4bf939bcc..c0a2a5819c 100644 --- a/internal/reaper/cache_test.go +++ b/pkg/reaper/cache_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/stretchr/testify/assert" ) diff --git a/internal/reaper/database.go b/pkg/reaper/database.go similarity index 98% rename from internal/reaper/database.go rename to pkg/reaper/database.go index 7d80dbae5a..53be75b4fe 100644 --- a/internal/reaper/database.go +++ b/pkg/reaper/database.go @@ -7,10 +7,10 @@ import ( "strings" "time" - "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/jackc/pgx/v5" ) diff --git a/internal/reaper/database_test.go b/pkg/reaper/database_test.go similarity index 99% rename from internal/reaper/database_test.go rename to pkg/reaper/database_test.go index 3c87242ae7..3708439367 100644 --- a/internal/reaper/database_test.go +++ b/pkg/reaper/database_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "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" pgxmock "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/reaper/doc.go b/pkg/reaper/doc.go similarity index 100% rename from internal/reaper/doc.go rename to pkg/reaper/doc.go diff --git a/internal/reaper/file.go b/pkg/reaper/file.go similarity index 95% rename from internal/reaper/file.go rename to pkg/reaper/file.go index e1a0e14b3e..518344fd00 100644 --- a/internal/reaper/file.go +++ b/pkg/reaper/file.go @@ -6,8 +6,8 @@ import ( "slices" - "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" ) func DoesEmergencyTriggerfileExist(fname string) bool { diff --git a/internal/reaper/logparser.go b/pkg/reaper/logparser.go similarity index 97% rename from internal/reaper/logparser.go rename to pkg/reaper/logparser.go index a2127073ce..0622dea919 100644 --- a/internal/reaper/logparser.go +++ b/pkg/reaper/logparser.go @@ -11,9 +11,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" "github.com/jackc/pgx/v5" ) diff --git a/internal/reaper/logparser_local.go b/pkg/reaper/logparser_local.go similarity index 98% rename from internal/reaper/logparser_local.go rename to pkg/reaper/logparser_local.go index 5b9111a0d9..feb9aa9da4 100644 --- a/internal/reaper/logparser_local.go +++ b/pkg/reaper/logparser_local.go @@ -7,7 +7,7 @@ import ( "path/filepath" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" ) func (lp *LogParser) parseLogsLocal() error { diff --git a/internal/reaper/logparser_remote.go b/pkg/reaper/logparser_remote.go similarity index 98% rename from internal/reaper/logparser_remote.go rename to pkg/reaper/logparser_remote.go index ab50479b5b..295b7e08a2 100644 --- a/internal/reaper/logparser_remote.go +++ b/pkg/reaper/logparser_remote.go @@ -5,7 +5,7 @@ import ( "strings" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" ) func (lp *LogParser) parseLogsRemote() error { diff --git a/internal/reaper/logparser_test.go b/pkg/reaper/logparser_test.go similarity index 99% rename from internal/reaper/logparser_test.go rename to pkg/reaper/logparser_test.go index b596433bc5..3f2f3b8105 100644 --- a/internal/reaper/logparser_test.go +++ b/pkg/reaper/logparser_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "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/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" diff --git a/internal/reaper/metric.go b/pkg/reaper/metric.go similarity index 95% rename from internal/reaper/metric.go rename to pkg/reaper/metric.go index 8bf87e5e2b..87d90cb5cf 100644 --- a/internal/reaper/metric.go +++ b/pkg/reaper/metric.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" - "github.com/cybertec-postgresql/pgwatch/v5/internal/sinks" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks" "github.com/sirupsen/logrus" ) diff --git a/internal/reaper/metric_test.go b/pkg/reaper/metric_test.go similarity index 97% rename from internal/reaper/metric_test.go rename to pkg/reaper/metric_test.go index 47d5c00ecf..51167f4053 100644 --- a/internal/reaper/metric_test.go +++ b/pkg/reaper/metric_test.go @@ -4,11 +4,11 @@ import ( "context" "testing" - "github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts" - "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/cmdopts" + "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/testutil" "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" diff --git a/internal/reaper/psutil.go b/pkg/reaper/psutil.go similarity index 99% rename from internal/reaper/psutil.go rename to pkg/reaper/psutil.go index 50c13a9b60..995598cf30 100644 --- a/internal/reaper/psutil.go +++ b/pkg/reaper/psutil.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/shirou/gopsutil/v4/cpu" "github.com/shirou/gopsutil/v4/disk" "github.com/shirou/gopsutil/v4/load" diff --git a/internal/reaper/psutil_darwin.go b/pkg/reaper/psutil_darwin.go similarity index 100% rename from internal/reaper/psutil_darwin.go rename to pkg/reaper/psutil_darwin.go diff --git a/internal/reaper/psutil_linux.go b/pkg/reaper/psutil_linux.go similarity index 100% rename from internal/reaper/psutil_linux.go rename to pkg/reaper/psutil_linux.go diff --git a/internal/reaper/psutil_test.go b/pkg/reaper/psutil_test.go similarity index 98% rename from internal/reaper/psutil_test.go rename to pkg/reaper/psutil_test.go index ee63b89194..49645a39a4 100644 --- a/internal/reaper/psutil_test.go +++ b/pkg/reaper/psutil_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/stretchr/testify/assert" ) diff --git a/internal/reaper/psutil_windows.go b/pkg/reaper/psutil_windows.go similarity index 100% rename from internal/reaper/psutil_windows.go rename to pkg/reaper/psutil_windows.go diff --git a/internal/reaper/reaper.go b/pkg/reaper/reaper.go similarity index 97% rename from internal/reaper/reaper.go rename to pkg/reaper/reaper.go index 11c5247f20..5b7ba51ba5 100644 --- a/internal/reaper/reaper.go +++ b/pkg/reaper/reaper.go @@ -9,11 +9,11 @@ import ( "sync/atomic" - "github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts" - "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/cmdopts" + "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" ) const ( diff --git a/internal/reaper/reaper_test.go b/pkg/reaper/reaper_test.go similarity index 98% rename from internal/reaper/reaper_test.go rename to pkg/reaper/reaper_test.go index 425708ed39..9c8c2cd49a 100644 --- a/internal/reaper/reaper_test.go +++ b/pkg/reaper/reaper_test.go @@ -7,11 +7,11 @@ import ( "path/filepath" "testing" - "github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts" - "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/cmdopts" + "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/testutil" "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" diff --git a/internal/reaper/source_reaper.go b/pkg/reaper/source_reaper.go similarity index 98% rename from internal/reaper/source_reaper.go rename to pkg/reaper/source_reaper.go index 6ae50e4a5c..12ce9ee233 100644 --- a/internal/reaper/source_reaper.go +++ b/pkg/reaper/source_reaper.go @@ -7,9 +7,9 @@ import ( "fmt" "time" - "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" "github.com/jackc/pgx/v5" ) diff --git a/internal/reaper/source_reaper_integration_test.go b/pkg/reaper/source_reaper_integration_test.go similarity index 96% rename from internal/reaper/source_reaper_integration_test.go rename to pkg/reaper/source_reaper_integration_test.go index 898305b541..dc7f65eefe 100644 --- a/internal/reaper/source_reaper_integration_test.go +++ b/pkg/reaper/source_reaper_integration_test.go @@ -5,12 +5,12 @@ 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/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/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/reaper/source_reaper_test.go b/pkg/reaper/source_reaper_test.go similarity index 98% rename from internal/reaper/source_reaper_test.go rename to pkg/reaper/source_reaper_test.go index 1fb4d8ee57..06365e19bb 100644 --- a/internal/reaper/source_reaper_test.go +++ b/pkg/reaper/source_reaper_test.go @@ -7,12 +7,12 @@ import ( "testing/synctest" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/cmdopts" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/cmdopts" "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/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" pgxmock "github.com/pashagolub/pgxmock/v4" diff --git a/internal/sinks/cmdopts.go b/pkg/sinks/cmdopts.go similarity index 100% rename from internal/sinks/cmdopts.go rename to pkg/sinks/cmdopts.go diff --git a/internal/sinks/doc.go b/pkg/sinks/doc.go similarity index 100% rename from internal/sinks/doc.go rename to pkg/sinks/doc.go diff --git a/internal/sinks/json.go b/pkg/sinks/json.go similarity index 93% rename from internal/sinks/json.go rename to pkg/sinks/json.go index 4c9d5057d0..e91e0f2639 100644 --- a/internal/sinks/json.go +++ b/pkg/sinks/json.go @@ -6,8 +6,8 @@ import ( jsoniter "github.com/json-iterator/go" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "gopkg.in/natefinch/lumberjack.v2" ) diff --git a/internal/sinks/json_test.go b/pkg/sinks/json_test.go similarity index 93% rename from internal/sinks/json_test.go rename to pkg/sinks/json_test.go index 26e2b5ac02..75d43c9d74 100644 --- a/internal/sinks/json_test.go +++ b/pkg/sinks/json_test.go @@ -7,8 +7,8 @@ import ( jsoniter "github.com/json-iterator/go" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" - "github.com/cybertec-postgresql/pgwatch/v5/internal/sinks" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/sinks/multiwriter.go b/pkg/sinks/multiwriter.go similarity index 97% rename from internal/sinks/multiwriter.go rename to pkg/sinks/multiwriter.go index d7e9952db5..c218d345ad 100644 --- a/internal/sinks/multiwriter.go +++ b/pkg/sinks/multiwriter.go @@ -7,7 +7,7 @@ import ( "strings" "sync" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" ) // Writer is an interface that writes metrics values diff --git a/internal/sinks/multiwriter_test.go b/pkg/sinks/multiwriter_test.go similarity index 98% rename from internal/sinks/multiwriter_test.go rename to pkg/sinks/multiwriter_test.go index be8b9d55ea..1fb09f184a 100644 --- a/internal/sinks/multiwriter_test.go +++ b/pkg/sinks/multiwriter_test.go @@ -3,8 +3,8 @@ package sinks_test import ( "testing" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" - "github.com/cybertec-postgresql/pgwatch/v5/internal/sinks" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/stretchr/testify/assert" ) diff --git a/internal/sinks/postgres.go b/pkg/sinks/postgres.go similarity index 99% rename from internal/sinks/postgres.go rename to pkg/sinks/postgres.go index bbf5512536..241d3fd17e 100644 --- a/internal/sinks/postgres.go +++ b/pkg/sinks/postgres.go @@ -13,8 +13,8 @@ import ( jsoniter "github.com/json-iterator/go" "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/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" migrator "github.com/cybertec-postgresql/pgx-migrator" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" diff --git a/internal/sinks/postgres_schema_test.go b/pkg/sinks/postgres_schema_test.go similarity index 100% rename from internal/sinks/postgres_schema_test.go rename to pkg/sinks/postgres_schema_test.go diff --git a/internal/sinks/postgres_test.go b/pkg/sinks/postgres_test.go similarity index 99% rename from internal/sinks/postgres_test.go rename to pkg/sinks/postgres_test.go index f35b3aa72e..cd23a02588 100644 --- a/internal/sinks/postgres_test.go +++ b/pkg/sinks/postgres_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/jackc/pgx/v5" jsoniter "github.com/json-iterator/go" diff --git a/internal/sinks/prometheus.go b/pkg/sinks/prometheus.go similarity index 98% rename from internal/sinks/prometheus.go rename to pkg/sinks/prometheus.go index 766f00a0cc..57154c8c11 100644 --- a/internal/sinks/prometheus.go +++ b/pkg/sinks/prometheus.go @@ -12,8 +12,8 @@ import ( "sync" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) diff --git a/internal/sinks/prometheus_race_test.go b/pkg/sinks/prometheus_race_test.go similarity index 98% rename from internal/sinks/prometheus_race_test.go rename to pkg/sinks/prometheus_race_test.go index 828c2581d7..7217fabf1e 100644 --- a/internal/sinks/prometheus_race_test.go +++ b/pkg/sinks/prometheus_race_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/prometheus/client_golang/prometheus" ) diff --git a/internal/sinks/prometheus_test.go b/pkg/sinks/prometheus_test.go similarity index 98% rename from internal/sinks/prometheus_test.go rename to pkg/sinks/prometheus_test.go index bbcdaaa76f..56e9c0950d 100644 --- a/internal/sinks/prometheus_test.go +++ b/pkg/sinks/prometheus_test.go @@ -4,8 +4,8 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" diff --git a/internal/sinks/rpc.go b/pkg/sinks/rpc.go similarity index 97% rename from internal/sinks/rpc.go rename to pkg/sinks/rpc.go index 255227db2f..5d64b5e15b 100644 --- a/internal/sinks/rpc.go +++ b/pkg/sinks/rpc.go @@ -11,8 +11,8 @@ import ( "time" "github.com/cybertec-postgresql/pgwatch/v5/api/pb" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" jsoniter "github.com/json-iterator/go" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/internal/sinks/rpc_test.go b/pkg/sinks/rpc_test.go similarity index 97% rename from internal/sinks/rpc_test.go rename to pkg/sinks/rpc_test.go index 0f4f3ebb44..593f54d52b 100644 --- a/internal/sinks/rpc_test.go +++ b/pkg/sinks/rpc_test.go @@ -6,8 +6,8 @@ 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/pkg/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sinks" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" diff --git a/internal/sinks/sql/README.md b/pkg/sinks/sql/README.md similarity index 100% rename from internal/sinks/sql/README.md rename to pkg/sinks/sql/README.md diff --git a/internal/sinks/sql/admin_functions.sql b/pkg/sinks/sql/admin_functions.sql similarity index 100% rename from internal/sinks/sql/admin_functions.sql rename to pkg/sinks/sql/admin_functions.sql diff --git a/internal/sinks/sql/admin_schema.sql b/pkg/sinks/sql/admin_schema.sql similarity index 100% rename from internal/sinks/sql/admin_schema.sql rename to pkg/sinks/sql/admin_schema.sql diff --git a/internal/sinks/sql/change_chunk_interval.sql b/pkg/sinks/sql/change_chunk_interval.sql similarity index 100% rename from internal/sinks/sql/change_chunk_interval.sql rename to pkg/sinks/sql/change_chunk_interval.sql diff --git a/internal/sinks/sql/change_compression_interval.sql b/pkg/sinks/sql/change_compression_interval.sql similarity index 100% rename from internal/sinks/sql/change_compression_interval.sql rename to pkg/sinks/sql/change_compression_interval.sql diff --git a/internal/sinks/sql/ensure_partition_postgres.sql b/pkg/sinks/sql/ensure_partition_postgres.sql similarity index 100% rename from internal/sinks/sql/ensure_partition_postgres.sql rename to pkg/sinks/sql/ensure_partition_postgres.sql diff --git a/internal/sinks/sql/ensure_partition_timescale.sql b/pkg/sinks/sql/ensure_partition_timescale.sql similarity index 100% rename from internal/sinks/sql/ensure_partition_timescale.sql rename to pkg/sinks/sql/ensure_partition_timescale.sql diff --git a/internal/sinks/types.go b/pkg/sinks/types.go similarity index 100% rename from internal/sinks/types.go rename to pkg/sinks/types.go diff --git a/internal/sources/cmdopts.go b/pkg/sources/cmdopts.go similarity index 100% rename from internal/sources/cmdopts.go rename to pkg/sources/cmdopts.go diff --git a/internal/sources/conn.go b/pkg/sources/conn.go similarity index 100% rename from internal/sources/conn.go rename to pkg/sources/conn.go diff --git a/internal/sources/conn_test.go b/pkg/sources/conn_test.go similarity index 99% rename from internal/sources/conn_test.go rename to pkg/sources/conn_test.go index ba81f93dc2..83b5eeb8f0 100644 --- a/internal/sources/conn_test.go +++ b/pkg/sources/conn_test.go @@ -14,8 +14,8 @@ import ( "github.com/stretchr/testify/require" "github.com/cybertec-postgresql/pgwatch/v5/internal/db" - "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" ) func TestSourceConn_Connect(t *testing.T) { diff --git a/internal/sources/doc.go b/pkg/sources/doc.go similarity index 100% rename from internal/sources/doc.go rename to pkg/sources/doc.go diff --git a/internal/sources/postgres.go b/pkg/sources/postgres.go similarity index 100% rename from internal/sources/postgres.go rename to pkg/sources/postgres.go diff --git a/internal/sources/postgres_test.go b/pkg/sources/postgres_test.go similarity index 97% rename from internal/sources/postgres_test.go rename to pkg/sources/postgres_test.go index 9628f1645e..4c38ed2edd 100644 --- a/internal/sources/postgres_test.go +++ b/pkg/sources/postgres_test.go @@ -7,8 +7,8 @@ import ( "github.com/pashagolub/pgxmock/v4" "github.com/stretchr/testify/assert" - "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" ) func TestNewPostgresSourcesReaderWriter(t *testing.T) { diff --git a/internal/sources/resolver.go b/pkg/sources/resolver.go similarity index 99% rename from internal/sources/resolver.go rename to pkg/sources/resolver.go index 69d790e422..252e6c4248 100644 --- a/internal/sources/resolver.go +++ b/pkg/sources/resolver.go @@ -20,7 +20,7 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/cybertec-postgresql/pgwatch/v5/internal/db" - "github.com/cybertec-postgresql/pgwatch/v5/internal/log" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/log" pgx "github.com/jackc/pgx/v5" client "go.etcd.io/etcd/client/v3" "go.uber.org/zap" diff --git a/internal/sources/resolver_test.go b/pkg/sources/resolver_test.go similarity index 99% rename from internal/sources/resolver_test.go rename to pkg/sources/resolver_test.go index 2a37cabcba..13ac98fe0d 100644 --- a/internal/sources/resolver_test.go +++ b/pkg/sources/resolver_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" client "go.etcd.io/etcd/client/v3" - "github.com/cybertec-postgresql/pgwatch/v5/internal/sources" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sources" "github.com/cybertec-postgresql/pgwatch/v5/internal/testutil" ) diff --git a/internal/sources/types.go b/pkg/sources/types.go similarity index 98% rename from internal/sources/types.go rename to pkg/sources/types.go index 206becc8e1..0f206a4b92 100644 --- a/internal/sources/types.go +++ b/pkg/sources/types.go @@ -7,7 +7,7 @@ import ( "reflect" "slices" - "github.com/cybertec-postgresql/pgwatch/v5/internal/metrics" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/metrics" "github.com/jackc/pgx/v5" ) diff --git a/internal/sources/types_test.go b/pkg/sources/types_test.go similarity index 94% rename from internal/sources/types_test.go rename to pkg/sources/types_test.go index 4efdf09e55..847c47818b 100644 --- a/internal/sources/types_test.go +++ b/pkg/sources/types_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/assert" - "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" ) var ctx = log.WithLogger(context.Background(), log.NewNoopLogger()) diff --git a/internal/sources/yaml.go b/pkg/sources/yaml.go similarity index 100% rename from internal/sources/yaml.go rename to pkg/sources/yaml.go diff --git a/internal/sources/yaml_test.go b/pkg/sources/yaml_test.go similarity index 99% rename from internal/sources/yaml_test.go rename to pkg/sources/yaml_test.go index 857c8742b6..c9b4a31ba9 100644 --- a/internal/sources/yaml_test.go +++ b/pkg/sources/yaml_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/cybertec-postgresql/pgwatch/v5/internal/sources" + "github.com/cybertec-postgresql/pgwatch/v5/pkg/sources" "github.com/stretchr/testify/assert" )