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-12895 Add metrics resolutions configuration to agents #2882

Merged
merged 15 commits into from
May 27, 2024
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
160 changes: 160 additions & 0 deletions api-tests/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,163 @@ func TestPGStatMonitorQanAgent(t *testing.T) {
}
})
}

func TestMetricsResolutionsChange(t *testing.T) {
t.Parallel()

genericNodeID := pmmapitests.AddGenericNode(t, pmmapitests.TestString(t, "")).NodeID
require.NotEmpty(t, genericNodeID)
defer pmmapitests.RemoveNodes(t, genericNodeID)

node := pmmapitests.AddRemoteNode(t, pmmapitests.TestString(t, "Remote node for Node exporter"))
nodeID := node.Remote.NodeID
defer pmmapitests.RemoveNodes(t, nodeID)

service := addPostgreSQLService(t, services.AddPostgreSQLServiceBody{
NodeID: genericNodeID,
Address: "localhost",
Port: 5432,
ServiceName: pmmapitests.TestString(t, "PostgreSQL Service for PostgresExporter test"),
})
serviceID := service.Postgresql.ServiceID
defer pmmapitests.RemoveServices(t, serviceID)

pmmAgent := pmmapitests.AddPMMAgent(t, nodeID)
pmmAgentID := pmmAgent.PMMAgent.AgentID
defer pmmapitests.RemoveAgents(t, pmmAgentID)

PostgresExporter := addPostgresExporter(t, agents.AddPostgresExporterBody{
ServiceID: serviceID,
Username: "username",
Password: "password",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},

SkipConnectionCheck: true,
})
agentID := PostgresExporter.PostgresExporter.AgentID
defer pmmapitests.RemoveAgents(t, agentID)

getAgentRes, err := client.Default.Agents.GetAgent(&agents.GetAgentParams{
Body: agents.GetAgentBody{AgentID: agentID},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.GetAgentOK{
Payload: &agents.GetAgentOKBody{
PostgresExporter: &agents.GetAgentOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
},
},
}, getAgentRes)

// Change metrics resolutions
changePostgresExporterOK, err := client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "100s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "100s",
},
},
},
}, changePostgresExporterOK)

// Reset part of metrics resolutions
changePostgresExporterOK, err = client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "600s",
Mr: "300s",
Lr: "0s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "600s",
Mr: "300s",
},
},
},
}, changePostgresExporterOK)

// Change part of metrics resolutions
changePostgresExporterOK, err = client.Default.Agents.ChangePostgresExporter(&agents.ChangePostgresExporterParams{
Body: agents.ChangePostgresExporterBody{
AgentID: agentID,
Common: &agents.ChangePostgresExporterParamsBodyCommon{
MetricsResolutions: &agents.ChangePostgresExporterParamsBodyCommonMetricsResolutions{
Hr: "500s",
},
},
},
Context: pmmapitests.Context,
})
require.NoError(t, err)
assert.Equal(t, &agents.ChangePostgresExporterOK{
Payload: &agents.ChangePostgresExporterOKBody{
PostgresExporter: &agents.ChangePostgresExporterOKBodyPostgresExporter{
AgentID: agentID,
ServiceID: serviceID,
Username: "username",
PMMAgentID: pmmAgentID,
CustomLabels: map[string]string{
"custom_label_postgres_exporter": "postgres_exporter",
},
Status: &AgentStatusUnknown,
MetricsResolutions: &agents.ChangePostgresExporterOKBodyPostgresExporterMetricsResolutions{
Hr: "500s",
Mr: "300s",
},
},
},
}, changePostgresExporterOK)
}
188 changes: 188 additions & 0 deletions api/common/metrics_resolutions.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading