Skip to content

Commit 9fa78dd

Browse files
BupycHukAlex Tymchuk
andauthored
PMM-11714 Don't return an error if API key can't be created. (#2469)
* PMM-11714 Don't return error if API key can't be created. * PMM-11714 Revert removed files. * PMM-11714 Fix tests. * PMM-11714 Fix tests. * PMM-11714 Fix format. * PMM-11714 Fix tests. * Update managed/services/grafana/client.go Co-authored-by: Alex Tymchuk <[email protected]> * Update docker-compose.yml * PMM-11714 add license header * PMM-11714 add extra info to logs. --------- Co-authored-by: Alex Tymchuk <[email protected]>
1 parent 80e4c8b commit 9fa78dd

File tree

15 files changed

+199
-38
lines changed

15 files changed

+199
-38
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ compose.yml
3838

3939
cli-tests/node_modules/
4040
cli-tests/playwright-report/
41+
42+
api-tests/pmm-api-tests-output.txt
43+
api-tests/pmm-api-tests-junit-report.xml

admin/commands/management/register.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ var registerResultT = commands.ParseTemplate(`
2828
pmm-agent registered.
2929
pmm-agent ID: {{ .PMMAgent.AgentID }}
3030
Node ID : {{ .PMMAgent.RunsOnNodeID }}
31+
{{ if .Warning }}
32+
Warning: {{ .Warning }}
33+
{{- end -}}
3134
`)
3235

3336
type registerResult struct {
3437
GenericNode *node.RegisterNodeOKBodyGenericNode `json:"generic_node"`
3538
ContainerNode *node.RegisterNodeOKBodyContainerNode `json:"container_node"`
3639
PMMAgent *node.RegisterNodeOKBodyPMMAgent `json:"pmm_agent"`
40+
Warning string `json:"warning"`
3741
}
3842

3943
func (res *registerResult) Result() {}
@@ -96,5 +100,6 @@ func (cmd *RegisterCommand) RunCmd() (commands.Result, error) {
96100
GenericNode: resp.Payload.GenericNode,
97101
ContainerNode: resp.Payload.ContainerNode,
98102
PMMAgent: resp.Payload.PMMAgent,
103+
Warning: resp.Payload.Warning,
99104
}, nil
100105
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2023 Percona LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package management
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
22+
"github.com/percona/pmm/api/managementpb/json/client/node"
23+
)
24+
25+
func TestRegisterResult(t *testing.T) {
26+
tests := []struct {
27+
name string
28+
result registerResult
29+
want string
30+
}{
31+
{
32+
name: "Success",
33+
result: registerResult{
34+
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
35+
AgentID: "/agent_id/new_id",
36+
RunsOnNodeID: "/node_id/second_id",
37+
},
38+
Warning: "",
39+
},
40+
want: `pmm-agent registered.
41+
pmm-agent ID: /agent_id/new_id
42+
Node ID : /node_id/second_id
43+
`,
44+
},
45+
{
46+
name: "With warning",
47+
result: registerResult{
48+
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
49+
AgentID: "/agent_id/warning",
50+
RunsOnNodeID: "/node_id/warning_node",
51+
},
52+
Warning: "Couldn't create Admin API Key",
53+
},
54+
want: `pmm-agent registered.
55+
pmm-agent ID: /agent_id/warning
56+
Node ID : /node_id/warning_node
57+
58+
Warning: Couldn't create Admin API Key
59+
`,
60+
},
61+
}
62+
for _, tt := range tests {
63+
t.Run(tt.name, func(t *testing.T) {
64+
assert.Equalf(t, tt.want, tt.result.String(), "String()")
65+
})
66+
}
67+
}

api/managementpb/json/client/node/register_node_responses.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/managementpb/json/managementpb.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,11 @@
38993899
"description": "Token represents token for vmagent auth config.",
39003900
"type": "string",
39013901
"x-order": 3
3902+
},
3903+
"warning": {
3904+
"description": "Warning message.",
3905+
"type": "string",
3906+
"x-order": 4
39023907
}
39033908
}
39043909
}

api/managementpb/node.pb.go

Lines changed: 34 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/managementpb/node.pb.validate.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/managementpb/node.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ message RegisterNodeResponse {
5252
inventory.PMMAgent pmm_agent = 3;
5353
// Token represents token for vmagent auth config.
5454
string token = 4;
55+
// Warning message.
56+
string warning = 5;
5557
}
5658

5759
// Node service provides public Management API methods for Nodes.

api/swagger/swagger-dev.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27492,6 +27492,11 @@
2749227492
"description": "Token represents token for vmagent auth config.",
2749327493
"type": "string",
2749427494
"x-order": 3
27495+
},
27496+
"warning": {
27497+
"description": "Warning message.",
27498+
"type": "string",
27499+
"x-order": 4
2749527500
}
2749627501
}
2749727502
}

api/swagger/swagger.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18661,6 +18661,11 @@
1866118661
"description": "Token represents token for vmagent auth config.",
1866218662
"type": "string",
1866318663
"x-order": 3
18664+
},
18665+
"warning": {
18666+
"description": "Warning message.",
18667+
"type": "string",
18668+
"x-order": 4
1866418669
}
1866518670
}
1866618671
}

0 commit comments

Comments
 (0)