Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
33c42c4
PMM-3978 Update deps.
May 7, 2019
e8c00f9
PMM-3978 Actions is working.
May 7, 2019
0a1403c
PMM-3978 Fix CI errors.
May 7, 2019
6a5820a
Merge branch 'PMM-2.0' into PMM-3978-actions
May 7, 2019
eb26648
PMM-3978 Merge with pmm-2.0.
May 7, 2019
08e06ac
PMM-3978 Update deps.
May 7, 2019
df60a8f
PMM-3978 handle agent request.
May 7, 2019
da96430
PMM-3978 update deps.
May 8, 2019
6557ba2
PMM-3978 Small rename.
May 8, 2019
3363768
Merge branch 'PMM-2.0' into PMM-3978-actions
May 9, 2019
adcda94
PMM-3978 Update deps.
May 9, 2019
f091dff
PMM-3978 Working actions.
May 9, 2019
e955704
PMM-3978 Workarround 'RunAction'.
May 9, 2019
145fb8b
PMM-3978 fix CI.
May 10, 2019
baf7133
PMM-3978 update deps and API.
May 10, 2019
1d1342b
Merge branch 'PMM-2.0' into PMM-3978-actions
May 10, 2019
953d740
PMM-3978 update deps.
May 10, 2019
afc8575
PMM-3978 api fix.
May 10, 2019
e469e7f
PMM-3978 fix tests.
May 10, 2019
2d68558
PMM-3978 fix API and deps.
May 10, 2019
fceb156
Merge branch 'PMM-2.0' into PMM-3978-actions
May 13, 2019
0c031b5
PMM-3978 fix deps.
May 13, 2019
735a485
PMM-3978 fix IDs.
May 13, 2019
da5781a
PMM-3978 fix IDs.
May 13, 2019
528623d
PMM-3978 Moving to Aleksi API.
May 14, 2019
3bc56c9
PMM-3978 Fix stupid linter.
May 14, 2019
64ed920
Merge branch 'PMM-2.0' into PMM-3978-actions
May 14, 2019
3e81817
PMM-3978 Fix deps.
May 14, 2019
c58934d
PMM-3978 Disable not working linter.
May 14, 2019
1d5201a
PMM-3978 Make it works.
May 14, 2019
8375669
PMM-3978 Update deps.
May 14, 2019
8ec1eb3
Merge branch 'PMM-2.0' into PMM-3978-actions
May 15, 2019
3393b2d
PMM-3978 Update deps.
May 15, 2019
1169c53
PMM-3978 Fix pmm agent selection.
May 16, 2019
560fb9c
PMM-3978 Fix golang-ci lint suggestions.
May 16, 2019
8605426
Merge branch 'PMM-2.0' into PMM-3978-actions
AlekSi May 19, 2019
55ecc30
PMM-3978 Fixing PR suggestions.
May 20, 2019
a85f90d
PMM-3978 Fixing PR suggestions.
May 20, 2019
aaa93d1
PMM-3978 Fixing PR suggestions (Generate mocks).
May 20, 2019
a8ec2a8
PMM-3978 revert prometheus config.
May 20, 2019
19ffc51
PMM-3978 fix pointers in storage.
May 20, 2019
db625e9
PMM-3978 fix PR suggestions.
May 20, 2019
f11d5d7
PMM-3978 fix PR suggestions.
May 20, 2019
183d98b
PMM-3978 fix PR SendRequest method.
May 20, 2019
4a3d01f
PMM-3978 remove dot.
May 20, 2019
ec7d149
PMM-3978 comment.
May 20, 2019
f98bbe4
PMM-3978 tests.
May 21, 2019
47ea099
Merge branch 'PMM-2.0' into PMM-3978-actions
May 21, 2019
bc909b2
PMM-3978 make init gen format.
May 21, 2019
e8363bf
PMM-3832 Start working on MySQL Explain Action.
May 22, 2019
daf25ee
PMM-3832 TODO Comment.
May 22, 2019
44af406
PMM-3832 Rethink actions implementation and dependency graph.
May 22, 2019
9d2101b
PMM-3832 Small refactoring.
May 23, 2019
946a79f
PMM-3832 Fix ids.
May 23, 2019
297de25
PMM-3832 Refactor interfaces.
May 23, 2019
3855e1e
PMM-3832 Fix error.
May 23, 2019
f9f6295
PMM-3832 Refactoring.
May 23, 2019
a34633e
PMM-3832 Abstract PMMAgentID resolving.
May 23, 2019
1644470
PMM-3832 Update deps.
May 23, 2019
7d9c2a1
PMM-3832 Add resolver to main.
May 23, 2019
3857949
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 23, 2019
a39da0c
PMM-3832 Create business layer.
May 24, 2019
1c253da
PMM-3832 PtSummary parameters.
May 24, 2019
0a7a2fa
PMM-3832 PtMysqlSummary remove parameter.
May 24, 2019
577f93a
PMM-3832 Add comments.
May 24, 2019
77d5993
PMM-3832 Fix PMM-agent ID extracting and nil pointer error.
BupycHuk May 24, 2019
80d77cc
PMM-3832 Refactoring to simpler and idiomatic code.
May 24, 2019
0ee8eb4
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 24, 2019
dd21319
PMM-3832 Comment fix.
May 24, 2019
cd583e6
PMM-3832 linter errors fix.
May 24, 2019
5f504e8
PMM-3832 error messages.
May 24, 2019
1a6a0e3
PMM-3832 linter fix.
May 24, 2019
c4918ef
PMM-3832 move package because of test restrictions.
May 24, 2019
19a2e84
PMM-3832 move action result call to factory.
May 24, 2019
a1ca4ff
PMM-3832 fix linter.
May 24, 2019
ef01e91
PMM-3832 Remove all interfaces to "avoid indirection".
May 26, 2019
06e59aa
PMM-3832 "Simplify" code.
May 26, 2019
ef61d15
PMM-3832 comments.
May 26, 2019
b308082
PMM-3832 comments.
May 26, 2019
156ef58
PMM-3832 linter fix.
May 26, 2019
cea9bc8
PMM-3832 linter fix and moving functions.
May 26, 2019
6bcc507
PMM-3832 More "simplify" and move storage to Postgres.
May 26, 2019
642e662
PMM-3832 More "simplify" and move storage to Postgres.
May 26, 2019
ed6dfbb
PMM-3832 Fix table name.
May 26, 2019
2c33d38
PMM-3832 linter fix.
May 26, 2019
caac617
PMM-3832 linter fix.
May 26, 2019
30728b9
PMM-3832 Add database parameter to mysql dsn.
May 27, 2019
69ab029
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 27, 2019
e85dcda
PMM-3832 merge with pmm-2.0.
May 27, 2019
5cfc5ce
PMM-3832 Fix some suggestions.
May 28, 2019
15e27a0
PMM-3832 Fixing.
May 28, 2019
5209ff8
PMM-3832 Fix codereview suggestions.
May 28, 2019
735fcb5
PMM-3832 CodeReview suggestions.
May 28, 2019
1a9181a
PMM-3832 CodeReview fix.
May 28, 2019
a6d22b9
PMM-3832 codereview fix.
May 28, 2019
b5dc9b6
PMM-3832 Tests for helpers.
May 28, 2019
0acd8d4
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 28, 2019
7ebb1a7
PMM-3832 Tests.
May 28, 2019
105dd17
PMM-3832 Fix test.
May 28, 2019
34827b8
PMM-3832 Fix error types and linter warnings.
May 29, 2019
713e8f8
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 29, 2019
e2facd7
PMM-3832 Fix errors.
May 29, 2019
8af8689
PMM-3832 Fix suggestions.
May 29, 2019
1cbd33d
PMM-3832 Fix.
May 29, 2019
6ae3988
PMM-3832 fix.
May 29, 2019
ffaff82
PMM-3832 fix.
May 29, 2019
adce543
PMM-3832 dsn helper test.
May 29, 2019
9739e5c
PMM-3832 Test for wrong DSN.
BupycHuk May 29, 2019
36a3b03
PMM-3832 fix test names.
May 29, 2019
b358afd
Merge branch 'PMM-3832-test-for-DSN' into PMM-3832-mysql-explain
May 29, 2019
e59cef3
PMM-3832 fix DSN algorithm.
May 29, 2019
727044d
PMM-3832 fix DSN algorithm.
May 29, 2019
f65cfe8
PMM-3832 fix.
May 29, 2019
04038e7
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
AlekSi May 30, 2019
5799f03
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
AlekSi May 30, 2019
93a78a2
PMM-3541 Remove dependency between inventory and management services …
AlekSi May 30, 2019
a05ffd8
Merge branch 'PMM-2.0' into PMM-3832-mysql-explain
May 30, 2019
8bed1a9
PMM-4013 show table action.
Jun 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/bin/
cover.out
crosscover.out
packages.png
4 changes: 2 additions & 2 deletions Gopkg.lock

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

