Skip to content

Commit ecdde88

Browse files
committed
PMM-12913 migrate /v1/management/Service
1 parent 8c5b6ff commit ecdde88

File tree

95 files changed

+19091
-20058
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+19091
-20058
lines changed

.github/workflows/main.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ jobs:
8181

8282
- name: Run API linter
8383
env:
84-
COMMAND: 'bin/buf lint -v api'
85-
REDIRECT: "| bin/reviewdog -f=buf -reporter=github-pr-review -fail-on-error=true"
8684
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.ROBOT_TOKEN || secrets.GITHUB_TOKEN }}
8785
run: |
88-
if out=$( ${{ env.COMMAND }} ); exit_code=$?; [ $exit_code -ne 0 ]; then
86+
if out=$(bin/buf lint -v api); code="$?"; test "$code" -ne 0; then
87+
echo "API linter exited with code: $code"
88+
echo "$out"
8989
## buf uses exit code 100 for linter warnings
90-
if [ $exit_code != 100 ] || ${{ github.event.pull_request == null }}; then
91-
echo "$out"
92-
exit $exit_code
90+
if [ "$code" -ne 100 ] || ${{ github.event.pull_request == null }}; then
91+
exit $code
9392
else
94-
echo "$out" ${{ env.REDIRECT }}
93+
# suppress passing to reviewdog because of https://github.com/reviewdog/reviewdog/issues/1696
94+
# echo "$out" | bin/reviewdog -f=buf -reporter=github-pr-review -fail-on-error=true
9595
fi
9696
else
9797
echo "$out"

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ issues:
149149
- forcetypeassert # for tests' brevity sake
150150
- funlen # tests may be long
151151
- gocognit # triggered by subtests
152+
- goconst # not critical for tests
152153
- gomnd # tests are full of magic numbers
153154
- ireturn # we have exceptions, so need to silence them in tests
154155
- lll # tests often require long lines

admin/commands/management/add_external.go

+22-20
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Group : {{ .Service.Group }}
4242
`)
4343

4444
type addExternalResult struct {
45-
Service *mservice.AddExternalOKBodyService `json:"service"`
45+
Service *mservice.AddServiceOKBodyExternalService `json:"service"`
4646
}
4747

4848
func (res *addExternalResult) Result() {}
@@ -120,32 +120,34 @@ func (cmd *AddExternalCommand) RunCmd() (commands.Result, error) {
120120
}
121121
}
122122

123-
params := &mservice.AddExternalParams{
124-
Body: mservice.AddExternalBody{
125-
RunsOnNodeID: cmd.RunsOnNodeID,
126-
ServiceName: cmd.ServiceName,
127-
Username: cmd.Username,
128-
Password: cmd.Password,
129-
Scheme: cmd.Scheme,
130-
MetricsPath: cmd.MetricsPath,
131-
ListenPort: int64(cmd.ListenPort),
132-
NodeID: cmd.NodeID,
133-
Environment: cmd.Environment,
134-
Cluster: cmd.Cluster,
135-
ReplicationSet: cmd.ReplicationSet,
136-
CustomLabels: customLabels,
137-
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
138-
Group: cmd.Group,
139-
SkipConnectionCheck: cmd.SkipConnectionCheck,
123+
params := &mservice.AddServiceParams{
124+
Body: mservice.AddServiceBody{
125+
External: &mservice.AddServiceParamsBodyExternal{
126+
RunsOnNodeID: cmd.RunsOnNodeID,
127+
ServiceName: cmd.ServiceName,
128+
Username: cmd.Username,
129+
Password: cmd.Password,
130+
Scheme: cmd.Scheme,
131+
MetricsPath: cmd.MetricsPath,
132+
ListenPort: int64(cmd.ListenPort),
133+
NodeID: cmd.NodeID,
134+
Environment: cmd.Environment,
135+
Cluster: cmd.Cluster,
136+
ReplicationSet: cmd.ReplicationSet,
137+
CustomLabels: customLabels,
138+
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
139+
Group: cmd.Group,
140+
SkipConnectionCheck: cmd.SkipConnectionCheck,
141+
},
140142
},
141143
Context: commands.Ctx,
142144
}
143-
resp, err := client.Default.ManagementService.AddExternal(params)
145+
resp, err := client.Default.ManagementService.AddService(params)
144146
if err != nil {
145147
return nil, err
146148
}
147149

148150
return &addExternalResult{
149-
Service: resp.Payload.Service,
151+
Service: resp.Payload.External.Service,
150152
}, nil
151153
}

admin/commands/management/add_external_serverless.go

+32-30
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Group : {{ .Service.Group }}
3737
`)
3838

