From e1226b175d2d09dd6d92e09f8e95149bd6ab086a Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Tue, 3 May 2022 17:36:38 +0200 Subject: [PATCH 01/14] PMM-9632 Struct draft. --- agentlocal/mock_client_test.go | 7 ++-- agents/postgres/pgstatmonitor/models.go | 14 +++++-- .../postgres/pgstatmonitor/models_reform.go | 38 +++++++++++++++++-- .../postgres/pgstatmonitor/pgstatmonitor.go | 3 +- client/mock_connection_checker_test.go | 1 + client/mock_supervisor_test.go | 3 +- 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/agentlocal/mock_client_test.go b/agentlocal/mock_client_test.go index 8dcf4b794..d8c36d8a4 100644 --- a/agentlocal/mock_client_test.go +++ b/agentlocal/mock_client_test.go @@ -3,11 +3,12 @@ package agentlocal import ( - time "time" - agentpb "github.com/percona/pmm/api/agentpb" - prometheus "github.com/prometheus/client_golang/prometheus" mock "github.com/stretchr/testify/mock" + + prometheus "github.com/prometheus/client_golang/prometheus" + + time "time" ) // mockClient is an autogenerated mock type for the client type diff --git a/agents/postgres/pgstatmonitor/models.go b/agents/postgres/pgstatmonitor/models.go index 82b589d2e..d0584de95 100644 --- a/agents/postgres/pgstatmonitor/models.go +++ b/agents/postgres/pgstatmonitor/models.go @@ -38,15 +38,21 @@ type pgUser struct { // pgStatMonitorSettings represents a row in pg_stat_monitor_settings view before 1.0.0-rc.2. //reform:pg_stat_monitor_settings type pgStatMonitorSettings struct { - Name string `reform:"name"` - Value int64 `reform:"value"` + Name *string `reform:"name"` + Value int64 `reform:"value"` } // pgStatMonitorSettingsTextValue represents a row in pg_stat_monitor_settings view 1.0.0-rc.2 and higher. //reform:pg_stat_monitor_settings type pgStatMonitorSettingsTextValue struct { - Name string `reform:"name"` - Value string `reform:"value"` + Name *string `reform:"name"` + Value *string `reform:"value"` + DefaultValue *string `reform:"default_value"` + Description *string `reform:"description"` + Minimum int64 `reform:"minimum"` + Maximum int64 `reform:"maximum"` + Options *string `reform:"options"` + Restart bool `reform:"restart"` } // pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data. diff --git a/agents/postgres/pgstatmonitor/models_reform.go b/agents/postgres/pgstatmonitor/models_reform.go index 38344853a..f43d52d39 100644 --- a/agents/postgres/pgstatmonitor/models_reform.go +++ b/agents/postgres/pgstatmonitor/models_reform.go @@ -206,7 +206,7 @@ var pgStatMonitorSettingsView = &pgStatMonitorSettingsViewType{ Type: "pgStatMonitorSettings", SQLName: "pg_stat_monitor_settings", Fields: []parse.FieldInfo{ - {Name: "Name", Type: "string", Column: "name"}, + {Name: "Name", Type: "*string", Column: "name"}, {Name: "Value", Type: "int64", Column: "value"}, }, PKFieldIndex: -1, @@ -272,6 +272,12 @@ func (v *pgStatMonitorSettingsTextValueViewType) Columns() []string { return []string{ "name", "value", + "default_value", + "description", + "minimum", + "maximum", + "options", + "restart", } } @@ -286,8 +292,14 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType Type: "pgStatMonitorSettingsTextValue", SQLName: "pg_stat_monitor_settings", Fields: []parse.FieldInfo{ - {Name: "Name", Type: "string", Column: "name"}, - {Name: "Value", Type: "string", Column: "value"}, + {Name: "Name", Type: "*string", Column: "name"}, + {Name: "Value", Type: "*string", Column: "value"}, + {Name: "DefaultValue", Type: "*string", Column: "default_value"}, + {Name: "Description", Type: "*string", Column: "description"}, + {Name: "Minimum", Type: "int64", Column: "minimum"}, + {Name: "Maximum", Type: "int64", Column: "maximum"}, + {Name: "Options", Type: "*string", Column: "options"}, + {Name: "Restart", Type: "bool", Column: "restart"}, }, PKFieldIndex: -1, }, @@ -296,9 +308,15 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType // String returns a string representation of this struct or record. func (s pgStatMonitorSettingsTextValue) String() string { - res := make([]string, 2) + res := make([]string, 8) res[0] = "Name: " + reform.Inspect(s.Name, true) res[1] = "Value: " + reform.Inspect(s.Value, true) + res[2] = "DefaultValue: " + reform.Inspect(s.DefaultValue, true) + res[3] = "Description: " + reform.Inspect(s.Description, true) + res[4] = "Minimum: " + reform.Inspect(s.Minimum, true) + res[5] = "Maximum: " + reform.Inspect(s.Maximum, true) + res[6] = "Options: " + reform.Inspect(s.Options, true) + res[7] = "Restart: " + reform.Inspect(s.Restart, true) return strings.Join(res, ", ") } @@ -308,6 +326,12 @@ func (s *pgStatMonitorSettingsTextValue) Values() []interface{} { return []interface{}{ s.Name, s.Value, + s.DefaultValue, + s.Description, + s.Minimum, + s.Maximum, + s.Options, + s.Restart, } } @@ -317,6 +341,12 @@ func (s *pgStatMonitorSettingsTextValue) Pointers() []interface{} { return []interface{}{ &s.Name, &s.Value, + &s.DefaultValue, + &s.Description, + &s.Minimum, + &s.Maximum, + &s.Options, + &s.Restart, } } diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index ae6c01e34..16de0b735 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -26,8 +26,7 @@ import ( "github.com/AlekSi/pointer" ver "github.com/hashicorp/go-version" - "github.com/lib/pq" //nolint:gci - _ "github.com/lib/pq" // register SQL driver. + "github.com/lib/pq" //nolint:gci "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/api/inventorypb" "github.com/percona/pmm/utils/sqlmetrics" diff --git a/client/mock_connection_checker_test.go b/client/mock_connection_checker_test.go index 9291234da..c807311be 100644 --- a/client/mock_connection_checker_test.go +++ b/client/mock_connection_checker_test.go @@ -6,6 +6,7 @@ import ( context "context" agentpb "github.com/percona/pmm/api/agentpb" + mock "github.com/stretchr/testify/mock" ) diff --git a/client/mock_supervisor_test.go b/client/mock_supervisor_test.go index dc69d6c3c..377bbeefd 100644 --- a/client/mock_supervisor_test.go +++ b/client/mock_supervisor_test.go @@ -4,8 +4,9 @@ package client import ( agentpb "github.com/percona/pmm/api/agentpb" - prometheus "github.com/prometheus/client_golang/prometheus" mock "github.com/stretchr/testify/mock" + + prometheus "github.com/prometheus/client_golang/prometheus" ) // mockSupervisor is an autogenerated mock type for the supervisor type From 564c1c72915940cac1794c868d01812eb332772e Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Wed, 4 May 2022 12:45:35 +0200 Subject: [PATCH 02/14] PMM-9632 Changes. --- agentlocal/mock_client_test.go | 7 ++- agents/postgres/pgstatmonitor/models.go | 26 ++++++----- .../postgres/pgstatmonitor/models_reform.go | 44 ++++++++++++++++--- .../postgres/pgstatmonitor/pgstatmonitor.go | 26 ++++++++++- client/mock_connection_checker_test.go | 1 - client/mock_supervisor_test.go | 3 +- go.mod | 20 ++++----- go.sum | 35 ++++++++------- 8 files changed, 109 insertions(+), 53 deletions(-) diff --git a/agentlocal/mock_client_test.go b/agentlocal/mock_client_test.go index d8c36d8a4..8dcf4b794 100644 --- a/agentlocal/mock_client_test.go +++ b/agentlocal/mock_client_test.go @@ -3,12 +3,11 @@ package agentlocal import ( - agentpb "github.com/percona/pmm/api/agentpb" - mock "github.com/stretchr/testify/mock" + time "time" + agentpb "github.com/percona/pmm/api/agentpb" prometheus "github.com/prometheus/client_golang/prometheus" - - time "time" + mock "github.com/stretchr/testify/mock" ) // mockClient is an autogenerated mock type for the client type diff --git a/agents/postgres/pgstatmonitor/models.go b/agents/postgres/pgstatmonitor/models.go index d0584de95..b4d680dd3 100644 --- a/agents/postgres/pgstatmonitor/models.go +++ b/agents/postgres/pgstatmonitor/models.go @@ -38,21 +38,27 @@ type pgUser struct { // pgStatMonitorSettings represents a row in pg_stat_monitor_settings view before 1.0.0-rc.2. //reform:pg_stat_monitor_settings type pgStatMonitorSettings struct { - Name *string `reform:"name"` - Value int64 `reform:"value"` + Name string `reform:"name"` + Value int64 `reform:"value"` + DefaultValue string `reform:"default_value"` + Description string `reform:"description"` + Minimum int64 `reform:"minimum"` + Maximum int64 `reform:"maximum"` + Options string `reform:"options"` + Restart bool `reform:"restart"` } // pgStatMonitorSettingsTextValue represents a row in pg_stat_monitor_settings view 1.0.0-rc.2 and higher. //reform:pg_stat_monitor_settings type pgStatMonitorSettingsTextValue struct { - Name *string `reform:"name"` - Value *string `reform:"value"` - DefaultValue *string `reform:"default_value"` - Description *string `reform:"description"` - Minimum int64 `reform:"minimum"` - Maximum int64 `reform:"maximum"` - Options *string `reform:"options"` - Restart bool `reform:"restart"` + Name string `reform:"name"` + Value string `reform:"value"` + DefaultValue string `reform:"default_value"` + Description string `reform:"description"` + Minimum int64 `reform:"minimum"` + Maximum int64 `reform:"maximum"` + Options string `reform:"options"` + Restart bool `reform:"restart"` } // pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data. diff --git a/agents/postgres/pgstatmonitor/models_reform.go b/agents/postgres/pgstatmonitor/models_reform.go index f43d52d39..f02027657 100644 --- a/agents/postgres/pgstatmonitor/models_reform.go +++ b/agents/postgres/pgstatmonitor/models_reform.go @@ -192,6 +192,12 @@ func (v *pgStatMonitorSettingsViewType) Columns() []string { return []string{ "name", "value", + "default_value", + "description", + "minimum", + "maximum", + "options", + "restart", } } @@ -206,8 +212,14 @@ var pgStatMonitorSettingsView = &pgStatMonitorSettingsViewType{ Type: "pgStatMonitorSettings", SQLName: "pg_stat_monitor_settings", Fields: []parse.FieldInfo{ - {Name: "Name", Type: "*string", Column: "name"}, + {Name: "Name", Type: "string", Column: "name"}, {Name: "Value", Type: "int64", Column: "value"}, + {Name: "DefaultValue", Type: "string", Column: "default_value"}, + {Name: "Description", Type: "string", Column: "description"}, + {Name: "Minimum", Type: "int64", Column: "minimum"}, + {Name: "Maximum", Type: "int64", Column: "maximum"}, + {Name: "Options", Type: "string", Column: "options"}, + {Name: "Restart", Type: "bool", Column: "restart"}, }, PKFieldIndex: -1, }, @@ -216,9 +228,15 @@ var pgStatMonitorSettingsView = &pgStatMonitorSettingsViewType{ // String returns a string representation of this struct or record. func (s pgStatMonitorSettings) String() string { - res := make([]string, 2) + res := make([]string, 8) res[0] = "Name: " + reform.Inspect(s.Name, true) res[1] = "Value: " + reform.Inspect(s.Value, true) + res[2] = "DefaultValue: " + reform.Inspect(s.DefaultValue, true) + res[3] = "Description: " + reform.Inspect(s.Description, true) + res[4] = "Minimum: " + reform.Inspect(s.Minimum, true) + res[5] = "Maximum: " + reform.Inspect(s.Maximum, true) + res[6] = "Options: " + reform.Inspect(s.Options, true) + res[7] = "Restart: " + reform.Inspect(s.Restart, true) return strings.Join(res, ", ") } @@ -228,6 +246,12 @@ func (s *pgStatMonitorSettings) Values() []interface{} { return []interface{}{ s.Name, s.Value, + s.DefaultValue, + s.Description, + s.Minimum, + s.Maximum, + s.Options, + s.Restart, } } @@ -237,6 +261,12 @@ func (s *pgStatMonitorSettings) Pointers() []interface{} { return []interface{}{ &s.Name, &s.Value, + &s.DefaultValue, + &s.Description, + &s.Minimum, + &s.Maximum, + &s.Options, + &s.Restart, } } @@ -292,13 +322,13 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType Type: "pgStatMonitorSettingsTextValue", SQLName: "pg_stat_monitor_settings", Fields: []parse.FieldInfo{ - {Name: "Name", Type: "*string", Column: "name"}, - {Name: "Value", Type: "*string", Column: "value"}, - {Name: "DefaultValue", Type: "*string", Column: "default_value"}, - {Name: "Description", Type: "*string", Column: "description"}, + {Name: "Name", Type: "string", Column: "name"}, + {Name: "Value", Type: "string", Column: "value"}, + {Name: "DefaultValue", Type: "string", Column: "default_value"}, + {Name: "Description", Type: "string", Column: "description"}, {Name: "Minimum", Type: "int64", Column: "minimum"}, {Name: "Maximum", Type: "int64", Column: "maximum"}, - {Name: "Options", Type: "*string", Column: "options"}, + {Name: "Options", Type: "string", Column: "options"}, {Name: "Restart", Type: "bool", Column: "restart"}, }, PKFieldIndex: -1, diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 16de0b735..f39281872 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "strconv" + "sync" "time" "github.com/AlekSi/pointer" @@ -57,10 +58,17 @@ type PGStatMonitorQAN struct { // with a placeholder. This parameter is used to toggle between the two said // options. pgsmNormalizedQuery bool + pgsmSettings *settingsCache waitTime time.Duration disableQueryExamples bool } +// settingsCache provides cached access to pg_stat_monitor_settings view. +type settingsCache struct { + rw sync.RWMutex + items []*pgStatMonitorSettingsTextValue +} + // Params represent Agent parameters. type Params struct { DSN string @@ -91,7 +99,7 @@ const ( commandTypeUpdate = "UPDATE" commandTypeInsert = "INSERT" commandTypeDelete = "DELETE" - commandTypeUtiity = "UTILITY" + commandTypeUtility = "UTILITY" ) var commandTypeToText = []string{ @@ -100,7 +108,7 @@ var commandTypeToText = []string{ commandTypeUpdate, commandTypeInsert, commandTypeDelete, - commandTypeUtiity, + commandTypeUtility, commandTextNotAvailable, } @@ -169,6 +177,7 @@ func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, return nil, errors.Wrap(err, "failed to get settings") } + var settingsCache *settingsCache var normalizedQuery bool waitTime := defaultWaitTime for _, row := range settings { @@ -177,6 +186,7 @@ func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, if settingsValuesAreText { setting := row.(*pgStatMonitorSettingsTextValue) + settingsCache.items = append(settingsCache.items, setting) name = setting.Name if !isPropertyValueInt(name) { continue @@ -191,6 +201,17 @@ func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, setting := row.(*pgStatMonitorSettings) name = setting.Name value = setting.Value + + settingsCache.items = append(settingsCache.items, &pgStatMonitorSettingsTextValue{ + Name: setting.Name, + Value: fmt.Sprintf("%d", value), + DefaultValue: setting.DefaultValue, + Description: setting.Description, + Minimum: setting.Minimum, + Maximum: setting.Maximum, + Options: setting.Options, + Restart: setting.Restart, + }) } if err == nil { @@ -213,6 +234,7 @@ func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, changes: make(chan agents.Change, 10), monitorCache: newStatMonitorCache(l), pgsmNormalizedQuery: normalizedQuery, + pgsmSettings: settingsCache, waitTime: waitTime, disableQueryExamples: disableQueryExamples, }, nil diff --git a/client/mock_connection_checker_test.go b/client/mock_connection_checker_test.go index c807311be..9291234da 100644 --- a/client/mock_connection_checker_test.go +++ b/client/mock_connection_checker_test.go @@ -6,7 +6,6 @@ import ( context "context" agentpb "github.com/percona/pmm/api/agentpb" - mock "github.com/stretchr/testify/mock" ) diff --git a/client/mock_supervisor_test.go b/client/mock_supervisor_test.go index 377bbeefd..dc69d6c3c 100644 --- a/client/mock_supervisor_test.go +++ b/client/mock_supervisor_test.go @@ -4,9 +4,8 @@ package client import ( agentpb "github.com/percona/pmm/api/agentpb" - mock "github.com/stretchr/testify/mock" - prometheus "github.com/prometheus/client_golang/prometheus" + mock "github.com/stretchr/testify/mock" ) // mockSupervisor is an autogenerated mock type for the supervisor type diff --git a/go.mod b/go.mod index 0be2680e3..b0ad034ae 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/AlekSi/pointer v1.2.0 github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/davecgh/go-spew v1.1.1 - github.com/go-openapi/runtime v0.23.3 + github.com/go-openapi/runtime v0.24.0 github.com/go-sql-driver/mysql v1.6.0 github.com/golang/protobuf v1.5.2 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -25,7 +25,7 @@ require ( github.com/percona/exporter_shared v0.7.3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 github.com/percona/percona-toolkit v3.2.1+incompatible - github.com/percona/pmm v0.0.0-20220418101857-7c8201461efd + github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa github.com/pganalyze/pg_query_go v1.0.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 @@ -34,27 +34,25 @@ require ( github.com/stretchr/objx v0.3.0 github.com/stretchr/testify v1.7.1 go.mongodb.org/mongo-driver v1.9.0 - golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 - google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a + golang.org/x/sys v0.0.0-20220412211240-33da011f77ad + google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 google.golang.org/grpc v1.46.0 - google.golang.org/protobuf v1.27.1 + google.golang.org/protobuf v1.28.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 gopkg.in/reform.v1 v1.5.1 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( - github.com/PuerkitoBio/purell v1.1.1 // indirect - github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/go-openapi/analysis v0.21.2 // indirect + github.com/go-openapi/analysis v0.21.3 // indirect github.com/go-openapi/errors v0.20.2 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect - github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/loads v0.21.1 // indirect github.com/go-openapi/spec v0.20.4 // indirect github.com/go-openapi/strfmt v0.21.2 // indirect @@ -63,7 +61,7 @@ require ( github.com/go-stack/stack v1.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/snappy v0.0.1 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.8.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/klauspost/compress v1.13.6 // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -81,7 +79,7 @@ require ( github.com/xdg-go/stringprep v1.0.2 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect - golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect + golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index b00e38b2f..2f6ea2b41 100644 --- a/go.sum +++ b/go.sum @@ -43,9 +43,7 @@ github.com/Percona-Lab/kingpin v2.2.6-percona+incompatible/go.mod h1:UC6j/e2eqpH github.com/Percona-Lab/pg_query_go v1.0.3-percona h1:z0co9LzCdA9YuZBgOWTSr3+bGj14T/ngFIsHJA8A46E= github.com/Percona-Lab/pg_query_go v1.0.3-percona/go.mod h1:tR53lU3ddnExxb0XeLyYuQIK3dkR03FjQ9sj8AV/up8= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= @@ -107,8 +105,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-openapi/analysis v0.21.2 h1:hXFrOYFHUAMQdu6zwAiKKJHJQ8kqZs1ux/ru1P1wLJU= github.com/go-openapi/analysis v0.21.2/go.mod h1:HZwRk4RRisyG8vx2Oe6aqeSQcoxRp47Xkp3+K6q+LdY= +github.com/go-openapi/analysis v0.21.3 h1:CPEa+B2oYCkb+lIKB4xP6Ork8Gvh0GNg9dm/twI3+QA= +github.com/go-openapi/analysis v0.21.3/go.mod h1:2rtHDVV21tLgvJd+eXu+ExiOhfMO4+dNb7496llyke0= github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= github.com/go-openapi/errors v0.20.2 h1:dxy7PGTqEh94zj2E3h1cUmQQWiM1+aeCROfAr02EmK8= @@ -116,12 +115,13 @@ github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpX github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= github.com/go-openapi/loads v0.21.1 h1:Wb3nVZpdEzDTcly8S4HMkey6fjARRzb7iEaySimlDW0= github.com/go-openapi/loads v0.21.1/go.mod h1:/DtAMXXneXFjbQMGEtbamCZb+4x7eGwkvZCvBmwUG+g= -github.com/go-openapi/runtime v0.23.3 h1:/dxjx4KCOQI5ImBMz036F6v/DzZ2NUjSRvbLJs1rgoE= -github.com/go-openapi/runtime v0.23.3/go.mod h1:AKurw9fNre+h3ELZfk6ILsfvPN+bvvlaU/M9q/r9hpk= +github.com/go-openapi/runtime v0.24.0 h1:vTgDijpGLCgJOJTdAp5kG+O+nRsVCbH417YQ3O0iZo0= +github.com/go-openapi/runtime v0.24.0/go.mod h1:AKurw9fNre+h3ELZfk6ILsfvPN+bvvlaU/M9q/r9hpk= github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+WaRADcS5iNg= @@ -234,8 +234,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.8.0 h1:/57CcG6YAO31FWwTVUnNl+2RcDUAaT55HtI71KQAXVw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.8.0/go.mod h1:/fckq3NE+vGiJsd4fDt4ge1XrK8cN+e5G5QWIzdg7Q8= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0 h1:ESEyqQqXXFIcImj/BE8oKEX37Zsuceb2cZI+EL/zNCY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.10.0/go.mod h1:XnLCLFp3tjoZJszVKjfpyAK6J8sYIcQXWQxmqLWF21I= github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4= github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -318,8 +318,8 @@ github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 h1:0tQBti5FIrKfH3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2/go.mod h1:/SGLf9OMxlnK6jq4mkFiImBcJXXk5jwD+lDrwDaGXcw= github.com/percona/percona-toolkit v3.2.1+incompatible h1:5jLvtZKcu9fDmaLRB8qA4bLR727t5iYyguHJJQTk9w0= github.com/percona/percona-toolkit v3.2.1+incompatible/go.mod h1:netQWdWMaF1cnmwiIS+i5uyaqNXz46yNeM6HKkR6yeI= -github.com/percona/pmm v0.0.0-20220418101857-7c8201461efd h1:2V+yWa8f81b8nKPNnbvH6oddoIOCxbrXn85XEtjnew8= -github.com/percona/pmm v0.0.0-20220418101857-7c8201461efd/go.mod h1:T1LlFmiSJQxKX18/lfBfmfj4VuGm2ktUnHlHlJeeQbY= +github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa h1:e1zEJ8qC82UHj3qSYg2mSICCsR9mjo3n2Gg2Lhkw9nA= +github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -479,8 +479,9 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5 h1:bRb386wvrE+oBNdF1d/Xh9mQrfQ4ecYhW5qJ5GvTGT4= +golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -547,8 +548,9 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= +golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -669,8 +671,8 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a h1:uqouglH745GoGeZ1YFZbPBiu961tgi/9Qm5jaorajjQ= -google.golang.org/genproto v0.0.0-20220302033224-9aa15565e42a/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= +google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 h1:myaecH64R0bIEDjNORIel4iXubqzaHU1K2z8ajBwWcM= +google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -685,7 +687,7 @@ google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= +google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.46.0 h1:oCjezcn6g6A75TGoKYBPgKmVBLexhYLM6MebdrPApP8= google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -700,8 +702,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 630d0ddb4c252e390349cab8ede41e9f44e47aac Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Wed, 4 May 2022 14:45:59 +0200 Subject: [PATCH 03/14] PMM-9632 Changes in models, methods, etc. --- agents/postgres/pgstatmonitor/models.go | 12 +- .../postgres/pgstatmonitor/models_reform.go | 34 +-- .../postgres/pgstatmonitor/pgstatmonitor.go | 246 +++++++++--------- .../pgstatmonitor/stat_monitor_cache_test.go | 7 +- go.mod | 2 +- go.sum | 2 + 6 files changed, 143 insertions(+), 160 deletions(-) diff --git a/agents/postgres/pgstatmonitor/models.go b/agents/postgres/pgstatmonitor/models.go index b4d680dd3..be8767da1 100644 --- a/agents/postgres/pgstatmonitor/models.go +++ b/agents/postgres/pgstatmonitor/models.go @@ -38,14 +38,8 @@ type pgUser struct { // pgStatMonitorSettings represents a row in pg_stat_monitor_settings view before 1.0.0-rc.2. //reform:pg_stat_monitor_settings type pgStatMonitorSettings struct { - Name string `reform:"name"` - Value int64 `reform:"value"` - DefaultValue string `reform:"default_value"` - Description string `reform:"description"` - Minimum int64 `reform:"minimum"` - Maximum int64 `reform:"maximum"` - Options string `reform:"options"` - Restart bool `reform:"restart"` + Name string `reform:"name"` + Value int64 `reform:"value"` } // pgStatMonitorSettingsTextValue represents a row in pg_stat_monitor_settings view 1.0.0-rc.2 and higher. @@ -58,7 +52,7 @@ type pgStatMonitorSettingsTextValue struct { Minimum int64 `reform:"minimum"` Maximum int64 `reform:"maximum"` Options string `reform:"options"` - Restart bool `reform:"restart"` + Restart string `reform:"restart"` } // pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data. diff --git a/agents/postgres/pgstatmonitor/models_reform.go b/agents/postgres/pgstatmonitor/models_reform.go index f02027657..782787387 100644 --- a/agents/postgres/pgstatmonitor/models_reform.go +++ b/agents/postgres/pgstatmonitor/models_reform.go @@ -192,12 +192,6 @@ func (v *pgStatMonitorSettingsViewType) Columns() []string { return []string{ "name", "value", - "default_value", - "description", - "minimum", - "maximum", - "options", - "restart", } } @@ -214,12 +208,6 @@ var pgStatMonitorSettingsView = &pgStatMonitorSettingsViewType{ Fields: []parse.FieldInfo{ {Name: "Name", Type: "string", Column: "name"}, {Name: "Value", Type: "int64", Column: "value"}, - {Name: "DefaultValue", Type: "string", Column: "default_value"}, - {Name: "Description", Type: "string", Column: "description"}, - {Name: "Minimum", Type: "int64", Column: "minimum"}, - {Name: "Maximum", Type: "int64", Column: "maximum"}, - {Name: "Options", Type: "string", Column: "options"}, - {Name: "Restart", Type: "bool", Column: "restart"}, }, PKFieldIndex: -1, }, @@ -228,15 +216,9 @@ var pgStatMonitorSettingsView = &pgStatMonitorSettingsViewType{ // String returns a string representation of this struct or record. func (s pgStatMonitorSettings) String() string { - res := make([]string, 8) + res := make([]string, 2) res[0] = "Name: " + reform.Inspect(s.Name, true) res[1] = "Value: " + reform.Inspect(s.Value, true) - res[2] = "DefaultValue: " + reform.Inspect(s.DefaultValue, true) - res[3] = "Description: " + reform.Inspect(s.Description, true) - res[4] = "Minimum: " + reform.Inspect(s.Minimum, true) - res[5] = "Maximum: " + reform.Inspect(s.Maximum, true) - res[6] = "Options: " + reform.Inspect(s.Options, true) - res[7] = "Restart: " + reform.Inspect(s.Restart, true) return strings.Join(res, ", ") } @@ -246,12 +228,6 @@ func (s *pgStatMonitorSettings) Values() []interface{} { return []interface{}{ s.Name, s.Value, - s.DefaultValue, - s.Description, - s.Minimum, - s.Maximum, - s.Options, - s.Restart, } } @@ -261,12 +237,6 @@ func (s *pgStatMonitorSettings) Pointers() []interface{} { return []interface{}{ &s.Name, &s.Value, - &s.DefaultValue, - &s.Description, - &s.Minimum, - &s.Maximum, - &s.Options, - &s.Restart, } } @@ -329,7 +299,7 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType {Name: "Minimum", Type: "int64", Column: "minimum"}, {Name: "Maximum", Type: "int64", Column: "maximum"}, {Name: "Options", Type: "string", Column: "options"}, - {Name: "Restart", Type: "bool", Column: "restart"}, + {Name: "Restart", Type: "string", Column: "restart"}, }, PKFieldIndex: -1, }, diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index f39281872..9ed7b22d5 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -22,7 +22,6 @@ import ( "fmt" "io" "strconv" - "sync" "time" "github.com/AlekSi/pointer" @@ -30,6 +29,7 @@ import ( "github.com/lib/pq" //nolint:gci "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/api/inventorypb" + qanv1beta1 "github.com/percona/pmm/api/qanpb" "github.com/percona/pmm/utils/sqlmetrics" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -41,34 +41,17 @@ import ( "github.com/percona/pmm-agent/utils/version" ) -const defaultWaitTime = 60 * time.Second - // PGStatMonitorQAN QAN services connects to PostgreSQL and extracts stats. type PGStatMonitorQAN struct { - q *reform.Querier - dbCloser io.Closer - agentID string - l *logrus.Entry - changes chan agents.Change - monitorCache *statMonitorCache - - // By default, query shows the actual parameter instead of the placeholder. - // It is quite useful when users want to use that query and try to run that - // query to check the abnormalities. But in most cases users like the queries - // with a placeholder. This parameter is used to toggle between the two said - // options. - pgsmNormalizedQuery bool - pgsmSettings *settingsCache - waitTime time.Duration + q *reform.Querier + dbCloser io.Closer + agentID string + l *logrus.Entry + changes chan agents.Change + monitorCache *statMonitorCache disableQueryExamples bool } -// settingsCache provides cached access to pg_stat_monitor_settings view. -type settingsCache struct { - rw sync.RWMutex - items []*pgStatMonitorSettingsTextValue -} - // Params represent Agent parameters. type Params struct { DSN string @@ -129,25 +112,6 @@ func New(params *Params, l *logrus.Entry) (*PGStatMonitorQAN, error) { return newPgStatMonitorQAN(q, sqlDB, params.AgentID, params.DisableQueryExamples, l) } -func isPropertyValueInt(property string) bool { - switch property { - case - "pg_stat_monitor.pgsm_histogram_max", - "pg_stat_monitor.pgsm_query_max_len", - "pg_stat_monitor.pgsm_max", - "pg_stat_monitor.pgsm_bucket_time", - "pg_stat_monitor.pgsm_query_shared_buffer", - "pg_stat_monitor.pgsm_max_buckets", - "pg_stat_monitor.pgsm_histogram_buckets", - "pg_stat_monitor.pgsm_overflow_target", - "pg_stat_monitor.pgsm_histogram_min": - - return true - } - - return false -} - func areSettingsTextValues(q *reform.Querier) (bool, error) { pgsmVersion, prerelease, err := getPGMonitorVersion(q) if err != nil { @@ -162,70 +126,6 @@ func areSettingsTextValues(q *reform.Querier) (bool, error) { } func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, disableQueryExamples bool, l *logrus.Entry) (*PGStatMonitorQAN, error) { - var settings []reform.Struct - - settingsValuesAreText, err := areSettingsTextValues(q) - if err != nil { - return nil, err - } - if settingsValuesAreText { - settings, err = q.SelectAllFrom(pgStatMonitorSettingsTextValueView, "") - } else { - settings, err = q.SelectAllFrom(pgStatMonitorSettingsView, "") - } - if err != nil { - return nil, errors.Wrap(err, "failed to get settings") - } - - var settingsCache *settingsCache - var normalizedQuery bool - waitTime := defaultWaitTime - for _, row := range settings { - var name string - var value int64 - - if settingsValuesAreText { - setting := row.(*pgStatMonitorSettingsTextValue) - settingsCache.items = append(settingsCache.items, setting) - name = setting.Name - if !isPropertyValueInt(name) { - continue - } - - valueInt, err := strconv.ParseInt(setting.Value, 10, 64) - if err != nil { - return nil, errors.Wrap(err, "value cannot be parsed as integer") - } - value = valueInt - } else { - setting := row.(*pgStatMonitorSettings) - name = setting.Name - value = setting.Value - - settingsCache.items = append(settingsCache.items, &pgStatMonitorSettingsTextValue{ - Name: setting.Name, - Value: fmt.Sprintf("%d", value), - DefaultValue: setting.DefaultValue, - Description: setting.Description, - Minimum: setting.Minimum, - Maximum: setting.Maximum, - Options: setting.Options, - Restart: setting.Restart, - }) - } - - if err == nil { - switch name { - case "pg_stat_monitor.pgsm_normalized_query": - normalizedQuery = value == 1 - case "pg_stat_monitor.pgsm_bucket_time": - if value < int64(defaultWaitTime.Seconds()) { - waitTime = time.Duration(value) * time.Second - } - } - } - } - return &PGStatMonitorQAN{ q: q, dbCloser: dbCloser, @@ -233,9 +133,6 @@ func newPgStatMonitorQAN(q *reform.Querier, dbCloser io.Closer, agentID string, l: l, changes: make(chan agents.Change, 10), monitorCache: newStatMonitorCache(l), - pgsmNormalizedQuery: normalizedQuery, - pgsmSettings: settingsCache, - waitTime: waitTime, disableQueryExamples: disableQueryExamples, }, nil } @@ -297,10 +194,21 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { close(m.changes) }() + settings, err := m.getSettings() + if err != nil { + m.l.Error(err) + m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + } + normalizedQuery, err := settings.getNormalizedQueryValue() + if err != nil { + m.l.Error(err) + m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + } + // add current stat monitor to cache so they are not send as new on first iteration with incorrect timestamps var running bool m.changes <- agents.Change{Status: inventorypb.AgentStatus_STARTING} - if current, _, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, m.pgsmNormalizedQuery); err == nil { + if current, _, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, normalizedQuery); err == nil { m.monitorCache.refresh(current) m.l.Debugf("Got %d initial stat monitor.", len(current)) running = true @@ -310,10 +218,16 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} } + waitTime, err := settings.getWaitTime() + if err != nil { + m.l.Error(err) + m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + } + // query pg_stat_monitor every waitTime seconds start := time.Now() - m.l.Debugf("Scheduling next collection in %s at %s.", m.waitTime, start.Add(m.waitTime).Format("15:04:05")) - t := time.NewTimer(m.waitTime) + m.l.Debugf("Scheduling next collection in %s at %s.", waitTime, start.Add(waitTime).Format("15:04:05")) + t := time.NewTimer(waitTime) defer t.Stop() for { @@ -328,12 +242,12 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { m.changes <- agents.Change{Status: inventorypb.AgentStatus_STARTING} } - lengthS := uint32(m.waitTime.Seconds()) + lengthS := uint32(waitTime.Seconds()) buckets, err := m.getNewBuckets(ctx, lengthS) start = time.Now() - m.l.Debugf("Scheduling next collection in %s at %s.", m.waitTime, start.Add(m.waitTime).Format("15:04:05")) - t.Reset(m.waitTime) + m.l.Debugf("Scheduling next collection in %s at %s.", waitTime, start.Add(waitTime).Format("15:04:05")) + t.Reset(waitTime) if err != nil { m.l.Error(errors.Wrap(err, "getNewBuckets failed")) @@ -352,8 +266,98 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { } } +type settings map[string]*pgStatMonitorSettingsTextValue + +func (m *PGStatMonitorQAN) getSettings() (settings, error) { + var settingsRows []reform.Struct + + settingsValuesAreText, err := areSettingsTextValues(m.q) + if err != nil { + return nil, err + } + if settingsValuesAreText { + settingsRows, err = m.q.SelectAllFrom(pgStatMonitorSettingsTextValueView, "") + } else { + settingsRows, err = m.q.SelectAllFrom(pgStatMonitorSettingsView, "") + } + if err != nil { + return nil, errors.Wrap(err, "failed to get settings") + } + + settings := make(settings) + for _, row := range settingsRows { + if settingsValuesAreText { + setting := row.(*pgStatMonitorSettingsTextValue) + settings[setting.Name] = setting + } else { + setting := row.(*pgStatMonitorSettings) + name := setting.Name + settings[name] = &pgStatMonitorSettingsTextValue{ + Name: name, + Value: fmt.Sprintf("%d", setting.Value), + } + } + } + + return settings, nil +} + +func (s settings) getNormalizedQueryValue() (bool, error) { + key := "pg_stat_monitor.pgsm_normalized_query" + if _, ok := s[key]; !ok { + return false, errors.New("failed to get pgsm_normalized_query property") + } + + if s[key].Value == "yes" { + return true, nil + } + + return false, nil +} + +func (s settings) toQANSettingsItems() []*qanv1beta1.SettingsItem { + var res []*qanv1beta1.SettingsItem + for _, setting := range s { + res = append(res, &qanv1beta1.SettingsItem{ + Name: setting.Name, + Value: setting.Value, + DefaultValue: setting.DefaultValue, + Description: setting.Description, + Minimum: setting.Minimum, + Maximum: setting.Maximum, + Options: setting.Options, + Restart: setting.Restart, + }) + } + + return res +} + +func (s settings) getWaitTime() (time.Duration, error) { + key := "pg_stat_monitor.pgsm_bucket_time" + if _, ok := s[key]; !ok { + return 0, errors.New("failed to get pgsm_bucket_time") + } + + valueInt, err := strconv.ParseInt(s[key].Value, 10, 64) + if err != nil { + return 0, errors.Wrap(err, "property pgsm_bucket_time cannot be parsed as uinteger") + } + + return time.Duration(valueInt) * time.Second, nil +} + func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs uint32) ([]*agentpb.MetricsBucket, error) { - current, prev, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, m.pgsmNormalizedQuery) + settings, err := m.getSettings() + if err != nil { + m.l.Errorf(err.Error()) + } + normalizedQuery, err := settings.getNormalizedQueryValue() + if err != nil { + m.l.Errorf(err.Error()) + } + + current, prev, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, normalizedQuery) if err != nil { return nil, err } @@ -382,6 +386,12 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u func (m *PGStatMonitorQAN) makeBuckets(current, cache map[time.Time]map[string]*pgStatMonitorExtended) []*agentpb.MetricsBucket { res := make([]*agentpb.MetricsBucket, 0, len(current)) + settings, err := m.getSettings() + if err != nil { + m.l.Errorf(err.Error()) + } + settingsItems := settings.toQANSettingsItems() + for bucketStartTime, bucket := range current { prev := cache[bucketStartTime] for queryID, currentPSM := range bucket { @@ -445,6 +455,8 @@ func (m *PGStatMonitorQAN) makeBuckets(current, cache map[time.Time]map[string]* mb.Postgresql.HistogramItems = histogram } + mb.Postgresql.SettingsItems = settingsItems + if (currentPSM.PlanTotalTime - prevPSM.PlanTotalTime) != 0 { mb.Postgresql.MPlanTimeSum = float32(currentPSM.PlanTotalTime-prevPSM.PlanTotalTime) / 1000 mb.Postgresql.MPlanTimeMin = float32(currentPSM.PlanMinTime) / 1000 diff --git a/agents/postgres/pgstatmonitor/stat_monitor_cache_test.go b/agents/postgres/pgstatmonitor/stat_monitor_cache_test.go index 66f504d83..fcd16c4de 100644 --- a/agents/postgres/pgstatmonitor/stat_monitor_cache_test.go +++ b/agents/postgres/pgstatmonitor/stat_monitor_cache_test.go @@ -46,7 +46,12 @@ func TestPGStatMonitorStructs(t *testing.T) { }() m := setup(t, db, false) - current, cache, err := m.monitorCache.getStatMonitorExtended(context.TODO(), db.Querier, m.pgsmNormalizedQuery) + settings, err := m.getSettings() + assert.NoError(t, err) + normalizedQuery, err := settings.getNormalizedQueryValue() + assert.NoError(t, err) + + current, cache, err := m.monitorCache.getStatMonitorExtended(context.TODO(), db.Querier, normalizedQuery) require.NoError(t, err) require.NotNil(t, current) diff --git a/go.mod b/go.mod index b0ad034ae..66901d50f 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/percona/exporter_shared v0.7.3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 github.com/percona/percona-toolkit v3.2.1+incompatible - github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa + github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb github.com/pganalyze/pg_query_go v1.0.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 diff --git a/go.sum b/go.sum index 2f6ea2b41..5473797c0 100644 --- a/go.sum +++ b/go.sum @@ -320,6 +320,8 @@ github.com/percona/percona-toolkit v3.2.1+incompatible h1:5jLvtZKcu9fDmaLRB8qA4b github.com/percona/percona-toolkit v3.2.1+incompatible/go.mod h1:netQWdWMaF1cnmwiIS+i5uyaqNXz46yNeM6HKkR6yeI= github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa h1:e1zEJ8qC82UHj3qSYg2mSICCsR9mjo3n2Gg2Lhkw9nA= github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb h1:988DVXanLLdaPazgkgKBgn9XwvcTCx+FzB2VUQhOPSI= +github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= From 5b380a19c8a5c447b441dfe20265baf28c14ff0c Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Wed, 4 May 2022 14:55:08 +0200 Subject: [PATCH 04/14] PMM-9632 Pointers to possible nil values. --- agents/postgres/pgstatmonitor/models.go | 16 ++++++++-------- agents/postgres/pgstatmonitor/pgstatmonitor.go | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/agents/postgres/pgstatmonitor/models.go b/agents/postgres/pgstatmonitor/models.go index be8767da1..0ff766379 100644 --- a/agents/postgres/pgstatmonitor/models.go +++ b/agents/postgres/pgstatmonitor/models.go @@ -45,14 +45,14 @@ type pgStatMonitorSettings struct { // pgStatMonitorSettingsTextValue represents a row in pg_stat_monitor_settings view 1.0.0-rc.2 and higher. //reform:pg_stat_monitor_settings type pgStatMonitorSettingsTextValue struct { - Name string `reform:"name"` - Value string `reform:"value"` - DefaultValue string `reform:"default_value"` - Description string `reform:"description"` - Minimum int64 `reform:"minimum"` - Maximum int64 `reform:"maximum"` - Options string `reform:"options"` - Restart string `reform:"restart"` + Name string `reform:"name"` + Value string `reform:"value"` + DefaultValue string `reform:"default_value"` + Description string `reform:"description"` + Minimum *int64 `reform:"minimum"` + Maximum *int64 `reform:"maximum"` + Options *string `reform:"options"` + Restart string `reform:"restart"` } // pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data. diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 9ed7b22d5..e0c95c569 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -323,9 +323,9 @@ func (s settings) toQANSettingsItems() []*qanv1beta1.SettingsItem { Value: setting.Value, DefaultValue: setting.DefaultValue, Description: setting.Description, - Minimum: setting.Minimum, - Maximum: setting.Maximum, - Options: setting.Options, + Minimum: pointer.GetInt64(setting.Minimum), + Maximum: pointer.GetInt64(setting.Maximum), + Options: pointer.GetString(setting.Options), Restart: setting.Restart, }) } From a764a322049ed2e60e1c6748463961a42fae947e Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Wed, 4 May 2022 14:57:07 +0200 Subject: [PATCH 05/14] PMM-9632 Gen. --- agents/postgres/pgstatmonitor/models_reform.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agents/postgres/pgstatmonitor/models_reform.go b/agents/postgres/pgstatmonitor/models_reform.go index 782787387..1901aefe7 100644 --- a/agents/postgres/pgstatmonitor/models_reform.go +++ b/agents/postgres/pgstatmonitor/models_reform.go @@ -296,9 +296,9 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType {Name: "Value", Type: "string", Column: "value"}, {Name: "DefaultValue", Type: "string", Column: "default_value"}, {Name: "Description", Type: "string", Column: "description"}, - {Name: "Minimum", Type: "int64", Column: "minimum"}, - {Name: "Maximum", Type: "int64", Column: "maximum"}, - {Name: "Options", Type: "string", Column: "options"}, + {Name: "Minimum", Type: "*int64", Column: "minimum"}, + {Name: "Maximum", Type: "*int64", Column: "maximum"}, + {Name: "Options", Type: "*string", Column: "options"}, {Name: "Restart", Type: "string", Column: "restart"}, }, PKFieldIndex: -1, From 3f7f08efc2bf927ac75b381c57ded13c1d546c22 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Thu, 5 May 2022 11:17:12 +0200 Subject: [PATCH 06/14] PMM-9632 Changes. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 13 ++++++------- agents/postgres/pgstatmonitor/pgstatmonitor_test.go | 9 ++++++++- go.mod | 2 +- go.sum | 2 ++ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index e0c95c569..685eae95e 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -29,7 +29,6 @@ import ( "github.com/lib/pq" //nolint:gci "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/api/inventorypb" - qanv1beta1 "github.com/percona/pmm/api/qanpb" "github.com/percona/pmm/utils/sqlmetrics" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -220,8 +219,8 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { waitTime, err := settings.getWaitTime() if err != nil { - m.l.Error(err) - m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + m.l.Warning(err) + waitTime = 60 } // query pg_stat_monitor every waitTime seconds @@ -315,10 +314,10 @@ func (s settings) getNormalizedQueryValue() (bool, error) { return false, nil } -func (s settings) toQANSettingsItems() []*qanv1beta1.SettingsItem { - var res []*qanv1beta1.SettingsItem +func (s settings) toQANSettingsItems() []*agentpb.SettingsItem { + var res []*agentpb.SettingsItem for _, setting := range s { - res = append(res, &qanv1beta1.SettingsItem{ + res = append(res, &agentpb.SettingsItem{ Name: setting.Name, Value: setting.Value, DefaultValue: setting.DefaultValue, @@ -341,7 +340,7 @@ func (s settings) getWaitTime() (time.Duration, error) { valueInt, err := strconv.ParseInt(s[key].Value, 10, 64) if err != nil { - return 0, errors.Wrap(err, "property pgsm_bucket_time cannot be parsed as uinteger") + return 0, errors.Wrap(err, "property pgsm_bucket_time cannot be parsed as integer") } return time.Duration(valueInt) * time.Second, nil diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go index 2003dd97e..64a824381 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go @@ -213,7 +213,13 @@ func TestPGStatMonitorSchema(t *testing.T) { assert.Equal(t, float32(5), actual.Postgresql.MSharedBlksHitSum+actual.Postgresql.MSharedBlksReadSum) assert.InDelta(t, 1.5, actual.Postgresql.MSharedBlksHitCnt+actual.Postgresql.MSharedBlksReadCnt, 0.5) example := "" - if !m.pgsmNormalizedQuery && !m.disableQueryExamples { + + settings, err := m.getSettings() + require.NoError(t, err) + normalizedQuery, err := settings.getNormalizedQueryValue() + require.NoError(t, err) + + if !normalizedQuery && !m.disableQueryExamples { example = actual.Common.Example } @@ -248,6 +254,7 @@ func TestPGStatMonitorSchema(t *testing.T) { MCpuSysTimeSum: actual.Postgresql.MCpuSysTimeSum, CmdType: selectCMDType, HistogramItems: actual.Postgresql.HistogramItems, + SettingsItems: actual.Postgresql.SettingsItems, MPlansCallsSum: actual.Postgresql.MPlansCallsSum, MPlansCallsCnt: mPlansCallsCnt, MPlanTimeCnt: mPlansTimeCnt, diff --git a/go.mod b/go.mod index 66901d50f..bdb52a704 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/percona/exporter_shared v0.7.3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 github.com/percona/percona-toolkit v3.2.1+incompatible - github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb + github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417 github.com/pganalyze/pg_query_go v1.0.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 diff --git a/go.sum b/go.sum index 5473797c0..ec7c2d549 100644 --- a/go.sum +++ b/go.sum @@ -322,6 +322,8 @@ github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa h1:e1zEJ8qC82UHj3qSYg2 github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb h1:988DVXanLLdaPazgkgKBgn9XwvcTCx+FzB2VUQhOPSI= github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417 h1:+up7wp2MPPdIJcdx+OaFZHrW2fm+ujze5bmpHWvUvhk= +github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= From cc7b296b7484016478a61f037469c0e5c6d94263 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Fri, 6 May 2022 12:49:40 +0200 Subject: [PATCH 07/14] PMM-9632 Another changes. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 6 +++--- go.mod | 2 +- go.sum | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 685eae95e..ee357ccf5 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -220,7 +220,6 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { waitTime, err := settings.getWaitTime() if err != nil { m.l.Warning(err) - waitTime = 60 } // query pg_stat_monitor every waitTime seconds @@ -333,14 +332,15 @@ func (s settings) toQANSettingsItems() []*agentpb.SettingsItem { } func (s settings) getWaitTime() (time.Duration, error) { + defaultWaitTime := 60 * time.Second key := "pg_stat_monitor.pgsm_bucket_time" if _, ok := s[key]; !ok { - return 0, errors.New("failed to get pgsm_bucket_time") + return defaultWaitTime, errors.New("failed to get pgsm_bucket_time, wait time set on 60 seconds") } valueInt, err := strconv.ParseInt(s[key].Value, 10, 64) if err != nil { - return 0, errors.Wrap(err, "property pgsm_bucket_time cannot be parsed as integer") + return defaultWaitTime, errors.Wrap(err, "property pgsm_bucket_time cannot be parsed as integer, wait time set on 60 seconds") } return time.Duration(valueInt) * time.Second, nil diff --git a/go.mod b/go.mod index bdb52a704..bd577db16 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/percona/exporter_shared v0.7.3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 github.com/percona/percona-toolkit v3.2.1+incompatible - github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417 + github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553 github.com/pganalyze/pg_query_go v1.0.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 diff --git a/go.sum b/go.sum index 5050c72a5..22817d892 100644 --- a/go.sum +++ b/go.sum @@ -325,6 +325,14 @@ github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb h1:988DVXanLLdaPazgkgK github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417 h1:+up7wp2MPPdIJcdx+OaFZHrW2fm+ujze5bmpHWvUvhk= github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220505104330-83c792635dce h1:me65k1BreTI5WfolD5gszKGS2tg/cEkCzH8Zv/u57Zo= +github.com/percona/pmm v0.0.0-20220505104330-83c792635dce/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220505105507-94c4ed2be9d7 h1:UKKNivFd9+7ujnX2WIb/P/y11e69fGdT1XhOvpJROxE= +github.com/percona/pmm v0.0.0-20220505105507-94c4ed2be9d7/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220505112525-0466764e44c5 h1:06AwvvECPSr1M/RZRNxtz0VKfNKJNYjHmq8SpF1xnG4= +github.com/percona/pmm v0.0.0-20220505112525-0466764e44c5/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553 h1:WZ2dFg4joMowSTo8ci3t9snbyJRTJEyU4ESZwzbmMEk= +github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= From ed93bb93bc01bc6b00d5e43e26bcda8c982060c6 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Fri, 6 May 2022 12:57:44 +0200 Subject: [PATCH 08/14] PMM-9632 Lint. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index ee357ccf5..feac05172 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -26,7 +26,7 @@ import ( "github.com/AlekSi/pointer" ver "github.com/hashicorp/go-version" - "github.com/lib/pq" //nolint:gci + "github.com/lib/pq" "github.com/percona/pmm/api/agentpb" "github.com/percona/pmm/api/inventorypb" "github.com/percona/pmm/utils/sqlmetrics" From 8054441373e13906bff316b21aa543a18337c286 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Tue, 10 May 2022 11:19:40 +0200 Subject: [PATCH 09/14] PMM-9632 Lint. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index feac05172..10cc4a2b5 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -40,6 +40,8 @@ import ( "github.com/percona/pmm-agent/utils/version" ) +const defaultWaitTime = 60 * time.Second + // PGStatMonitorQAN QAN services connects to PostgreSQL and extracts stats. type PGStatMonitorQAN struct { q *reform.Querier @@ -332,7 +334,6 @@ func (s settings) toQANSettingsItems() []*agentpb.SettingsItem { } func (s settings) getWaitTime() (time.Duration, error) { - defaultWaitTime := 60 * time.Second key := "pg_stat_monitor.pgsm_bucket_time" if _, ok := s[key]; !ok { return defaultWaitTime, errors.New("failed to get pgsm_bucket_time, wait time set on 60 seconds") From d524caaf39469dc980eac6ecf97a7f25f487e3d8 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Fri, 13 May 2022 10:33:02 +0200 Subject: [PATCH 10/14] PMM-9632 Revert settings into QAN feature. --- .../postgres/pgstatmonitor/pgstatmonitor.go | 26 ------------------- .../pgstatmonitor/pgstatmonitor_test.go | 1 - go.mod | 2 +- go.sum | 16 ++---------- 4 files changed, 3 insertions(+), 42 deletions(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 10cc4a2b5..073ce75f2 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -315,24 +315,6 @@ func (s settings) getNormalizedQueryValue() (bool, error) { return false, nil } -func (s settings) toQANSettingsItems() []*agentpb.SettingsItem { - var res []*agentpb.SettingsItem - for _, setting := range s { - res = append(res, &agentpb.SettingsItem{ - Name: setting.Name, - Value: setting.Value, - DefaultValue: setting.DefaultValue, - Description: setting.Description, - Minimum: pointer.GetInt64(setting.Minimum), - Maximum: pointer.GetInt64(setting.Maximum), - Options: pointer.GetString(setting.Options), - Restart: setting.Restart, - }) - } - - return res -} - func (s settings) getWaitTime() (time.Duration, error) { key := "pg_stat_monitor.pgsm_bucket_time" if _, ok := s[key]; !ok { @@ -386,12 +368,6 @@ func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs u func (m *PGStatMonitorQAN) makeBuckets(current, cache map[time.Time]map[string]*pgStatMonitorExtended) []*agentpb.MetricsBucket { res := make([]*agentpb.MetricsBucket, 0, len(current)) - settings, err := m.getSettings() - if err != nil { - m.l.Errorf(err.Error()) - } - settingsItems := settings.toQANSettingsItems() - for bucketStartTime, bucket := range current { prev := cache[bucketStartTime] for queryID, currentPSM := range bucket { @@ -455,8 +431,6 @@ func (m *PGStatMonitorQAN) makeBuckets(current, cache map[time.Time]map[string]* mb.Postgresql.HistogramItems = histogram } - mb.Postgresql.SettingsItems = settingsItems - if (currentPSM.PlanTotalTime - prevPSM.PlanTotalTime) != 0 { mb.Postgresql.MPlanTimeSum = float32(currentPSM.PlanTotalTime-prevPSM.PlanTotalTime) / 1000 mb.Postgresql.MPlanTimeMin = float32(currentPSM.PlanMinTime) / 1000 diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go index 64a824381..d2023eb4c 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go @@ -254,7 +254,6 @@ func TestPGStatMonitorSchema(t *testing.T) { MCpuSysTimeSum: actual.Postgresql.MCpuSysTimeSum, CmdType: selectCMDType, HistogramItems: actual.Postgresql.HistogramItems, - SettingsItems: actual.Postgresql.SettingsItems, MPlansCallsSum: actual.Postgresql.MPlansCallsSum, MPlansCallsCnt: mPlansCallsCnt, MPlanTimeCnt: mPlansTimeCnt, diff --git a/go.mod b/go.mod index bd577db16..29c54eb5f 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/percona/exporter_shared v0.7.3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 github.com/percona/percona-toolkit v3.2.1+incompatible - github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553 + github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1 github.com/pganalyze/pg_query_go v1.0.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 diff --git a/go.sum b/go.sum index 22817d892..bce4d6760 100644 --- a/go.sum +++ b/go.sum @@ -319,20 +319,8 @@ github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2 h1:0tQBti5FIrKfH3 github.com/percona/go-mysql v0.0.0-20200630114833-b77f37c0bfa2/go.mod h1:/SGLf9OMxlnK6jq4mkFiImBcJXXk5jwD+lDrwDaGXcw= github.com/percona/percona-toolkit v3.2.1+incompatible h1:5jLvtZKcu9fDmaLRB8qA4bLR727t5iYyguHJJQTk9w0= github.com/percona/percona-toolkit v3.2.1+incompatible/go.mod h1:netQWdWMaF1cnmwiIS+i5uyaqNXz46yNeM6HKkR6yeI= -github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa h1:e1zEJ8qC82UHj3qSYg2mSICCsR9mjo3n2Gg2Lhkw9nA= -github.com/percona/pmm v0.0.0-20220504104101-ef6c0ee9f2aa/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb h1:988DVXanLLdaPazgkgKBgn9XwvcTCx+FzB2VUQhOPSI= -github.com/percona/pmm v0.0.0-20220504110333-7841a152efbb/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417 h1:+up7wp2MPPdIJcdx+OaFZHrW2fm+ujze5bmpHWvUvhk= -github.com/percona/pmm v0.0.0-20220505075843-4c5b747aa417/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220505104330-83c792635dce h1:me65k1BreTI5WfolD5gszKGS2tg/cEkCzH8Zv/u57Zo= -github.com/percona/pmm v0.0.0-20220505104330-83c792635dce/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220505105507-94c4ed2be9d7 h1:UKKNivFd9+7ujnX2WIb/P/y11e69fGdT1XhOvpJROxE= -github.com/percona/pmm v0.0.0-20220505105507-94c4ed2be9d7/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220505112525-0466764e44c5 h1:06AwvvECPSr1M/RZRNxtz0VKfNKJNYjHmq8SpF1xnG4= -github.com/percona/pmm v0.0.0-20220505112525-0466764e44c5/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= -github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553 h1:WZ2dFg4joMowSTo8ci3t9snbyJRTJEyU4ESZwzbmMEk= -github.com/percona/pmm v0.0.0-20220506093550-f05ed97ac553/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= +github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1 h1:Iil3UzE49DPn4keMZ4apU396bzRJRQZvNGJc8jWRp08= +github.com/percona/pmm v0.0.0-20220505164356-d8b4097358e1/go.mod h1:k7HS59HPX33tmrSZGiNzUTYuLr0+a49F3BEZ48MAbuo= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= From ecc37e75ff32ff9fdd70899dfee4144a582f17b7 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Sun, 15 May 2022 08:25:07 +0200 Subject: [PATCH 11/14] PMM-9632 Required changes. --- agents/postgres/pgstatmonitor/models.go | 10 ++---- .../postgres/pgstatmonitor/models_reform.go | 32 +------------------ .../postgres/pgstatmonitor/pgstatmonitor.go | 27 ++++++++++------ 3 files changed, 20 insertions(+), 49 deletions(-) diff --git a/agents/postgres/pgstatmonitor/models.go b/agents/postgres/pgstatmonitor/models.go index c164f6ee1..a62603998 100644 --- a/agents/postgres/pgstatmonitor/models.go +++ b/agents/postgres/pgstatmonitor/models.go @@ -49,14 +49,8 @@ type pgStatMonitorSettings struct { // //reform:pg_stat_monitor_settings type pgStatMonitorSettingsTextValue struct { - Name string `reform:"name"` - Value string `reform:"value"` - DefaultValue string `reform:"default_value"` - Description string `reform:"description"` - Minimum *int64 `reform:"minimum"` - Maximum *int64 `reform:"maximum"` - Options *string `reform:"options"` - Restart string `reform:"restart"` + Name string `reform:"name"` + Value string `reform:"value"` } // pgStatMonitorExtended contains pgStatMonitor data and extends it with database, username and tables data. diff --git a/agents/postgres/pgstatmonitor/models_reform.go b/agents/postgres/pgstatmonitor/models_reform.go index 1901aefe7..38344853a 100644 --- a/agents/postgres/pgstatmonitor/models_reform.go +++ b/agents/postgres/pgstatmonitor/models_reform.go @@ -272,12 +272,6 @@ func (v *pgStatMonitorSettingsTextValueViewType) Columns() []string { return []string{ "name", "value", - "default_value", - "description", - "minimum", - "maximum", - "options", - "restart", } } @@ -294,12 +288,6 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType Fields: []parse.FieldInfo{ {Name: "Name", Type: "string", Column: "name"}, {Name: "Value", Type: "string", Column: "value"}, - {Name: "DefaultValue", Type: "string", Column: "default_value"}, - {Name: "Description", Type: "string", Column: "description"}, - {Name: "Minimum", Type: "*int64", Column: "minimum"}, - {Name: "Maximum", Type: "*int64", Column: "maximum"}, - {Name: "Options", Type: "*string", Column: "options"}, - {Name: "Restart", Type: "string", Column: "restart"}, }, PKFieldIndex: -1, }, @@ -308,15 +296,9 @@ var pgStatMonitorSettingsTextValueView = &pgStatMonitorSettingsTextValueViewType // String returns a string representation of this struct or record. func (s pgStatMonitorSettingsTextValue) String() string { - res := make([]string, 8) + res := make([]string, 2) res[0] = "Name: " + reform.Inspect(s.Name, true) res[1] = "Value: " + reform.Inspect(s.Value, true) - res[2] = "DefaultValue: " + reform.Inspect(s.DefaultValue, true) - res[3] = "Description: " + reform.Inspect(s.Description, true) - res[4] = "Minimum: " + reform.Inspect(s.Minimum, true) - res[5] = "Maximum: " + reform.Inspect(s.Maximum, true) - res[6] = "Options: " + reform.Inspect(s.Options, true) - res[7] = "Restart: " + reform.Inspect(s.Restart, true) return strings.Join(res, ", ") } @@ -326,12 +308,6 @@ func (s *pgStatMonitorSettingsTextValue) Values() []interface{} { return []interface{}{ s.Name, s.Value, - s.DefaultValue, - s.Description, - s.Minimum, - s.Maximum, - s.Options, - s.Restart, } } @@ -341,12 +317,6 @@ func (s *pgStatMonitorSettingsTextValue) Pointers() []interface{} { return []interface{}{ &s.Name, &s.Value, - &s.DefaultValue, - &s.Description, - &s.Minimum, - &s.Maximum, - &s.Options, - &s.Restart, } } diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 073ce75f2..6b8f1858c 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -242,8 +242,23 @@ func (m *PGStatMonitorQAN) Run(ctx context.Context) { m.changes <- agents.Change{Status: inventorypb.AgentStatus_STARTING} } + settings, err := m.getSettings() + if err != nil { + m.l.Errorf(err.Error()) + running = false + m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + continue + } + normalizedQuery, err := settings.getNormalizedQueryValue() + if err != nil { + m.l.Errorf(err.Error()) + running = false + m.changes <- agents.Change{Status: inventorypb.AgentStatus_WAITING} + continue + } + lengthS := uint32(waitTime.Seconds()) - buckets, err := m.getNewBuckets(ctx, lengthS) + buckets, err := m.getNewBuckets(ctx, lengthS, normalizedQuery) start = time.Now() m.l.Debugf("Scheduling next collection in %s at %s.", waitTime, start.Add(waitTime).Format("15:04:05")) @@ -329,15 +344,7 @@ func (s settings) getWaitTime() (time.Duration, error) { return time.Duration(valueInt) * time.Second, nil } -func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs uint32) ([]*agentpb.MetricsBucket, error) { - settings, err := m.getSettings() - if err != nil { - m.l.Errorf(err.Error()) - } - normalizedQuery, err := settings.getNormalizedQueryValue() - if err != nil { - m.l.Errorf(err.Error()) - } +func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs uint32, normalizedQuery bool) ([]*agentpb.MetricsBucket, error) { current, prev, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, normalizedQuery) if err != nil { From 6bac794f2a9b5cb47621c121401efbfd0af87806 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Sun, 15 May 2022 08:28:37 +0200 Subject: [PATCH 12/14] PMM-9632 Remove empty line. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 6b8f1858c..96b652087 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -345,7 +345,6 @@ func (s settings) getWaitTime() (time.Duration, error) { } func (m *PGStatMonitorQAN) getNewBuckets(ctx context.Context, periodLengthSecs uint32, normalizedQuery bool) ([]*agentpb.MetricsBucket, error) { - current, prev, err := m.monitorCache.getStatMonitorExtended(ctx, m.q, normalizedQuery) if err != nil { return nil, err From 3e8c192f8a91335034301efb3a5f7090503e665b Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Sun, 15 May 2022 08:37:22 +0200 Subject: [PATCH 13/14] PMM-9632 Fix tests. --- .../pgstatmonitor/pgstatmonitor_test.go | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go index d2023eb4c..b9a8dcd93 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor_test.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor_test.go @@ -201,7 +201,12 @@ func TestPGStatMonitorSchema(t *testing.T) { _, err := db.Exec(selectAllCountries) require.NoError(t, err) - buckets, err := m.getNewBuckets(context.Background(), 60) + settings, err := m.getSettings() + require.NoError(t, err) + normalizedQuery, err := settings.getNormalizedQueryValue() + require.NoError(t, err) + + buckets, err := m.getNewBuckets(context.Background(), 60, normalizedQuery) require.NoError(t, err) buckets = filter(buckets) t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) @@ -214,11 +219,6 @@ func TestPGStatMonitorSchema(t *testing.T) { assert.InDelta(t, 1.5, actual.Postgresql.MSharedBlksHitCnt+actual.Postgresql.MSharedBlksReadCnt, 0.5) example := "" - settings, err := m.getSettings() - require.NoError(t, err) - normalizedQuery, err := settings.getNormalizedQueryValue() - require.NoError(t, err) - if !normalizedQuery && !m.disableQueryExamples { example = actual.Common.Example } @@ -270,7 +270,7 @@ func TestPGStatMonitorSchema(t *testing.T) { _, err = db.Exec(selectAllCountries) require.NoError(t, err) - buckets, err = m.getNewBuckets(context.Background(), 60) + buckets, err = m.getNewBuckets(context.Background(), 60, normalizedQuery) require.NoError(t, err) buckets = filter(buckets) t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) @@ -333,7 +333,12 @@ func TestPGStatMonitorSchema(t *testing.T) { _, err := db.Exec(q, args...) require.NoError(t, err) - buckets, err := m.getNewBuckets(context.Background(), 60) + settings, err := m.getSettings() + require.NoError(t, err) + normalizedQuery, err := settings.getNormalizedQueryValue() + require.NoError(t, err) + + buckets, err := m.getNewBuckets(context.Background(), 60, normalizedQuery) require.NoError(t, err) buckets = filter(buckets) t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) @@ -391,7 +396,7 @@ func TestPGStatMonitorSchema(t *testing.T) { _, err = db.Exec(q, args...) require.NoError(t, err) - buckets, err = m.getNewBuckets(context.Background(), 60) + buckets, err = m.getNewBuckets(context.Background(), 60, normalizedQuery) require.NoError(t, err) buckets = filter(buckets) t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) @@ -475,9 +480,14 @@ func TestPGStatMonitorSchema(t *testing.T) { } waitGroup.Wait() + settings, err := m.getSettings() + require.NoError(t, err) + normalizedQuery, err := settings.getNormalizedQueryValue() + require.NoError(t, err) + var buckets []*agentpb.MetricsBucket for i := 0; i < 100; i++ { - buckets, err = m.getNewBuckets(context.Background(), 60) + buckets, err = m.getNewBuckets(context.Background(), 60, normalizedQuery) require.NoError(t, err) buckets = filter(buckets) t.Logf("Actual:\n%s", tests.FormatBuckets(buckets)) From 86d99a2a6fb0280b32e78c9651250757de0ac676 Mon Sep 17 00:00:00 2001 From: Jiri Ctvrtka Date: Mon, 16 May 2022 07:59:07 +0200 Subject: [PATCH 14/14] PMM-9632 Fix bug for older versions. --- agents/postgres/pgstatmonitor/pgstatmonitor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/postgres/pgstatmonitor/pgstatmonitor.go b/agents/postgres/pgstatmonitor/pgstatmonitor.go index 96b652087..4e558c3f6 100644 --- a/agents/postgres/pgstatmonitor/pgstatmonitor.go +++ b/agents/postgres/pgstatmonitor/pgstatmonitor.go @@ -323,7 +323,7 @@ func (s settings) getNormalizedQueryValue() (bool, error) { return false, errors.New("failed to get pgsm_normalized_query property") } - if s[key].Value == "yes" { + if s[key].Value == "yes" || s[key].Value == "1" { return true, nil }