Skip to content

Commit

Permalink
PMM-12913 migrate /v1/management/Service
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 28, 2024
1 parent 8c5b6ff commit 6b6a566
Show file tree
Hide file tree
Showing 95 changed files with 19,092 additions and 20,058 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,18 @@ jobs:

- name: Run API linter
env:
COMMAND: 'bin/buf lint -v api'
REDIRECT: "| bin/reviewdog -f=buf -reporter=github-pr-review -fail-on-error=true"
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.ROBOT_TOKEN || secrets.GITHUB_TOKEN }}
run: |
if out=$( ${{ env.COMMAND }} ); exit_code=$?; [ $exit_code -ne 0 ]; then
if out=$(bin/buf lint -v api); code="$?"; test "$code" -ne 0; then
echo "API linter exited with code: $code"
echo "$out"
## buf uses exit code 100 for linter warnings
if [ $exit_code != 100 ] || ${{ github.event.pull_request == null }}; then
echo "$out"
exit $exit_code
if [ "$code" -ne 100 ] || ${{ github.event.pull_request == null }}; then
exit $code
else
echo "$out" ${{ env.REDIRECT }}
echo
# suppress passing to reviewdog because of https://github.com/reviewdog/reviewdog/issues/1696
# echo "$out" | bin/reviewdog -f=buf -reporter=github-pr-review -fail-on-error=true
fi
else
echo "$out"
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ issues:
- forcetypeassert # for tests' brevity sake
- funlen # tests may be long
- gocognit # triggered by subtests
- goconst # not critical for tests
- gomnd # tests are full of magic numbers
- ireturn # we have exceptions, so need to silence them in tests
- lll # tests often require long lines
Expand Down
42 changes: 22 additions & 20 deletions admin/commands/management/add_external.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Group : {{ .Service.Group }}
`)

type addExternalResult struct {
Service *mservice.AddExternalOKBodyService `json:"service"`
Service *mservice.AddServiceOKBodyExternalService `json:"service"`
}

func (res *addExternalResult) Result() {}
Expand Down Expand Up @@ -120,32 +120,34 @@ func (cmd *AddExternalCommand) RunCmd() (commands.Result, error) {
}
}

params := &mservice.AddExternalParams{
Body: mservice.AddExternalBody{
RunsOnNodeID: cmd.RunsOnNodeID,
ServiceName: cmd.ServiceName,
Username: cmd.Username,
Password: cmd.Password,
Scheme: cmd.Scheme,
MetricsPath: cmd.MetricsPath,
ListenPort: int64(cmd.ListenPort),
NodeID: cmd.NodeID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
CustomLabels: customLabels,
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
Group: cmd.Group,
SkipConnectionCheck: cmd.SkipConnectionCheck,
params := &mservice.AddServiceParams{
Body: mservice.AddServiceBody{
External: &mservice.AddServiceParamsBodyExternal{
RunsOnNodeID: cmd.RunsOnNodeID,
ServiceName: cmd.ServiceName,
Username: cmd.Username,
Password: cmd.Password,
Scheme: cmd.Scheme,
MetricsPath: cmd.MetricsPath,
ListenPort: int64(cmd.ListenPort),
NodeID: cmd.NodeID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
CustomLabels: customLabels,
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
Group: cmd.Group,
SkipConnectionCheck: cmd.SkipConnectionCheck,
},
},
Context: commands.Ctx,
}
resp, err := client.Default.ManagementService.AddExternal(params)
resp, err := client.Default.ManagementService.AddService(params)
if err != nil {
return nil, err
}

return &addExternalResult{
Service: resp.Payload.Service,
Service: resp.Payload.External.Service,
}, nil
}
62 changes: 32 additions & 30 deletions admin/commands/management/add_external_serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Group : {{ .Service.Group }}
`)

type addExternalServerlessResult struct {
Service *mservice.AddExternalOKBodyService `json:"service"`
Service *mservice.AddServiceOKBodyExternalService `json:"service"`
}

func (res *addExternalServerlessResult) Result() {}
Expand Down Expand Up @@ -125,44 +125,46 @@ func (cmd *AddExternalServerlessCommand) RunCmd() (commands.Result, error) {
}
}

