Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff authored Nov 14, 2023
2 parents 5acfab3 + 9fa78dd commit a31a242
Show file tree
Hide file tree
Showing 41 changed files with 468 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ compose.yml

cli-tests/node_modules/
cli-tests/playwright-report/

api-tests/pmm-api-tests-output.txt
api-tests/pmm-api-tests-junit-report.xml
5 changes: 5 additions & 0 deletions admin/commands/management/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ var registerResultT = commands.ParseTemplate(`
pmm-agent registered.
pmm-agent ID: {{ .PMMAgent.AgentID }}
Node ID : {{ .PMMAgent.RunsOnNodeID }}
{{ if .Warning }}
Warning: {{ .Warning }}
{{- end -}}
`)

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"`
}

func (res *registerResult) Result() {}
Expand Down Expand Up @@ -96,5 +100,6 @@ func (cmd *RegisterCommand) RunCmd() (commands.Result, error) {
GenericNode: resp.Payload.GenericNode,
ContainerNode: resp.Payload.ContainerNode,
PMMAgent: resp.Payload.PMMAgent,
Warning: resp.Payload.Warning,
}, nil
}
67 changes: 67 additions & 0 deletions admin/commands/management/register_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (C) 2023 Percona LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package management

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/managementpb/json/client/node"
)

func TestRegisterResult(t *testing.T) {
tests := []struct {
name string
result registerResult
want string
}{
{
name: "Success",
result: registerResult{
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
AgentID: "/agent_id/new_id",
RunsOnNodeID: "/node_id/second_id",
},
Warning: "",
},
want: `pmm-agent registered.
pmm-agent ID: /agent_id/new_id
Node ID : /node_id/second_id
`,
},
{
name: "With warning",
result: registerResult{
PMMAgent: &node.RegisterNodeOKBodyPMMAgent{
AgentID: "/agent_id/warning",
RunsOnNodeID: "/node_id/warning_node",
},
Warning: "Couldn't create Admin API Key",
},
want: `pmm-agent registered.
pmm-agent ID: /agent_id/warning
Node ID : /node_id/warning_node
Warning: Couldn't create Admin API Key
`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.result.String(), "String()")
})
}
}
7 changes: 3 additions & 4 deletions agent/agents/postgres/pgstatstatements/pgstatstatements.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,9 @@ func (m *PGStatStatementsQAN) getStatStatementsExtended(
databases := queryDatabases(q)
usernames := queryUsernames(q)

rows, e := rowsByVersion(q, "WHERE queryid IS NOT NULL AND query IS NOT NULL")
if e != nil {
err = e
return nil, nil, err
rows, err := rowsByVersion(q, "WHERE queryid IS NOT NULL AND query IS NOT NULL")
if err != nil {
return nil, nil, errors.Wrap(err, "couldn't get rows from pg_stat_statements")
}
defer rows.Close() //nolint:errcheck

Expand Down
3 changes: 3 additions & 0 deletions api/managementpb/json/client/node/register_node_responses.go

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

5 changes: 5 additions & 0 deletions api/managementpb/json/managementpb.json
Original file line number Diff line number Diff line change
Expand Up @@ -3899,6 +3899,11 @@
"description": "Token represents token for vmagent auth config.",
"type": "string",
"x-order": 3
},
"warning": {
"description": "Warning message.",
"type": "string",
"x-order": 4
}
}
}
Expand Down
57 changes: 34 additions & 23 deletions api/managementpb/node.pb.go

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

2 changes: 2 additions & 0 deletions api/managementpb/node.pb.validate.go

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

2 changes: 2 additions & 0 deletions api/managementpb/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ message RegisterNodeResponse {
inventory.PMMAgent pmm_agent = 3;
// Token represents token for vmagent auth config.
string token = 4;
// Warning message.
string warning = 5;
}

