Skip to content

Commit

Permalink
PMM-12913 migrate /v1/inventory/Agents/Remove
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 22, 2024
1 parent 46d51e0 commit 731f650
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 256 deletions.
7 changes: 3 additions & 4 deletions admin/commands/inventory/remove_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package inventory

import (
"github.com/AlekSi/pointer"
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventory/v1/json/client"
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
Expand All @@ -41,10 +42,8 @@ type RemoveAgentCommand struct {
// RunCmd executes the RemoveAgentCommand and returns the result.
func (cmd *RemoveAgentCommand) RunCmd() (commands.Result, error) {
params := &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: cmd.AgentID,
Force: cmd.Force,
},
AgentID: cmd.AgentID,
Force: pointer.ToBool(cmd.Force),
Context: commands.Ctx,
}
_, err := client.Default.AgentsService.RemoveAgent(params)
Expand Down
4 changes: 1 addition & 3 deletions api-tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ func RemoveAgents(t TestingT, agentIDs ...string) {

for _, agentID := range agentIDs {
params := &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: agentID,
},
AgentID: agentID,
Context: context.Background(),
}
res, err := client.Default.AgentsService.RemoveAgent(params)
Expand Down
27 changes: 8 additions & 19 deletions api-tests/inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,7 @@ func TestPMMAgent(t *testing.T) {
}, getAgentRes)

params := &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: agentID,
},
AgentID: agentID,
Context: context.Background(),
}
removeAgentOK, err := client.Default.AgentsService.RemoveAgent(params)
Expand Down Expand Up @@ -353,14 +351,12 @@ func TestPMMAgent(t *testing.T) {
mySqldExporterID := mySqldExporter.MysqldExporter.AgentID

params := &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: pmmAgentID,
},
AgentID: pmmAgentID,
Context: context.Background(),
}
res, err := client.Default.AgentsService.RemoveAgent(params)
assert.Nil(t, res)
pmmapitests.AssertAPIErrorf(t, err, 400, codes.FailedPrecondition, `pmm-agent with ID %q has agents.`, pmmAgentID)
pmmapitests.AssertAPIErrorf(t, err, 400, codes.FailedPrecondition, `pmm-agent with ID %s has agents.`, pmmAgentID)

// Check that agents aren't removed.
getAgentRes, err := client.Default.AgentsService.GetAgent(
Expand Down Expand Up @@ -413,10 +409,8 @@ func TestPMMAgent(t *testing.T) {

// Remove with force flag.
params = &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: pmmAgentID,
Force: true,
},
AgentID: pmmAgentID,
Force: pointer.ToBool(true),
Context: context.Background(),
}
res, err = client.Default.AgentsService.RemoveAgent(params)
Expand Down Expand Up @@ -445,9 +439,7 @@ func TestPMMAgent(t *testing.T) {

agentID := "not-exist-pmm-agent"
params := &agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: agentID,
},
AgentID: agentID,
Context: context.Background(),
}
res, err := client.Default.AgentsService.RemoveAgent(params)
Expand All @@ -459,7 +451,6 @@ func TestPMMAgent(t *testing.T) {
t.Parallel()

removeResp, err := client.Default.AgentsService.RemoveAgent(&agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{},
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid RemoveAgentRequest.AgentId: value length must be at least 1 runes")
Expand All @@ -471,10 +462,8 @@ func TestPMMAgent(t *testing.T) {

removeResp, err := client.Default.AgentsService.RemoveAgent(
&agents.RemoveAgentParams{
Body: agents.RemoveAgentBody{
AgentID: "pmm-server",
Force: true,
},
AgentID: "pmm-server",
Force: pointer.ToBool(true),
Context: context.Background(),
})
pmmapitests.AssertAPIErrorf(t, err, 403, codes.PermissionDenied, "pmm-agent on PMM Server can't be removed.")
Expand Down
2 changes: 1 addition & 1 deletion api/MIGRATION_TO_V3.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ POST /v1/inventory/Agents/Add POST /v1/inventory/agents
POST /v1/inventory/Agents/Change PUT /v1/inventory/agents/{agent_id} ✅
POST /v1/inventory/Agents/Get GET /v1/inventory/agents/{agent_id} ✅
POST /v1/inventory/Agents/List GET /v1/inventory/agents ✅ Query param filters: service_id, node_id, pmm_agent_id and agent_type
POST /v1/inventory/Agents/Remove DELETE /v1/inventory/agents/{id}
POST /v1/inventory/Agents/Remove DELETE /v1/inventory/agents/{agent_id} ✅
POST /v1/inventory/Agents/GetLogs GET /v1/inventory/agents/{id}/logs

**NodesService** **NodesService**
Expand Down
34 changes: 17 additions & 17 deletions api/inventory/v1/agents.pb.go

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

56 changes: 49 additions & 7 deletions api/inventory/v1/agents.pb.gw.go

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

5 changes: 1 addition & 4 deletions api/inventory/v1/agents.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1365,10 +1365,7 @@ service AgentsService {

// RemoveAgent removes an Agent.
rpc RemoveAgent(RemoveAgentRequest) returns (RemoveAgentResponse) {
option (google.api.http) = {
post: "/v1/inventory/Agents/Remove"
body: "*"
};
option (google.api.http) = {delete: "/v1/inventory/agents/{agent_id}"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
summary: "Remove an Agent from Inventory"
description: "Removes an Agent from Inventory."
Expand Down

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

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

Loading

0 comments on commit 731f650

Please sign in to comment.