2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func runGRPCServer(ctx context.Context, deps *serviceDependencies) {
managementpb.RegisterMySQLServer(gRPCServer, managementgrpc.NewManagementMySQLServer(mysqlSvc))
managementpb.RegisterMongoDBServer(gRPCServer, managementgrpc.NewManagementMongoDBServer(mongodbSvc))
managementpb.RegisterPostgreSQLServer(gRPCServer, managementgrpc.NewManagementPostgreSQLServer(postgresqlSvc))
managementpb.RegisterActionsServer(gRPCServer, managementgrpc.NewActionsServer(deps.agentsRegistry, deps.db))

if *debugF {
l.Debug("Reflection and channelz are enabled.")
Expand Down Expand Up @@ -228,6 +229,7 @@ func runJSONServer(ctx context.Context, logs *logs.Logs) {
managementpb.RegisterNodeHandlerFromEndpoint,
managementpb.RegisterServiceHandlerFromEndpoint,
managementpb.RegisterMongoDBHandlerFromEndpoint,
managementpb.RegisterActionsHandlerFromEndpoint,
} {
if err := r(ctx, proxyMux, *gRPCAddrF, opts); err != nil {
l.Panic(err)
Expand Down
86 changes: 73 additions & 13 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package main

import (
"fmt"
"go/build"
"os"
"os/exec"
"sort"
"strings"
"testing"

Expand All @@ -41,6 +44,7 @@ func TestImports(t *testing.T) {
blacklistPrefixes []string
}

allImports := make(map[string]map[string]struct{})
for path, c := range map[string]constraint{
// models should not import services or APIs.
"github.com/percona/pmm-managed/models": {
Expand All @@ -50,23 +54,27 @@ func TestImports(t *testing.T) {
},
},

// Services should be independent: agents, inventory, management, prometheus, qan.
// services should be independent
"github.com/percona/pmm-managed/services/action": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
},
},
"github.com/percona/pmm-managed/services/agents": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
},
},
"github.com/percona/pmm-managed/services/inventory": {
"github.com/percona/pmm-managed/services/grafana": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
},
},
"github.com/percona/pmm-managed/services/logs": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
},
},
// FIXME https://jira.percona.com/browse/PMM-3541
// "github.com/percona/pmm-managed/services/management": {
// blacklistPrefixes: []string{
// "github.com/percona/pmm-managed/services",
// },
// },
"github.com/percona/pmm-managed/services/prometheus": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
Expand All @@ -77,23 +85,42 @@ func TestImports(t *testing.T) {
"github.com/percona/pmm-managed/services",
},
},
"github.com/percona/pmm-managed/services/telemetry": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services",
},
},

