Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

PMM-8884 PMM doesn't get MySQL and PostgreSQL metrics after upgrade. #838

Merged
merged 5 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions services/agents/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package agents
import (
"github.com/AlekSi/pointer"

"github.com/percona/pmm/version"

"github.com/percona/pmm-managed/models"
)

Expand All @@ -29,6 +31,8 @@ const (
exposeSecrets
)

var pmmAgentPathsBaseSupport = version.MustParse("2.22.99")

// redactWords returns words that should be redacted from given Agent logs/output.
func redactWords(agent *models.Agent) []string {
var words []string
Expand All @@ -48,3 +52,13 @@ func redactWords(agent *models.Agent) []string {
}
return words
}

// pathsBase returns paths base and in case of unsupported PMM client old hardcoded value.
func pathsBase(ver, tdpLeft, tdpRight string) string {
pmmAgentVersion, err := version.Parse(ver)
if err != nil || pmmAgentVersion.Less(pmmAgentPathsBaseSupport) {
return "/usr/local/percona/pmm2"
}

return tdpLeft + " .paths_base " + tdpRight
}
10 changes: 10 additions & 0 deletions services/agents/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ func requireNoDuplicateFlags(t *testing.T, flags []string) {
s[name] = struct{}{}
}
}

func TestPathsBaseForDifferentVersions(t *testing.T) {
left := "{{"
right := "}}"
assert.Equal(t, "/usr/local/percona/pmm2", pathsBase("2.22.01", left, right))
assert.Equal(t, "{{ .paths_base }}", pathsBase("2.23.0", left, right))
assert.Equal(t, "{{ .paths_base }}", pathsBase("2.23.0-3-g7aa417c", left, right))
assert.Equal(t, "{{ .paths_base }}", pathsBase("2.23.0-beta4", left, right))
assert.Equal(t, "{{ .paths_base }}", pathsBase("2.23.0-rc1", left, right))
}
6 changes: 3 additions & 3 deletions services/agents/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func mysqldExporterConfig(service *models.Service, exporter *models.Agent, redac
"--collect.standard.go",
"--collect.standard.process",

"--collect.custom_query.lr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.mr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/mysql/medium-resolution",
"--collect.custom_query.hr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/mysql/medium-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/mysql/high-resolution",

"--exporter.max-idle-conns=3",
"--exporter.max-open-conns=3",
Expand Down
18 changes: 9 additions & 9 deletions services/agents/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func TestMySQLdExporterConfig(t *testing.T) {
"--collect.auto_increment.columns",
"--collect.binlog_size",
"--collect.custom_query.hr",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/mysql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/medium-resolution",
"--collect.engine_innodb_status",
"--collect.engine_tokudb_status",
"--collect.global_status",
Expand Down Expand Up @@ -153,11 +153,11 @@ func TestMySQLdExporterConfigTablestatsGroupDisabled(t *testing.T) {
Args: []string{
"--collect.binlog_size",
"--collect.custom_query.hr",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/mysql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/medium-resolution",
"--collect.engine_innodb_status",
"--collect.engine_tokudb_status",
"--collect.global_status",
Expand Down Expand Up @@ -234,11 +234,11 @@ func TestMySQLdExporterConfigDisabledCollectors(t *testing.T) {
Args: []string{
"--collect.auto_increment.columns",
"--collect.binlog_size",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/mysql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/mysql/medium-resolution",
"--collect.engine_innodb_status",
"--collect.engine_tokudb_status",
"--collect.global_status",
Expand Down
6 changes: 3 additions & 3 deletions services/agents/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func nodeExporterConfig(node *models.Node, exporter *models.Agent) *agentpb.SetS
)

args := []string{
"--collector.textfile.directory.lr=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/textfile-collector/high-resolution",

"--web.disable-exporter-metrics", // we enable them as a part of HR metrics

Expand Down
19 changes: 10 additions & 9 deletions services/agents/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package agents
import (
"testing"

"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -61,9 +62,9 @@ func TestNodeExporterConfig(t *testing.T) {
"--collector.standard.go",
"--collector.standard.process",
"--collector.stat",
"--collector.textfile.directory.hr={{ .paths_base }}/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr={{ .paths_base }}/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr={{ .paths_base }}/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/medium-resolution",
"--collector.textfile.hr",
"--collector.textfile.lr",
"--collector.textfile.mr",
Expand Down Expand Up @@ -139,9 +140,9 @@ func TestNodeExporterConfig(t *testing.T) {
"--collector.standard.go",
"--collector.standard.process",
"--collector.stat",
"--collector.textfile.directory.hr={{ .paths_base }}/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr={{ .paths_base }}/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr={{ .paths_base }}/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/medium-resolution",
"--collector.textfile.hr",
"--collector.textfile.lr",
"--collector.textfile.mr",
Expand Down Expand Up @@ -203,9 +204,9 @@ func TestNodeExporterConfig(t *testing.T) {
TemplateLeftDelim: "{{",
TemplateRightDelim: "}}",
Args: []string{
"--collector.textfile.directory.hr={{ .paths_base }}/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr={{ .paths_base }}/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr={{ .paths_base }}/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/high-resolution",
"--collector.textfile.directory.lr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/low-resolution",
"--collector.textfile.directory.mr=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/textfile-collector/medium-resolution",
"--web.disable-exporter-metrics",
"--web.listen-address=:{{ .listen_port }}",
},
Expand Down
6 changes: 3 additions & 3 deletions services/agents/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func postgresExporterConfig(service *models.Service, exporter *models.Agent, red
// HR
"--collect.custom_query.hr",

"--collect.custom_query.lr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.hr.directory=" + tdp.Left + " .paths_base " + tdp.Right + "/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), tdp.Left, tdp.Right) + "/collectors/custom-queries/postgresql/high-resolution",
"--web.listen-address=:" + tdp.Left + " .listen_port " + tdp.Right,
}

Expand Down
22 changes: 11 additions & 11 deletions services/agents/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func TestPostgresExporterConfig(t *testing.T) {
TemplateRightDelim: "}}",
Args: []string{
"--collect.custom_query.hr",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/medium-resolution",
"--web.listen-address=:{{ .listen_port }}",
},
Env: []string{
Expand Down Expand Up @@ -99,9 +99,9 @@ func TestPostgresExporterConfig(t *testing.T) {
TemplateRightDelim: "}}",
Args: []string{
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/medium-resolution",
"--web.listen-address=:{{ .listen_port }}",
},
}
Expand Down Expand Up @@ -131,11 +131,11 @@ func TestPostgresExporterConfig(t *testing.T) {
Args: []string{
"--auto-discover-databases",
"--collect.custom_query.hr",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/medium-resolution",
"--exclude-databases=template0,template1,postgres,cloudsqladmin,pmm-managed-dev,azure_maintenance",
"--web.listen-address=:{{ .listen_port }}",
},
Expand Down Expand Up @@ -180,11 +180,11 @@ func TestPostgresExporterConfig(t *testing.T) {
Args: []string{
"--auto-discover-databases",
"--collect.custom_query.hr",
"--collect.custom_query.hr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.hr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/high-resolution",
"--collect.custom_query.lr",
"--collect.custom_query.lr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.lr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/low-resolution",
"--collect.custom_query.mr",
"--collect.custom_query.mr.directory={{ .paths_base }}/collectors/custom-queries/postgresql/medium-resolution",
"--collect.custom_query.mr.directory=" + pathsBase(pointer.GetString(exporter.Version), "{{", "}}") + "/collectors/custom-queries/postgresql/medium-resolution",
"--exclude-databases=template0,template1,postgres,cloudsqladmin,pmm-managed-dev,azure_maintenance",
"--web.listen-address=:{{ .listen_port }}",
},
Expand Down