params := &mservice.AddExternalParams{
Body: mservice.AddExternalBody{
AddNode: &mservice.AddExternalParamsBodyAddNode{
NodeType: pointer.ToString(mservice.AddExternalParamsBodyAddNodeNodeTypeNODETYPEREMOTENODE),
NodeName: serviceName,
MachineID: cmd.MachineID,
Distro: cmd.Distro,
ContainerID: cmd.ContainerID,
ContainerName: cmd.ContainerName,
NodeModel: cmd.NodeModel,
Region: cmd.Region,
Az: cmd.Az,
CustomLabels: customLabels,
params := &mservice.AddServiceParams{
Body: mservice.AddServiceBody{
External: &mservice.AddServiceParamsBodyExternal{
AddNode: &mservice.AddServiceParamsBodyExternalAddNode{
NodeType: pointer.ToString(mservice.AddServiceParamsBodyExternalAddNodeNodeTypeNODETYPEREMOTENODE),
NodeName: serviceName,
MachineID: cmd.MachineID,
Distro: cmd.Distro,
ContainerID: cmd.ContainerID,
ContainerName: cmd.ContainerName,
NodeModel: cmd.NodeModel,
Region: cmd.Region,
Az: cmd.Az,
CustomLabels: customLabels,
},
Address: address,
ServiceName: serviceName,
Username: cmd.Username,
Password: cmd.Password,
Scheme: scheme,
MetricsPath: metricsPath,
ListenPort: int64(port),
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
CustomLabels: customLabels,
MetricsMode: pointer.ToString(mservice.AddServiceParamsBodyExternalMetricsModeMETRICSMODEPULL),
Group: cmd.Group,
SkipConnectionCheck: cmd.SkipConnectionCheck,
},
Address: address,
ServiceName: serviceName,
Username: cmd.Username,
Password: cmd.Password,
Scheme: scheme,
MetricsPath: metricsPath,
ListenPort: int64(port),
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
CustomLabels: customLabels,
MetricsMode: pointer.ToString(mservice.AddExternalBodyMetricsModeMETRICSMODEPULL),
Group: cmd.Group,
SkipConnectionCheck: cmd.SkipConnectionCheck,
},
Context: commands.Ctx,
}
resp, err := client.Default.ManagementService.AddExternal(params)
resp, err := client.Default.ManagementService.AddService(params)
if err != nil {
return nil, err
}

return &addExternalServerlessResult{
Service: resp.Payload.Service,
Service: resp.Payload.External.Service,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion admin/commands/management/add_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestAddExternal(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
res := &addExternalResult{
Service: &mservice.AddExternalOKBodyService{
Service: &mservice.AddServiceOKBodyExternalService{
ServiceID: "/service_id/1",
ServiceName: "myhost-redis",
Group: "redis",
Expand Down
80 changes: 41 additions & 39 deletions admin/commands/management/add_mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Service name: {{ .Service.ServiceName }}
`)

type addMongoDBResult struct {
Service *mservice.AddMongoDBOKBodyService `json:"service"`
Service *mservice.AddServiceOKBodyMongodbService `json:"service"`
}

func (res *addMongoDBResult) Result() {}
Expand Down Expand Up @@ -159,51 +159,53 @@ func (cmd *AddMongoDBCommand) RunCmd() (commands.Result, error) {
}
}

params := &mservice.AddMongoDBParams{
Body: mservice.AddMongoDBBody{
NodeID: cmd.NodeID,
ServiceName: serviceName,
Address: host,
Socket: socket,
Port: int64(port),
ExposeExporter: cmd.ExposeExporter,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,

QANMongodbProfiler: cmd.QuerySource == MongodbQuerySourceProfiler,

CustomLabels: customLabels,
SkipConnectionCheck: cmd.SkipConnectionCheck,
MaxQueryLength: cmd.MaxQueryLength,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
AuthenticationDatabase: cmd.AuthenticationDatabase,

MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),

EnableAllCollectors: cmd.EnableAllCollectors,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
CollectionsLimit: cmd.CollectionsLimit,
LogLevel: &cmd.AddLogLevel,
params := &mservice.AddServiceParams{
Body: mservice.AddServiceBody{
Mongodb: &mservice.AddServiceParamsBodyMongodb{
NodeID: cmd.NodeID,
ServiceName: serviceName,
Address: host,
Socket: socket,
Port: int64(port),
ExposeExporter: cmd.ExposeExporter,
PMMAgentID: cmd.PMMAgentID,
Environment: cmd.Environment,
Cluster: cmd.Cluster,
ReplicationSet: cmd.ReplicationSet,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,

QANMongodbProfiler: cmd.QuerySource == MongodbQuerySourceProfiler,

CustomLabels: customLabels,
SkipConnectionCheck: cmd.SkipConnectionCheck,
MaxQueryLength: cmd.MaxQueryLength,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
AuthenticationDatabase: cmd.AuthenticationDatabase,

MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),

EnableAllCollectors: cmd.EnableAllCollectors,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
CollectionsLimit: cmd.CollectionsLimit,
LogLevel: &cmd.AddLogLevel,
},
},
Context: commands.Ctx,
}
resp, err := client.Default.ManagementService.AddMongoDB(params)
resp, err := client.Default.ManagementService.AddService(params)
if err != nil {
return nil, err
}

return &addMongoDBResult{
Service: resp.Payload.Service,
Service: resp.Payload.Mongodb.Service,
}, nil
}
2 changes: 1 addition & 1 deletion admin/commands/management/add_mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestAddMongoDB(t *testing.T) {
t.Run("TablestatEnabled", func(t *testing.T) {
res := &addMongoDBResult{
Service: &mservice.AddMongoDBOKBodyService{
Service: &mservice.AddServiceOKBodyMongodbService{
ServiceID: "/service_id/1",
ServiceName: "mysql-1",
},
Expand Down
Loading

0 comments on commit 6b6a566

Please sign in to comment.