// those services should be independent too, but import converters
"github.com/percona/pmm-managed/services/inventory": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services/",
},
},
"github.com/percona/pmm-managed/services/management": {
blacklistPrefixes: []string{
"github.com/percona/pmm-managed/services/",
},
},
} {
p, err := build.Import(path, ".", build.IgnoreVendor)
require.NoError(t, err)

allImports := make(map[string]struct{})
if allImports[path] == nil {
allImports[path] = make(map[string]struct{})
}
for _, i := range p.Imports {
allImports[i] = struct{}{}
allImports[path][i] = struct{}{}
}
for _, i := range p.TestImports {
allImports[i] = struct{}{}
allImports[path][i] = struct{}{}
}
for _, i := range p.XTestImports {
allImports[i] = struct{}{}
allImports[path][i] = struct{}{}
}

for _, b := range c.blacklistPrefixes {
for i := range allImports {
for i := range allImports[path] {
// whitelist own subpackages
if strings.HasPrefix(i, path) {
continue
Expand All @@ -106,4 +133,37 @@ func TestImports(t *testing.T) {
}
}
}

f, err := os.Create("packages.dot")
require.NoError(t, err)
defer f.Close()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error return value of f.Close is not checked (from errcheck)


fmt.Fprintf(f, "digraph packages {\n")

packages := make([]string, 0, len(allImports))
for p := range allImports {
packages = append(packages, p)
}
sort.Strings(packages)

for _, p := range packages {
imports := make([]string, 0, len(allImports[p]))
for p := range allImports[p] {
imports = append(imports, p)
}
sort.Strings(imports)

p = strings.TrimPrefix(p, "github.com/percona/pmm-managed")
for _, i := range imports {
if strings.Contains(i, "/utils/") || strings.Contains(i, "/internal/") {
continue
}
if strings.HasPrefix(i, "github.com/percona/pmm-managed") {
i = strings.TrimPrefix(i, "github.com/percona/pmm-managed")
fmt.Fprintf(f, "\t%q -> %q;\n", p, i)
}
}
}

fmt.Fprintf(f, "}\n")
}
66 changes: 66 additions & 0 deletions models/action_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package models

import (
"github.com/google/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gopkg.in/reform.v1"
)

// CreateActionResult stores an action result in action results storage.
func CreateActionResult(q *reform.Querier, pmmAgentID string) (*ActionResult, error) {
result := &ActionResult{ID: "/action_id/" + uuid.New().String(), PmmAgentID: pmmAgentID}
if err := q.Insert(result); err != nil {
return result, status.Errorf(codes.FailedPrecondition, "Couldn't create ActionResult, reason: %v", err)
}

return result, nil
}

// ChangeActionResult updates an action result in action results storage.
func ChangeActionResult(q *reform.Querier, actionID, pmmAgentID, aError, output string, done bool) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U1000: func ChangeActionResult is unused (from unused)

result := &ActionResult{
ID: actionID,
PmmAgentID: pmmAgentID,
Done: done,
Error: aError,
Output: output,
}
if err := q.Update(result); err != nil {
return status.Errorf(codes.FailedPrecondition, "Couldn't update ActionResult, reason: %v", err)
}
return nil
}

// FindActionResultByID loads an action result from storage by action id.
func FindActionResultByID(q *reform.Querier, id string) (*ActionResult, error) {
if id == "" {
return nil, status.Errorf(codes.InvalidArgument, "Couldn't get AgentResult, as id is empty.")
}

row := &ActionResult{ID: id}
switch err := q.Reload(row); err {
case nil:
return row, nil
case reform.ErrNoRows:
return nil, status.Errorf(codes.NotFound, "ActionResult with ID %q not found.", id)
default:
return nil, status.Errorf(codes.FailedPrecondition, "Couldn't get AgentResult, reason: %v", err)
}
}
75 changes: 75 additions & 0 deletions models/action_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package models_test

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/reform.v1"
"gopkg.in/reform.v1/dialects/postgresql"

"github.com/percona/pmm-managed/models"
"github.com/percona/pmm-managed/utils/testdb"
)