// Node service provides public Management API methods for Nodes.
Expand Down
5 changes: 5 additions & 0 deletions api/swagger/swagger-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -27467,6 +27467,11 @@
"description": "Token represents token for vmagent auth config.",
"type": "string",
"x-order": 3
},
"warning": {
"description": "Warning message.",
"type": "string",
"x-order": 4
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -18661,6 +18661,11 @@
"description": "Token represents token for vmagent auth config.",
"type": "string",
"x-order": 3
},
"warning": {
"description": "Warning message.",
"type": "string",
"x-order": 4
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
profiles:
- pmm
image: ${PMM_CONTAINER:-perconalab/pmm-server:dev-container}
platform: linux/amd64
# build:
# context: .
# args:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/jhunters/bigqueue v1.2.7
github.com/jmoiron/sqlx v1.3.5
github.com/jotaen/kong-completion v0.0.5
github.com/lib/pq v1.10.6
github.com/lib/pq v1.10.9
github.com/minio/minio-go/v7 v7.0.55
github.com/operator-framework/api v0.17.6
github.com/operator-framework/operator-lifecycle-manager v0.24.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
Expand Down
39 changes: 25 additions & 14 deletions managed/models/agent_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,15 @@ func (s *Agent) DBConfig(service *Service) *DBConfig {
}
}

type DSNParams struct {
DialTimeout time.Duration
Database string

PostgreSQLSupportsSSLSNI bool
}

// DSN returns DSN string for accessing given Service with this Agent (and implicit driver).
func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string, tdp *DelimiterPair) string { //nolint:cyclop,maintidx
func (s *Agent) DSN(service *Service, dsnParams DSNParams, tdp *DelimiterPair) string { //nolint:cyclop,maintidx
host := pointer.GetString(service.Address)
port := pointer.GetUint16(service.Port)
socket := pointer.GetString(service.Socket)
Expand All @@ -320,8 +327,8 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string
cfg.Net = tcp
cfg.Addr = net.JoinHostPort(host, strconv.Itoa(int(port)))
}
cfg.Timeout = dialTimeout
cfg.DBName = database
cfg.Timeout = dsnParams.DialTimeout
cfg.DBName = dsnParams.Database
cfg.Params = make(map[string]string)
if s.TLS {
switch {
Expand Down Expand Up @@ -349,8 +356,8 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string
cfg.Net = tcp
cfg.Addr = net.JoinHostPort(host, strconv.Itoa(int(port)))
}
cfg.Timeout = dialTimeout
cfg.DBName = database
cfg.Timeout = dsnParams.DialTimeout
cfg.DBName = dsnParams.Database
cfg.Params = make(map[string]string)
if s.TLS {
switch {
Expand Down Expand Up @@ -382,8 +389,8 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string
cfg.Net = tcp
cfg.Addr = net.JoinHostPort(host, strconv.Itoa(int(port)))
}
cfg.Timeout = dialTimeout
cfg.DBName = database
cfg.Timeout = dsnParams.DialTimeout
cfg.DBName = dsnParams.Database
cfg.Params = make(map[string]string)
if s.TLS {
if s.TLSSkipVerify {
Expand All @@ -400,16 +407,16 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string

case QANMongoDBProfilerAgentType, MongoDBExporterType:
q := make(url.Values)
if dialTimeout != 0 {
q.Set("connectTimeoutMS", strconv.Itoa(int(dialTimeout/time.Millisecond)))
q.Set("serverSelectionTimeoutMS", strconv.Itoa(int(dialTimeout/time.Millisecond)))
if dsnParams.DialTimeout != 0 {
q.Set("connectTimeoutMS", strconv.Itoa(int(dsnParams.DialTimeout/time.Millisecond)))
q.Set("serverSelectionTimeoutMS", strconv.Itoa(int(dsnParams.DialTimeout/time.Millisecond)))
}

// https://docs.mongodb.com/manual/reference/connection-string/
// > If the connection string does not specify a database/ you must specify a slash (/)
// between the last host and the question mark (?) that begins the string of options.
path := database
if database == "" {
path := dsnParams.Database
if path == "" {
path = "/"
}

Expand Down Expand Up @@ -475,6 +482,9 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string
} else {
sslmode = VerifyCaSSLMode
}
if dsnParams.PostgreSQLSupportsSSLSNI {
q.Set("sslsni", "0")
}
}
q.Set("sslmode", sslmode)

Expand All @@ -493,11 +503,12 @@ func (s *Agent) DSN(service *Service, dialTimeout time.Duration, database string
}
}

if dialTimeout != 0 {
q.Set("connect_timeout", strconv.Itoa(int(dialTimeout.Seconds())))
if dsnParams.DialTimeout != 0 {
q.Set("connect_timeout", strconv.Itoa(int(dsnParams.DialTimeout.Seconds())))
}

address := ""
database := dsnParams.Database
if socket == "" {
address = net.JoinHostPort(host, strconv.Itoa(int(port)))
} else {
Expand Down
Loading

0 comments on commit a31a242

Please sign in to comment.