From e57bbc9b9f083685157decade6eefebe46e70d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20=C4=8Ctvrtka?= Date: Tue, 3 Dec 2024 21:50:43 +0100 Subject: [PATCH] PMM-5086 Fix Node nil handling. --- managed/services/agents/node.go | 3 --- managed/services/agents/node_test.go | 25 +++++++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/managed/services/agents/node.go b/managed/services/agents/node.go index db8a4d5951..9fe3bb994d 100644 --- a/managed/services/agents/node.go +++ b/managed/services/agents/node.go @@ -36,9 +36,6 @@ var ( func nodeExporterConfig(node *models.Node, exporter *models.Agent, agentVersion *version.Parsed) (*agentv1.SetStateRequest_AgentProcess, error) { listenAddress := getExporterListenAddress(node, exporter) - if exporter.ExporterOptions == nil { - exporter.ExporterOptions = &models.ExporterOptions{} - } tdp := models.TemplateDelimsPair(pointer.GetString(exporter.ExporterOptions.MetricsPath)) args := []string{ "--collector.textfile.directory.lr=" + pathsBase(agentVersion, tdp.Left, tdp.Right) + "/collectors/textfile-collector/low-resolution", diff --git a/managed/services/agents/node_test.go b/managed/services/agents/node_test.go index 3de1512e52..8b70d371d3 100644 --- a/managed/services/agents/node_test.go +++ b/managed/services/agents/node_test.go @@ -34,8 +34,9 @@ func TestAuthWebConfig(t *testing.T) { node := &models.Node{} exporter := &models.Agent{ - AgentID: "agent-id", - AgentType: models.NodeExporterType, + AgentID: "agent-id", + AgentType: models.NodeExporterType, + ExporterOptions: &models.ExporterOptions{}, } agentVersion := version.MustParse("2.26.1") @@ -58,8 +59,9 @@ func TestAuthWebConfig(t *testing.T) { node := &models.Node{} exporter := &models.Agent{ - AgentID: "agent-id", - AgentType: models.NodeExporterType, + AgentID: "agent-id", + AgentType: models.NodeExporterType, + ExporterOptions: &models.ExporterOptions{}, } agentVersion := version.MustParse("2.28.0") @@ -83,8 +85,9 @@ func TestAuthWebConfig(t *testing.T) { node := &models.Node{} exporter := &models.Agent{ - AgentID: "agent-id", - AgentType: models.NodeExporterType, + AgentID: "agent-id", + AgentType: models.NodeExporterType, + ExporterOptions: &models.ExporterOptions{}, } agentVersion := version.MustParse("3.0.0") @@ -114,8 +117,9 @@ func TestNodeExporterConfig(t *testing.T) { Address: "1.2.3.4", } exporter := &models.Agent{ - AgentID: "agent-id", - AgentType: models.NodeExporterType, + AgentID: "agent-id", + AgentType: models.NodeExporterType, + ExporterOptions: &models.ExporterOptions{}, } agentVersion := version.MustParse("2.15.1") @@ -293,8 +297,9 @@ func TestNodeExporterConfig(t *testing.T) { Distro: "darwin", } exporter := &models.Agent{ - AgentID: "agent-id", - AgentType: models.NodeExporterType, + AgentID: "agent-id", + AgentType: models.NodeExporterType, + ExporterOptions: &models.ExporterOptions{}, } agentVersion := version.MustParse("2.15.1")