3939
type addExternalServerlessResult struct {
40-
Service *mservice.AddExternalOKBodyService `json:"service"`
40+
Service *mservice.AddServiceOKBodyExternalService `json:"service"`
4141
}
4242

4343
func (res *addExternalServerlessResult) Result() {}
@@ -125,44 +125,46 @@ func (cmd *AddExternalServerlessCommand) RunCmd() (commands.Result, error) {
125125
}
126126
}
127127

128-
params := &mservice.AddExternalParams{
129-
Body: mservice.AddExternalBody{
130-
AddNode: &mservice.AddExternalParamsBodyAddNode{
131-
NodeType: pointer.ToString(mservice.AddExternalParamsBodyAddNodeNodeTypeNODETYPEREMOTENODE),
132-
NodeName: serviceName,
133-
MachineID: cmd.MachineID,
134-
Distro: cmd.Distro,
135-
ContainerID: cmd.ContainerID,
136-
ContainerName: cmd.ContainerName,
137-
NodeModel: cmd.NodeModel,
138-
Region: cmd.Region,
139-
Az: cmd.Az,
140-
CustomLabels: customLabels,
128+
params := &mservice.AddServiceParams{
129+
Body: mservice.AddServiceBody{
130+
External: &mservice.AddServiceParamsBodyExternal{
131+
AddNode: &mservice.AddServiceParamsBodyExternalAddNode{
132+
NodeType: pointer.ToString(mservice.AddServiceParamsBodyExternalAddNodeNodeTypeNODETYPEREMOTENODE),
133+
NodeName: serviceName,
134+
MachineID: cmd.MachineID,
135+
Distro: cmd.Distro,
136+
ContainerID: cmd.ContainerID,
137+
ContainerName: cmd.ContainerName,
138+
NodeModel: cmd.NodeModel,
139+
Region: cmd.Region,
140+
Az: cmd.Az,
141+
CustomLabels: customLabels,
142+
},
143+
Address: address,
144+
ServiceName: serviceName,
145+
Username: cmd.Username,
146+
Password: cmd.Password,
147+
Scheme: scheme,
148+
MetricsPath: metricsPath,
149+
ListenPort: int64(port),
150+
Environment: cmd.Environment,
151+
Cluster: cmd.Cluster,
152+
ReplicationSet: cmd.ReplicationSet,
153+
CustomLabels: customLabels,
154+
MetricsMode: pointer.ToString(mservice.AddServiceParamsBodyExternalMetricsModeMETRICSMODEPULL),
155+
Group: cmd.Group,
156+
SkipConnectionCheck: cmd.SkipConnectionCheck,
141157
},
142-
Address: address,
143-
ServiceName: serviceName,
144-
Username: cmd.Username,
145-
Password: cmd.Password,
146-
Scheme: scheme,
147-
MetricsPath: metricsPath,
148-
ListenPort: int64(port),
149-
Environment: cmd.Environment,
150-
Cluster: cmd.Cluster,
151-
ReplicationSet: cmd.ReplicationSet,
152-
CustomLabels: customLabels,
153-
MetricsMode: pointer.ToString(mservice.AddExternalBodyMetricsModeMETRICSMODEPULL),
154-
Group: cmd.Group,
155-
SkipConnectionCheck: cmd.SkipConnectionCheck,
156158
},
157159
Context: commands.Ctx,
158160
}
159-
resp, err := client.Default.ManagementService.AddExternal(params)
161+
resp, err := client.Default.ManagementService.AddService(params)
160162
if err != nil {
161163
return nil, err
162164
}
163165

164166
return &addExternalServerlessResult{
165-
Service: resp.Payload.Service,
167+
Service: resp.Payload.External.Service,
166168
}, nil
167169
}
168170

admin/commands/management/add_external_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
func TestAddExternal(t *testing.T) {
2727
t.Run("Basic", func(t *testing.T) {
2828
res := &addExternalResult{
29-
Service: &mservice.AddExternalOKBodyService{
29+
Service: &mservice.AddServiceOKBodyExternalService{
3030
ServiceID: "/service_id/1",
3131
ServiceName: "myhost-redis",
3232
Group: "redis",

admin/commands/management/add_mongodb.go

+41-39
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Service name: {{ .Service.ServiceName }}
4040
`)
4141

4242
type addMongoDBResult struct {
43-
Service *mservice.AddMongoDBOKBodyService `json:"service"`
43+
Service *mservice.AddServiceOKBodyMongodbService `json:"service"`
4444
}
4545

4646
func (res *addMongoDBResult) Result() {}
@@ -159,51 +159,53 @@ func (cmd *AddMongoDBCommand) RunCmd() (commands.Result, error) {
159159
}
160160
}
161161

162-
params := &mservice.AddMongoDBParams{
163-
Body: mservice.AddMongoDBBody{
164-
NodeID: cmd.NodeID,
165-
ServiceName: serviceName,
166-
Address: host,
167-
Socket: socket,
168-
Port: int64(port),
169-
ExposeExporter: cmd.ExposeExporter,
170-
PMMAgentID: cmd.PMMAgentID,
171-
Environment: cmd.Environment,
172-
Cluster: cmd.Cluster,
173-
ReplicationSet: cmd.ReplicationSet,
174-
Username: cmd.Username,
175-
Password: cmd.Password,
176-
AgentPassword: cmd.AgentPassword,
177-
178-
QANMongodbProfiler: cmd.QuerySource == MongodbQuerySourceProfiler,
179-
180-
CustomLabels: customLabels,
181-
SkipConnectionCheck: cmd.SkipConnectionCheck,
182-
MaxQueryLength: cmd.MaxQueryLength,
183-
TLS: cmd.TLS,
184-
TLSSkipVerify: cmd.TLSSkipVerify,
185-
TLSCertificateKey: tlsCertificateKey,
186-
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
187-
TLSCa: tlsCa,
188-
AuthenticationMechanism: cmd.AuthenticationMechanism,
189-
AuthenticationDatabase: cmd.AuthenticationDatabase,
190-
191-
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
192-
193-
EnableAllCollectors: cmd.EnableAllCollectors,
194-
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
195-
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
196-
CollectionsLimit: cmd.CollectionsLimit,
197-
LogLevel: &cmd.AddLogLevel,
162+
params := &mservice.AddServiceParams{
163+
Body: mservice.AddServiceBody{
164+
Mongodb: &mservice.AddServiceParamsBodyMongodb{
165+
NodeID: cmd.NodeID,
166+
ServiceName: serviceName,
167+
Address: host,
168+
Socket: socket,
169+
Port: int64(port),
170+
ExposeExporter: cmd.ExposeExporter,
171+
PMMAgentID: cmd.PMMAgentID,
172+
Environment: cmd.Environment,
173+
Cluster: cmd.Cluster,
174+
ReplicationSet: cmd.ReplicationSet,
175+
Username: cmd.Username,
176+
Password: cmd.Password,
177+
AgentPassword: cmd.AgentPassword,
178+
179+
QANMongodbProfiler: cmd.QuerySource == MongodbQuerySourceProfiler,
180+
181+
CustomLabels: customLabels,
182+
SkipConnectionCheck: cmd.SkipConnectionCheck,
183+
MaxQueryLength: cmd.MaxQueryLength,
184+
TLS: cmd.TLS,
185+
TLSSkipVerify: cmd.TLSSkipVerify,
186+
TLSCertificateKey: tlsCertificateKey,
187+
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
188+
TLSCa: tlsCa,
189+
AuthenticationMechanism: cmd.AuthenticationMechanism,
190+
AuthenticationDatabase: cmd.AuthenticationDatabase,
191+
192+
MetricsMode: pointer.ToString(strings.ToUpper(cmd.MetricsMode)),
193+
194+
EnableAllCollectors: cmd.EnableAllCollectors,
195+
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
196+
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
197+
CollectionsLimit: cmd.CollectionsLimit,
198+
LogLevel: &cmd.AddLogLevel,
199+
},
198200
},
199201
Context: commands.Ctx,
200202
}
201-
resp, err := client.Default.ManagementService.AddMongoDB(params)
203+
resp, err := client.Default.ManagementService.AddService(params)
202204
if err != nil {
203205
return nil, err
204206
}
205207

206208
return &addMongoDBResult{
207-
Service: resp.Payload.Service,
209+
Service: resp.Payload.Mongodb.Service,
208210
}, nil
209211
}

admin/commands/management/add_mongodb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
func TestAddMongoDB(t *testing.T) {
2727
t.Run("TablestatEnabled", func(t *testing.T) {
2828
res := &addMongoDBResult{
29-
Service: &mservice.AddMongoDBOKBodyService{
29+
Service: &mservice.AddServiceOKBodyMongodbService{
3030
ServiceID: "/service_id/1",
3131
ServiceName: "mysql-1",
3232
},

0 commit comments

Comments
 (0)