diff --git a/services/agents/agents.go b/services/agents/agents.go index 78cee88f45..67a1b7e9ea 100644 --- a/services/agents/agents.go +++ b/services/agents/agents.go @@ -19,6 +19,8 @@ package agents import ( "github.com/AlekSi/pointer" + "github.com/percona/pmm/version" + "github.com/percona/pmm-managed/models" ) @@ -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 @@ -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 +} diff --git a/services/agents/agents_test.go b/services/agents/agents_test.go index c1d34abe60..e2917690c0 100644 --- a/services/agents/agents_test.go +++ b/services/agents/agents_test.go @@ -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)) +} diff --git a/services/agents/mysql.go b/services/agents/mysql.go index 5d73f49a0c..df8dc6028d 100644 --- a/services/agents/mysql.go +++ b/services/agents/mysql.go @@ -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", diff --git a/services/agents/mysql_test.go b/services/agents/mysql_test.go index ce270561e6..c7f894adeb 100644 --- a/services/agents/mysql_test.go +++ b/services/agents/mysql_test.go @@ -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", @@ -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", @@ -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", diff --git a/services/agents/node.go b/services/agents/node.go index de20ba872d..2a7e864c88 100644 --- a/services/agents/node.go +++ b/services/agents/node.go @@ -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 diff --git a/services/agents/node_test.go b/services/agents/node_test.go index 2056069062..63e42a0134 100644 --- a/services/agents/node_test.go +++ b/services/agents/node_test.go @@ -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" @@ -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", @@ -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", @@ -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 }}", }, diff --git a/services/agents/postgresql.go b/services/agents/postgresql.go index 3813c751da..662d2371cc 100644 --- a/services/agents/postgresql.go +++ b/services/agents/postgresql.go @@ -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, } diff --git a/services/agents/postgresql_test.go b/services/agents/postgresql_test.go index a00ab05b88..0aa45239c0 100644 --- a/services/agents/postgresql_test.go +++ b/services/agents/postgresql_test.go @@ -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{ @@ -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 }}", }, } @@ -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 }}", }, @@ -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 }}", },