Skip to content

Commit

Permalink
PMM-12895 Add metrics resolutions configuration to agents (#2882)
Browse files Browse the repository at this point in the history
* PMM-12895 Add metrics resolutions configuration to agents

* PMM-12895 Fix linter warnings

* Update api-tests/inventory/agents_test.go

* PMM-12895 Add tests

* PMM-12895 Fix linter

* PMM-12895 Fix linter

* PMM-12895 Fix API tests

* PMM-12895 Revert breaking changes

* Revert "PMM-12895 Fix API tests"

This reverts commit 54dda0b.

* PMM-12895 Don't retrun empty metrics resoutions object
  • Loading branch information
artemgavrilov authored May 27, 2024
1 parent 09f3823 commit 4bf51d1
Show file tree
Hide file tree
Showing 54 changed files with 12,320 additions and 2,485 deletions.
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

0 comments on commit 4bf51d1

Please sign in to comment.