Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12375 add database version to services #2488

Merged
merged 61 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
0e53d62
PMM-12375 create serviceInfoBroker component
Sep 18, 2023
5f4980a
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 18, 2023
f45cc2c
PMM-12375 serviceInfoBroker won't ping the db
Sep 18, 2023
6ed2921
Merge branch 'PMM-12375-add-database-version-to-services2' of github.…
Sep 18, 2023
a5efc31
PMM-12375 fix the test
Sep 18, 2023
c477cd2
PMM-12375 add tests for serviceInfoBroker
Sep 18, 2023
272e670
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 18, 2023
1092e4a
PMM-12375 fix the agent tests
Sep 18, 2023
6f896b3
PMM-12375 fix agent tests, server-side
Sep 18, 2023
8f61035
PMM-12375 fix services tests
Sep 18, 2023
ac80cad
PMM-12375 do not update if version is empty
Sep 19, 2023
5b4b388
PMM-12375 remove the unused parameter
Sep 19, 2023
df90672
PMM-12375 remove the version from Stats
Sep 20, 2023
156fda7
PMM-12375 add message type processing to channel
Sep 20, 2023
d154c04
PMM-12375 update codeowners
Sep 20, 2023
8ee6e76
PMM-12375 respect skipConnectionCheck, simpler schema
Sep 20, 2023
791f97c
PMM-12375 fix linter warnings
Sep 20, 2023
de0a56c
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 20, 2023
9c3de41
PMM-12375 fix license headers
Sep 20, 2023
09db068
PMM-12375 respect skipConnectionCheck param
Sep 21, 2023
cf2a1d1
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 21, 2023
c1ccea2
PMM-12375 minor fixes
Sep 22, 2023
94dea4f
PMM-12375 update the docs
Sep 22, 2023
e17d889
PMM-12375 do not run serviceInfo for older clients
Sep 22, 2023
d842adc
PMM-12375 add serviceInfoBroker to rds
Sep 22, 2023
2148db2
PMM-12375 add serviceInfoBroker to azure
Sep 23, 2023
97a8191
PMM-12375 add version to ListServices result
Sep 23, 2023
0189b3b
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 25, 2023
3aa01bf
PMM-12375 a minor fix in teardown fn
Sep 25, 2023
09f3a69
Merge branch 'PMM-12375-add-database-version-to-services2' of github.…
Sep 25, 2023
bc1330e
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 26, 2023
bc39c6f
PMM-12375 cleanup the inevntory_metrics_test
Sep 26, 2023
ee6a91a
PMM-12375 follow up on review
Sep 26, 2023
aebc4d8
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 26, 2023
b345c2e
PMM-12375 revert changes, move to other PRs
Sep 26, 2023
4983e2d
PMM-12375 revert changed related to linter
Sep 26, 2023
e36b218
PMM-12375 make version nullable
Sep 27, 2023
50d5d4b
PMM-12375 do not call FindService when skipping connection check
Sep 27, 2023
ae70e51
PMM-12375 fix pointer reference
Sep 27, 2023
dc51cdc
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 27, 2023
b277882
PMM-12375 re-generate interfaces
Sep 27, 2023
d588a58
PMM-12375 fix a dereference
Sep 27, 2023
bd77a69
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 27, 2023
8f439f0
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Sep 28, 2023
2e91627
PMM-12375 make ServiceInfoBroker work for older agents
Oct 1, 2023
e994109
Merge branch 'main' into PMM-12375-add-database-version-to-services2
Oct 1, 2023
85fec0f
Merge branch 'PMM-12375-add-database-version-to-services2' of github.…
Oct 1, 2023
de16f65
PMM-12375 fix the linter error
ademidoff Oct 1, 2023
775ef7c
PMM-12375 follow up on review
ademidoff Oct 2, 2023
e323f03
PMM-12375 a few corrections to managed's readme.md
ademidoff Oct 2, 2023
7f293e4
Merge branch 'main' into PMM-12375-add-database-version-to-services2
ademidoff Oct 11, 2023
e1204cf
Merge branch 'PMM-12375-add-database-version-to-services2' of github.…
ademidoff Oct 11, 2023
a543266
PMM-12375 fix the mock file version
ademidoff Oct 11, 2023
8c6346b
PMM-12375 bump up the compatibility version
ademidoff Oct 20, 2023
ea24e40
Merge branch 'main' into PMM-12375-add-database-version-to-services2
ademidoff Oct 20, 2023
22d91cc
PMM-12375 regen the mockfiles
ademidoff Oct 20, 2023
fe5999c
Merge branch 'main' into PMM-12375-add-database-version-to-services2
ademidoff Oct 20, 2023
e086b74
PMM-12375 remove debug msg
ademidoff Oct 20, 2023
efdd59c
Merge branch 'main' into PMM-12375-add-database-version-to-services2
ademidoff Oct 23, 2023
1153b2d
Merge branch 'main' into PMM-12375-add-database-version-to-services2
BupycHuk Oct 24, 2023
635ea40
Fix linter
BupycHuk Oct 24, 2023
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
25 changes: 14 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ We'd be glad to welcome you to Percona community which tries to keep the open so

