Skip to content

Commit

Permalink
PMM-12895 Add metrics resolutions configuration to agents
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Mar 7, 2024
1 parent 5e2ae3f commit a76d66a
Show file tree
Hide file tree
Showing 62 changed files with 12,993 additions and 3,382 deletions.
167 changes: 167 additions & 0 deletions api-tests/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,170 @@ 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,
MetricsResolutions: &agents.GetAgentOKBodyPostgresExporterMetricsResolutions{
Hr: "0s",
Mr: "0s",
Lr: "0s",
},
},
},
}, 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",
Lr: "0s",
},
},
},
}, 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: "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",
Lr: "0s",
},
},
},
}, 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

0 comments on commit a76d66a

Please sign in to comment.