Skip to content

Commit

Permalink
PMM-12913 merge anotation & node to management/service
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Feb 18, 2024
1 parent 9755375 commit 08b2ecc
Show file tree
Hide file tree
Showing 64 changed files with 1,177 additions and 1,695 deletions.
1 change: 0 additions & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ packages:
interfaces:
agentsRegistry:
agentsStateUpdater:
apiKeyProvider:
checksService:
connectionChecker:
grafanaClient:
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
annotation "github.com/percona/pmm/api/management/v1/json/client/annotation_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

var annotationResultT = ParseTemplate(`
Expand Down Expand Up @@ -156,8 +156,8 @@ func (cmd *AnnotationCommand) RunCmd() (Result, error) {
return nil, err
}

_, err = managementClient.Default.AnnotationService.AddAnnotation(&annotation.AddAnnotationParams{
Body: annotation.AddAnnotationBody{
_, err = managementClient.Default.Service.AddAnnotation(&service.AddAnnotationParams{
Body: service.AddAnnotationBody{
Text: cmd.Text,
Tags: cmd.Tags,
NodeName: nodeName,
Expand Down
7 changes: 3 additions & 4 deletions admin/commands/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
package management

import (
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

var (
allNodeTypes = map[string]string{
"generic": node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE,
"container": node.RegisterNodeBodyNodeTypeNODETYPECONTAINERNODE,
"remote": node.RegisterNodeBodyNodeTypeNODETYPEREMOTENODE,
"generic": service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE,
"container": service.RegisterNodeBodyNodeTypeNODETYPECONTAINERNODE,
"remote": service.RegisterNodeBodyNodeTypeNODETYPEREMOTENODE,
}

allServiceTypes = map[string]string{
Expand Down
16 changes: 8 additions & 8 deletions admin/commands/management/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/management/v1/json/client"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

var registerResultT = commands.ParseTemplate(`
Expand All @@ -34,10 +34,10 @@ Warning: {{ .Warning }}
`)

type registerResult struct {
GenericNode *node.RegisterNodeOKBodyGenericNode `json:"generic_node"`
ContainerNode *node.RegisterNodeOKBodyContainerNode `json:"container_node"`
PMMAgent *node.RegisterNodeOKBodyPMMAgent `json:"pmm_agent"`
Warning string `json:"warning"`
GenericNode *service.RegisterNodeOKBodyGenericNode `json:"generic_node"`
ContainerNode *service.RegisterNodeOKBodyContainerNode `json:"container_node"`
PMMAgent *service.RegisterNodeOKBodyPMMAgent `json:"pmm_agent"`
Warning string `json:"warning"`
}

func (res *registerResult) Result() {}
Expand Down Expand Up @@ -70,8 +70,8 @@ type RegisterCommand struct {
func (cmd *RegisterCommand) RunCmd() (commands.Result, error) {
customLabels := commands.ParseCustomLabels(cmd.CustomLabels)

params := &node.RegisterNodeParams{
Body: node.RegisterNodeBody{
params := &service.RegisterNodeParams{
Body: service.RegisterNodeBody{
NodeType: pointer.ToString(allNodeTypes[cmd.NodeType]),
NodeName: cmd.NodeName,
MachineID: cmd.MachineID,
Expand All @@ -91,7 +91,7 @@ func (cmd *RegisterCommand) RunCmd() (commands.Result, error) {
},
Context: commands.Ctx,
}
resp, err := client.Default.NodeService.RegisterNode(params)
resp, err := client.Default.Service.RegisterNode(params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/management/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/stretchr/testify/assert"

node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

func TestRegisterResult(t *testing.T) {
Expand All @@ -31,7 +31,7 @@ func TestRegisterResult(t *testing.T) {
{
name: "Success",
result: registerResult{
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
PMMAgent: &service.RegisterNodeOKBodyPMMAgent{
AgentID: "/agent_id/new_id",
RunsOnNodeID: "/node_id/second_id",
},
Expand All @@ -45,7 +45,7 @@ Node ID : /node_id/second_id
{
name: "With warning",
result: registerResult{
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
PMMAgent: &service.RegisterNodeOKBodyPMMAgent{
AgentID: "/agent_id/warning",
RunsOnNodeID: "/node_id/warning_node",
},
Expand Down
4 changes: 2 additions & 2 deletions admin/commands/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
agents_info "github.com/percona/pmm/api/agentlocal/v1/json/client/agent_local_service"
"github.com/percona/pmm/api/inventory/v1/types"
"github.com/percona/pmm/api/server/v1/json/client"
"github.com/percona/pmm/api/server/v1/json/client/server"
server "github.com/percona/pmm/api/server/v1/json/client/server_service"
"github.com/percona/pmm/version"
)

Expand Down Expand Up @@ -166,7 +166,7 @@ func addClientData(ctx context.Context, zipW *zip.Writer) {
// addServerData adds logs.zip from PMM Server to zip file.
func addServerData(ctx context.Context, zipW *zip.Writer, usePprof bool) {
var buf bytes.Buffer
_, err := client.Default.Server.Logs(&server.LogsParams{Context: ctx, Pprof: &usePprof}, &buf)
_, err := client.Default.ServerService.Logs(&server.LogsParams{Context: ctx, Pprof: &usePprof}, &buf)
if err != nil {
logrus.Errorf("%s", err)
return
Expand Down
10 changes: 5 additions & 5 deletions agent/commands/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/percona/pmm/agent/config"
agentlocalClient "github.com/percona/pmm/api/agentlocal/v1/json/client"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
"github.com/percona/pmm/utils/tlsconfig"
)

Expand Down Expand Up @@ -162,8 +162,8 @@ func ParseCustomLabels(labels string) (map[string]string, error) {
// This method is not thread-safe.
func serverRegister(cfgSetup *config.Setup) (agentID, token string, _ error) { //nolint:nonamedreturns
nodeTypes := map[string]string{
"generic": node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE,
"container": node.RegisterNodeBodyNodeTypeNODETYPECONTAINERNODE,
"generic": service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE,
"container": service.RegisterNodeBodyNodeTypeNODETYPECONTAINERNODE,
}

var disableCollectors []string
Expand All @@ -179,8 +179,8 @@ func serverRegister(cfgSetup *config.Setup) (agentID, token string, _ error) { /
return "", "", err
}

res, err := managementClient.Default.NodeService.RegisterNode(&node.RegisterNodeParams{
Body: node.RegisterNodeBody{
res, err := managementClient.Default.Service.RegisterNode(&service.RegisterNodeParams{
Body: service.RegisterNodeBody{
NodeType: pointer.ToString(nodeTypes[cfgSetup.NodeType]),
NodeName: cfgSetup.NodeName,
MachineID: cfgSetup.MachineID,
Expand Down
4 changes: 2 additions & 2 deletions agent/commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/percona/pmm/agent/config"
agent_local "github.com/percona/pmm/api/agentlocal/v1/json/client/agent_local_service"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

// Setup implements `pmm-agent setup` command.
Expand Down Expand Up @@ -142,7 +142,7 @@ func register(cfg *config.Config, l *logrus.Entry) {
l.Debugf("Register error: %#v", err)
if err != nil {
msg := err.Error()
if e, _ := err.(*node.RegisterNodeDefault); e != nil { //nolint:errorlint
if e, _ := err.(*service.RegisterNodeDefault); e != nil { //nolint:errorlint
msg = e.Payload.Message + ""
switch e.Code() {
case http.StatusConflict:
Expand Down
5 changes: 2 additions & 3 deletions api-tests/backup/backups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ import (
backups "github.com/percona/pmm/api/backup/v1/json/client/backups_service"
locations "github.com/percona/pmm/api/backup/v1/json/client/locations_service"
managementClient "github.com/percona/pmm/api/management/v1/json/client"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
service "github.com/percona/pmm/api/management/v1/json/client/service"
)

func TestScheduleBackup(t *testing.T) {
t.Run("mongo", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "node-for-basic-name")
nodeID, pmmAgentID := management.RegisterGenericNode(t, node.RegisterNodeBody{
nodeID, pmmAgentID := management.RegisterGenericNode(t, service.RegisterNodeBody{
NodeName: nodeName,
NodeType: pointer.ToString(node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
NodeType: pointer.ToString(service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
})
defer pmmapitests.RemoveNodes(t, nodeID)
defer management.RemovePMMAgentWithSubAgents(t, pmmAgentID)
Expand Down
14 changes: 7 additions & 7 deletions api-tests/management/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
"github.com/percona/pmm/api/management/v1/json/client"
annotation "github.com/percona/pmm/api/management/v1/json/client/annotation_service"
annotation "github.com/percona/pmm/api/management/v1/json/client/service"
)

func TestAddAnnotation(t *testing.T) {
Expand All @@ -39,7 +39,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err := client.Default.AnnotationService.AddAnnotation(params)
_, err := client.Default.Service.AddAnnotation(params)
require.NoError(t, err)
})

Expand All @@ -51,7 +51,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err := client.Default.AnnotationService.AddAnnotation(params)
_, err := client.Default.Service.AddAnnotation(params)
pmmapitests.AssertAPIErrorf(t, err, 400, codes.InvalidArgument, "invalid AddAnnotationRequest.Text: value length must be at least 1 runes")
})

Expand All @@ -63,7 +63,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err := client.Default.AnnotationService.AddAnnotation(params)
_, err := client.Default.Service.AddAnnotation(params)
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, `Service with name "no-service" not found.`)
})

Expand All @@ -75,7 +75,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err := client.Default.AnnotationService.AddAnnotation(params)
_, err := client.Default.Service.AddAnnotation(params)
pmmapitests.AssertAPIErrorf(t, err, 404, codes.NotFound, `Node with name "no-node" not found.`)
})

Expand Down Expand Up @@ -121,7 +121,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err = client.Default.AnnotationService.AddAnnotation(paramsAdd)
_, err = client.Default.Service.AddAnnotation(paramsAdd)
require.NoError(t, err)
})

Expand All @@ -147,7 +147,7 @@ func TestAddAnnotation(t *testing.T) {
},
Context: pmmapitests.Context,
}
_, err = client.Default.AnnotationService.AddAnnotation(paramsAdd)
_, err = client.Default.Service.AddAnnotation(paramsAdd)
require.NoError(t, err)
})
}
13 changes: 6 additions & 7 deletions api-tests/management/haproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ import (
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
services "github.com/percona/pmm/api/inventory/v1/json/client/services_service"
"github.com/percona/pmm/api/management/v1/json/client"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

func TestAddHAProxy(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "genericNode-for-basic-name")
nodeID, pmmAgentID := RegisterGenericNode(t, node.RegisterNodeBody{
nodeID, pmmAgentID := RegisterGenericNode(t, service.RegisterNodeBody{
NodeName: nodeName,
NodeType: pointer.ToString(node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
NodeType: pointer.ToString(service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
})
defer pmmapitests.RemoveNodes(t, nodeID)
defer RemovePMMAgentWithSubAgents(t, pmmAgentID)
Expand Down Expand Up @@ -104,9 +103,9 @@ func TestAddHAProxy(t *testing.T) {

t.Run("With labels", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "genericNode-for-basic-name")
nodeID, pmmAgentID := RegisterGenericNode(t, node.RegisterNodeBody{
nodeID, pmmAgentID := RegisterGenericNode(t, service.RegisterNodeBody{
NodeName: nodeName,
NodeType: pointer.ToString(node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
NodeType: pointer.ToString(service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
})
defer pmmapitests.RemoveNodes(t, nodeID)
defer RemovePMMAgentWithSubAgents(t, pmmAgentID)
Expand Down Expand Up @@ -252,9 +251,9 @@ func TestAddHAProxy(t *testing.T) {

t.Run("With the same name", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "genericNode-for-basic-name")
nodeID, pmmAgentID := RegisterGenericNode(t, node.RegisterNodeBody{
nodeID, pmmAgentID := RegisterGenericNode(t, service.RegisterNodeBody{
NodeName: nodeName,
NodeType: pointer.ToString(node.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
NodeType: pointer.ToString(service.RegisterNodeBodyNodeTypeNODETYPEGENERICNODE),
})
defer pmmapitests.RemoveNodes(t, nodeID)
defer RemovePMMAgentWithSubAgents(t, pmmAgentID)
Expand Down
14 changes: 7 additions & 7 deletions api-tests/management/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ import (
agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service"
nodes "github.com/percona/pmm/api/inventory/v1/json/client/nodes_service"
"github.com/percona/pmm/api/management/v1/json/client"
node "github.com/percona/pmm/api/management/v1/json/client/node_service"
"github.com/percona/pmm/api/management/v1/json/client/service"
)

// AgentStatusUnknown means agent is not connected and we don't know anything about its status.
var AgentStatusUnknown = inventoryv1.AgentStatus_name[int32(inventoryv1.AgentStatus_AGENT_STATUS_UNKNOWN)]

func RegisterGenericNode(t pmmapitests.TestingT, body node.RegisterNodeBody) (string, string) {
func RegisterGenericNode(t pmmapitests.TestingT, body service.RegisterNodeBody) (string, string) {
t.Helper()
params := node.RegisterNodeParams{
params := service.RegisterNodeParams{
Context: pmmapitests.Context,
Body: body,
}
registerOK, err := client.Default.NodeService.RegisterNode(&params)
registerOK, err := client.Default.Service.RegisterNode(&params)
require.NoError(t, err)
require.NotNil(t, registerOK)
require.NotNil(t, registerOK.Payload.PMMAgent)
Expand All @@ -51,14 +51,14 @@ func RegisterGenericNode(t pmmapitests.TestingT, body node.RegisterNodeBody) (st
return registerOK.Payload.GenericNode.NodeID, registerOK.Payload.PMMAgent.AgentID
}

func registerContainerNode(t pmmapitests.TestingT, body node.RegisterNodeBody) (string, string) {
func registerContainerNode(t pmmapitests.TestingT, body service.RegisterNodeBody) (string, string) {
t.Helper()

params := node.RegisterNodeParams{
params := service.RegisterNodeParams{
Context: pmmapitests.Context,
Body: body,
}
registerOK, err := client.Default.NodeService.RegisterNode(&params)
registerOK, err := client.Default.Service.RegisterNode(&params)
require.NoError(t, err)
require.NotNil(t, registerOK)
require.NotNil(t, registerOK.Payload.PMMAgent)
Expand Down
Loading

0 comments on commit 08b2ecc

Please sign in to comment.