func TestActionHelpers(t *testing.T) {
now, origNowF := models.Now(), models.Now
models.Now = func() time.Time {
return now
}
sqlDB := testdb.Open(t)
defer func() {
models.Now = origNowF
require.NoError(t, sqlDB.Close())
}()

setup := func(t *testing.T) (q *reform.Querier, teardown func(t *testing.T)) {
db := reform.NewDB(sqlDB, postgresql.Dialect, reform.NewPrintfLogger(t.Logf))
tx, err := db.Begin()
require.NoError(t, err)
q = tx.Querier

for _, str := range []reform.Struct{
&models.ActionResult{
ID: "A1",
PmmAgentID: "A2",
},
} {
require.NoError(t, q.Insert(str))
}

teardown = func(t *testing.T) {
require.NoError(t, tx.Rollback())
}
return
}

t.Run("FindActionResultByID", func(t *testing.T) {
q, teardown := setup(t)
defer teardown(t)

a, err := models.FindActionResultByID(q, "A1")
require.NoError(t, err)
assert.NotEmpty(t, a.ID)

_, err = models.FindActionResultByID(q, "A2")
require.Error(t, err)
})
}
65 changes: 65 additions & 0 deletions models/action_models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package models

import (
"time"

"gopkg.in/reform.v1"
)

//go:generate reform

// ActionResult describes an action result which is storing in persistent storage.
//reform:action_results
type ActionResult struct {
ID string `reform:"id,pk"`
PmmAgentID string `reform:"pmm_agent_id"`
Done bool `reform:"done"`
Error string `reform:"error"`
Output string `reform:"output"`
CreatedAt time.Time `reform:"created_at"`
UpdatedAt time.Time `reform:"updated_at"`
}

// BeforeInsert implements reform.BeforeInserter interface.
func (s *ActionResult) BeforeInsert() error {
now := Now()
s.CreatedAt = now
s.UpdatedAt = now
return nil
}

// BeforeUpdate implements reform.BeforeUpdater interface.
func (s *ActionResult) BeforeUpdate() error {
s.UpdatedAt = Now()
return nil
}

// AfterFind implements reform.AfterFinder interface.
func (s *ActionResult) AfterFind() error {
s.CreatedAt = s.CreatedAt.UTC()
s.UpdatedAt = s.UpdatedAt.UTC()
return nil
}

// check interfaces
var (
_ reform.BeforeInserter = (*ActionResult)(nil)
_ reform.BeforeUpdater = (*ActionResult)(nil)
_ reform.AfterFinder = (*ActionResult)(nil)
)
Loading