## Table of contents
1. [Project repos structure](#Project-repos-structure)
2. [API documentation](#API-documentation)
2. [API documentation](#API-Reference-Documentation)
3. [Prerequisites](#Prerequisites)
4. [Submitting a Bug](#Submitting-a-Bug)
4. [Submitting a bug](#Submitting-a-Bug)
5. [Setup your local development environment](#Setup-your-local-development-environment)
6. [Tests](#Tests)
7. [Feature Build](#Feature-Build)
Expand Down Expand Up @@ -202,19 +202,22 @@ There are number of approaches for the code review and ownership: Code Ownership

For more efficient review process we use a mixed approach:
* repos that have CODEOWNERS
* add **auto-review-team** additionally to CODEOWNERS assigned
* github will assign reviewers automatically
* repos that don't have CODEOWNERS
* add **auto-review-team**
* add reviewers as follows:
* add `pmm-review-fe` for UI/UX reviews
* add `pmm-review-exporters` for exporter reviews [see PMM Client](#PMM-Client)
* add `pmm-review-be` for backend reviews
* if you know exactly who should review your code
* add ppl to the review
* add them to the review


| Team | Description | Members |
| -------------------- | ----------------------------------------------------------------------- | ------- |
| pmm-review-fe | ppl for UI/UX reviews for [FrontEnd repos](#FrontEnd) | [FE team](https://github.com/orgs/percona/teams/pmm-review-fe/members) |
| pmm-review-exporters | reviewers for all exporters [see PMM Client](#PMM-Client) | [Exporters team](https://github.com/orgs/percona/teams/pmm-review-exporters/members) |
| pmm-review-be | Back-End engineers | [BE team](https://github.com/orgs/percona/teams/pmm-review-be/members) |
| PMM Admins | ppl that could use admins rights to force merge or change repo settings | [PMM Admin team](https://github.com/orgs/percona/teams/pmm-admins/members) |
| Team | Description | Members |
| -------------------- | -------------------------------------------------------------- | ------- |
| pmm-review-fe | UI reviewers of PRs to [FrontEnd repos](#FrontEnd) | [FE team](https://github.com/orgs/percona/teams/pmm-review-fe/members) |
| pmm-review-exporters | exporter reviewers of PRs to [PMM Client](#PMM-Client) | [Exporters team](https://github.com/orgs/percona/teams/pmm-review-exporters/members) |
| pmm-review-be | reviewers of backend (Go) PRs | [BE team](https://github.com/orgs/percona/teams/pmm-review-be/members) |
| PMM Admins | reviewers that could use admins rights to force merge or change repo settings | [PMM Admin team](https://github.com/orgs/percona/teams/pmm-admins/members) |


## After your Pull Request is merged
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/management/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// AddCommand is used by Kong for CLI flags and commands.
type AddCommand struct {
External AddExternalCommand `cmd:"" help:"Add External source of data (like a custom exporter running on a port) to the monitoring"`
External AddExternalCommand `cmd:"" help:"Add External source of data (like a custom exporter running on a port) to monitoring"`
ExternalServerless AddExternalServerlessCommand `cmd:"" help:"Add External Service on Remote node to monitoring"`
HAProxy AddHAProxyCommand `cmd:"" name:"haproxy" help:"Add HAProxy to monitoring"`
MongoDB AddMongoDBCommand `cmd:"" name:"mongodb" help:"Add MongoDB to monitoring"`
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/management/add_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (cmd *AddMySQLCommand) RunCmd() (commands.Result, error) {

if cmd.CreateUser {
return nil, errors.New("Unrecognized option. To create a user, see " +
"'https://www.percona.com/doc/percona-monitoring-and-management/2.x/concepts/services-mysql.html#pmm-conf-mysql-user-account-creating'")
"'https://docs.percona.com/percona-monitoring-and-management/setting-up/client/mysql.html#create-a-database-account-for-pmm'")
}

var (
Expand Down
2 changes: 1 addition & 1 deletion admin/commands/management/add_mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestRun(t *testing.T) {
_, err := cmd.RunCmd()

if assert.Error(t, err) {
expected := "Unrecognized option. To create a user, see 'https://www.percona.com/doc/percona-monitoring-and-management/2.x/concepts/services-mysql.html#pmm-conf-mysql-user-account-creating'"
expected := "Unrecognized option. To create a user, see 'https://docs.percona.com/percona-monitoring-and-management/setting-up/client/mysql.html#create-a-database-account-for-pmm'"
assert.Equal(t, expected, err.Error())
}
})
Expand Down
5 changes: 5 additions & 0 deletions agent/client/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func (c *Channel) runReceiver() {
ID: msg.Id,
Payload: p.AgentLogs,
}
case *agentpb.ServerMessage_ServiceInfo:
c.requests <- &ServerRequest{
ID: msg.Id,
Payload: p.ServiceInfo,
}

// responses
case *agentpb.ServerMessage_Pong:
Expand Down
7 changes: 6 additions & 1 deletion agent/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Client struct {
supervisor supervisor
connectionChecker connectionChecker
softwareVersioner softwareVersioner
serviceInfoBroker serviceInfoBroker

l *logrus.Entry
backoff *backoff.Backoff
Expand All @@ -89,12 +90,13 @@ type Client struct {
// New creates new client.
//
// Caller should call Run.
func New(cfg configGetter, supervisor supervisor, r *runner.Runner, connectionChecker connectionChecker, sv softwareVersioner, cus *connectionuptime.Service, logStore *tailog.Store) *Client { //nolint:lll
func New(cfg configGetter, supervisor supervisor, r *runner.Runner, connectionChecker connectionChecker, sv softwareVersioner, sib serviceInfoBroker, cus *connectionuptime.Service, logStore *tailog.Store) *Client { //nolint:lll
return &Client{
cfg: cfg,
supervisor: supervisor,
connectionChecker: connectionChecker,
softwareVersioner: sv,
serviceInfoBroker: sib,
l: logrus.WithField("component", "client"),
backoff: backoff.New(backoffMinDelay, backoffMaxDelay),
dialTimeout: dialTimeout,
Expand Down Expand Up @@ -388,6 +390,9 @@ loop:
case *agentpb.CheckConnectionRequest:
responsePayload = c.connectionChecker.Check(ctx, p, req.ID)

case *agentpb.ServiceInfoRequest:
responsePayload = c.serviceInfoBroker.GetInfoFromService(ctx, p, req.ID)

case *agentpb.StartJobRequest:
var resp agentpb.StartJobResponse
if err := c.handleStartJobRequest(p); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions agent/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestClient(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

cfgStorage := config.NewStorage(&config.Config{})
client := New(cfgStorage, nil, nil, nil, nil, nil, nil)
client := New(cfgStorage, nil, nil, nil, nil, nil, nil, nil)
cancel()
err := client.Run(ctx)
assert.EqualError(t, err, "missing PMM Server address: context canceled")
Expand All @@ -98,7 +98,7 @@ func TestClient(t *testing.T) {
Address: "127.0.0.1:1",
},
})
client := New(cfgStorage, nil, nil, nil, nil, nil, nil)
client := New(cfgStorage, nil, nil, nil, nil, nil, nil, nil)
cancel()
err := client.Run(ctx)
assert.EqualError(t, err, "missing Agent ID: context canceled")
Expand All @@ -115,7 +115,7 @@ func TestClient(t *testing.T) {
Address: "127.0.0.1:1",
},
})
client := New(cfgStorage, nil, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
client := New(cfgStorage, nil, nil, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
err := client.Run(ctx)
assert.EqualError(t, err, "failed to dial: context deadline exceeded")
})
Expand Down Expand Up @@ -164,7 +164,7 @@ func TestClient(t *testing.T) {
s.On("ClearChangesChannel").Return()

r := runner.New(cfgStorage.Get().RunnerCapacity)
client := New(cfgStorage, &s, r, nil, nil, connectionuptime.NewService(time.Hour), nil)
client := New(cfgStorage, &s, r, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
err := client.Run(context.Background())
assert.NoError(t, err)
assert.Equal(t, serverMD, client.GetServerConnectMetadata())
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestClient(t *testing.T) {
},
})

client := New(cfgStorage, nil, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
client := New(cfgStorage, nil, nil, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
client.dialTimeout = 100 * time.Millisecond
err := client.Run(ctx)
assert.EqualError(t, err, "failed to get server metadata: rpc error: code = Canceled desc = context canceled", "%+v", err)
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestUnexpectedActionType(t *testing.T) {
s.On("ClearChangesChannel").Return()

r := runner.New(cfgStorage.Get().RunnerCapacity)
client := New(cfgStorage, s, r, nil, nil, connectionuptime.NewService(time.Hour), nil)
client := New(cfgStorage, s, r, nil, nil, nil, connectionuptime.NewService(time.Hour), nil)
err := client.Run(context.Background())
assert.NoError(t, err)
assert.Equal(t, serverMD, client.GetServerConnectMetadata())
Expand Down
6 changes: 6 additions & 0 deletions agent/client/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
)

//go:generate ../../bin/mockery --name=connectionChecker --case=snake --inpackage --testonly
//go:generate ../../bin/mockery --name=serviceInfoBroker --case=snake --inpackage --testonly
//go:generate ../../bin/mockery --name=supervisor --case=snake --inpackage --testonly

// connectionChecker is a subset of methods of connectionchecker.ConnectionChecker used by this package.
Expand All @@ -32,6 +33,11 @@ type connectionChecker interface {
Check(ctx context.Context, req *agentpb.CheckConnectionRequest, id uint32) *agentpb.CheckConnectionResponse
}

// serviceInfoBroker is a subset of methods of serviceinfobroker.ServiceInfoBroker used by this package.
type serviceInfoBroker interface {
GetInfoFromService(ctx context.Context, req *agentpb.ServiceInfoRequest, id uint32) *agentpb.ServiceInfoResponse
}

// softwareVersioner is a subset of methods of version.Versioner used by this package.
type softwareVersioner interface {
MySQLdVersion() (string, error)
Expand Down
47 changes: 47 additions & 0 deletions agent/client/mock_service_info_broker_test.go

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

4 changes: 3 additions & 1 deletion agent/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/percona/pmm/agent/connectionchecker"
"github.com/percona/pmm/agent/connectionuptime"
"github.com/percona/pmm/agent/runner"
"github.com/percona/pmm/agent/serviceinfobroker"
"github.com/percona/pmm/agent/tailog"
"github.com/percona/pmm/agent/versioner"
"github.com/percona/pmm/api/inventorypb"
Expand Down Expand Up @@ -69,8 +70,9 @@ func Run() {

supervisor := supervisor.NewSupervisor(ctx, v, configStorage)
connectionChecker := connectionchecker.New(configStorage)
serviceInfoBroker := serviceinfobroker.New(configStorage)
r := runner.New(cfg.RunnerCapacity)
client := client.New(configStorage, supervisor, r, connectionChecker, v, prepareConnectionService(ctx, cfg), logStore)
client := client.New(configStorage, supervisor, r, connectionChecker, v, serviceInfoBroker, prepareConnectionService(ctx, cfg), logStore)
localServer := agentlocal.NewServer(configStorage, supervisor, client, configFilepath, logStore)

logrus.Infof("Window check connection time is %.2f hour(s)", cfg.WindowConnectedTime.Hours())
Expand Down
17 changes: 0 additions & 17 deletions agent/connectionchecker/connection_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"database/sql"
"fmt"
"io"
"math"
"net/http"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -140,22 +139,6 @@ func (cc *ConnectionChecker) checkMySQLConnection(ctx context.Context, dsn strin
} else {
res.Error = err.Error()
}
return &res
}

var count uint64
if err = db.QueryRowContext(ctx, "SELECT /* agent='connectionchecker' */ COUNT(*) FROM information_schema.tables").Scan(&count); err != nil {
res.Error = err.Error()
return &res
}

tableCount := int32(count)
if count > math.MaxInt32 {
tableCount = math.MaxInt32
}

res.Stats = &agentpb.CheckConnectionResponse_Stats{
TableCount: tableCount,
}

return &res
Expand Down
5 changes: 3 additions & 2 deletions agent/connectionchecker/connection_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestConnectionChecker(t *testing.T) {
})
}

t.Run("TableCount", func(t *testing.T) {
t.Run("Stats should be empty", func(t *testing.T) {
cfgStorage := config.NewStorage(&config.Config{
Paths: config.Paths{TempDir: t.TempDir()},
})
Expand All @@ -247,7 +247,8 @@ func TestConnectionChecker(t *testing.T) {
Type: inventorypb.ServiceType_MYSQL_SERVICE,
}, 0)
require.NotNil(t, resp)
assert.InDelta(t, 250, resp.Stats.TableCount, 150)
// CheckConnectionResponse_Stats are deprecated, but we can't remove them yet without breaking older clients.
assert.Equal(t, (*agentpb.CheckConnectionResponse_Stats)(nil), resp.Stats) //nolint:staticcheck
})

t.Run("MongoDBWithSSL", func(t *testing.T) {
Expand Down
Loading
Loading