From dcd65091af538ce3bd9e9afa862f28bb27846483 Mon Sep 17 00:00:00 2001 From: Mikhail Grigorev Date: Tue, 29 Oct 2024 19:56:11 +0500 Subject: [PATCH] Fixed revive warning --- cmd/pgscv.go | 1 + internal/collector/collector.go | 1 + internal/collector/collector_common.go | 10 ++++++---- internal/collector/config.go | 1 + internal/collector/filesystem_common.go | 4 +++- internal/collector/linux_cpu.go | 8 +++++--- internal/collector/linux_diskstats.go | 10 ++++++---- internal/collector/linux_filesystem.go | 10 ++++++---- internal/collector/linux_load_average.go | 8 +++++--- internal/collector/linux_memory.go | 10 ++++++---- internal/collector/linux_netdev.go | 10 ++++++---- internal/collector/linux_network.go | 7 +++++-- internal/collector/linux_sysconfig.go | 10 ++++++---- internal/collector/linux_sysinfo.go | 8 +++++--- internal/collector/patroni_common.go | 1 + internal/collector/pgbouncer_pools.go | 6 ++++-- internal/collector/pgbouncer_settings.go | 12 +++++++----- internal/collector/pgbouncer_stats.go | 4 +++- internal/collector/pgscv_services.go | 1 + internal/collector/postgres_activity.go | 12 +++++++----- internal/collector/postgres_archiver.go | 4 +++- internal/collector/postgres_bgwriter.go | 1 + internal/collector/postgres_common.go | 4 +++- internal/collector/postgres_conflicts.go | 4 +++- internal/collector/postgres_custom.go | 1 + internal/collector/postgres_database.go | 4 +++- internal/collector/postgres_functions.go | 8 +++++--- internal/collector/postgres_indexes.go | 1 + internal/collector/postgres_locks.go | 4 +++- internal/collector/postgres_logs.go | 10 ++++++---- internal/collector/postgres_replication.go | 4 +++- .../collector/postgres_replication_slots.go | 1 + internal/collector/postgres_schema.go | 8 +++++--- internal/collector/postgres_settings.go | 10 ++++++---- internal/collector/postgres_statements.go | 19 ++++++++++--------- internal/collector/postgres_storage.go | 1 + internal/collector/postgres_tables.go | 1 + internal/collector/postgres_wal.go | 4 +++- internal/collector/strings.go | 1 + internal/filter/filter.go | 4 +++- internal/http/http_client.go | 14 ++++++++++---- internal/http/http_server.go | 1 + internal/http/testing.go | 5 ++++- internal/log/log.go | 5 ++++- internal/model/model.go | 1 + internal/pgscv/config.go | 3 ++- internal/pgscv/config_test.go | 1 + internal/pgscv/pgscv.go | 1 + internal/service/config.go | 1 + internal/service/service.go | 1 + internal/store/store.go | 2 ++ internal/store/testing.go | 8 +++++++- 52 files changed, 183 insertions(+), 88 deletions(-) diff --git a/cmd/pgscv.go b/cmd/pgscv.go index 737c19e..13fbf0c 100644 --- a/cmd/pgscv.go +++ b/cmd/pgscv.go @@ -1,3 +1,4 @@ +// Package main is a pgSCV main package package main import ( diff --git a/internal/collector/collector.go b/internal/collector/collector.go index f5a6738..a5c87c8 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/collector_common.go b/internal/collector/collector_common.go index fc2c19e..2e57fa3 100644 --- a/internal/collector/collector_common.go +++ b/internal/collector/collector_common.go @@ -1,16 +1,18 @@ +// Package collector is a pgSCV collectors package collector import ( "database/sql" - "github.com/jackc/pgx/v4" + "regexp" + "strconv" + "strings" + "github.com/cherts/pgscv/internal/filter" "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" + "github.com/jackc/pgx/v4" "github.com/prometheus/client_golang/prometheus" - "regexp" - "strconv" - "strings" ) // labels is a local wrapper over prometheus.Labels which is a simple map[string]string. diff --git a/internal/collector/config.go b/internal/collector/config.go index 9345077..28c0412 100644 --- a/internal/collector/config.go +++ b/internal/collector/config.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/filesystem_common.go b/internal/collector/filesystem_common.go index 756c1a8..98c7045 100644 --- a/internal/collector/filesystem_common.go +++ b/internal/collector/filesystem_common.go @@ -1,12 +1,14 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "fmt" - "github.com/cherts/pgscv/internal/log" "io" "os" "strings" + + "github.com/cherts/pgscv/internal/log" ) // mount describes properties of mounted filesystems diff --git a/internal/collector/linux_cpu.go b/internal/collector/linux_cpu.go index 368747b..d78844e 100644 --- a/internal/collector/linux_cpu.go +++ b/internal/collector/linux_cpu.go @@ -1,18 +1,20 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "bytes" "fmt" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "os/exec" "path/filepath" "strconv" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type cpuCollector struct { diff --git a/internal/collector/linux_diskstats.go b/internal/collector/linux_diskstats.go index 92ba52c..18a2d77 100644 --- a/internal/collector/linux_diskstats.go +++ b/internal/collector/linux_diskstats.go @@ -1,19 +1,21 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "bytes" "fmt" - "github.com/cherts/pgscv/internal/filter" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "path/filepath" "regexp" "strconv" "strings" + + "github.com/cherts/pgscv/internal/filter" + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) const ( diff --git a/internal/collector/linux_filesystem.go b/internal/collector/linux_filesystem.go index e5ad0b9..04371ef 100644 --- a/internal/collector/linux_filesystem.go +++ b/internal/collector/linux_filesystem.go @@ -1,16 +1,18 @@ +// Package collector is a pgSCV collectors package collector import ( "errors" "fmt" - "github.com/cherts/pgscv/internal/filter" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "syscall" "time" + + "github.com/cherts/pgscv/internal/filter" + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) var ( diff --git a/internal/collector/linux_load_average.go b/internal/collector/linux_load_average.go index 27e0754..2986e70 100644 --- a/internal/collector/linux_load_average.go +++ b/internal/collector/linux_load_average.go @@ -1,13 +1,15 @@ +// Package collector is a pgSCV collectors package collector import ( "fmt" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "os" "strconv" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type loadaverageCollector struct { diff --git a/internal/collector/linux_memory.go b/internal/collector/linux_memory.go index 45bf55d..9b4ac36 100644 --- a/internal/collector/linux_memory.go +++ b/internal/collector/linux_memory.go @@ -1,17 +1,19 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "fmt" - "github.com/cherts/pgscv/internal/filter" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "regexp" "strconv" "strings" + + "github.com/cherts/pgscv/internal/filter" + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type meminfoCollector struct { diff --git a/internal/collector/linux_netdev.go b/internal/collector/linux_netdev.go index 2f4116e..25e48c7 100644 --- a/internal/collector/linux_netdev.go +++ b/internal/collector/linux_netdev.go @@ -1,16 +1,18 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "fmt" - "github.com/cherts/pgscv/internal/filter" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "strconv" "strings" + + "github.com/cherts/pgscv/internal/filter" + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type netdevCollector struct { diff --git a/internal/collector/linux_network.go b/internal/collector/linux_network.go index 5779699..fc82787 100644 --- a/internal/collector/linux_network.go +++ b/internal/collector/linux_network.go @@ -1,12 +1,14 @@ +// Package collector is a pgSCV collectors package collector import ( "fmt" + "net" + "strings" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/prometheus/client_golang/prometheus" - "net" - "strings" ) type networkCollector struct { @@ -14,6 +16,7 @@ type networkCollector struct { publicAddresses typedDesc } +// NewNetworkCollector returns a new Collector exposing network interfaces addresses. func NewNetworkCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) { return &networkCollector{ publicAddresses: newBuiltinTypedDesc( diff --git a/internal/collector/linux_sysconfig.go b/internal/collector/linux_sysconfig.go index b26738c..64e2a59 100644 --- a/internal/collector/linux_sysconfig.go +++ b/internal/collector/linux_sysconfig.go @@ -1,12 +1,10 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "bytes" "fmt" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "path" @@ -14,6 +12,10 @@ import ( "regexp" "strconv" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type systemCollector struct { @@ -27,7 +29,7 @@ type systemCollector struct { btime typedDesc } -// NewSystemCollector returns a new Collector exposing system-wide stats. +// NewSysconfigCollector returns a new Collector exposing system-wide stats. func NewSysconfigCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) { return &systemCollector{ sysctlList: []string{ diff --git a/internal/collector/linux_sysinfo.go b/internal/collector/linux_sysinfo.go index 4ba2e2a..80b7c8d 100644 --- a/internal/collector/linux_sysinfo.go +++ b/internal/collector/linux_sysinfo.go @@ -1,15 +1,17 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "fmt" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/prometheus/client_golang/prometheus" "io" "os" "path/filepath" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/prometheus/client_golang/prometheus" ) type sysinfoCollector struct { diff --git a/internal/collector/patroni_common.go b/internal/collector/patroni_common.go index 9795355..427b608 100644 --- a/internal/collector/patroni_common.go +++ b/internal/collector/patroni_common.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/pgbouncer_pools.go b/internal/collector/pgbouncer_pools.go index b4bfaf7..416780f 100644 --- a/internal/collector/pgbouncer_pools.go +++ b/internal/collector/pgbouncer_pools.go @@ -1,12 +1,14 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "strings" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" - "strings" ) const ( diff --git a/internal/collector/pgbouncer_settings.go b/internal/collector/pgbouncer_settings.go index 45e8354..5c9de02 100644 --- a/internal/collector/pgbouncer_settings.go +++ b/internal/collector/pgbouncer_settings.go @@ -1,19 +1,21 @@ +// Package collector is a pgSCV collectors package collector import ( "bufio" "context" "fmt" - "github.com/jackc/pgx/v4" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/cherts/pgscv/internal/store" - "github.com/prometheus/client_golang/prometheus" "os" "path/filepath" "regexp" "strconv" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/cherts/pgscv/internal/store" + "github.com/jackc/pgx/v4" + "github.com/prometheus/client_golang/prometheus" ) const ( diff --git a/internal/collector/pgbouncer_stats.go b/internal/collector/pgbouncer_stats.go index 1796f6b..5271283 100644 --- a/internal/collector/pgbouncer_stats.go +++ b/internal/collector/pgbouncer_stats.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const pgbouncerStatsQuery = "SHOW STATS" diff --git a/internal/collector/pgscv_services.go b/internal/collector/pgscv_services.go index c8d84ed..592b722 100644 --- a/internal/collector/pgscv_services.go +++ b/internal/collector/pgscv_services.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_activity.go b/internal/collector/postgres_activity.go index e30fd52..a7a34d7 100644 --- a/internal/collector/postgres_activity.go +++ b/internal/collector/postgres_activity.go @@ -1,14 +1,16 @@ +// Package collector is a pgSCV collectors package collector import ( "context" + "regexp" + "strconv" + "strings" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "regexp" - "strconv" - "strings" ) const ( @@ -82,8 +84,8 @@ type postgresActivityCollector struct { // NewPostgresActivityCollector returns a new Collector exposing postgres activity stats. // For details see: -// 1. https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW -// 2. https://www.postgresql.org/docs/current/view-pg-prepared-xacts.html +// 1. https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-ACTIVITY-VIEW +// 2. https://www.postgresql.org/docs/current/view-pg-prepared-xacts.html func NewPostgresActivityCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) { return &postgresActivityCollector{ up: newBuiltinTypedDesc( diff --git a/internal/collector/postgres_archiver.go b/internal/collector/postgres_archiver.go index 22e6612..d9b177c 100644 --- a/internal/collector/postgres_archiver.go +++ b/internal/collector/postgres_archiver.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const walArchivingQuery = "SELECT archived_count, failed_count, " + diff --git a/internal/collector/postgres_bgwriter.go b/internal/collector/postgres_bgwriter.go index 11653bb..f4feb04 100644 --- a/internal/collector/postgres_bgwriter.go +++ b/internal/collector/postgres_bgwriter.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_common.go b/internal/collector/postgres_common.go index 8c4e8b3..b73976e 100644 --- a/internal/collector/postgres_common.go +++ b/internal/collector/postgres_common.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( @@ -10,6 +11,7 @@ import ( "github.com/cherts/pgscv/internal/store" ) +// Postgres server versions const ( // Postgres server versions numeric representations. PostgresV95 = 90500 @@ -23,7 +25,7 @@ const ( PostgresV16 = 160000 PostgresV17 = 170000 - // Minimal required version is 9.5. + // Minimal required version is 9.5 PostgresVMinNum = PostgresV95 PostgresVMinStr = "9.5" ) diff --git a/internal/collector/postgres_conflicts.go b/internal/collector/postgres_conflicts.go index 193c9e0..d74d785 100644 --- a/internal/collector/postgres_conflicts.go +++ b/internal/collector/postgres_conflicts.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const ( diff --git a/internal/collector/postgres_custom.go b/internal/collector/postgres_custom.go index 92349d3..d9d596f 100644 --- a/internal/collector/postgres_custom.go +++ b/internal/collector/postgres_custom.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_database.go b/internal/collector/postgres_database.go index c9523fc..ec725c1 100644 --- a/internal/collector/postgres_database.go +++ b/internal/collector/postgres_database.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const ( diff --git a/internal/collector/postgres_functions.go b/internal/collector/postgres_functions.go index 1216c15..54fb21e 100644 --- a/internal/collector/postgres_functions.go +++ b/internal/collector/postgres_functions.go @@ -1,13 +1,15 @@ +// Package collector is a pgSCV collectors package collector import ( - "github.com/jackc/pgx/v4" + "strconv" + "strings" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" + "github.com/jackc/pgx/v4" "github.com/prometheus/client_golang/prometheus" - "strconv" - "strings" ) const postgresFunctionsQuery = "SELECT current_database() AS database, schemaname AS schema, funcname AS function, calls, total_time, self_time FROM pg_stat_user_functions" diff --git a/internal/collector/postgres_indexes.go b/internal/collector/postgres_indexes.go index 255e8c3..399d756 100644 --- a/internal/collector/postgres_indexes.go +++ b/internal/collector/postgres_indexes.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_locks.go b/internal/collector/postgres_locks.go index e5ff9dc..370cdbb 100644 --- a/internal/collector/postgres_locks.go +++ b/internal/collector/postgres_locks.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const ( diff --git a/internal/collector/postgres_logs.go b/internal/collector/postgres_logs.go index 06cabe7..e883742 100644 --- a/internal/collector/postgres_logs.go +++ b/internal/collector/postgres_logs.go @@ -1,16 +1,18 @@ +// Package collector is a pgSCV collectors package collector import ( "context" + "io" + "regexp" + "strings" + "sync" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/nxadm/tail" "github.com/prometheus/client_golang/prometheus" - "io" - "regexp" - "strings" - "sync" ) // Current implementation has an issue described here: https://github.com/nxadm/tail/issues/18. diff --git a/internal/collector/postgres_replication.go b/internal/collector/postgres_replication.go index 606efa5..a459fb0 100644 --- a/internal/collector/postgres_replication.go +++ b/internal/collector/postgres_replication.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const ( diff --git a/internal/collector/postgres_replication_slots.go b/internal/collector/postgres_replication_slots.go index 409fc51..f19fa9f 100644 --- a/internal/collector/postgres_replication_slots.go +++ b/internal/collector/postgres_replication_slots.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_schema.go b/internal/collector/postgres_schema.go index 8108fbc..e8a9b9b 100644 --- a/internal/collector/postgres_schema.go +++ b/internal/collector/postgres_schema.go @@ -1,13 +1,15 @@ +// Package collector is a pgSCV collectors package collector import ( - "github.com/jackc/pgx/v4" + "strings" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" + "github.com/jackc/pgx/v4" "github.com/prometheus/client_golang/prometheus" "golang.org/x/net/context" - "strings" ) // postgresSchemaCollector defines metric descriptors and stats store. @@ -21,7 +23,7 @@ type postgresSchemaCollector struct { difftypefkey typedDesc } -// NewPostgresSchemaCollector returns a new Collector exposing postgres schema stats. Stats are based on different +// NewPostgresSchemasCollector returns a new Collector exposing postgres schema stats. Stats are based on different // sources inside system catalog. func NewPostgresSchemasCollector(constLabels labels, settings model.CollectorSettings) (Collector, error) { return &postgresSchemaCollector{ diff --git a/internal/collector/postgres_settings.go b/internal/collector/postgres_settings.go index cb0b863..0e83a93 100644 --- a/internal/collector/postgres_settings.go +++ b/internal/collector/postgres_settings.go @@ -1,15 +1,17 @@ +// Package collector is a pgSCV collectors package collector import ( "fmt" - "github.com/cherts/pgscv/internal/log" - "github.com/cherts/pgscv/internal/model" - "github.com/cherts/pgscv/internal/store" - "github.com/prometheus/client_golang/prometheus" "os" "regexp" "strconv" "strings" + + "github.com/cherts/pgscv/internal/log" + "github.com/cherts/pgscv/internal/model" + "github.com/cherts/pgscv/internal/store" + "github.com/prometheus/client_golang/prometheus" ) // postgresSettingsCollector defines metric descriptors and stats store. diff --git a/internal/collector/postgres_statements.go b/internal/collector/postgres_statements.go index cc2fdf7..90c1d73 100644 --- a/internal/collector/postgres_statements.go +++ b/internal/collector/postgres_statements.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( @@ -521,26 +522,26 @@ func parsePostgresStatementsStats(r *model.PGResult, labelNames []string) map[st // selectStatementsQuery returns suitable statements query depending on passed version. func selectStatementsQuery(version int, schema string, notrackmode bool, topK int) string { - var query_columm string + var queryColumm string if notrackmode { - query_columm = "null" + queryColumm = "null" } else { - query_columm = "p.query" + queryColumm = "p.query" } if version < PostgresV13 { if topK > 0 { - return fmt.Sprintf(postgresStatementsQuery12TopK, query_columm, schema) + return fmt.Sprintf(postgresStatementsQuery12TopK, queryColumm, schema) } - return fmt.Sprintf(postgresStatementsQuery12, query_columm, schema) + return fmt.Sprintf(postgresStatementsQuery12, queryColumm, schema) } else if version > PostgresV12 && version < PostgresV17 { if topK > 0 { - return fmt.Sprintf(postgresStatementsQuery16TopK, query_columm, schema) + return fmt.Sprintf(postgresStatementsQuery16TopK, queryColumm, schema) } - return fmt.Sprintf(postgresStatementsQuery16, query_columm, schema) + return fmt.Sprintf(postgresStatementsQuery16, queryColumm, schema) } else { if topK > 0 { - return fmt.Sprintf(postgresStatementsQueryLatestTopK, query_columm, schema) + return fmt.Sprintf(postgresStatementsQueryLatestTopK, queryColumm, schema) } - return fmt.Sprintf(postgresStatementsQueryLatest, query_columm, schema) + return fmt.Sprintf(postgresStatementsQueryLatest, queryColumm, schema) } } diff --git a/internal/collector/postgres_storage.go b/internal/collector/postgres_storage.go index 29ad4f7..507e397 100644 --- a/internal/collector/postgres_storage.go +++ b/internal/collector/postgres_storage.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_tables.go b/internal/collector/postgres_tables.go index 684f073..b3e678e 100644 --- a/internal/collector/postgres_tables.go +++ b/internal/collector/postgres_tables.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/collector/postgres_wal.go b/internal/collector/postgres_wal.go index 0db7458..426ffb5 100644 --- a/internal/collector/postgres_wal.go +++ b/internal/collector/postgres_wal.go @@ -1,11 +1,13 @@ +// Package collector is a pgSCV collectors package collector import ( + "strconv" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/cherts/pgscv/internal/store" "github.com/prometheus/client_golang/prometheus" - "strconv" ) const ( diff --git a/internal/collector/strings.go b/internal/collector/strings.go index 80cda21..b30e23f 100644 --- a/internal/collector/strings.go +++ b/internal/collector/strings.go @@ -1,3 +1,4 @@ +// Package collector is a pgSCV collectors package collector import ( diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 0b3a070..a4fa28c 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -1,8 +1,10 @@ +// Package filter is a pgSCV filter package filter import ( - "github.com/cherts/pgscv/internal/log" "regexp" + + "github.com/cherts/pgscv/internal/log" ) // Filter describes settings for filtering stats values for metrics. diff --git a/internal/http/http_client.go b/internal/http/http_client.go index 780f1e4..2bf63b3 100644 --- a/internal/http/http_client.go +++ b/internal/http/http_client.go @@ -1,3 +1,4 @@ +// Package http is a pgSCV http helper package http import ( @@ -6,11 +7,16 @@ import ( "time" ) +// Status code const ( - StatusOK = http.StatusOK // 200 - StatusBadRequest = http.StatusBadRequest // 400 - StatusUnauthorized = http.StatusUnauthorized // 401 - StatusNotFound = http.StatusNotFound // 404 + // Code 200 + StatusOK = http.StatusOK + // Code 400 + StatusBadRequest = http.StatusBadRequest + // Code 401 + StatusUnauthorized = http.StatusUnauthorized + // Code 404 + StatusNotFound = http.StatusNotFound ) // Client defines local wrapper on standard http.Client. diff --git a/internal/http/http_server.go b/internal/http/http_server.go index d72d8be..f51d53c 100644 --- a/internal/http/http_server.go +++ b/internal/http/http_server.go @@ -1,3 +1,4 @@ +// Package http is a pgSCV http helper package http import ( diff --git a/internal/http/testing.go b/internal/http/testing.go index 2e18c8c..86eee68 100644 --- a/internal/http/testing.go +++ b/internal/http/testing.go @@ -2,12 +2,14 @@ package http import ( "fmt" - "github.com/stretchr/testify/assert" "net/http" "net/http/httptest" "testing" + + "github.com/stretchr/testify/assert" ) +// TestServer create http test server func TestServer(t *testing.T, code int, response string) *httptest.Server { return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { if code == http.StatusOK { @@ -23,6 +25,7 @@ func TestServer(t *testing.T, code int, response string) *httptest.Server { })) } +// TestFileServer create http test server func TestFileServer(_ *testing.T, dir string) *httptest.Server { return httptest.NewServer(http.FileServer(http.Dir(dir))) } diff --git a/internal/log/log.go b/internal/log/log.go index 9b259eb..a01713a 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -1,9 +1,11 @@ +// Package log is a pgSCV logger package log import ( "fmt" - "github.com/rs/zerolog" "os" + + "github.com/rs/zerolog" ) // Logger is the global logger with predefined settings @@ -28,6 +30,7 @@ func SetLevel(level string) { } } +// New create logger func New() zerolog.Logger { var logger = Logger return logger diff --git a/internal/model/model.go b/internal/model/model.go index e04349d..a51d57c 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -1,3 +1,4 @@ +// Package model is a pgSCV model package model import ( diff --git a/internal/pgscv/config.go b/internal/pgscv/config.go index 015bc3a..82b2f2b 100644 --- a/internal/pgscv/config.go +++ b/internal/pgscv/config.go @@ -1,3 +1,4 @@ +// Package pgscv is a pgSCV main helper package pgscv import ( @@ -141,7 +142,7 @@ func mergeServicesConnsSettings(dest, src service.ConnsSettings) service.ConnsSe return dest } -// Read real config file path +// RealPath read real config file path func RealPath(filePath string) (string, error) { log.Infoln("reading file information ", filePath) fileInfo, err := os.Lstat(filepath.Clean(filePath)) diff --git a/internal/pgscv/config_test.go b/internal/pgscv/config_test.go index c7ce928..659bdf8 100644 --- a/internal/pgscv/config_test.go +++ b/internal/pgscv/config_test.go @@ -1,3 +1,4 @@ +// Package pgscv is a pgSCV helper package pgscv import ( diff --git a/internal/pgscv/pgscv.go b/internal/pgscv/pgscv.go index a8d9c41..ed3d227 100644 --- a/internal/pgscv/pgscv.go +++ b/internal/pgscv/pgscv.go @@ -1,3 +1,4 @@ +// Package pgscv is a pgSCV main helper package pgscv import ( diff --git a/internal/service/config.go b/internal/service/config.go index 131bbc9..a624196 100644 --- a/internal/service/config.go +++ b/internal/service/config.go @@ -1,3 +1,4 @@ +// Package service is a pgSCV service helper package service import ( diff --git a/internal/service/service.go b/internal/service/service.go index 8caedf3..6f31e32 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -1,3 +1,4 @@ +// Package service is a pgSCV service helper package service import ( diff --git a/internal/store/store.go b/internal/store/store.go index 7b117db..78c7db0 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -1,9 +1,11 @@ +// Package store is a pgSCV database helper package store import ( "context" "database/sql" "fmt" + "github.com/cherts/pgscv/internal/log" "github.com/cherts/pgscv/internal/model" "github.com/jackc/pgx/v4" diff --git a/internal/store/testing.go b/internal/store/testing.go index 78361e1..46603ee 100644 --- a/internal/store/testing.go +++ b/internal/store/testing.go @@ -1,19 +1,25 @@ package store import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) +// TestPostgresConnStr PostgreSQL connection string const TestPostgresConnStr = "host=127.0.0.1 port=5432 user=pgscv dbname=pgscv_fixtures sslmode=disable" + +// TestPgbouncerConnStr Pgbouncer connection string const TestPgbouncerConnStr = "host=127.0.0.1 port=6432 user=pgscv dbname=pgbouncer sslmode=disable password=pgscv" +// NewTest create PostgreSQL test func NewTest(t *testing.T) *DB { db, err := New(TestPostgresConnStr) assert.NoError(t, err) return db } +// NewTestPgbouncer create Pgbouncer test func NewTestPgbouncer(t *testing.T) *DB { db, err := New(TestPgbouncerConnStr) assert.NoError(t, err)