Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12155 Use new option name for node_exporter #2186

Open
wants to merge 15 commits into
base: v3
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion agent/client/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type ServerRequest struct {
}

// AgentResponse represents agent's response.
// It is similar to agentpb.AgentMessage except it can contain only responses,
// It is similar to agentv1.AgentMessage except it can contain only responses,
// and the payload is already unwrapped (XXX instead of AgentMessage_XXX).
type AgentResponse struct {
ID uint32
Expand Down
10 changes: 8 additions & 2 deletions managed/services/agents/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ func pathsBase(agentVersion *version.Parsed, tdpLeft, tdpRight string) string {
}

// ensureAuthParams updates agent start parameters to contain prometheus webconfig.
func ensureAuthParams(exporter *models.Agent, params *agentv1.SetStateRequest_AgentProcess, agentVersion *version.Parsed, minAuthVersion *version.Parsed) error {
func ensureAuthParams(exporter *models.Agent, params *agentv1.SetStateRequest_AgentProcess,
agentVersion *version.Parsed, minAuthVersion *version.Parsed, useNewTLSConfig bool,
) error {
if agentVersion.Less(minAuthVersion) {
params.Env = append(params.Env, fmt.Sprintf("HTTP_AUTH=pmm:%s", exporter.GetAgentPassword()))
} else {
Expand All @@ -155,7 +157,11 @@ func ensureAuthParams(exporter *models.Agent, params *agentv1.SetStateRequest_Ag
}
params.TextFiles["webConfigPlaceholder"] = wcf
// see https://github.com/prometheus/exporter-toolkit/tree/v0.1.0/https
params.Args = append(params.Args, "--web.config="+params.TemplateLeftDelim+" .TextFiles.webConfigPlaceholder "+params.TemplateRightDelim)
if useNewTLSConfig {
params.Args = append(params.Args, "--web.config.file="+params.TemplateLeftDelim+" .TextFiles.webConfigPlaceholder "+params.TemplateRightDelim)
} else {
params.Args = append(params.Args, "--web.config="+params.TemplateLeftDelim+" .TextFiles.webConfigPlaceholder "+params.TemplateRightDelim)
}
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func mongodbExporterConfig(node *models.Node, service *models.Service, exporter
res.RedactWords = redactWords(exporter)
}

if err := ensureAuthParams(exporter, res, pmmAgentVersion, v2_27_99); err != nil {
if err := ensureAuthParams(exporter, res, pmmAgentVersion, v2_28_00, false); err != nil {
return nil, err
}

Expand Down
6 changes: 4 additions & 2 deletions managed/services/agents/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
// The node exporter prior 2.28 use exporter_shared and gets basic auth config from env.
// Starting with pmm 2.28, the exporter uses Prometheus Web Toolkit and needs a config file
// with the basic auth users.
var v2_27_99 = version.MustParse("2.27.99")
var (
v2_28_00 = version.MustParse("2.28.0-0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw do you think we should eventually move this to features for consistency?

)

func nodeExporterConfig(node *models.Node, exporter *models.Agent, agentVersion *version.Parsed) (*agentv1.SetStateRequest_AgentProcess, error) {
listenAddress := getExporterListenAddress(node, exporter)
Expand All @@ -40,9 +42,9 @@
)

args := []string{
"--collector.textfile.directory.lr=" + pathsBase(agentVersion, tdp.Left, tdp.Right) + "/collectors/textfile-collector/low-resolution",

Check failure on line 45 in managed/services/agents/node.go

View workflow job for this annotation

GitHub Actions / Checks

string `/collectors/textfile-collector/low-resolution` has 4 occurrences, make it a constant (goconst)
"--collector.textfile.directory.mr=" + pathsBase(agentVersion, tdp.Left, tdp.Right) + "/collectors/textfile-collector/medium-resolution",
"--collector.textfile.directory.hr=" + pathsBase(agentVersion, tdp.Left, tdp.Right) + "/collectors/textfile-collector/high-resolution",

Check failure on line 47 in managed/services/agents/node.go

View workflow job for this annotation

GitHub Actions / Checks

string `/collectors/textfile-collector/high-resolution` has 4 occurrences, make it a constant (goconst)

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

Expand Down Expand Up @@ -142,7 +144,7 @@
Args: args,
}

if err := ensureAuthParams(exporter, params, agentVersion, v2_27_99); err != nil {
if err := ensureAuthParams(exporter, params, agentVersion, v2_28_00, agentVersion.IsFeatureSupported(version.NodeExporterNewTLSConfigVersion)); err != nil {
return nil, err
}

Expand Down
26 changes: 26 additions & 0 deletions managed/services/agents/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ func TestAuthWebConfig(t *testing.T) {

require.Equal(t, expected.Env, actual.Env)
require.Equal(t, expected.TextFiles, actual.TextFiles)
require.Contains(t, actual.Args, "--web.config={{ .TextFiles.webConfigPlaceholder }}")
})

t.Run("v3.0.0", func(t *testing.T) {
t.Parallel()

node := &models.Node{}
exporter := &models.Agent{
AgentID: "agent-id",
AgentType: models.NodeExporterType,
}
agentVersion := version.MustParse("3.0.0")

actual, err := nodeExporterConfig(node, exporter, agentVersion)
require.NoError(t, err, "Unable to build node exporter config")

expected := &agentv1.SetStateRequest_AgentProcess{
Env: []string(nil),
TextFiles: map[string]string{
"webConfigPlaceholder": "basic_auth_users:\n pmm: agent-id\n",
},
}

require.Equal(t, expected.Env, actual.Env)
require.Equal(t, expected.TextFiles, actual.TextFiles)
require.Contains(t, actual.Args, "--web.config.file={{ .TextFiles.webConfigPlaceholder }}")
})
}

Expand Down
2 changes: 1 addition & 1 deletion managed/services/agents/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func postgresExporterConfig(node *models.Node, service *models.Service, exporter
res.RedactWords = redactWords(exporter)
}

if err := ensureAuthParams(exporter, res, pmmAgentVersion, postgresExporterWebConfigVersion); err != nil {
if err := ensureAuthParams(exporter, res, pmmAgentVersion, postgresExporterWebConfigVersion, false); err != nil {
return nil, err
}

Expand Down
34 changes: 34 additions & 0 deletions version/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2023 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package version

// versions list.
var (
V3_0_0 = MustParse("3.0.0") //nolint:revive
)

// FeatureVersion represents a minimum version feature being supported.
type FeatureVersion *Parsed

// features list.
var (
NodeExporterNewTLSConfigVersion FeatureVersion = V3_0_0
)

// IsFeatureSupported checks if the feature is supported by the version.
func (p *Parsed) IsFeatureSupported(f FeatureVersion) bool {
return !p.Less(f)
}
Loading