Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
artemgavrilov committed Dec 25, 2023
2 parents fbb4e34 + 804a30c commit 7491172
Show file tree
Hide file tree
Showing 115 changed files with 604 additions and 346 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def setup():
# Having fsync off in dev environment is fine.
"sed -i -e \"s/#fsync = on/fsync = off/\" /srv/postgres14/postgresql.conf",
"echo 'host all all 0.0.0.0/0 trust' >> /srv/postgres14/pg_hba.conf",
"supervisorctl restart postgresql",
# "supervisorctl restart postgresql",
])


Expand All @@ -99,8 +99,7 @@ def main():
make_init()

# do basic setup
# TODO: fix the setup and revert
# setup()
setup()


MARKER = "/tmp/devcontainer-setup-done"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:

- name: Attach the report on failure
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: "report-${{ matrix.go-version }}-${{ matrix.test-type }}"
path: ${{ github.workspace }}/cli-tests/playwright-report/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ jobs:

- name: Upload the logs on failure
if: ${{ failure() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: "logs.zip"
path: ${{ github.workspace }}/logs.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
env:
# to avoid error due to `go version` accepting -v flag with an argument since 1.15
GOFLAGS: ""
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go.version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
fail_on_error: true
cache: false
golangci_lint_flags: "-c=.golangci.yml"
golangci_lint_version: v1.51.2 # Version should match specified in Makefile
golangci_lint_version: v1.55.2 # Version should match specified in Makefile

- name: Run go-consistent
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qan-api2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/vmproxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go release
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: ${{ github.workspace }}/go.mod
cache: false
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ linters:
- revive
- paralleltest
- gocognit
- tagalign

# ENDTODO

Expand Down
2 changes: 1 addition & 1 deletion Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ init: ## Install tools
cd tools && go generate -x -tags=tools

# Install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.51.2 # Version should match specified in CI
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.55.2 # Version should match specified in CI

release: ## Build release versions of all components
make -C agent release
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestReadFile(t *testing.T) {
err = os.Remove(cert.Name())
assert.NoError(t, err)
}()
_, err = cert.Write([]byte("cert"))
_, err = cert.WriteString("cert")
require.NoError(t, err)

certificate, err := ReadFile(cert.Name())
Expand Down
37 changes: 23 additions & 14 deletions admin/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type ListCommand struct {
NodeID string `help:"Node ID (default is autodetected)"`
}

func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
func (cmd *ListCommand) RunCmd() (Result, error) {
if cmd.NodeID == "" {
status, err := agentlocal.GetStatus(agentlocal.DoNotRequestNetworkInfo)
if err != nil {
Expand All @@ -142,6 +142,20 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
return nil, err
}

agentsRes, err := client.Default.Agents.ListAgents(&agents.ListAgentsParams{
Context: Ctx,
})
if err != nil {
return nil, err
}

return &listResult{
Services: servicesList(servicesRes),
Agents: agentsList(agentsRes, cmd.NodeID),
}, nil
}

func servicesList(servicesRes *services.ListServicesOK) []listResultService {
getSocketOrHost := func(socket, address string, port int64) string {
if socket != "" {
return socket
Expand All @@ -152,6 +166,7 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
l := len(servicesRes.Payload.Mysql) + len(servicesRes.Payload.Mongodb) + len(servicesRes.Payload.Postgresql)
l += len(servicesRes.Payload.Proxysql) + len(servicesRes.Payload.Haproxy) + len(servicesRes.Payload.External)
servicesList := make([]listResultService, 0, l)

for _, s := range servicesRes.Payload.Mysql {
servicesList = append(servicesList, listResultService{
ServiceType: types.ServiceTypeMySQLService,
Expand Down Expand Up @@ -200,13 +215,10 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
})
}

agentsRes, err := client.Default.Agents.ListAgents(&agents.ListAgentsParams{
Context: Ctx,
})
if err != nil {
return nil, err
}
return servicesList
}

func agentsList(agentsRes *agents.ListAgentsOK, nodeID string) []listResultAgent { //nolint:cyclop
getStatus := func(s *string) string {
res := pointer.GetString(s)
if res == "" {
Expand All @@ -222,9 +234,9 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
return "pull"
}
pmmAgentIDs := make(map[string]struct{})
var agentsList []listResultAgent
agentsList := []listResultAgent{}
for _, a := range agentsRes.Payload.PMMAgent {
if a.RunsOnNodeID == cmd.NodeID {
if a.RunsOnNodeID == nodeID {
pmmAgentIDs[a.AgentID] = struct{}{}

status := "disconnected"
Expand Down Expand Up @@ -370,7 +382,7 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
}
}
for _, a := range agentsRes.Payload.ExternalExporter {
if a.RunsOnNodeID == cmd.NodeID {
if a.RunsOnNodeID == nodeID {
agentsList = append(agentsList, listResultAgent{
AgentType: types.AgentTypeExternalExporter,
AgentID: a.AgentID,
Expand All @@ -394,8 +406,5 @@ func (cmd *ListCommand) RunCmd() (Result, error) { //nolint:cyclop,maintidx
}
}

return &listResult{
Services: servicesList,
Agents: agentsList,
}, nil
return agentsList
}
101 changes: 101 additions & 0 deletions admin/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
package commands

import (
"encoding/json"
"strings"
"testing"

"github.com/AlekSi/pointer"
"github.com/stretchr/testify/assert"

"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventorypb/json/client/services"
"github.com/percona/pmm/api/inventorypb/types"
)

Expand Down Expand Up @@ -119,3 +123,100 @@ func TestNiceAgentStatus(t *testing.T) {
})
}
}

func TestListJSONOutput(t *testing.T) {
t.Parallel()
t.Run("basic", func(t *testing.T) {
t.Parallel()
services := &services.ListServicesOK{
Payload: &services.ListServicesOKBody{
Mysql: []*services.ListServicesOKBodyMysqlItems0{
{
ServiceID: "/service_id/4ff49c41-80a1-4030-bc02-cd76e3b0b84a",
ServiceName: "mysql-service",
Address: "127.0.0.1",
Port: 3306,
},
},
},
}
agents := &agents.ListAgentsOK{
Payload: &agents.ListAgentsOKBody{
PMMAgent: []*agents.ListAgentsOKBodyPMMAgentItems0{
{
AgentID: "/agent_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1140",
RunsOnNodeID: "/node_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1140",
Connected: true,
},
},
MysqldExporter: []*agents.ListAgentsOKBodyMysqldExporterItems0{
{
AgentID: "/agent_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1198",
PMMAgentID: "/agent_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1140",
ServiceID: "/service_id/4ff49c41-80a1-4030-bc02-cd76e3b0b84a",
Status: pointer.ToString("RUNNING"),
PushMetricsEnabled: false,
ListenPort: 3306,
},
},
},
}
result := listResult{
Services: servicesList(services),
Agents: agentsList(agents, "/node_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1140"),
}

res, err := json.Marshal(result)
assert.NoError(t, err)
expected := `
{
"service": [
{
"service_type": "MYSQL_SERVICE",
"service_id": "/service_id/4ff49c41-80a1-4030-bc02-cd76e3b0b84a",
"service_name": "mysql-service",
"address_port": "127.0.0.1:3306",
"external_group": ""
}
],
"agent": [
{
"agent_type": "PMM_AGENT",
"agent_id": "/agent_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1140",
"service_id": "",
"status": "CONNECTED",
"disabled": false,
"push_metrics_enabled": ""
},
{
"agent_type": "MYSQLD_EXPORTER",
"agent_id": "/agent_id/8b732ac3-8256-40b0-a98b-0fd5fa9a1198",
"service_id": "/service_id/4ff49c41-80a1-4030-bc02-cd76e3b0b84a",
"status": "RUNNING",
"disabled": false,
"push_metrics_enabled": "pull",
"port": 3306
}
]
}
`
expected = strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(expected, "\t", ""), "\n", ""), " ", "")
assert.Equal(t, expected, string(res))
})
t.Run("empty", func(t *testing.T) {
t.Parallel()
result := listResult{
Services: servicesList(&services.ListServicesOK{
Payload: &services.ListServicesOKBody{},
}),
Agents: agentsList(&agents.ListAgentsOK{
Payload: &agents.ListAgentsOKBody{},
}, ""),
}

res, err := json.Marshal(result)
assert.NoError(t, err)
expected := `{"service":[],"agent":[]}`
assert.Equal(t, expected, string(res))
})
}
8 changes: 4 additions & 4 deletions admin/commands/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func addFile(zipW *zip.Writer, name string, fileName string) {
logrus.Debugf("%s", err)
r = io.NopCloser(bytes.NewReader([]byte(err.Error() + "\n")))
}
defer r.Close() //nolint:gosec,errcheck
defer r.Close() //nolint:gosec,errcheck,nolintlint

modTime := time.Now()
if fi, _ := os.Stat(fileName); fi != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func addVMAgentTargets(ctx context.Context, zipW *zip.Writer, agentsInfo []*agen
addData(zipW, "client/vmagent-targets.html", now, bytes.NewReader([]byte(err.Error())))
return
}
defer res.Body.Close() //nolint:gosec,errcheck
defer res.Body.Close() //nolint:gosec,errcheck,nolintlint
html, err = io.ReadAll(res.Body)
if err != nil {
logrus.Debugf("%s", err)
Expand All @@ -241,7 +241,7 @@ func getURL(ctx context.Context, url string) ([]byte, error) {
if err != nil {
return nil, errors.WithStack(err)
}
defer resp.Body.Close() //nolint:gosec,errcheck
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

if resp.StatusCode != http.StatusOK {
return nil, errors.Errorf("status code: %d", resp.StatusCode)
Expand Down Expand Up @@ -362,7 +362,7 @@ func (cmd *SummaryCommand) makeArchive(ctx context.Context, globals *flags.Globa

if f, err = os.Create(cmd.Filename); err != nil {
err = errors.WithStack(err)
return
return //nolint:nakedret
}

defer func() {
Expand Down
2 changes: 1 addition & 1 deletion admin/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func GetLatestVersion(ctx context.Context) (string, error) {
return "", err
}

defer res.Body.Close() //nolint:errcheck,gosec
defer res.Body.Close() //nolint:errcheck,gosec,nolintlint

url, err := res.Location()
if err != nil {
Expand Down
Loading

0 comments on commit 7491172

Please sign in to comment.